Subject: | CDBI upgrade problem with MSSQL |
I just tried to upgrade CDBI::FormBuilder from .351 to .421 and had problems with my MSSQL table. I'm using CDBI::MSSQL as a base class and the odbc driver (dsn = dbi:ODBC:dbname). Here is the error I get:
undef error - DBD::ODBC::st execute failed: [unixODBC][Driver Manager]Function sequence error (SQL-HY010)(DBD: st_execute/SQLExecute err=-1) [for Statement "SQLColumns"] at /usr/local/lib/perl5/site_perl/5.8.6/DBIx/ContextualFetch.pm line 52.
- at /usr/local/lib/perl5/site_perl/5.8.6/Maypole.pm line 123
I found that if I eliminate the execute() statement from _load_meta, I get further. Then I get:
:undef error - DBD::ODBC::st fetchall_hashref failed: Field 'TABLE_CAT' does not exist (not one of table_schem char_octet_length column_size column_def ordinal_position buffer_length data_type column_name sql_datetime_sub decimal_digits remarks ss_data_type is_nullable sql_data_type type_name table_cat nullable num_prec_radix table_name) [for Statement "SQLColumns"] at /usr/local/lib/perl5/site_perl/5.8.6/Class/DBI/FormBuilder.pm line 841.
- at /usr/local/lib/perl5/site_perl/5.8.6/Maypole.pm
Changing the columns to lowercase in the fetchall_hashref call gets past that, but then there are problems in column_meta with this line:
my @rv = map { $them->__fb_meta->{ $_ }->{ $k } } @columns;
To fix that, in _load_meta I replaced:
my $column_info = $sth->fetchall_hashref( [ qw(TABLE_CAT TABLE_SCHEM TABLE_NAME COLUMN_NAME)])->{''}->{''}->{$table};
with:
my $column_info = $sth->fetchall_hashref( [ qw( table_cat table_schem table_name column_name ) ] )->{'pathdb'}->{'dbo'}->{ $table };
and changed:
$meta->{ $col } = { map { $_ => $column_info->{ $col }->{ $_ } }
to:
$meta->{ $col } = { map { $_ => $column_info->{ $col }->{ lc($_) } }
This resolved my issue for mssql, but of course breaks it for mysql. I'm not sure how to best integrate these changes transparently.