Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I have one comment that hasn't been addressed yet, is slightly OT, but still important.

In your SQL query you may want to explicitly specify the columns you are inserting into. This has a large benefit: if you add a column to the table or the column ordering changes, your code is less likely to break. A good rule of thumb I use is to:

  • never assume the order of columns in an SQL query
  • always explicitly define the columns

I've found this to be especially helpful in SELECT and INSERT -type statements.

Here's an example that demonstrates what I mean and answers your question:

$dbh->do( 'INSERT INTO table (Col1, Col2, Col3) VALUES (?, ?, ?)', {}, map scalar param($_), qw(Col1 Col2 Col3), );

I began doing this after thinking about the issues raised in Topics in Perl Programming: Table-Mutation Tolerant Database Fetches with DBI, and realizing the way I was doing SQL does not lend itself to change very well.


In reply to (dkubb) Re: (1) Using CGI.pm params to make a DBI MySQL query by dkubb
in thread Using CGI.pm params to make a DBI MySQL query by George_Sherston

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 05:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found