in reply to Parsing text-based queries to SQL queries

Just a general observation:

..that doesn't allow error checking or using placeholders..

I think I would be much more worried about security. Imagine a mischevious user that gave:
A>6 AND B<3 OR (C>5 AND B=3); DELETE FROM table;
or even...
A>6 AND B<3 OR (C>5 AND B=3); DROP DATABASE foo;
I'm sure there are lots of ways you could allow the level of flexibility you are looking for, but you'd want to make damned sure you do some serious data validation.

--Darren

Replies are listed 'Best First'.
Re^2: Parsing text-based queries to SQL queries
by neilwatson (Priest) on Sep 29, 2005 at 13:04 UTC
    Since the purpose of this is to allow users to query a table then the DB handler should use a DB user that has only query rights. No fancy parsing needed.

    Neil Watson
    watson-wilson.ca

Re^2: Parsing text-based queries to SQL queries
by srdst13 (Pilgrim) on Sep 29, 2005 at 11:50 UTC

    Placeholders are the safety net against SQL injection attacks; hence my desire to find a way to use them. But thanks for clarifying the problem; I wasn't explicit enough about the security issue.

    Sean
      Actually, they're only one part of it. The bigger part is the execution of only one statement at a time. Some DBD's will allow you to restrict yourself to one SQL statement per $sth, which is the big win.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re^2: Parsing text-based queries to SQL queries
by Anonymous Monk on Sep 29, 2005 at 12:12 UTC
    I think I would be much more worried about security.

    That depends. The OP only talks about "the user", he doesn't talk about the environment. If the OP writes a program that's run with the permissions of the user (that is, asking the user for a database user name and password), you don't need to worry about SQL attacks - the program can't do anything the user couldn't do already. If the user has permission to drop the database, he doesn't need your program to drop it. If he doesn't have permission, the program wouldn't give it to him.

    Not every program is a web program. And even then, if I were to create a web program where I wanted to let users type in queries, I'd create a database user with only permissions to query - and only query the tables the webusers are allowed to see, and use that user to log in from my web program. That way, you are protecting the data at its source, and you only have to do it once, not for every possible program.