Skip Menu |

This queue is for tickets about the CGI-Session CPAN distribution.

Report information
The Basics
Id: 19832
Status: resolved
Priority: 0/
Queue: CGI-Session

People
Owner: MARKSTOS [...] cpan.org
Requestors: ron [...] savage.net.au
Cc:
AdminCc:

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



Subject: Non-bug :-): Adding ODBC support to CGI::Session
I've added a test which looks for an ODBC DSN. Also, I've cleaned up the usage of env vars for these 3 tests, so they either use DBI_DSN/DBI_USER/DBI_PASS or they use env vars specialized for each test. Also, I've changes the spelling of CGISESS_*_PASSWORD to CGISESS_*_PASS to match both DBI_PASS and Rose::DB's spelling. I've patched the Makefile.PL too. I've tested this using ODBC to connect to both Oracle for Windows and PostgreSQL for Windows, using CGI::Session::Driver::odbc, and all tests pass, using CGI::Session V 4.14. In each case the test program was running under Windows.
Subject: g4_postgresql.t
# $Id: /mirror/cgi-session/trunk/t/g4_postgresql.t 220 2005-08-30T11:47:14.305150Z sherzodr $ use strict; use diagnostics; my %dsn; if ($ENV{DBI_DSN} && ($ENV{DBI_DSN} =~ m/^dbi:Pg:/)) { %dsn = ( DataSource => $ENV{DBI_DSN}, User => $ENV{DBI_USER}, Password => $ENV{DBI_PASS}, TableName => 'sessions' ); } else { %dsn = ( DataSource => $ENV{CGISESS_PG_DSN}, User => $ENV{CGISESS_PG_USER}, Password => $ENV{CGISESS_PG_PASS}, TableName => 'sessions' ); } use File::Spec; use Test::More; use CGI::Session::Test::Default; unless ( $dsn{DataSource} ) { plan(skip_all=>"DataSource is not known"); exit(0); } for ( "DBI", "DBD::Pg" ) { eval "require $_"; if ( $@ ) { plan(skip_all=>"$_ is NOT available"); exit(0); } } my $dbh = DBI->connect($dsn{DataSource}, $dsn{User}, $dsn{Password}, {RaiseError=>0, PrintError=>0}); unless ( $dbh ) { plan(skip_all=>"Couldn't establish connection with the PostgreSQL server"); exit(0); } my ($count) = $dbh->selectrow_array("SELECT COUNT(*) FROM $dsn{TableName}"); unless ( defined $count ) { unless( $dbh->do(qq| CREATE TABLE $dsn{TableName} ( id CHAR(32) NOT NULL PRIMARY KEY, a_session TEXT NULL )|) ) { plan(skip_all=>$dbh->errstr); exit(0); } } my $t = CGI::Session::Test::Default->new( dsn => "dr:postgresql", args=>{Handle=>$dbh, TableName=>$dsn{TableName}}); plan tests => $t->number_of_tests; $t->run();
Subject: g4_mysql.t
# $Id: /mirror/cgi-session/trunk/t/g4_mysql.t 272 2006-02-14T11:29:59.639693Z sherzodr $ use strict; use diagnostics; my %dsn; if ($ENV{DBI_DSN} && ($ENV{DBI_DSN} =~ m/^dbi:mysql:/)) { %dsn = ( DataSource => $ENV{DBI_DSN}, User => $ENV{DBI_USER}, Password => $ENV{DBI_PASS}, TableName => 'sessions' ); } else { %dsn = ( DataSource => $ENV{CGISESS_MYSQL_DSN}, User => $ENV{CGISESS_MYSQL_USER}, Password => $ENV{CGISESS_MYSQL_PASS}, Socket => $ENV{CGISESS_MYSQL_SOCKET}, TableName => 'sessions' ); } use File::Spec; use Test::More; use CGI::Session::Test::Default; for (qw/DBI DBD::mysql/) { eval "require $_"; if ( $@ ) { plan(skip_all=>"$_ is NOT available"); exit(0); } } require CGI::Session::Driver::mysql; my $dsnstring = CGI::Session::Driver::mysql->_mk_dsnstr(\%dsn); my $dbh; eval { $dbh = DBI->connect($dsnstring, $dsn{User}, $dsn{Password}, {RaiseError=>0, PrintError=>1}) }; if ( $@ ) { plan(skip_all=>"Couldn't establish connection with the MySQL server: " . (DBI->errstr || $@)); exit(0); } my $count; eval { ($count) = $dbh->selectrow_array("SELECT COUNT(*) FROM $dsn{TableName}") }; unless ( defined $count ) { unless( $dbh->do(qq| CREATE TABLE $dsn{TableName} ( id CHAR(32) NOT NULL PRIMARY KEY, a_session TEXT NULL )|) ) { plan(skip_all=>"Couldn't create $dsn{TableName}: " . $dbh->errstr); exit(0); } } my $t = CGI::Session::Test::Default->new( dsn => "dr:mysql", args=>{Handle=>$dbh, TableName=>$dsn{TableName}}); plan tests => $t->number_of_tests + 2; $t->run(); { # This was documented to work in 3.95 and should be supported for compatibility my $obj; eval { # test.sessions will refer to the same 'sessions' table but is a unique name to test with $CGI::Session::MySQL::TABLE_NAME = 'test.sessions'; my $avoid_warning = $CGI::Session::MySQL::TABLE_NAME; require CGI::Session::Driver::mysql; $obj = CGI::Session::Driver::mysql->new( {Handle=>$dbh} ); }; is($@,'', 'survived eval'); is($obj->table_name, 'test.sessions', "setting table name through CGI::Session::MySQL::TABLE_NAME works"); }
Subject: g4_odbc.t
# $Id: /mirror/cgi-session/trunk/t/g4_odbc.t 111 2006-06-06T06:06:06.060606Z Ron Savage $ use strict; use diagnostics; my %dsn; if ($ENV{DBI_DSN} && ($ENV{DBI_DSN} =~ m/^dbi:ODBC:/)) { %dsn = ( DataSource => $ENV{DBI_DSN}, User => $ENV{DBI_USER}, Password => $ENV{DBI_PASS}, TableName => 'sessions' ); } else { %dsn = ( DataSource => $ENV{CGISESS_ODBC_DSN}, User => $ENV{CGISESS_ODBC_USER}, Password => $ENV{CGISESS_ODBC_PASS}, TableName => 'sessions' ); } use File::Spec; use Test::More; use CGI::Session::Test::Default; for (qw/DBI DBD::ODBC/) { eval "require $_"; if ( $@ ) { plan(skip_all=>"$_ is NOT available"); exit(0); } } my $dbh; eval { $dbh = DBI->connect($dsn{DataSource}, $dsn{User}, $dsn{Password}, {RaiseError=>0, PrintError=>0, LongReadLen => 999}) }; if ( $@ ) { plan(skip_all=>"Couldn't establish connection with the ODBC driver: " . (DBI->errstr || $@)); exit(0); } my $count; eval { ($count) = $dbh->selectrow_array("SELECT COUNT(*) FROM $dsn{TableName}") }; unless ( defined $count ) { my($session_type) = $dsn{DataSource} =~ /Oracle/i ? 'long' : 'text'; unless( $dbh->do(qq| CREATE TABLE $dsn{TableName} ( id CHAR(32) NOT NULL PRIMARY KEY, a_session $session_type NULL )|) ) { plan(skip_all=>"Couldn't create $dsn{TableName}: " . $dbh->errstr); exit(0); } } my $t = CGI::Session::Test::Default->new( dsn => "dr:odbc", args=>{Handle=>$dbh, TableName=>$dsn{TableName}}); plan tests => $t->number_of_tests + 2; $t->run(); { # This was documented to work in 3.95 and should be supported for compatibility my $obj; eval { # test.sessions will refer to the same 'sessions' table but is a unique name to test with $CGI::Session::ODBC::TABLE_NAME = 'test.sessions'; my $avoid_warning = $CGI::Session::ODBC::TABLE_NAME; require CGI::Session::Driver::odbc; $obj = CGI::Session::Driver::odbc->new( {Handle=>$dbh} ); }; is($@,'', 'survived eval'); is($obj->table_name, 'test.sessions', "setting table name through CGI::Session::ODBC::TABLE_NAME works"); }
Subject: Makefile.PL
# $Id: /mirror/cgi-session/trunk/Makefile.PL 288 2006-03-09T11:08:34.672952Z tyler $ use strict; use Text::Wrap; use File::Spec; use lib './t/lib'; use ExtUtils::MakeMaker; print "-" x 40, "\n"; print fill("", "", <<'MESSAGE'); #### WARNING #### If you are using custom CGI::Session drivers they may not be compatible with the current driver specifications. You will need to make some changes to your drivers' code before proceeding with this installation to make it compatible with CGI::Session 4.x. Fortunately, current driver specifications are a lot easier to adapt to. Should you have any assistance re-coding your current drivers, please let me know. Current driver specs are documented in CGI/Session/Driver.pm #### TESTING ##### You are encouraged to run tests for the backend you will be using. The database backends that need a customized connection string won't run by default. To run them, some environment variables must be set. The simplest method is to use the standard "DBI_DSN/DBI_USER/DBI_PASS" environment variables. Otherwise, you can set these variables: MESSAGE print " For PostgreSQL: CGISESS_PG_DSN CGISESS_PG_USER CGISESS_PG_PASS For MySQL: CGISESS_MYSQL_DSN CGISESS_MYSQL_USER CGISESS_MYSQL_PASS CGISESS_MYSQL_SOCKET For ODBC: CGISESS_ODBC_DSN CGISESS_ODBC_USER CGISESS_ODBC_PASS Note: For Oracle the sessions table must be declared as: CREATE TABLE sessions ( id CHAR(32) NOT NULL PRIMARY KEY, a_session long NULL ) whereas for MySQL, PostgreSQL etc it will be declared as: CREATE TABLE sessions ( id CHAR(32) NOT NULL PRIMARY KEY, a_session text NULL ) To make the ODBC test work under Oracle, just declare a DSN containing /Oracle/i, e.g. CGISESS_ODBC_DSN=dbi:ODBC:oracle-test, so test t/g4_odbc.t can set the column type. Warning: ODBC takes 16 (sic) seconds to connect to Oracle Database XE for Windows, when the test program is running under Win2K, so be patient. WinXP is slightly faster. "; print "\n"; print "-" x 40, "\n"; WriteMakefile( NAME => 'CGI::Session', VERSION_FROM => 'lib/CGI/Session.pm', PREREQ_PM => { 'Digest::MD5' => undef, 'Data::Dumper' => undef, 'Test::More' => undef, 'Scalar::Util' => undef, }, ABSTRACT => 'Persistent session data in CGI applications', AUTHOR => 'Sherzod Ruzmetov <sherzodr@cpan.org>', clean => { FILES => [ 't/cgisess.*', 't/sessiondata' ] }, ); # # Creating place for test-scripts. Some of the scripts needs this to be present # mkdir(File::Spec->catfile('t', 'sessiondata')); package MY; use strict; sub postamble { return <<'MAKE_TEXT'; prepare_dist :: metafile manifest dist $(NOECHO) $(NOOP) MAKE_TEXT } sub libscan { my ($self, $path) = @_; return '' if $path =~ m/\.svn/; return $path; }
Although the title of this bug was about ODBC, most of the patches weren't. Still, I liked the changes and am applying them subversion now. It seems ODBC support has been released in its own driver, as seems best, so this ticket is resolvable on that count as well. Thanks for the contribution, Ron. Mark
Subject: Re: [rt.cpan.org #19832] Non-bug :-): Adding ODBC support to CGI::Session
Date: Thu, 26 Oct 2006 02:11:00 -0000 (UTC)
To: bug-CGI-Session [...] rt.cpan.org
From: "Ron Savage" <ron [...] savage.net.au>
Hi Mark Show quoted text
> Although the title of this bug was about ODBC, most of the patches > weren't. Still, I liked the changes and am applying them subversion now.
Thanx. Show quoted text
> It seems ODBC support has been released in its own driver, as seems > best, so this ticket is resolvable on that count as well.
Right. -- Ron Savage ron@savage.net.au http://savage.net.au/index.html