Author: spadkins
Date: Tue Nov 24 19:44:06 2009
New Revision: 13601
Modified:
p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm
Log:
cleaned up some extra white space and comments. added --debug_sql support for
dbi_post_connect_stmt's
Modified: p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm Tue Nov 24 19:44:06 2009
@@ -157,7 +157,7 @@
* Throws: App::Exception::Repository
* Since: 0.50
- Sample Usage:
+ Sample Usage:
$repository->_connect();
@@ -184,10 +184,12 @@
eval {
my $dbh = DBI->connect($dsn, $self->{dbuser}, $self->{dbpass},
$attr);
if ($self->{dbi_post_connect_stmt}) {
+ my $debug_sql = $self->{context}{options}{debug_sql};
my $stmts = $self->{dbi_post_connect_stmt};
$stmts =~ s/;$//;
foreach my $stmt (split(/\s*;\s*/, $stmts)) {
$dbh->do($stmt);
+ print $App::DEBUG_FILE "DEBUG_SQL: $stmt [$DBI::errstr]\n";
}
}
$self->{dbh} = $dbh;
@@ -281,7 +283,7 @@
* Throws: App::Exception::Repository
* Since: 0.50
- Sample Usage:
+ Sample Usage:
$repository->_disconnect();
@@ -355,7 +357,7 @@
return $self->{preconnected} = 1 if (defined $self->{dbh});
my @opts = qw{
- dbdsn dbdriver dbhost dbport dbsocket dbname
+ dbdsn dbdriver dbhost dbport dbsocket dbname
dbuser dbpass dbschema dbioptions
};
@@ -427,7 +429,7 @@
### TODO: make this similar to the _connect code, using a regex named
retryable_select_error_regex
while (1) {
my ($column, %deserializer, $deserializer_name, $serializer);
- my $column_defs = $self->{table}{$table}{column};
+ my $column_defs = $self->{table}{$table}{column};
eval {
$row = $dbh->selectrow_arrayref($sql);
for (my $i = 0; $i <= $#$cols; $i++) {
@@ -485,7 +487,6 @@
my ($sql, $rows, $startrow, $endrow);
my $table_def = $self->get_table_def($table);
#print $App::DEBUG_FILE "DBI._get_rows : table=[$table]
rawaccess=[$table_def->{rawaccess}]\n";
- #if ($self->{table}{$table}{rawaccess}) {
if ($table_def->{rawaccess}) {
$sql = $self->_mk_select_sql($table, $params, $cols, $options);
}
@@ -514,7 +515,7 @@
}
while (1) {
my ($column, %deserializer, $deserializer_name, $serializer);
- my $column_defs = $self->{table}{$table}{column};
+ my $column_defs = $self->{table}{$table}{column};
eval {
$rows = $self->_selectrange_arrayref($sql, $startrow, $endrow);
foreach my $row (@$rows) {
@@ -662,7 +663,7 @@
my @o_keys = keys %$slice;
next if ++$rownum < $startrow;
last if ($endrow > 0 && $rownum > $endrow);
- push @rows, @o_keys ?
+ push @rows, @o_keys ?
{ map {shift @o_keys => $_ } @{$ro...@i_keys} } :
$row
}
@@ -842,7 +843,7 @@
}
next;
}
-
+
next if (defined $paramdefs->{$param} && defined
$paramdefs->{$param}{all_value} &&
$value eq $paramdefs->{$param}{all_value});
@@ -1015,7 +1016,7 @@
}
my $suffix = $self->_mk_select_sql_suffix($table, $options);
$sql .= $suffix if ($suffix);
-
+
&App::sub_exit($sql) if ($App::trace);
return($sql);
}
@@ -1122,7 +1123,7 @@
push(@keycolidx, $colidx);
$write[$colidx] = 0; # keys aren't editable
}
-
+
$dbexpr = $table_def->{column}{$column}{dbexpr}; # take note
of table the key is on
if ($dbexpr && $dbexpr =~
/^([a-zA-Z][a-zA-Z0-9_]*)\.[a-zA-Z_][a-zA-Z_0-9]*$/) {
$primary_table = $1;
@@ -2063,18 +2064,12 @@
else {
$insert_sth->bind_param($i+1, $row->[$i], $sqltype ? {TYPE
=> $sqltype} : () );
}
-#print STDERR "insert_sth->bind_param(", $i+1, ", $row->[$i], $sqltype)
[$column]\n";
}
-#print STDERR "2. lii=[$last_inserted_id]
liirfi=[$is_last_inserted_id_returned_from_insert]
liic=[$last_inserted_id_column]\n";
if ($is_last_inserted_id_returned_from_insert) {
$sqltype = $column_defs->{$last_inserted_id_column}{sqltype};
-#print STDERR "insert_sth->bind_param_inout(", $#$cols+2, ",
\$last_inserted_id, 20, $sqltype) [$last_inserted_id_column] BEFORE\n";
$insert_sth->bind_param_inout($#$cols+2, \$last_inserted_id,
20, $sqltype ? {TYPE => $sqltype} : () );
-#print STDERR "insert_sth->bind_param_inout(", $#$cols+2, ",
\$last_inserted_id, 20, $sqltype) [$last_inserted_id_column] AFTER\n";
}
-#print STDERR "BEFORE execute: last_inserted_id=[$last_inserted_id]\n";
$nrows = $insert_sth->execute;
-#print STDERR "AFTER execute: last_inserted_id=[$last_inserted_id]\n";
$nrows = 0 if ($nrows == 0); # turn "0E0" into plain old "0"
if ($is_last_inserted_id_returned_from_insert && $nrows) {
$self->{last_inserted_id} = $last_inserted_id;
@@ -2126,7 +2121,6 @@
my ($self, $table, $cols, $rows, $options) = @_;
$self->{error} = "";
my ($sql, $retval);
-
my $dbh = $self->{dbh};
return 0 if (!defined $dbh);
@@ -2173,7 +2167,7 @@
$row->[$i] =
$serializer->serialize($row->[$i]);
}
}
- $insert_sth->bind_param($i+1, undef, $sqltype ? {TYPE
=> $sqltype} : () );
+ $insert_sth->bind_param($i+1, undef, $sqltype ? {TYPE
=> $sqltype} : () );
if (defined $row->[$i] && $row->[$i] eq "" && ($type
eq "integer" || $type eq "float")) {
$row->[$i] = undef;
}
@@ -2193,7 +2187,6 @@
print $App::DEBUG_FILE "DEBUG_SQL: retval [$retval]
$DBI::errstr\n";
print $App::DEBUG_FILE "\n";
}
-
if ($retval) {
$nrows ++;
}
@@ -2239,7 +2232,6 @@
print $App::DEBUG_FILE "DEBUG_SQL: retval [$retval]
$DBI::errstr\n";
print $App::DEBUG_FILE "\n";
}
-
if ($retval) {
$nrows ++;
}
@@ -2378,7 +2370,7 @@
}
#$retval = $update_sth->execute();
- #$retval = $dbh->do($sql);
+ #$retval = $dbh->do($sql);
$retval = 0 if ($retval == 0); # turn "0E0" into plain old "0"
};
if (my $e = $@) { # Log the error message with the SQL and rethrow
the exception
@@ -2601,7 +2593,7 @@
* Throws: App::Exception::Repository
* Since: 0.01
- Sample Usage:
+ Sample Usage:
$rep->begin_work();
@@ -2630,7 +2622,7 @@
* Throws: App::Exception::Repository
* Since: 0.01
- Sample Usage:
+ Sample Usage:
$rep->commit();
@@ -2658,7 +2650,7 @@
* Throws: App::Exception::Repository
* Since: 0.01
- Sample Usage:
+ Sample Usage:
$rep->rollback();
@@ -2765,7 +2757,7 @@
@values = ( $rows );
}
}
- $sth->finish();
+ $sth->finish();
if ($return_type eq "LIST") {
&App::sub_exit(@values) if ($App::trace);
return(@values);
@@ -2911,7 +2903,7 @@
foreach my $ntype_attribute_values (@ntype_attribute_values) {
my $ntype_def = {};
- for (qw(TYPE_NAME DATA_TYPE COLUMN_SIZE LITERAL_PREFIX LITERAL_SUFFIX
+ for (qw(TYPE_NAME DATA_TYPE COLUMN_SIZE LITERAL_PREFIX LITERAL_SUFFIX
UNSIGNED_ATTRIBUTE AUTO_UNIQUE_VALUE))
{
my $key = lc($_);