Author: spadkins
Date: Mon Mar 12 12:58:23 2007
New Revision: 9232
Modified:
p5ee/trunk/App-Repository/lib/App/Repository/MySQL.pm
Log:
fix bugs in insert_rows()
Modified: p5ee/trunk/App-Repository/lib/App/Repository/MySQL.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository/MySQL.pm (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository/MySQL.pm Mon Mar 12 12:58:23 2007
@@ -134,8 +134,12 @@
my $dbh = $self->{dbh};
if ($#$cols == -1) {
- $self->{error} = "Database->_mk_insert_rows_sql(): no columns specified";
- return();
+ if ($#$rows > -1 && ref($rows->[0]) eq "ARRAY") {
+ die "_mk_insert_rows_sql(): no columns specified";
+ }
+ else {
+ $cols = [ keys %{$rows->[0]} ];
+ }
}
my $column_defs = $self->{table}{$table}{column};
@@ -191,10 +195,12 @@
if (!$options->{replace} && $options->{update}) {
my $update = $options->{update};
$sql .= "on duplicate key update";
+ my $first_update_column = 1;
for ($colnum = 0; $colnum <= $#$cols; $colnum++) {
$col = $cols->[$colnum];
if (!ref($update) || $update->{$col}) {
- $sql .= "," if ($colnum > 0);
+ $sql .= "," if (!$first_update_column);
+ $first_update_column = 0;
$sql .= "\n $col = values($col)";
}
}
@@ -293,7 +299,7 @@
}
if ($debug_sql) {
$elapsed_time = $self->_read_timer($timer);
- print "DEBUG_SQL: nrows [$nrows] ($elapsed_time sec)\n";
+ print "DEBUG_SQL: total rows [$nrows] ($elapsed_time sec)\n";
}
$self->{sql} = $sql;
$self->{numrows} = $nrows;
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.