From: Peter Rabbitson Date: Thu, 22 Mar 2012 08:42:24 +0000 (+0100) Subject: Remove all "magic number" DBI get_info calls from the codebase X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=af1f4f842ae446a3339b92b33851ea80c928f17a;p=dbsrgits%2FDBIx-Class-Historic.git Remove all "magic number" DBI get_info calls from the codebase --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 7a43db2..1566fec 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -16,6 +16,7 @@ use Context::Preserve 'preserve_context'; use Try::Tiny; use overload (); use Data::Compare (); # no imports!!! guard against insane architecture +use DBI::Const::GetInfoType (); # no import of retarded global hash use namespace::clean; # default cursor class, overridable in connect_info attributes @@ -1106,12 +1107,18 @@ sub _server_info { } sub _get_server_version { - shift->_dbh_get_info(18); + shift->_dbh_get_info('SQL_DBMS_VER'); } sub _dbh_get_info { my ($self, $info) = @_; + if ($info =~ /[^0-9]/) { + $info = $DBI::Const::GetInfoType::GetInfoType{$info}; + $self->throw_exception("Info type '$_[1]' not provided by DBI::Const::GetInfoType") + unless defined $info; + } + return try { $self->_get_dbh->get_info($info) } || undef; } diff --git a/lib/DBIx/Class/Storage/DBI/ADO.pm b/lib/DBIx/Class/Storage/DBI/ADO.pm index 577d2d3..8cca22d 100644 --- a/lib/DBIx/Class/Storage/DBI/ADO.pm +++ b/lib/DBIx/Class/Storage/DBI/ADO.pm @@ -22,7 +22,7 @@ should be transparent to the user. sub _rebless { my $self = shift; - my $dbtype = $self->_dbh_get_info(17); + my $dbtype = $self->_dbh_get_info('SQL_DBMS_NAME'); if (not $dbtype) { warn "Unable to determine ADO driver, failling back to generic support.\n"; diff --git a/lib/DBIx/Class/Storage/DBI/DB2.pm b/lib/DBIx/Class/Storage/DBI/DB2.pm index aea773f..7634eb6 100644 --- a/lib/DBIx/Class/Storage/DBI/DB2.pm +++ b/lib/DBIx/Class/Storage/DBI/DB2.pm @@ -18,7 +18,7 @@ sub sql_name_sep { my $v = $self->next::method(@_); if (! defined $v and ! @_) { - $v = $self->next::method($self->_dbh_get_info(41) || '.'); + $v = $self->next::method($self->_dbh_get_info('SQL_QUALIFIER_NAME_SEPARATOR') || '.'); } return $v; diff --git a/lib/DBIx/Class/Storage/DBI/ODBC.pm b/lib/DBIx/Class/Storage/DBI/ODBC.pm index 0f3259e..fec6613 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC.pm @@ -7,7 +7,7 @@ use mro 'c3'; sub _rebless { my ($self) = @_; - if (my $dbtype = $self->_dbh_get_info(17)) { + if (my $dbtype = $self->_dbh_get_info('SQL_DBMS_NAME')) { # Translate the backend name into a perl identifier $dbtype =~ s/\W/_/gi; my $subclass = "DBIx::Class::Storage::DBI::ODBC::${dbtype}"; diff --git a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm index 7aff37c..e94c938 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm @@ -287,7 +287,7 @@ sub using_freetds { $dsn = '' if ref $dsn eq 'CODE'; return 1 if $dsn =~ /driver=FreeTDS/i - || ($self->_dbh_get_info(6)||'') =~ /tdsodbc/i; + || ($self->_dbh_get_info('SQL_DRIVER_NAME')||'') =~ /tdsodbc/i; return 0; } diff --git a/lib/DBIx/Class/Storage/DBI/mysql.pm b/lib/DBIx/Class/Storage/DBI/mysql.pm index a0c0b52..dc7ff90 100644 --- a/lib/DBIx/Class/Storage/DBI/mysql.pm +++ b/lib/DBIx/Class/Storage/DBI/mysql.pm @@ -58,7 +58,7 @@ sub sql_maker { my $maker = $self->next::method (@_); # mysql 3 does not understand a bare JOIN - my $mysql_ver = $self->_dbh_get_info(18); + my $mysql_ver = $self->_dbh_get_info('SQL_DBMS_VER'); $maker->{_default_jointype} = 'INNER' if $mysql_ver =~ /^3/; } diff --git a/t/53lean_startup.t b/t/53lean_startup.t index f1752f4..30f1d90 100644 --- a/t/53lean_startup.t +++ b/t/53lean_startup.t @@ -51,6 +51,7 @@ BEGIN { Data::Compare DBI + DBI::Const::GetInfoType SQL::Abstract Carp diff --git a/t/71mysql.t b/t/71mysql.t index b4f01f4..c656a7f 100644 --- a/t/71mysql.t +++ b/t/71mysql.t @@ -173,15 +173,10 @@ $schema->populate ('BooksInLibrary', [ } SKIP: { - my $mysql_version = $dbh->get_info( $GetInfoType{SQL_DBMS_VER} ); - skip "Cannot determine MySQL server version", 1 if !$mysql_version; + my $norm_version = $schema->storage->_server_info->{normalized_dbms_version} + or skip "Cannot determine MySQL server version", 1; - my ($v1, $v2, $v3) = $mysql_version =~ /^(\d+)\.(\d+)(?:\.(\d+))?/; - skip "Cannot determine MySQL server version", 1 if !$v1 || !defined($v2); - - $v3 ||= 0; - - if( ($v1 < 5) || ($v1 == 5 && $v2 == 0 && $v3 <= 3) ) { + if ($norm_version < 5.000003_01) { $test_type_info->{charfield}->{data_type} = 'VARCHAR'; } diff --git a/t/72pg.t b/t/72pg.t index 5e2f08f..5e4ec84 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -91,14 +91,12 @@ DBICTest::Schema->load_classes( map {s/.+:://;$_} @test_classes ) if @test_class # check if we indeed do support stuff my $test_server_supports_insert_returning = do { - my $v = DBICTest::Schema->connect($dsn, $user, $pass) - ->storage - ->_get_dbh - ->get_info(18); - $v =~ /^(\d+)\.(\d+)/ - or die "Unparseable Pg server version: $v\n"; - - ( sprintf ('%d.%d', $1, $2) >= 8.2 ) ? 1 : 0; + + my $si = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_server_info; + die "Unparseable Pg server version: $si->{dbms_version}\n" + unless $si->{normalized_dbms_version}; + + $si->{normalized_dbms_version} < 8.002 ? 0 : 1; }; is ( DBICTest::Schema->connect($dsn, $user, $pass)->storage->_use_insert_returning, diff --git a/t/73oracle.t b/t/73oracle.t index 7028e95..1866a3d 100644 --- a/t/73oracle.t +++ b/t/73oracle.t @@ -74,11 +74,9 @@ DBICTest::Schema::Track->load_components('PK::Auto::Oracle'); # check if we indeed do support stuff my $v = do { - my $v = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_dbh_get_info(18); - $v =~ /^(\d+)\.(\d+)/ - or die "Unparseable Oracle server version: $v\n"; - - sprintf('%d.%03d', $1, $2); + my $si = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_server_info; + $si->{normalized_dbms_version} + or die "Unparseable Oracle server version: $si->{dbms_version}\n"; }; my $test_server_supports_only_orajoins = $v < 9; diff --git a/t/73oracle_blob.t b/t/73oracle_blob.t index 46d91f1..c94cec3 100644 --- a/t/73oracle_blob.t +++ b/t/73oracle_blob.t @@ -24,12 +24,11 @@ $ENV{NLS_COMP} = "BINARY"; $ENV{NLS_LANG} = "AMERICAN"; my $v = do { - my $v = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_dbh_get_info(18); - $v =~ /^(\d+)\.(\d+)/ - or die "Unparseable Oracle server version: $v\n"; - - sprintf('%d.%03d', $1, $2); + my $si = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_server_info; + $si->{normalized_dbms_version} + or die "Unparseable Oracle server version: $si->{dbms_version}\n"; }; + ########## # the recyclebin (new for 10g) sometimes comes in the way my $on_connect_sql = $v >= 10 ? ["ALTER SESSION SET recyclebin = OFF"] : []; diff --git a/t/745db2.t b/t/745db2.t index 573fe0e..12e7045 100644 --- a/t/745db2.t +++ b/t/745db2.t @@ -20,10 +20,11 @@ plan skip_all => 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test' my $schema = DBICTest::Schema->connect($dsn, $user, $pass); +my $name_sep = $schema->storage->_dbh_get_info('SQL_QUALIFIER_NAME_SEPARATOR'); + my $dbh = $schema->storage->dbh; # test RNO and name_sep detection -my $name_sep = $dbh->get_info(41); is $schema->storage->sql_maker->name_sep, $name_sep, 'name_sep detection'; diff --git a/t/sqlmaker/quotes/quotes.t b/t/sqlmaker/quotes/quotes.t index 0b6716a..1566a7d 100644 --- a/t/sqlmaker/quotes/quotes.t +++ b/t/sqlmaker/quotes/quotes.t @@ -11,8 +11,6 @@ use_ok('DBICTest'); use_ok('DBIC::DebugObj'); my $schema = DBICTest->init_schema(); -#diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/)); - $schema->storage->sql_maker->quote_char('`'); $schema->storage->sql_maker->name_sep('.'); diff --git a/t/sqlmaker/quotes/quotes_newstyle.t b/t/sqlmaker/quotes/quotes_newstyle.t index 6d448ea..c122517 100644 --- a/t/sqlmaker/quotes/quotes_newstyle.t +++ b/t/sqlmaker/quotes/quotes_newstyle.t @@ -11,8 +11,6 @@ use_ok('DBIC::DebugObj'); my $schema = DBICTest->init_schema(); -#diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/)); - my $dsn = $schema->storage->_dbi_connect_info->[0]; $schema->connection( $dsn,