Author: turnstep
Date: Tue Jan 15 16:21:50 2008
New Revision: 10561

Modified:
   DBD-Pg/trunk/Pg.pm
   DBD-Pg/trunk/t/03dbmethod.t
   DBD-Pg/trunk/t/09arrays.t

Log:
Many tweaks and test twists to support 7.4.


Modified: DBD-Pg/trunk/Pg.pm
==============================================================================
--- DBD-Pg/trunk/Pg.pm  (original)
+++ DBD-Pg/trunk/Pg.pm  Tue Jan 15 16:21:50 2008
@@ -657,6 +657,11 @@
                        $whereclause .= "\n\t\t\tAND n.nspname = " . 
$dbh->quote($schema);
                }
 
+               my $TSJOIN = 'pg_catalog.pg_tablespace t ON (t.oid = 
c.reltablespace)';
+               if ($dbh->{private_dbdpg}{version} < 80000) {
+                       $TSJOIN = '(SELECT 0 AS oid, 0 AS spcname, 0 AS 
spclocation LIMIT 0) AS t ON (t.oid=1)';
+               }
+
                my $pri_key_sql = qq{
                        SELECT
                                  c.oid
@@ -670,7 +675,7 @@
                                JOIN pg_catalog.pg_index i ON (i.indrelid = 
c.oid)
                                JOIN pg_catalog.pg_class c2 ON (c2.oid = 
i.indexrelid)
                                LEFT JOIN pg_catalog.pg_namespace n ON (n.oid = 
c.relnamespace)
-                               LEFT JOIN pg_catalog.pg_tablespace t ON (t.oid 
= c.reltablespace)
+                               LEFT JOIN $TSJOIN
                        WHERE
                                i.indisprimary IS TRUE
                        $whereclause
@@ -1067,10 +1072,9 @@
                }
                else {
                        # Default SQL
-                       my $showtablespace = '';
                        $extracols = q{,n.nspname AS pg_schema, c.relname AS 
pg_table};
                        my @search;
-                       $showtablespace = ', quote_ident(t.spcname) AS 
"pg_tablespace_name", quote_ident(t.spclocation) AS "pg_tablespace_location"';
+                       my $showtablespace = ', quote_ident(t.spcname) AS 
"pg_tablespace_name", quote_ident(t.spclocation) AS "pg_tablespace_location"';
 
                        ## If the schema or table has an underscore or a %, use 
a LIKE comparison
                        if (defined $schema and length $schema) {
@@ -1091,6 +1095,10 @@
                        }
                        push @search, "c.relkind $typesearch";
 
+                       my $TSJOIN = 'pg_catalog.pg_tablespace t ON (t.oid = 
c.reltablespace)';
+                       if ($dbh->{private_dbdpg}{version} < 80000) {
+                               $TSJOIN = '(SELECT 0 AS oid, 0 AS spcname, 0 AS 
spclocation LIMIT 0) AS t ON (t.oid=1)';
+                       }
                        my $whereclause = join "\n\t\t\t\t\t AND " => @search;
                        $tbl_sql = qq{
                                SELECT NULL::text AS "TABLE_CAT"
@@ -1107,7 +1115,7 @@
                                        LEFT JOIN pg_catalog.pg_description AS d
                                                ON (c.oid = d.objoid AND 
c.tableoid = d.classoid AND d.objsubid = 0)
                                        LEFT JOIN pg_catalog.pg_namespace n ON 
(n.oid = c.relnamespace)
-                                       LEFT JOIN pg_catalog.pg_tablespace t ON 
(t.oid = c.reltablespace)
+                                       LEFT JOIN $TSJOIN
                                WHERE $whereclause
                                ORDER BY "TABLE_TYPE", "TABLE_CAT", 
"TABLE_SCHEM", "TABLE_NAME"
                                };

Modified: DBD-Pg/trunk/t/03dbmethod.t
==============================================================================
--- DBD-Pg/trunk/t/03dbmethod.t (original)
+++ DBD-Pg/trunk/t/03dbmethod.t Tue Jan 15 16:21:50 2008
@@ -30,6 +30,7 @@
 my $dbh = connect_database();
 ok( defined $dbh, 'Connect to database for database handle method testing');
 
+my ($pglibversion,$pgversion) = 
($dbh->{pg_lib_version},$dbh->{pg_server_version});
 my ($schema,$schema2) = ('dbd_pg_testschema', 'dbd_pg_testschema2');
 my ($table1,$table2,$table3) = ('dbd_pg_test1','dbd_pg_test2','dbd_pg_test3');
 my ($sequence2,$sequence3) = ('dbd_pg_testsequence2','dbd_pg_testsequence3');
