Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Architecture of Constructing Complex SQL

by beachbum (Beadle)
on Dec 22, 2005 at 20:08 UTC ( [id://518621]=note: print w/replies, xml ) Need Help??


in reply to Architecture of Constructing Complex SQL

I've written a bit of dynamic SQL many different ways... I generally group the statements by the FROM clause. In this case, the format of your queries look pretty similar. I might try Something Like(tm) this:

my ($sr_from, $sr_where); if( $ref_sid ) { $sr_from = ", Search_Results SR "; $sr_where = "AND P.id = SR.page_id AND SR.search_id = ? "; push @query_args, $ref_sid; } my $mquery =<<"SQL" INSERT INTO Search_Results ( search_id, page_id ) SELECT ?, P.id FROM Pages P, Documents D, Dirs DI $sr_from WHERE MATCH ( P.pgdata ) AGAINST ( ? IN BOOLEAN MODE ) AND P.doc_id = D.id AND D.dir_id = DI.id $sr_where SQL
I'm unsure if the bind parameter '?' is buying you anything in this query as each statement prepare() would have to see what is being SELECTed. Either way, be careful not let the interpolated variables be changed through the program interface.

All said, I'm thinking that SQL::Builder does look very interesting.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-23 18:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found