Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: In search of an efficient query abstractor

by xaprb (Scribe)
on Dec 07, 2008 at 20:28 UTC ( #728776=note: print w/replies, xml ) Need Help??

in reply to Re: In search of an efficient query abstractor
in thread In search of an efficient query abstractor

I should explain a little extra subtlety here. Suppose I have an SQL statement of the form

insert into foo (col1, col2, col3) values(1, 2, 3), (4, 5, 6), ......

Now assume there are a million sets of values there. I want them all mushed down to a single "values(N, N, N)".

This happens to me all the time in the real world. How fast is this going to be?

And then, when the parser is done with it, I still have to reassemble the thing into a fingerprint of the query... which will be a lot of special-case code. MySQL's grammar is nontrivial.

So I don't think this will be a fast or easy way to do what I want, although I appreciate the idea.

Replies are listed 'Best First'.
Re^3: In search of an efficient query abstractor
by CountZero (Bishop) on Dec 07, 2008 at 22:37 UTC
    SQL::Statement also understands INSERT statements but unfortunately it will choke on multiple sets of VALUES. So you would have to collapse these into one beforehand anyhow, which of course sort-of defeats the use of this module ...

    May be you can petition the module's author jZED to extend it to include this case?

    If you want to parse the SQL statements yourself, it can do no harm to look at the code of DBI::SQL::Nano which has a nice (but limited) set of regexes that parse them and it shouldn't be too difficult to expend these, although to parse the full MySQL grammar you will probably need something like Parse::RecDescent or Parse::Yapp.


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://728776]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2021-06-18 17:38 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (89 votes). Check out past polls.