Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
For Ovid -- prepares an insert from an array or hash.
#################### # # sub create_SQLpreparedinsert # # in : a database handle, the name of the table to update, and an arr +ay # of fieldnames. # out : a statement handle. # # this sub will create a prepared statement, or die with a verbose err +or. # note that under sybase, prepare statements may not include TEXT or I +MAGE types. # for those cases, use create_SQLinsert. # Typically, however, prepared statements will run faster, so this sho +uld be the sub of choice. # #################### sub create_SQLpreparedinsert{ my ($l_database, $l_tablename,@l_fields) = @_; my $l_fieldnames; my $l_placeholder; my $l_prepare; my $l_fieldnames = join ",", (@l_fields); $l_placeholder = (join ",", ('?')x(@l_fields)); $l_prepare = $l_database->prepare("INSERT $l_tablename (" . $l_fie +ldnames . ")\n VALUES (" . $l_placeholder . ")") or die ("Could not c +reate statement handle in sub create_SQLpreparedinsert! Database obj +ect says : ", $DBI::errstr); } #################### # # sub create_SQLinsert # # in : a database handle, the name of the table to update, and an arr +ay # of fieldnames. # out : a statement handle. # #################### sub create_SQLinsert{ my ($database, $l_tablename,%l_fields) = @_; my $l_sth; #foreach (values %l_fields) {$_=$database->quote($_)} my $l_prepare; my $l_fieldnames = join ",", (keys %l_fields); my $l_fieldvalues = join ",", (values %l_fields); $l_prepare = "INSERT $l_tablename (" . $l_fieldnames . ")\n VALUES + (" . $l_fieldvalues . ")"; $sth= $database->prepare($l_prepare) or die ("Could not create sta +tement handler in create_SQLinsert. database object says : ", $DBI::e +rstr); }

In reply to SQL INSERT creator by boo_radley

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 scrutinizing the Monastery: (3)
As of 2024-04-26 07:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found