Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: dbi style questions (code, discussion)

by Ryszard (Priest)
on Dec 30, 2001 at 11:35 UTC ( [id://135222]=note: print w/replies, xml ) Need Help??


in reply to dbi style questions (code, discussion)

If performance isnt an issue, one trick i use is to read the sql in from a file.

another trick i use to line up my sql and make it look nice in the code (when i embed it) is concatenation

my $sql .= "rest of statement"

I also package up my dbi stuff into a couple of subbies, one for selecting, and one for insert, update, delete, and do all the appropriate error checking (ie DB alive, uname/pwd ok et al). I also pass all the params as anon hashes.

Its not amazing code, buts its functional, and works for me.

It also means, once i've written my dbi subbies, i dont need to go about writing dbi stuff again, just remember the parameters that must be parsed.. :-)

Replies are listed 'Best First'.
Re: Re: dbi style questions (code, discussion)
by steves (Curate) on Dec 30, 2001 at 12:21 UTC

    I write tons of SQL each week using Perl/DBI. 99% of the SQL I put in here documents, ala:

    my $sql = <<"END_SQL"; SELECT name, address, phone_number, order_id FROM customer, customer_order, order_item WHERE blah blah blah END_SQL

    That makes it readable and it looks pretty nice when you log it, etc. Here documents: another reason Perl rocks.

Log In?
Username:
Password:

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

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

    No recent polls found