views:

88

answers:

2

On facebook many of you probably know of there API which uses there own FQL (facebook version of a mysql query)

I am curious, how could I support my own user submitted queries in the same manner on my site?

Do you basicly pass in the custom query into a function, in the function you just use regex to match SELECT from ect?

Hope my question makes sense

A: 

The simplest option would be to parse the queries yourself though even that will take some work. What you're wanting to do basically requires writing a language parser, albeit a comparatively simple one.

You probably don't want to be passing the custom query straight in as that is a security nightmare begging to happen.

Darrell Brogdon
+1  A: 

normally it's a proper grammar rather than regex. Regex don't work well for this application as it can only match the tokens, you still have to write the rest of the parser yourself.

If you want to check out a grammar you can use from many languages, look at antlr:

http://www.antlr.org/

EDIT:

Start here: http://en.wikipedia.org/wiki/Parser%5Fgenerator

follow the 'see also' links at the bottom

Luke Schafer