I have lots of code for a project which has sql statements stuck in the code
like this ...
(my $sql = <<SQLCREATE) =~ s/^\s+//gm;
CREATE TABLE $table
(id INTEGER NOT NULL AUTO_INCREMENT,
name CHAR(40) NOT NULL,
address CHAR(40)
PRIMARY KEY (id)
)
SQLCREATE
$sql =~ s/\s+$//gm;
...and it's gotten very messy. I am playing around with putting all the sql statements in a text file and parsing them in to a hash. After parsing and some double interpolation of $things like $table in the above example I can just say...
$sth = $dbh->dosql($sqls{CreateNameTable});
and my code is more manageable.
My goal is to build towards a library of useful and hopefully generic sql statements. I was wondering what other people do within perl to manage lots of sql statements. I imagine one solution would be to put the sql statements in the database and grab them as necessary.
Another question I have is how best to debug them - the debugger gives not very helpful messages like "You have an error in your SQL syntax near ''". Should I be writing and debugging the sql outside of Perl (which makes me nervous) or is there a good perl solution?
thanks, tonyday
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.