DBI under SOAP/mod_perl

Hello All,

(This is perl, v5.8.8). Sorry if this is a bit specialised (EG not v.
beginner) but I'm getting rather frustrated and could use some help.


I have a strange issue with a DBI/DBD::SQLite. I have a class that
creates an instance of DBI, EG:

package Foo;

use strict;
use warnings;
use DBI;
use Carp;

my $DEBUG = 1

sub new {
my $class = shift;
my %args = [at] _;
my $self = {};
$self->{debug} = $args{debug} || $DEBUG;
.....
.....
$self->{dbh} = DBI->connect($dsn,'','', { PrintError=>1,
PrintWarn=>1} ) or confess "Can't connect: DBI->errstr: $!\n";

bless $self, $class;
return $self;
}

sub dbh {
return $_[0]->{dbh};
}

sub get_record {
my $self = shift;

my $sql = q(SELECT * FROM records WHERE path = ?);
my $sth = $self->dbh->prepare($sql);
print STDERR "STH=$sth DBH=".$self->dbh."\n";
$sth->execute($self->file) or confess "Can't prepare: ".
$self->dbh->errstr."\n";
while (my $href = $sth->fetchrow_hashref ) {
print STDERR "Record found $href->{id} Rows=". $sth->rows."\n"
if $self->{debug};
$self->{record} = $href;
}
}

....

1;
###

When I create an instance from a command-line script all works fine.

my $foo = Foo->new();
$foo->get_record();

This prints: "STH=DBI::st=HASH(0x92b3f2c) DBH=DBI::db=HASH(0x92b1ee4)"


The problem arise when I create an instance under a SOAP::Lite
package. The package is running under mod_perl's Registry. In the
HTTPD logs I see:

