Skip Menu |

This queue is for tickets about the DBD-DB2 CPAN distribution.

Report information
The Basics
Id: 79265
Status: resolved
Priority: 0/
Queue: DBD-DB2

People
Owner: Nobody in particular
Requestors: dmcbride [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.84
Fixed in: (no value)



DBD::DB2::tables doesn't accept the same parameters as given in the DBI documentation: $ perl -MDBI -le '$dbh=DBI->connect("dbi:DB2:cbstats");print for $dbh- Show quoted text
>tables("%","CBSTATS","%")'
DBI::st=HASH(0x1da0ec0)->_table_info(...): attribute parameter '%' is not a hash ref at /usr/lib64/perl5/site_perl/5.12.2/x86_64-linux-thread- multi/DBD/DB2.pm line 215. This should list all tables in the CBSTATS schema, but only the first parameter is passed through to table_info. Using SQLite as an example: $ perl -MDBI -le '$dbh=DBI->connect("dbi:SQLite:myorg.db");print for $dbh->tables("%","main","%")' "main"."MEMBERS" "main"."MEMBERS" "main"."sqlite_master" "main"."EXECUTIVE" "main"."LISTS" "main"."MEMBERS" "main"."SPECIAL" (Why there are three tables labelled "main"."MEMBERS", I don't know, but that's another topic.)
Hi Darin, Sorry for the delayed response. The DBD::DB2 driver has overwritten the table_info method to take in only 1 argument, that is a hash list of values for SCHEMA, Table name and Table Type. You will need to use this syntax while using DBD::DB2. You can find the doc here http://search.cpan.org/~ibmtordb2/DBD-DB2-1.84/DB2.pod#Getting_Table_information I am not sure if DBI had this syntax earlier and changed it in the latest versions and hence the syntax. For now you could use this DB2 syntax. I will look into this and see how can I restructure to adhere to DBI spec. -- Thanks Praveen IBM OpenSource Application Development Team India Software Labs, Bangalore (India)
Ok. I see that the API syntax is changed in version 1.19 of DBI. Will make changes in DBD::DB2 to adhere to new changes as per DB2 requirements. -- Thanks Praveen IBM OpenSource Application Development Team India Software Labs, Bangalore (India)
Hi Darin, I have fixed this issue. I am attaching the modified files. Try them and let me know how it goes. If everything is fine will go ahead and make a release along with the fix for defect 77414. -- Thanks Praveen IBM OpenSource Application Development Team India Software Labs, Bangalore (India)
Subject: DB2.pm
# # engn/perldb2/DB2.pm, engn_perldb2, db2_v82fp9, 1.10 04/09/19 17:17:44 # # Copyright (c) 1995-2004 International Business Machines Corp. # { package DBD::DB2; use DBI; use DynaLoader; @ISA = qw(Exporter DynaLoader); @EXPORT_OK = qw( $attrib_dec $attrib_int $attrib_char $attrib_float $attrib_date $attrib_ts $attrib_binary $attrib_blobfile $attrib_clobfile $attrib_dbclobfile ); $VERSION = '1.84'; require_version DBI 1.41; bootstrap DBD::DB2; use DBD::DB2::Constants; $err = 0; # holds error code for DBI::err $errstr = ""; # holds error string for DBI::errstr $state = ""; # holds SQL state for DBI::state $drh = undef; # holds driver handle once initialised $warn_success = $ENV{'WARNING_OK'}; $attrib_dec = { 'db2_param_type' => SQL_PARAM_INPUT_OUTPUT, 'db2_c_type' => SQL_C_CHAR, 'db2_type' => SQL_DECIMAL, 'PRECISION' => 31, 'SCALE' => 4, }; $attrib_int = { 'db2_param_type' => SQL_PARAM_INPUT_OUTPUT, 'db2_c_type' => SQL_C_CHAR, 'db2_type' => SQL_INTEGER, 'PRECISION' => 10, }; $attrib_char = { 'db2_param_type' => SQL_PARAM_INPUT_OUTPUT, 'db2_c_type' => SQL_C_CHAR, 'db2_type' => SQL_CHAR, 'PRECISION' => 0, }; $attrib_float = { 'db2_param_type' => SQL_PARAM_INPUT_OUTPUT, 'db2_c_type' => SQL_C_CHAR, 'db2_type' => SQL_FLOAT, 'PRECISION' => 15, 'SCALE' => 6, }; $attrib_date = { 'db2_param_type' => SQL_PARAM_INPUT_OUTPUT, 'db2_c_type' => SQL_C_CHAR, 'db2_type' => SQL_DATE, 'PRECISION' => 10, }; $attrib_ts = { 'db2_param_type' => SQL_PARAM_INPUT_OUTPUT, 'db2_c_type' => SQL_C_CHAR, 'db2_type' => SQL_TIMESTAMP, 'PRECISION' => 26, 'SCALE' => 11, }; $attrib_binary = { 'db2_param_type' => SQL_PARAM_INPUT_OUTPUT, 'db2_c_type' => SQL_C_BINARY, 'db2_type' => SQL_BINARY, 'PRECISION' => 0, }; $attrib_blobfile = { 'db2_param_type' => SQL_PARAM_INPUT, 'db2_c_type' => SQL_C_CHAR, 'db2_type' => SQL_BLOB, 'db2_file' => 1, }; $attrib_clobfile = { 'db2_param_type' => SQL_PARAM_INPUT, 'db2_c_type' => SQL_C_CHAR, 'db2_type' => SQL_CLOB, 'db2_file' => 1, }; $attrib_dbclobfile = { 'db2_param_type' => SQL_PARAM_INPUT, 'db2_c_type' => SQL_C_CHAR, 'db2_type' => SQL_DBCLOB, 'db2_file' => 1, }; sub driver{ return $drh if $drh; my($class, $attr) = @_; $class .= "::dr"; # not a 'my' since we use it above to prevent multiple drivers $drh = DBI::_new_drh($class, { 'Name' => 'DB2', 'Version' => $VERSION, 'Err' => \$DBD::DB2::err, 'Errstr' => \$DBD::DB2::errstr, 'State' => \$DBD::DB2::state, 'Attribution' => 'DB2 DBD by IBM', }); $drh; } sub CLONE{ undef $drh; } 1; } { package DBD::DB2::dr; # ====== DRIVER ====== use strict; sub connect { my($drh, $dbname, $user, $auth, $attr)= @_; # create a 'blank' dbh my $this = DBI::_new_dbh($drh, { 'Name' => $dbname, 'USER' => $user, 'CURRENT_USER' => $user }); DBD::DB2::db::_login($this, $dbname, $user, $auth, $attr) or return undef; $this; } sub data_sources { my ($drh, $attr) = @_; my $dsref = DBD::DB2::dr::_data_sources( $drh, $attr ); if( defined( $dsref ) && ref( $dsref ) eq "ARRAY" ) { return @$dsref; } return (); # Return empty array } } { package DBD::DB2::db; # ====== DATABASE ====== use strict; sub do { my($dbh, $statement, $attr, @params) = @_; my $rows = 0; if( -1 == $#params ) { # No parameters, use execute immediate $rows = DBD::DB2::db::_do( $dbh, $statement ); if( 0 == $rows ) { $rows = "0E0"; } elsif( $rows < -1 ) { undef $rows; } } else { $rows = $dbh->SUPER::do( $statement, $attr, @params ); } return $rows } sub prepare { my($dbh, $statement)= @_; # create a 'blank' dbh my $sth = DBI::_new_sth($dbh, { 'Statement' => $statement, }); DBD::DB2::st::_prepare($sth, $statement) or return undef; $sth; } sub ping { my($dbh) = @_; DBD::DB2::db::_ping( $dbh ); } sub table_info { my( $dbh, $ctlg, $schema, $table, $type ) = @_; my $attr = {}; if(ref($ctlg) eq "HASH") { $attr = $ctlg; } else { $attr = {'TABLE_SCHEM' => $schema, 'TABLE_TYPE' => $type, 'TABLE_NAME' => $table}; } my $sth = DBI::_new_sth($dbh, {}); DBD::DB2::st::_table_info( $sth, $attr ) or return undef; $sth; } sub primary_key_info { my( $dbh, $catalog, $schema, $table ) = @_; my $sth = DBI::_new_sth( $dbh, {} ); DBD::DB2::st::_primary_key_info( $sth, $catalog, $schema, $table ) or return undef; $sth; } sub foreign_key_info { my( $dbh, $pkcat, $pkschema, $pktable, $fkcat, $fkschema, $fktable ) = @_; my $sth = DBI::_new_sth( $dbh, {} ); DBD::DB2::st::_foreign_key_info( $sth, $pkcat, $pkschema, $pktable, $fkcat, $fkschema, $fktable ) or return undef; $sth; } sub column_info { my( $dbh, $cat, $schema, $table, $column ) = @_; my $sth = DBI::_new_sth( $dbh, {} ); # Applications can use undef instead of NULL, and they are not the same # We have to map undef to "match all" here before going into C code if( !defined($cat) ) { $cat = ""; } if( !defined($schema) ) { $schema = "%"; } if( !defined($table) ) { $table = "%"; } if( !defined($column) ) { $column = "%"; } DBD::DB2::st::_column_info( $sth, $cat, $schema, $table, $column ) or return undef; $sth; } sub type_info_all { my( $dbh ) = @_; my $cols = { TYPE_NAME => 0, DATA_TYPE => 1, COLUMN_SIZE => 2, LITERAL_PREFIX => 3, LITERAL_SUFFIX => 4, CREATE_PARAMS => 5, NULLABLE => 6, CASE_SENSITIVE => 7, SEARCHABLE => 8, UNSIGNED_ATTRIBUTE => 9, FIXED_PREC_SCALE => 10, AUTO_UNIQUE_VALUE => 11, LOCAL_TYPE_NAME => 12, MINIMUM_SCALE => 13, MAXIMUM_SCALE => 14, SQL_DATA_TYPE => 15, SQL_DATETIME_SUB => 16, NUM_PREC_RADIX => 17, INTERVAL_PRECISION => 18 }; my $type_info_all = [ $cols ]; my $sth = DBI::_new_sth( $dbh, {} ); DBD::DB2::st::_type_info_all( $sth ) or return undef; push( @$type_info_all, @{$sth->fetchall_arrayref} ); $sth->finish; return $type_info_all; } sub get_info { my( $dbh, $infotype ) = @_; my $v = DBD::DB2::db::_get_info( $dbh, $infotype ); return $v; } } { package DBD::DB2::st; # ====== STATEMENT ====== use strict; } 1;
Subject: dbdimp.c

Message body is not shown because it is too large.

On Sun Oct 07 10:43:28 2012, IBMTORDB2 wrote: Show quoted text
> Hi Darin, > > I have fixed this issue. I am attaching the modified files. Try them and > let me know how it goes. If everything is fine will go ahead and make a > release along with the fix for defect 77414. >
Unfortunately, this doesn't quite work: [dmcbride@naboo mibe]$ db2 list tables for schema cbstats Table/View Schema Type Creation time ------------------------------- --------------- ----- ------------------- ------- KARMA CBSTATS T 2011-05-12- 10.41.19.393540 LOGS CBSTATS T 2011-05-10- 17.18.33.726612 NEWS CBSTATS T 2011-05-10- 15.54.00.716809 REFERU CBSTATS T 2011-05-12- 10.41.19.223724 REFERW CBSTATS T 2011-05-12- 10.41.19.320754 USER CBSTATS T 2011-05-10- 15.54.00.320570 6 record(s) selected. [dmcbride@naboo mibe]$ dev_perl -MData::Dumper -MDBI -lE '$dbh=DBI->connect("dbi:DB2:CBSTATS") or die $DBI::errstr;$sth=$dbh- Show quoted text
>table_info("%","CBSTATS","%","VIEW");say Dumper($sth- >fetchall_arrayref())'
$VAR1 = []; Note that if I change the CBSTATS to %, I see all the system tables, but not any in the CBSTATS schema. This is definitely somewhat odd even though as you can see above there are definitely tables in that schema.
Hi Darin, You have specified the table type as VIEW hence the behaviour. Specify the type as TABLE and you should be able to get the list of tables in schema CBSTATS. -- Thanks Praveen IBM OpenSource Application Development Team India Software Labs, Bangalore (India)
On Mon Oct 08 04:14:40 2012, IBMTORDB2 wrote: Show quoted text
> Hi Darin, > > You have specified the table type as VIEW hence the behaviour. Specify > the type as TABLE and you should be able to get the list of tables in > schema CBSTATS. >
Gah! I really shouldn't respond to these things after a big turkey dinner. Thanks, you're right, it works. (I had most of this in my bash history, so I just made modifications there, but apparently didn't pay attention to the fourth field.)
Yeah, understandable. I will go ahead and make a release of the new version including this fix and the for the issue 77414 ASAP -- Thanks Praveen IBM OpenSource Application Development Team India Software Labs, Bangalore (India)
Fix available in version 1.85 -- Thanks Praveen IBM OpenSource Application Development Team India Software Labs, Bangalore (India)