Oracle sequence detection
Rafael Kitover [Thu, 20 May 2010 14:56:13 +0000 (10:56 -0400)]
Changes
lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm
t/14ora_common.t

diff --git a/Changes b/Changes
index 0f959b2..bee1d26 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 Revision history for Perl extension DBIx::Class::Schema::Loader
 
+        - sequence is detected for Oracle
+        - fix for SQLite is_auto_increment detection when table is empty (hobbs)
         - rescan now reloads all tables
         - minor type info improvements for all DBs
         - fix erroneous default_value for MySQL NOT NULL columns (RT#57225)
index a3fb1eb..55e6a4e 100644 (file)
@@ -137,8 +137,11 @@ sub _columns_info_for {
 
     my $dbh = $self->schema->storage->dbh;
 
+    local $dbh->{LongReadLen} = 100000;
+    local $dbh->{LongTruncOk} = 1;
+
     my $sth = $dbh->prepare_cached(q{
-SELECT atc.column_name
+SELECT atc.column_name, ut.trigger_body
 FROM all_triggers ut
 JOIN all_trigger_cols atc USING (trigger_name)
 WHERE atc.table_name = ?
@@ -148,8 +151,16 @@ AND upper(trigger_type) LIKE '%BEFORE EACH ROW%' AND lower(triggering_event) LIK
 
     $sth->execute($self->_uc($table));
 
-    while (my ($col_name) = $sth->fetchrow_array) {
-        $result->{$self->_lc($col_name)}{is_auto_increment} = 1;
+    while (my ($col_name, $trigger_body) = $sth->fetchrow_array) {
+        $col_name = $self->_lc($col_name);
+
+        $result->{$col_name}{is_auto_increment} = 1;
+
+        if (my ($seq_name) = $trigger_body =~ /"?(\w+)"?\.nextval/i) {
+            $seq_name = $self->_lc($seq_name);
+
+            $result->{$col_name}{sequence} = $seq_name;
+        }
     }
 
     while (my ($col, $info) = each %$result) {
index 1cab6fa..1232939 100644 (file)
@@ -124,6 +124,23 @@ my $tester = dbixcsl_common_tests->new(
         'urowid'       => { data_type => 'urowid' },
         'urowid(3333)' => { data_type => 'urowid', size => 3333 },
     },
+    extra => {
+        count => 1,
+        run   => sub {
+            my ($schema, $monikers, $classes) = @_;
+
+            SKIP: {
+                if (my $source = $monikers->{loader_test1s}) {
+                    is $schema->source($source)->column_info('id')->{sequence},
+                        'loader_test1s_id_seq',
+                        'Oracle sequence detection';
+                }
+                else {
+                    skip 1, 'not running common tests';
+                }
+            }
+        },
+    },
 );
 
 if( !$dsn || !$user ) {