Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'subject:code': 0.07; 'string': 0.09; 'attributes': 0.09; '-tkc': 0.16; 'boolean': 0.16; 'computes': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'subject:generation': 0.16; 'url:file': 0.16; 'url:py': 0.16; 'wrote:': 0.18; 'library': 0.18; 'stack': 0.19; 'url:view': 0.20; 'input': 0.22; 'query': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; '[1]': 0.29; '(which': 0.31; 'piece': 0.31; 'probably': 0.32; 'table': 0.34; 'subject:from': 0.34; 'something': 0.35; 'there': 0.35; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'generic': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'such': 0.63; 'as:': 0.81; 'received:50.22': 0.84; 'subject:SQL': 0.84; 'subject:free': 0.91 Date: Wed, 26 Jun 2013 18:29:14 -0500 From: Tim Chase To: python-list@python.org Subject: Re: SQL code generation from table-free boolean queries? In-Reply-To: <08a32a47-849b-4526-82c4-269df60ac818@googlegroups.com> References: <08a32a47-849b-4526-82c4-269df60ac818@googlegroups.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372289258 news.xs4all.nl 15892 [2001:888:2000:d::a6]:35498 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49286 On 2013-06-26 16:17, Foo Stack wrote: > Given string input such as: > foo=5 AND a=6 AND date=now OR date='2013/6' AND bar='hello' > > I am going to implement: > > - boolean understanding (which operator takes precendence) > - spliting off of attributes into my function which computes their > table in the SQL database > - piece everything together into an SQL query > > However, it came to me that this is probably a very generic thing; > and there might be a library for it. It sounds like you might want to use pyparsing and start with something akin to this[1] -tkc [1] http://pyparsing.wikispaces.com/file/view/simpleSQL.py