DBD::SQLite::db prepare failed: not an error at /etc/perl/Foo.pm line 190.
Use of uninitialized value in concatenation (.) or string at
/etc/perl/Foo.pm line 191 (#2)
STH= DBH=DBI::db=HASH(0x8a1568c)


I suspect this is an oddity with mod_perl and SOAP but I can't see a
why through. Does anyone have any ideas what I might try? I can't
change the architecture and have to make this work within what's
installed.


Any ideas appreciated.
Thanx,
Dp,

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
dermot [ Fr, 16 Juli 2010 18:29 ] [ ID #2044698 ]

Re: DBI under SOAP/mod_perl

Does the $dsn contain the full path to the database?

--
Octavian

----- Original Message -----
From: "Dermot" <paikkos [at] gmail.com>
To: "Perl Beginners" <beginners [at] perl.org>
Sent: Friday, July 16, 2010 7:29 PM
Subject: DBI under SOAP/mod_perl


> Hello All,
>
> (This is perl, v5.8.8). Sorry if this is a bit specialised (EG not v.
> beginner) but I'm getting rather frustrated and could use some help.
>
>
> I have a strange issue with a DBI/DBD::SQLite. I have a class that
> creates an instance of DBI, EG:
>
> package Foo;
>
> use strict;
> use warnings;
> use DBI;
> use Carp;
>
> my $DEBUG = 1
>
> sub new {
> my $class = shift;
> my %args = [at] _;
> my $self = {};
> $self->{debug} = $args{debug} || $DEBUG;
> .....
> .....
> $self->{dbh} = DBI->connect($dsn,'','', { PrintError=>1,
> PrintWarn=>1} ) or confess "Can't connect: DBI->errstr: $!\n";
>
> bless $self, $class;
> return $self;
> }
>
> sub dbh {
> return $_[0]->{dbh};
> }
>
> sub get_record {
> my $self = shift;
>
> my $sql = q(SELECT * FROM records WHERE path = ?);
> my $sth = $self->dbh->prepare($sql);
> print STDERR "STH=$sth DBH=".$self->dbh."\n";
> $sth->execute($self->file) or confess "Can't prepare: ".
> $self->dbh->errstr."\n";
> while (my $href = $sth->fetchrow_hashref ) {
> print STDERR "Record found $href->{id} Rows=". $sth->rows."\n"
> if $self->{debug};
> $self->{record} = $href;
> }
> }
>
> ...
>
> 1;
> ###
>
> When I create an instance from a command-line script all works fine.
>
> my $foo = Foo->new();
> $foo->get_record();
>
> This prints: "STH=DBI::st=HASH(0x92b3f2c) DBH=DBI::db=HASH(0x92b1ee4)"
>
>
> The problem arise when I create an instance under a SOAP::Lite
> package. The package is running under mod_perl's Registry. In the
> HTTPD logs I see:
>
> DBD::SQLite::db prepare failed: not an error at /etc/perl/Foo.pm line 190.
> Use of uninitialized value in concatenation (.) or string at
> /etc/perl/Foo.pm line 191 (#2)
> STH= DBH=DBI::db=HASH(0x8a1568c)
>
>
> I suspect this is an oddity with mod_perl and SOAP but I can't see a
> why through. Does anyone have any ideas what I might try? I can't
> change the architecture and have to make this work within what's
> installed.
>
>
> Any ideas appreciated.
> Thanx,
> Dp,
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
> For additional commands, e-mail: beginners-help [at] perl.org
> http://learn.perl.org/
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 5290 (20100718) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>


__________ Information from ESET NOD32 Antivirus, version of virus signature database 5290 (20100718) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Octavian Rasnita [ Mo, 19 Juli 2010 07:07 ] [ ID #2044772 ]

Re: DBI under SOAP/mod_perl

Hi Octavian,

On 19 July 2010 06:07, Octavian Rasnita <orasnita [at] gmail.com> wrote:
> Does the $dsn contain the full path to the database?

Yes. The dsn line is declared like this:

#### DBI SQLite3 ###
my $dsn = 'dbi:SQLite:dbname=/var/db/MyApp/myapp.db';



It's outside the constructor which I am not sure is good practise. I
created the /var/db/MyApp directory and made it's owner apache:apache
with permissions at 0777:

drwxrwxrwx 2 apache apache 4096 Jul 16 16:38 /var/db/MyApp/
-rwxrwxrwx 1 apache apache 97907712 Jul 16 11:30 myapp.db


I have tried in enable trace but I am not getting any the details to
the httpd log. This is all I see in the logs:

7:24:1 [19/7/2010] About to updateDB for c006/9219
[Mon Jul 19 17:24:01 2010] -e: DBD::SQLite::db prepare failed: not an
error at /etc/perl/Foo.pm line 186.
[Mon Jul 19 17:24:01 2010] -e: Use of uninitialized value in
concatenation (.) or string at /etc/perl/Foo.pm line 187.
STH= DBH=DBI::db=HASH(0x9d175c8)

Which refers to these lines:

my $sql = qq(SELECT * FROM lowres where path = ?);
my $sth = $self->dbh->prepare($sql) or cluck "Error happening\n" .
$self->dbh->errstr ." DBI->errstr\n"; # line 187
print STDERR "STH=$sth DBH=".$self->dbh."\n";
$sth->execute($self->file) or confess "Can't prepare: ".
$self->dbh->errstr."\n";
while (my $href = $sth->fetchrow_hashref ) {
print STDERR "Record found $href->{id} Rows=". $sth->rows."\n"
if $self->{debug};
$self->{image} = $href;
}


I did finally manage to get my DBI trace to appear in the logs (needed
to restart the server) but the details are not much more revealing.
Still the statement handler is undef before execution and I can't not
see any reference to the dbname file. The most telling messge is "
DBI::st=HASH(0x9d7002c) ignored - handle not initialised"

dbih_setup_attrib(DBI::st=HASH(0x9d7002c), FetchHashKeyName,
DBI::db=HASH(0x9d6fd5c)) 'NAME' (already defined)
dbih_setup_attrib(DBI::st=HASH(0x9d7002c), HandleSetErr,
DBI::db=HASH(0x9d6fd5c)) undef (not defined)
dbih_setup_attrib(DBI::st=HASH(0x9d7002c), HandleError,
DBI::db=HASH(0x9d6fd5c)) undef (not defined)
dbih_setup_attrib(DBI::st=HASH(0x9d7002c), ReadOnly,
DBI::db=HASH(0x9d6fd5c)) undef (not defined)
dbih_setup_attrib(DBI::st=HASH(0x9d7002c), Profile,
DBI::db=HASH(0x9d6fd5c)) undef (not defined)
sqlite trace: prepare statement: SELECT * FROM lowres where path = ?
at dbdimp.c line 425
sqlite error 21 recorded: not an error at dbdimp.c line 435
>> DESTROY DISPATCH (DBI::st=HASH(0x9d7008c) rc1/1 [at] 1 g0
ima10004 pid#1086) at /etc/perl/Foo.pm line 187 via at
/etc/perl/Foo.pm line 187
<> DESTROY(DBI::st=HASH(0x9d7008c)) ignored for outer handle
(inner DBI::st=HASH(0x9d7002c) has ref cnt 1)
>> DESTROY DISPATCH (DBI::st=HASH(0x9d7002c) rc1/1 [at] 1 g0
ima10004 pid#1086) at /etc/perl/Foo.pm line 187 via at
/etc/perl/Foo.pm line 187
-> DESTROY for DBD::SQLite::st (DBI::st=HASH(0x9d7002c)~INNER) thr#8a2fb48
DESTROY for DBI::st=HASH(0x9d7002c) ignored - handle not initialised
ERROR: '21' 'not an error' (err#1)
<- DESTROY= undef at /etc/perl/Foo.pm line 187 via at
/etc/perl/Foo.pm line 187
DESTROY (dbih_clearcom) (sth 0x9d7002c, com 0x9f25b28, imp DBD::SQLite::st):
FLAGS 0x100111: COMSET Warn PrintError PrintWarn
ERR '21'
ERRSTR 'not an error'
PARENT DBI::db=HASH(0x9d6fd5c)
KIDS 0 (0 Active)
NUM_OF_FIELDS -1
NUM_OF_PARAMS 0
dbih_clearcom 0x9d7002c (com 0x9f25b28, type 3) done.

!! ERROR: '21' 'not an error' (err#0)
<- prepare= undef at /etc/perl/Foo.pm line 187 via at
/etc/perl/Foo.pm line 149
DBD::SQLite::db prepare failed: not an error at /etc/perl/Foo.pm line 187.
-> errstr in DBD::_::common for DBD::SQLite::db
(DBI::db=HASH(0x9d6fdbc)~0x9d6fd5c) thr#8a2fb48
ERROR: '21' 'not an error' (err#0)
<- errstr= 'not an error' at /etc/perl/Foo.pm line 187 via at
/etc/perl/Foo.pm line 149
Error happening
not an error DBI->errstr
at /etc/perl/Foo.pm line 187
SPL::Image::get_record('SPL::Image=HASH(0x9c00cc8)') called at
/etc/perl/Foo.pm line 149
SPL::Image::_verify('SPL::Image=HASH(0x9c00cc8)') called at
/etc/perl/Foo.pm line 142
SPL::Image::verify('SPL::Image=HASH(0x9c00cc8)') called at
/etc/perl/Foo.pm line 110
SPL::Image::update_or_create('Foo=HASH(0x9c00cc8)') called at
/var/www/soap/ProcessImage.pl line 123
Images::updateDB('spl_number', 'c006/9219') called at
/var/www/soap/ProcessImage.pl line 84
Images::ProcessTiff('Images', '/transfer/c0069219.tif') called at
/usr/lib/perl5/site_perl/5.8.8/SOAP/Lite.pm line 2569
eval {...} called at /usr/lib/perl5/site_perl/5.8.8/SOAP/Lite.pm line 2557
eval {...} called at /usr/lib/perl5/site_perl/5.8.8/SOAP/Lite.pm line 2526
SOAP::Server::handle('SOAP::Transport::HTTP::CGI=HASH(0x9af7 094)',
'<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xs...')
called at /usr/lib/perl5/site_perl/5.8.8/SOAP/Transport/HTTP.pm line
327
SOAP::Transport::HTTP::Server::handle('SOAP::Transport::HTTP ::CGI=HASH(0x9af7094)')
called at /usr/lib/perl5/site_perl/5.8.8/SOAP/Transport/HTTP.pm line
423
SOAP::Transport::HTTP::CGI::handle('SOAP::Transport::HTTP::C GI=HASH(0x9af7094)')
called at /var/www/soap/ProcessImage.pl line 3
ModPerl::ROOT::ModPerl::Registry::var_www_soap_ProcessImage_ 2epl::handler('Apache2::RequestRec=SCALAR(0x90c7a9c)')
called at /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/Mod Perl/RegistryCooker.pm
line 203
eval {...} called at
/usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/Mod Perl/RegistryCooker.pm
line 203
ModPerl::RegistryCooker::run('ModPerl::Registry=HASH(0x90c40 54)')
called at /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/Mod Perl/RegistryCooker.pm
line 169
ModPerl::RegistryCooker::default_handler('ModPerl::Registry= HASH(0x90c4054)')
called at /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/Mod Perl/Registry.pm
line 30
ModPerl::Registry::handler('ModPerl::Registry',
'Apache2::RequestRec=SCALAR(0x90c7a9c)') called at -e line 0
eval {...} called at -e line 0
Use of uninitialized value in concatenation (.) or string at
/etc/perl/Foo.pm line 188 (#2)
STH= DBH=DBI::db=HASH(0x9d6fdbc)
-> DESTROY for DBD::SQLite::db (DBI::db=HASH(0x9d6fd5c)~INNER) thr#8a2fb48
ERROR: '21' 'not an error' (err#0)


I'm completely stuck at this point and am going to have to think about
work a around.

Thanx,
Dp.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
dermot [ Mo, 19 Juli 2010 18:19 ] [ ID #2044816 ]
Perl » gmane.comp.lang.perl.beginners » DBI under SOAP/mod_perl

Vorheriges Thema: Calling Exit from within a subroutine
Nächstes Thema: Perl stat script ... ???