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":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.