SQL code generation from table-free boolean queries?

F

Foo Stack

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.

If that's so, can you recommend it?

Thanks!
 
T

Tim Chase

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
 
A

alex23

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.

Not a library per se, but I did see an article that did something quite
similar using SQLAlchemy that might make a good starting point:

http://www.wiggy.net/articles/sqlalchemy-in-reverse
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top