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);
}
-
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.