Author: spadkins
Date: Mon Nov 10 20:31:41 2008
New Revision: 12063

Modified:
   p5ee/trunk/App-Repository/lib/App/Repository.pm
   p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm
   p5ee/trunk/App-Repository/lib/App/Repository/Oracle.pm
   p5ee/trunk/App-Repository/t/DBI-repobjects.t
   p5ee/trunk/App-Repository/t/DBI-select-ora.t

Log:
latest

Modified: p5ee/trunk/App-Repository/lib/App/Repository.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository.pm     (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository.pm     Mon Nov 10 20:31:41 2008
@@ -910,6 +910,7 @@
 sub get_rows {
     &App::sub_entry if ($App::trace);
     my ($self, $table, $params, $cols, $options) = @_;
+    $params = {} if (!defined $params && !defined $cols && !defined $options);
 
     my $context = $self->{context};
     my $context_options = $context->{options};
@@ -1262,6 +1263,7 @@
 sub get_hashes {
     &App::sub_entry if ($App::trace);
     my ($self, $table, $params, $cols, $options) = @_;
+    $params = {} if (!defined $params && !defined $cols && !defined $options);
     $cols = [] if (!$cols);
     my $rows = $self->get_rows($table, $params, $cols, $options);
     my $hashes = [];
@@ -2117,10 +2119,12 @@
     $object->_init();
     $self->_check_default_and_required_fields($object);
 
+    $options = $options ? { %$options } : {};
+    $options->{last_inserted_id} = 1;
     if (!$options->{temp}) {
         my $retval = $self->insert_row($table, $object, undef, $options);
         die "new($table) unable to create a new row" if (!$retval);
-        my $params = $self->_last_inserted_id($table);
+        my $params = $self->last_inserted_id($table);
         if (!$params) {
             $params = {};
             foreach my $col (keys %$object) {
@@ -2131,7 +2135,7 @@
     }
 
     &App::sub_exit($object) if ($App::trace);
-    $object;
+    return($object);
 }
 
 sub _check_default_and_required_fields {

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 Mon Nov 10 20:31:41 2008
@@ -645,7 +645,6 @@
             my @o_keys = keys %$slice;
             next if ++$rownum < $startrow;
             last if ($endrow > 0 && $rownum > $endrow);
-
             push @rows, @o_keys ? 
                 { map {shift @o_keys => $_ } @[EMAIL PROTECTED] } :
                 $row
@@ -1449,7 +1448,7 @@
 # $insert_sql = $rep->_mk_insert_row_sql ($table, [EMAIL PROTECTED], [EMAIL 
PROTECTED]);
 sub _mk_insert_row_sql {
     &App::sub_entry if ($App::trace);
-    my ($self, $table, $cols, $row) = @_;
+    my ($self, $table, $cols, $row, $options) = @_;
 
     $self->_load_table_metadata($table) if (!defined 
$self->{table}{$table}{loaded});
     my $dbh = $self->{dbh};
@@ -1493,10 +1492,16 @@
     $sql .= ")\n";
     $values .= ")\n";
     $sql .= $values;
+    $sql .= $self->_mk_insert_row_suffix($table, $options);
     &App::sub_exit($sql) if ($App::trace);
     $sql;
 }
 
+sub _mk_insert_row_suffix {
+    my ($self, $table, $options) = @_;
+    return("");
+}
+
 sub _mk_insert_rows_sql {
     &_mk_insert_row_sql;
 }
@@ -3015,41 +3020,6 @@
     &App::sub_exit() if ($App::trace);
 }
 
-sub _set_insert_id {
-    my ($self) = shift;
-    my ($table, $cols, $row) = @_;
-
-    my $pk_col;
-    my $pknum=0;
-    for my $col (@$cols) {
-        if ($col eq $self->{table}{$table}->{primary_key}[0]) {
-            $pk_col = $pknum;
-        }
-        ++$pknum;
-    }
-
-    if (defined($pk_col)) {
-         $self->{last_inserted_id} = $row->[$pk_col];
-         return;
-    }
-
-    my $id = $self->{last_inserted_id} = 
$self->{dbh}->last_insert_id($self->{dbcatalog}, $self->{dbschema}, $table, 
$self->{table}{$table}{primary_key});
-
-   return if $id;
-
-   eval {
-        my $dbh = $self->{dbh};
-        my $pk = $self->{table}{$table}{primary_key}[0];
-        $id = ($dbh->selectall_arrayref(qq{SELECT max($pk) FROM 
$table}))->[0][0];
-        #warn "Primary key old skoo: $id";
-        $self->{last_inserted_id} = $id;
-   }; warn ($@) if $@;
-
-    warn "Could not find _last_inserted_id for table $id" if !$id;
-
-    return;
-}
-
 sub _last_inserted_id {
     my ($self, $table) = @_;
     return $self->{last_inserted_id};

Modified: p5ee/trunk/App-Repository/lib/App/Repository/Oracle.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository/Oracle.pm      (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository/Oracle.pm      Mon Nov 10 
20:31:41 2008
@@ -122,6 +122,18 @@
     }
 }
 
+#sub _mk_insert_row_suffix {
+#    my ($self, $table, $options) = @_;
+#    my $suffix = "";
+#    if ($options->{last_inserted_id}) {
+#        my $primary_key = $self->{table}{$table}{primary_key};
+#        if ($primary_key && $#$primary_key == 0) {
+#            $suffix = " returning $primary_key->[0] into ?";
+#        }
+#    }
+#    return($suffix);
+#}
+
 sub _load_table_metadata_from_source2 {
     &App::sub_entry if ($App::trace);
     my ($self, $table) = @_;
@@ -414,5 +426,11 @@
     return(undef, uc($dbschema), uc($table), "%");
 }
 
+#INSERT ALL
+#   INTO suppliers (supplier_id, supplier_name) VALUES (1000, 'IBM')
+#   INTO suppliers (supplier_id, supplier_name) VALUES (2000, 'Microsoft')
+#   INTO suppliers (supplier_id, supplier_name) VALUES (3000, 'Google')
+#SELECT * FROM dual;
+
 1;
 

Modified: p5ee/trunk/App-Repository/t/DBI-repobjects.t
==============================================================================
--- p5ee/trunk/App-Repository/t/DBI-repobjects.t        (original)
+++ p5ee/trunk/App-Repository/t/DBI-repobjects.t        Mon Nov 10 20:31:41 2008
@@ -176,16 +176,13 @@
     is($obj3->{age},$obj->{age}, "new.age seems ok");
     is($obj3->{_key},$obj->{_key}, "new._key seems ok");
 
-    if ($dbtype eq 'mysql') {
+    if ($dbtype eq "mysql") {
         my $obj4 = $rep->new_object("test_person",{first_name => "christine", 
gender => "F"});
         is($obj4->{first_name},"christine", "new.first_name (2) seems ok");
         is($obj4->{_key},8, "new._key is ok");
         is($obj4->{person_id},8, "new.person_id is ok");
         isa_ok($obj4, "App::RepositoryObject::Woman", "by new_object(), 
christine");
     }
-    if ($dbtype eq 'oracle') {
-        print STDERR "**************************** WE NEED TO LOOK INTO THIS - 
 ORA-00001: unique constraint (MVHDA_DEV_NF.SYS_C0016131) violated\n";
-    }
 }
 
 {

Modified: p5ee/trunk/App-Repository/t/DBI-select-ora.t
==============================================================================
--- p5ee/trunk/App-Repository/t/DBI-select-ora.t        (original)
+++ p5ee/trunk/App-Repository/t/DBI-select-ora.t        Mon Nov 10 20:31:41 2008
@@ -811,8 +811,7 @@
 select
    t1.gender as gnd,
    max(age) as max_age_
-from
-   test_person t1
+from test_person t1
 group by
    t1.gender
 order by
@@ -827,9 +826,8 @@
 $expect_sql = <<EOF;
 select
    t1.gender as gnd,
-   2*age as _2_age
-from
-   test_person t1
+   2*age as x_2_age
+from test_person t1
 EOF
 &test_get_rows($expect_sql, 0, "_mk_select_joined_sql(): literal aggregation 
function",
     "test_person",

Reply via email to