@@ -127,25 +128,33 @@
 };
 is ($@, q{}, 'DB handle method "last_insert_id" works when called with a 
schema not in the search path');
 $dbh->commit();
-
 $t=q{ DB handle method "last_insert_id" fails when the sequence name is 
changed and cache is used};
-$dbh->do("ALTER SEQUENCE $schema2.$sequence2 RENAME TO $sequence3");
-$dbh->commit();
-eval {
-       $dbh->last_insert_id(undef,$schema2,$table2,undef);
-};
-like ($@, qr{last_insert_id}, $t);
-$dbh->rollback();
 
-$t=q{ DB handle method "last_insert_id" works when the sequence name is 
changed and cache is turned off};
-$dbh->commit();
-eval {
-       $dbh->last_insert_id(undef,$schema2,$table2,undef, {pg_cache=>0});
-};
-is ($@, q{}, $t);
+SKIP: {
+       if ($pgversion < 80000) {
+               $dbh->do("DROP TABLE $schema2.$table2");
+               $dbh->do("DROP SEQUENCE $schema2.$sequence2");
+               skip 'Cannot test sequence rename on pre-8.0 servers', 2;
+       }
+       $dbh->do("ALTER SEQUENCE $schema2.$sequence2 RENAME TO $sequence3");
+       $dbh->commit();
+       eval {
+               $dbh->last_insert_id(undef,$schema2,$table2,undef);
+       };
+       like ($@, qr{last_insert_id}, $t);
+       $dbh->rollback();
+
+       $t=q{ DB handle method "last_insert_id" works when the sequence name is 
changed and cache is turned off};
+       $dbh->commit();
+       eval {
+               $dbh->last_insert_id(undef,$schema2,$table2,undef, 
{pg_cache=>0});
+       };
+       is ($@, q{}, $t);
+       $dbh->do("DROP TABLE $schema2.$table2");
+       $dbh->do("DROP SEQUENCE $schema2.$sequence3");
+}
+
 
-$dbh->do("DROP TABLE $schema2.$table2");
-$dbh->do("DROP SEQUENCE $schema2.$sequence3");
 $dbh->do("DROP SCHEMA $schema2");
 
 #
@@ -478,6 +487,9 @@
        $DBI::VERSION >= 1.52
                or skip 'DBI must be at least version 1.52 to test the database 
handle method "statistics_info"', 10;
 
+       $dbh->{private_dbdpg}{version} >= 800000
+               or skip 'Server must be version 8.0 or higher to test database 
handle method "statistics_info"', 10;
+
        $sth = $dbh->statistics_info(undef,undef,undef,undef,undef);
        is ($sth, undef, 'DB handle method "statistics_info" returns undef: no 
table');
 
@@ -1088,7 +1100,6 @@
 # Test of the "state" database handle method
 #
 
-my ($pglibversion,$pgversion) = 
($dbh->{pg_lib_version},$dbh->{pg_server_version});
 $result = $dbh->state();
 is( $result, q{}, q{DB handle method "state" returns an empty string on 
success});
 

Modified: DBD-Pg/trunk/t/09arrays.t
==============================================================================
--- DBD-Pg/trunk/t/09arrays.t   (original)
+++ DBD-Pg/trunk/t/09arrays.t   Tue Jan 15 16:21:50 2008
@@ -13,7 +13,7 @@
 select(($|=1,select(STDERR),$|=1)[1]);
 
 if (defined $ENV{DBI_DSN}) {
-       plan tests => 223;
+       plan tests => 196;
 } else {
        plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the 
README file';
 }
@@ -23,10 +23,12 @@
 my $dbh = connect_database();
 ok( defined $dbh, 'Connect to database for array testing');
 
-$dbh->do('SET escape_string_warning = false');
-
 my $pgversion = $dbh->{pg_server_version};
 
+if ($pgversion >= 80100) {
+  $dbh->do('SET escape_string_warning = false');
+}
+
 my $SQL = q{DELETE FROM dbd_pg_test WHERE pname = 'Array Testing'};
 my $cleararray = $dbh->prepare($SQL);
 
@@ -262,8 +264,11 @@
 ## Pure string to array conversion testing
 
 ## Use ourselves as a valid role
-$SQL = 'SELECT current_role';
-my $role = $dbh->selectall_arrayref($SQL)->[0][0];
+my $role = 'SKIP';
+if ($pgversion >= 80000) {
+       $SQL = 'SELECT current_role';
+       $role = $dbh->selectall_arrayref($SQL)->[0][0];
+}
 
 my $array_tests_out =
 qq!1
@@ -416,7 +421,15 @@
                my $ver = $1;
                if ($pgversion < $ver) {
                  SKIP: {
-                               skip 'Cannot test NULL arrays unless version 
8.2 or better', 4;
+                               skip 'Cannot test NULL arrays unless version 
8.2 or better', 1;
+                       }
+                       next;
+               }
+       }
+       if ($pgversion < 80000) {
+               if ($input =~ /SKIP/ or $test =~ /Fake NULL|boolean/) {
+                 SKIP: {
+                               skip 'Cannot test some array items on old 
pre-8.0 servers', 1;
                        }
                        next;
                }
@@ -431,13 +444,12 @@
                like($@, qr{$1}, "Array failed : $msg : $input");
        }
        else {
-               is($@, q{}, "Array worked : $msg : $input");
                $expected = eval $expected;
                $@ and BAIL_OUT "Eval failed ($@) for $expected\n";
                ## is_deeply does not handle type differences
                is((Dumper $result), (Dumper $expected), "Array test $msg : 
$input");
        }
-
+       
 }
 
 cleanup_database($dbh,'test');

Reply via email to