use fetchall_hashref instead of fetchall_arrayref
authorJason Etheridge <jason@esilibrary.com>
Wed, 24 Jul 2013 21:36:09 +0000 (17:36 -0400)
committerJason Etheridge <jason@esilibrary.com>
Wed, 24 Jul 2013 21:36:09 +0000 (17:36 -0400)
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/src/sql/Pg/make-pgtap-tests.pl

index 07896fa..76bc1e5 100755 (executable)
@@ -169,9 +169,9 @@ sub fetch_columns {
             AND table_name = ?
     ");
     $sth->execute(($db_name,$schema,$table));
-    my $columns = $sth->fetchall_arrayref();
+    my $columns = $sth->fetchall_hashref('column_name');
     $sth->finish;
-    return sort { $a->[0] cmp $b->[0] } (map { $_ } @{ $columns });
+    return $columns;
 }
 
 sub handle_schemas {
@@ -239,8 +239,8 @@ sub handle_views {
 
 sub handle_columns {
     my ($schema,$table) = (shift,shift);
-    my @columns = fetch_columns($schema,$table);
-    if (scalar @columns == 0) {
+    my $columns = fetch_columns($schema,$table);
+    if (!%{ $columns }) {
         return;
     }
 
@@ -250,23 +250,22 @@ sub handle_columns {
     print "\tARRAY[\n\t\t";
     print join(
         ",\n\t\t",
-        map { $dbh->quote($_->[0]) } @columns
+        map { $dbh->quote($_) } sort keys %{ $columns }
     );
     print "\n\t],\t" . $dbh->quote("Found expected columns for $schema.$table");
     print "\n);\n";
 
-    foreach my $column_array ( @columns ) {
+    foreach my $column ( sort keys %{ $columns } ) {
 
-        my $column = $column_array->[0];
-        my $col_type_original = $column_array->[1];
+        my $col_type_original = $columns->{$column}->{data_type};
         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];
-        my $col_character_maximum_length = $column_array->[8];
+        my $col_nullable = $columns->{$column}->{is_nullable};
+        my $col_default = $columns->{$column}->{column_default};
+        my $col_numeric_precision = $columns->{$column}->{numeric_precision};
+        my $col_numeric_scale = $columns->{$column}->{numeric_scale};
+        my $col_udt_schema = $columns->{$column}->{udt_schema};
+        my $col_udt_name = $columns->{$column}->{udt_name};
+        my $col_character_maximum_length = $columns->{$column}->{character_maximum_length};
 
         if (defined $col_default && $col_default =~ /::text/) {
             $col_default =~ s/^'(.*)'::text$/$1/;