new in CGI::Session::Driver::postgredsql nonexisting

I

IDK

I've been trying all day to make sessions in perl work.

This is the error message I get:

[Thu Jun 28 20:11:25 2007] login: (in cleanup) Can't locate
object method "new" via package "CGI::Session::Driver::postgredsql"
at /usr/share/perl5/CGI/Session.pm line 113 during global destruction.
From the code:
*********************************************************
sub openDB
{
#open db
$dbh = DBI->connect("dbi:pg:dbname=zerus;host=localhost;port=5432",
"*", "*");

if ( !defined $dbh ) {
die "Cannot connect to database!\n";
}
}


openDB;

$session = new CGI::Session("driver:postgredsql;id:md5", undef,
{Handle=>$dbh, $
$CGISESSID = $session->id();
print $session->header();
....
*********************************************************

I cannot find anything wrong with my code, and I've done exactly as
the docs say, so I suspect that there's something wrong with
Session.pm ...
If so, where should I turn to report this bug?
 
G

goodgautam

I've been trying all day to make sessions in perl work.

This is the error message I get:

[Thu Jun 28 20:11:25 2007] login: (in cleanup) Can't locate
object method "new" via package "CGI::Session::Driver::postgredsql"
at /usr/share/perl5/CGI/Session.pm line 113 during global destruction.
From the code:

*********************************************************
sub openDB
{
#open db
$dbh = DBI->connect("dbi:pg:dbname=zerus;host=localhost;port=5432",
"*", "*");

if ( !defined $dbh ) {
die "Cannot connect to database!\n";
}

}

openDB;

$session = new CGI::Session("driver:postgredsql;id:md5", undef,
{Handle=>$dbh, $
$CGISESSID = $session->id();
print $session->header();
...
*********************************************************

I cannot find anything wrong with my code, and I've done exactly as
the docs say, so I suspect that there's something wrong with
Session.pm ...
If so, where should I turn to report this bug?

In your code the first param being passed to CGI::Session's
constructor reads : "driver:postgredsql;id:md5" ..
Is that a typo in the code too ( s~postgredsql~postgresql~; ) ? I
think it should be like driver:postgresql ...
http://search.cpan.org/dist/CGI-Session/lib/CGI/Session/Driver/postgresql.pm
 
I

IDK

In your code the first param being passed to CGI::Session's
constructor reads : "driver:postgredsql;id:md5" ..
Is that a typo in the code too ( s~postgredsql~postgresql~; ) ? I
think it should be like driver:postgresql ...http://search.cpan.org/dist/CGI-Session/lib/CGI/Session/Driver/postgr...

Wow, that's it!
Thanks!


But now it gives me another error:

[Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't connect to
data source '' because I can't work out what driver to use (it doesn't
seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is
not set) at /usr/share/perl5/CGI/Session/Driver/DBI.pm line 26
[Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't call method
"commit" on unblessed reference at /usr/share/perl5/CGI/Session/Driver/
DBI.pm line 130 during global destruction.
 
J

J. Gleixner

IDK said:
Wow, that's it!
Thanks!


But now it gives me another error:

Now you should do some debugging before posting another error.
[Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't connect to
data source '' because I can't work out what driver to use (it doesn't
seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is
not set) at /usr/share/perl5/CGI/Session/Driver/DBI.pm line 26
[Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't call method
"commit" on unblessed reference at /usr/share/perl5/CGI/Session/Driver/
DBI.pm line 130 during global destruction.

Read the docs for DBI's connect method, your data source isn't correct,
just as the error is telling you.
 
I

IDK

Wow, that's it!
Thanks!
But now it gives me another error:

Now you should do some debugging before posting another error.


[Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't connect to
data source '' because I can't work out what driver to use (it doesn't
seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is
not set) at /usr/share/perl5/CGI/Session/Driver/DBI.pm line 26
[Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't call method
"commit" on unblessed reference at /usr/share/perl5/CGI/Session/Driver/
DBI.pm line 130 during global destruction.

Read the docs for DBI's connect method, your data source isn't correct,
just as the error is telling you.

I've been debugging that exact error all day, but only recently got
some
progress and found that session.pm was buggy...

I can access other databases with the same DBI handle.

If I replace all the session code with:
$cgi = new CGI;
print header();

Everything works fine, but my goal is to use sessions.
 
G

gautam chekuri

Now you should do some debugging before posting another error.
[Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't connect to
data source '' because I can't work out what driver to use (it doesn't
seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is
not set) at /usr/share/perl5/CGI/Session/Driver/DBI.pm line 26
[Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't call method
"commit" on unblessed reference at /usr/share/perl5/CGI/Session/Driver/
DBI.pm line 130 during global destruction.

Niklas,

Are you sure you are passing the all the params correctly in your
program ?

I use CGI::Session version 4.20 .. and it all works fine ..
[root@deepdark gautam]# perl -MCGI::Session -e 'print
$CGI::Session::VERSION, "\n";'
4.20

If you are sure that your program is correct, you might want to run it
under the debugger and
see what arguments are being passed to DBI->connect( ) from the code
in /usr/share/perl5/CGI/Session/Driver/DBI.pm at line 26

One thing that we can be sure of from the error msg you pasted is that
DBI->connect didn't get its params correctly ...

- Gautam
 
I

IDK

[Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't connect to
data source '' because I can't work out what driver to use (it doesn't
seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is
not set) at /usr/share/perl5/CGI/Session/Driver/DBI.pm line 26
[Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't call method
"commit" on unblessed reference at /usr/share/perl5/CGI/Session/Driver/
DBI.pm line 130 during global destruction.

Niklas,

Are you sure you are passing the all the params correctly in your
program ?

I use CGI::Session version 4.20 .. and it all works fine ..
[root@deepdark gautam]# perl -MCGI::Session -e 'print
$CGI::Session::VERSION, "\n";'
4.20

If you are sure that your program is correct, you might want to run it
under the debugger and
see what arguments are being passed to DBI->connect( ) from the code
in /usr/share/perl5/CGI/Session/Driver/DBI.pm at line 26

One thing that we can be sure of from the error msg you pasted is that
DBI->connect didn't get its params correctly ...

- Gautam

A conclusion I got to some time ago was that somehow my parameters
don't
get to the func:
package CGI::Session::Driver::DBI;

sub init {
my $self = shift;
if ( defined $self->{Handle} ) {
...
}
else {
line 26
}
}

And my line:
$session = new CGI::Session("driver:postgresql;id:md5", undef,
{Handle=>$dbh, ColumnType=>"binary"});

{Handle} doesn't seem to get to init, and as I'm not very good at
perl, I don't know why...

The dbh handle is working, and I've written the session code exactly
as instructed by
the docs, so my conclusion is that either the docs or libraries are
wrong. But I may
have misinterpreted the docs...
 
J

J. Gleixner

IDK said:
$session = new CGI::Session("driver:postgresql;id:md5", undef,
{Handle=>$dbh, ColumnType=>"binary"});

I don't use it, however to try to help you, I scanned the
documentation for the current CGI::Session on CPAN and this
might be of interest:

Following data source components are supported:

driver - CGI::Session driver. Available drivers are file, db_file, mysql
and sqlite.


If there is a driver for PostgreSQL, it's not mentioned.

Also,

SUPPORT

If you need help using CGI::Session consider the mailing list. You can
ask the list by sending your questions to
(e-mail address removed) .

You can subscribe to the mailing list at
https://lists.sourceforge.net/lists/listinfo/cgi-session-user .

{Handle} doesn't seem to get to init, and as I'm not very good at
perl, I don't know why...

Either do we.


There's no mention of Handle or ColumnType in the documentation, that I
could see.
The dbh handle is working, and I've written the session code exactly
as instructed by
the docs, so my conclusion is that either the docs or libraries are
wrong. But I may have misinterpreted the docs...

Post a short example. <10 lines should cover it. We don't need to
see the code from CGI::Session, only your code and what errors
you receive.
 
G

gautam chekuri

I don't use it, however to try to help you, I scanned the
documentation for the current CGI::Session on CPAN and this
might be of interest:

Following data source components are supported:

driver - CGI::Session driver. Available drivers are file, db_file, mysql
and sqlite.

If there is a driver for PostgreSQL, it's not mentioned.

Also,

SUPPORT

If you need help using CGI::Session consider the mailing list. You can
ask the list by sending your questions to
(e-mail address removed) .

You can subscribe to the mailing list athttps://lists.sourceforge.net/lists/listinfo/cgi-session-user.




Either do we.

There's no mention of Handle or ColumnType in the documentation, that I
could see.




Post a short example. <10 lines should cover it. We don't need to
see the code from CGI::Session, only your code and what errors
you receive.

well.. the pgsql driver is a third party implementation based on
CGI::Session::Driver
http://search.cpan.org/~sherzodr/CGI-Session-4.10/lib/CGI/Session/Driver/postgresql.pm

Niklas, as suggested by J.G a short example ( without typos etc.. )
would be very helpfull..
i would suggest you turn on strict and warnings in this example..
Such small examples act as test cases, that help in understanding the
problem...

for eg, I did this and I see that things are working fine :

[root@deepdark gautam]# cat ./session.pl
#!/usr/bin/perl
use strict;
use warnings;

use CGI::Session;
use DBI;

my $dbh = DBI->connect("dbi:pg:dbname=test;host=localhost;port=5432",
"USERNAME", "");
if ( !defined $dbh ) {
die "Cannot connect to database!\n";
}

my $session = new CGI::Session(
"driver:postgresql:id:md5",
undef,
{
Handle => $dbh,
ColumnType => "binary",
}
);

my $CGISESSID = $session->id();
print $session->header();
[root@deepdark gautam]# ./session.pl
Set-Cookie: CGISESSID=1d75a870d52ed9c6064cdb52e406ea49; path=/
Date: Thu, 28 Jun 2007 22:41:23 GMT
Content-Type: text/html; charset=ISO-8859-1

[root@deepdark gautam]#
 
I

IDK

I don't use it, however to try to help you, I scanned the
documentation for the current CGI::Session on CPAN and this
might be of interest:
Following data source components are supported:
driver - CGI::Session driver. Available drivers are file, db_file, mysql
and sqlite.
If there is a driver for PostgreSQL, it's not mentioned.


If you need help using CGI::Session consider the mailing list. You can
ask the list by sending your questions to
(e-mail address removed) .
You can subscribe to the mailing list athttps://lists.sourceforge.net/lists/listinfo/cgi-session-user.
Either do we.
There's no mention of Handle or ColumnType in the documentation, that I
could see.
Post a short example. <10 lines should cover it. We don't need to
see the code from CGI::Session, only your code and what errors
you receive.

well.. the pgsql driver is a third party implementation based on
CGI::Session::Driverhttp://search.cpan.org/~sherzodr/CGI-Session-4.10/lib/CGI/Session/Dri...

Niklas, as suggested by J.G a short example ( without typos etc.. )
would be very helpfull..
i would suggest you turn on strict and warnings in this example..
Such small examples act as test cases, that help in understanding the
problem...

for eg, I did this and I see that things are working fine :

[root@deepdark gautam]# cat ./session.pl
#!/usr/bin/perl
use strict;
use warnings;

use CGI::Session;
use DBI;

my $dbh = DBI->connect("dbi:pg:dbname=test;host=localhost;port=5432",
"USERNAME", "");
if ( !defined $dbh ) {
die "Cannot connect to database!\n";

}

my $session = new CGI::Session(
"driver:postgresql:id:md5",
undef,
{
Handle => $dbh,
ColumnType => "binary",
}
);

How can the above code work?
"driver:postgresql:id:md5" should be "driver:postgresql;id:md5".
Atleast as I interpret the docs...

The postgres driver is included my package.

With strict I only get loads of:
login: Global symbol "$s" requires explicit package name at ./login
line 25.
And I always has warn on.

Here's all my code:
****************************** login *************************
#!/usr/bin/perl -w

use funcs;
use Digest::SHA1 qw(sha1_base64);
#use strict;


makeHTML('register');

if(!param('user')){
print '<form name="input" action="login" method="post">
Username: <input type="text" name="user"><BR>
Password: <input type="password" name="password"><BR>
<input type="submit" value="Submit">
</form>';
}else{
$user = param('user');
$pass = param('password');
$digest = sha1_base64($pass);

$s = sqlQuerry("SELECT id, pass FROM zerus.players WHERE
name='$user'")
or die "cannot prepare";

@data = $s->fetchrow();

if($data[1] eq $digest){
print "\n<H1>You've successfully logged on</H1>\n"
} else {
print "\n<H1>Wrong password, or no user with that name</H1>
\n"
}

$s->finish or die "Cannot finnish";
}

finnishUp();

********************************** funcs.pm
************************************
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
use DBI;
#use Apache::Session::postgres;

use DBD::pg qw:)pg_types);
use CGI::Session;
use CGI::Session::Driver::postgresql;
use CGI::Session::ID::md5;
use CGI::Session::Serialize::default;

sub openDB
{
#open db
$dbh = DBI->connect("dbi:pg:dbname=zerus;host=localhost;port=5432",
"*", "*");

if ( !defined $dbh ) {
die "Cannot connect to database!\n";
}
}
sub makeHTML
{
# Get the CGI form data
print "<HTML><TITLE>${_[0]}</TITLE><BODY bgcolor='\#000000'
text='\#aaa666'>";
}


sub sqlQuerry
{
$sth = $dbh->prepare($_[0]);

if ( !defined $sth ) {
die "Cannot prepare statement: $DBI::errstr\n";
}

$sth->execute;

$sth;
}

sub finnishUp
{
print end_html();
print $@, "<BR>\n";
if(defined($DBI)){ print $DBI::errstr, "<BR>\n"; }
eval { $dbh->disconnect; };
}

openDB;

$session = new CGI::Session("driver:postgresql;id:md5", undef,
{Handle=>$dbh, ColumnType=>"binary"});

$CGISESSID = $session->id();
# send proper HTTP header with cookies:
print $session->header();


#$cgi = new CGI;
#print header();

*************************************************************************

If I replace all the session stuff with the commented out stuff, I get
no
errors.

This is the output:
Set-Cookie: CGISESSID=d07adf2adfd6ded310af61f101c1bed1; path=/
Date: Thu, 28 Jun 2007 23:13:37 GMT
Content-Type: text/html; charset=ISO-8859-1

<HTML><TITLE>register</TITLE><BODY bgcolor='#000000'
text='#aaa666'><form name="input" action="login" method="post">
Username: <input type="text" name="user"><BR>
Password: <input type="password" name="password"><BR>
<input type="submit" value="Submit">
</form>
</body>
</html><BR>
[Fri Jun 29 01:13:37 2007] login: (in cleanup) Can't connect to
data source '' because I can't work out what driver to use (it doesn't
seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is
not set) at /usr/share/perl5/CGI/Session/Driver/DBI.pm line 26
[Fri Jun 29 01:13:37 2007] login: (in cleanup) Can't call method
"commit" on unblessed reference at /usr/share/perl5/CGI/Session/Driver/
DBI.pm line 130 during global destruction.

*************************************************************
 
G

gautam chekuri

How can the above code work?
"driver:postgresql:id:md5" should be "driver:postgresql;id:md5".
Atleast as I interpret the docs...

Well that works because parse_dsn in CGI::Session does the following :
my %dsn_map = map { split /:/ } (split /;/, $dsn_str);
Hence, it work for both : and ; ..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top