handle USER-DEFINED types
authorJason Etheridge <jason@esilibrary.com>
Tue, 23 Jul 2013 20:17:40 +0000 (16:17 -0400)
committerJason Etheridge <jason@esilibrary.com>
Tue, 23 Jul 2013 20:17:40 +0000 (16:17 -0400)
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/src/sql/Pg/make-pgtap-tests.pl

index 314645d..e9f8543 100755 (executable)
@@ -62,15 +62,20 @@ foreach my $schema ( @schemas ) {
         my ($schema,$table) = (shift,shift);
         my @columns = fetch_columns($schema,$table);
         foreach my $column_array ( @columns ) {
+
             my $column = $column_array->[0];
-            my $col_type = $column_array->[1];
+            my $col_type_original = $column_array->[1];
+            my $col_type = $col_type_original;
             my $col_nullable = $column_array->[2];
             my $col_default = $column_array->[3];
+            my $col_numeric_precision = $column_array->[4];
+            my $col_numeric_scale = $column_array->[5];
+            my $col_udt_schema = $column_array->[6];
+            my $col_udt_name = $column_array->[7];
+
             if (defined $col_default && $col_default =~ /::text/) {
                 $col_default =~ s/^'(.*)'::text$/$1/;
             }
-            my $col_numeric_precision = $column_array->[4];
-            my $col_numeric_scale = $column_array->[5];
             if ($col_type eq 'numeric' && defined $col_numeric_precision) {
                 $col_type .= "($col_numeric_precision";
                 if (defined $col_numeric_scale) {
@@ -78,6 +83,9 @@ foreach my $schema ( @schemas ) {
                 }
                 $col_type .= ')';
             }
+            if ($col_type eq 'USER-DEFINED' && defined $col_udt_schema) {
+                $col_type = "$col_udt_schema.$col_udt_name";
+            }
             print "\n-- -- -- column " . $dbh->quote("$schema.$table.$column") . "\n\n";
             print "SELECT has_column(\n";
             print "\t" . $dbh->quote($schema) . ",\n";
@@ -120,7 +128,7 @@ foreach my $schema ( @schemas ) {
                 } elsif ($col_type eq 'integer' && $col_default =~ '\(-?\d+\)') {
                     # FIXME - ERROR:  invalid input syntax for integer: "(-1)"
                     $fixme = '-- FIXME type 4 -- ';
-                } elsif ($col_type eq 'USER-DEFINED') {
+                } elsif ($col_type_original eq 'USER-DEFINED') {
                     # FIXME - ERROR:  Unexpected end of string
                     $fixme = '-- FIXME type 5 -- ';
                 }
@@ -160,7 +168,6 @@ foreach my $schema ( @schemas ) {
         print "\t" . $dbh->quote($schema) . ",\n";
         print "\t" . $dbh->quote($view) . ",\n";
         print "\t" . $dbh->quote("Has view $schema.$view") . "\n);\n";
-
         handle_columns($schema,$view);
     }
 
@@ -222,7 +229,9 @@ sub fetch_columns {
             is_nullable,
             column_default,
             numeric_precision,
-            numeric_scale
+            numeric_scale,
+            udt_schema,
+            udt_name
         FROM information_schema.columns
             WHERE table_catalog = ?
             AND table_schema = ?