Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: dbi style questions (code, discussion)

by BazB (Priest)
on Dec 29, 2001 at 15:13 UTC ( [id://135105]=note: print w/replies, xml ) Need Help??


in reply to dbi style questions (code, discussion)

At this point, I've only used a combination of Tcl and SQL to query a database.
IMHO, I think it's irrelevant which languages you're using, things are really going to get confusing if you've got a mix of scripting, markup and SQL unless you format everything to the point of excess.

Have a look at Philip Greenspun's SQL for Web Nerds, particularly the style section.
It's all Oracle8i stuff, but it should apply to anything with SQL.

When I've coded scripts with large SQL queries, I often put the query into a string:

my $query = "SELECT post, post_time, user_id, post_id FROM my_table WHERE post_time > sysdate + 1 ORDER BY post_id;";
Then query the database with the command required (can't do it in Perl yet :-) with $query in that command instead of a lump of SQL and scripting/Perl mashed together.

Even if you don't like my idea of having the query seperate, or it's impossible, then just get used formatting the queries so that they stand out from the Perl and are readable as SQL.

Hope that helps,

BazB.

Update: Seems like a slight more Perl-y way of doing this might be to use HERE documents, as described in this node by steves.

Further update: fixed the link to SQL for Web Nerds

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-19 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found