Re: DBI and hosts file entries

2017-06-06 Thread Davide Olivieri
Hi,

According to my experience with DBD::Sybase + Freetds, the name resolution
is done for the host names specified in the freetds.conf file.

The following code will try to create an handler object for the host+port
specified in the [ENGINEERING] section of the freetds.conf file

$dbh = DBI->connect("dbi:Sybase:server=ENGINEERING", $user, $passwd);

This is the content of  freetds.conf:

[ENGINEERING]
host = host.domain.com
port = 1433
tds version = 5.0

More information are available here:
http://www.freetds.org/userguide/freetdsconf.htm

Thank you.

Davide


2017-06-01 22:45 GMT+02:00 Chris Fedde :

> first you want to be sure that your host can connect to the remote host
> onn the right port.   You can use the telnet command to do that
>
>telnet server port
>
> where server is the name for the server in  your /etc/hosts file and port
> is the port number on the remote where sybase is listening.
> iirc the default for sybase is 2638.Also iirc DBD::Sybase expects
> freeTDS to be installed and configured.
>
> good luck
>
> On Thu, Jun 1, 2017 at 2:08 PM, Paul M via beginners 
> wrote:
>
>> I have a hosts entry that points to a specific IP address. It does not
>> appear that DBI:Sybase:server uses the /etc/hosts file? Is this correct?
>> Ping works fine in shell.
>> How would I point a server name to different IP addresses locally?
>> What does DBI use for name resolution?
>>
>> Thanks!
>>
>
>


Re: DBI and hosts file entries

2017-06-01 Thread Bruce Ferrell

Hi Paul,

I'm going to assume you're on a Linux system.  I have exactly that configuration on my system (name to ip address mapping in /etc/hosts) and here's my understanding of how it's 
supposed to work:


DBI uses a database driver (DBD).  DBD uses the database client libraries. In 
my case MySQL, in yours, sybase.

The client libraries, have hooks into routines in glibc called the resolver library.  Usually those are configured by the file /etc/nsswitch.conf.  Those routines allow the the 
client library to resolve name to ip address mappings and vice versa and the order of services to follow for resolution.


Some db client libraries, like Informix, have their own configuration files 
that have to correct, but ultimately use the glibc resolution library.

If ping  correctly finds the address in /etc/hosts, the system 
resolver is functioning correctly.  If not, check the order specified in 
nsswitch.conf.

Usually the order is files then dns.  It doesn't have to be.  If you see dns then files, the configured dns server will take precedence and /etc/hosts might not be checked at 
all... Especially if dns returns an IP address for the host name you're trying to use.  Changes to nsswitch.conf are instant.


On some systems an interesting little "cache" daemon called nscd (name service cache daemon) might be present to muddy the waters. If nscd is running it will intercept resolution 
calls and return the last thing it knew, making a liar of me (changes are instant). If nscd is running, stop, or restart the nscd service after making changes to nsswitch.conf


I HAVE seen one instance where nsswitch.conf was a zero length file.  This is EXTREMELY non-standard.  Much hilarity ensued for some time trying to find out why localhost didn't 
resolve... It was in /etc/hosts


I'm sure any mistakes I may have made here WILL be called out, post hasty, but 
this is my understanding.

Bruce

On 06/01/2017 01:08 PM, Paul M via beginners wrote:

I have a hosts entry that points to a specific IP address. It does not appear 
that DBI:Sybase:server uses the /etc/hosts file? Is this correct?
Ping works fine in shell.
How would I point a server name to different IP addresses locally?
What does DBI use for name resolution?

Thanks!


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: DBI and hosts file entries

2017-06-01 Thread Chris Fedde
first you want to be sure that your host can connect to the remote host onn
the right port.   You can use the telnet command to do that

   telnet server port

where server is the name for the server in  your /etc/hosts file and port
is the port number on the remote where sybase is listening.
iirc the default for sybase is 2638.Also iirc DBD::Sybase expects
freeTDS to be installed and configured.

good luck

On Thu, Jun 1, 2017 at 2:08 PM, Paul M via beginners 
wrote:

> I have a hosts entry that points to a specific IP address. It does not
> appear that DBI:Sybase:server uses the /etc/hosts file? Is this correct?
> Ping works fine in shell.
> How would I point a server name to different IP addresses locally?
> What does DBI use for name resolution?
>
> Thanks!
>


Re: DBI and field type 'bit'

2016-10-08 Thread hw

Chas. Owens schrieb:

The URL for the bug report is 
https://rt.cpan.org/Ticket/Display.html?id=118207=52bad5c05e442e5750731e7011056012


Thank you very much!

I resorted to use an integer instead of a bitfield,
and it works fine with things like


... SET `status` = `status` + 32 WHERE (NOT (`status` & 32)) AND foo ...


I´m not sure what might happen if endianess ever changes, though.



On Sat, Oct 1, 2016 at 11:44 AM Chas. Owens > wrote:

Poking around in the source, it does not appear to be well tested WRT bind 
variables (see the test file below).  I will file a bug at 
https://rt.cpan.org/Public/Dist/Display.html?Name=DBD-mysql but I wouldn't hold 
my breath on seeing anything other than a documentation change.  There is 
probably too much code in the darkpan that counts on the current behavior (ie 
making it sensible would break existing code that expects it to be broken).

use strict ;
use warnings ;

use Test::More ;
use DBI ;
use vars  qw($test_dsn $test_user 
$test_password);
use lib  '.', 't';
require 'lib.pl ';

sub VerifyBit ($) {
}

my $dbh;
my $charset= 'DEFAULT CHARSET=utf8';

eval {$dbh = DBI->connect($test_dsn, $test_user, $test_password,
{ RaiseError => 1, AutoCommit => 1}) or ServerError() ;};

if ($@) {
plan skip_all => "no database connection";
}
else {
plan tests => 15;
}

if (!MinimumVersion($dbh, '4.1')) {
$charset= '';
}

ok $dbh->do("DROP TABLE IF EXISTS dbd_mysql_b1"), "Drop table if exists 
dbd_mysql_b1";

ok( $dbh->do('CREATE TABLE dbd_mysql_b1 (b BIT(8))') );

ok ($dbh->do("insert into dbd_mysql_b1 set b = b''"));
ok ($dbh->do("insert into dbd_mysql_b1 set b = b'1010'"));
ok ($dbh->do("insert into dbd_mysql_b1 set b = b'0101'"));

ok (my $sth = $dbh->prepare("select BIN(b+0) FROM dbd_mysql_b1"));

ok ($sth->execute);

ok (my $result = $sth->fetchall_arrayref);

ok defined($result), "result returned defined";

is $result->[0][0], , "should be ";
is $result->[1][0], 1010, "should be 1010";
is $result->[2][0], 101, "should be 101";

ok ($sth->finish);

ok $dbh->do("DROP TABLE dbd_mysql_b1"), "Drop table dbd_mysql_b1";

ok $dbh->disconnect;


On Sat, Oct 1, 2016 at 11:34 AM Chas. Owens > wrote:

Whoops, meant to include links for the docs to those two functions:

http://perldoc.perl.org/functions/pack.html
http://perldoc.perl.org/functions/vec.html

On Sat, Oct 1, 2016 at 11:31 AM Chas. Owens > wrote:

DBD::mysql is treating 1 and 3 as their ASCII values on insert due 
to quoting.  You need to create values that are bit fields themselves.  This 
being Perl, there are lots of ways of doing that:

$dbh->do("create table bittest (lilbits bit(8))");

my $insert = $dbh->prepare("insert into bittest values (?)");
my $select = $dbh->prepare("select * from bittest where lilbits = 
?");

$insert->execute(pack "n", 5);
$insert->execute(pack "b", "101");

vec(my $bitstring, 0, 8) = 5;

$insert->execute($bitstring);

$select->execute(5);

while (my $row = $select->fetch) {
 printf "%08b\n", ord $row->[0];
}

The first two use the pack function to pack the input into a binary 
representation (n converts integers, b converts strings of 0s and 1s).  The 
third uses the vec function as an lvalue to build a bitstring.  Interestingly, 
selecting with bitstrings doesn't seem to work and you have to use the number.  
I am not sure if this is a bug or not.  The inconsistent behavior for select 
and insert is certainly surprising enough that I would expect it to be 
mentioned in the docs, but I didn't see it.

On Sat, Oct 1, 2016 at 10:35 AM hw > wrote:


Hi,

what´s the correct way with DBI to update a field in a mysql 
database
when the field type is 'bit'?

I´m getting, for example, converted to integer, 53 instead of 3 
into
the field.

It goes like this:


my $sth = $dbh->prepare("INSERT INTO t (`status`) VALUES (?)
   ON DUPLICATE KEY UPDATE `status` = 
?");

$sth->execute(($var eq 'x' ? 1 : 0), ($var eq 'x' ? 3 : 0));


That should work just fine but doesn´t in that the wrong bits 
of the
field are 

Re: DBI and field type 'bit'

2016-10-01 Thread Chas. Owens
The URL for the bug report is
https://rt.cpan.org/Ticket/Display.html?id=118207=52bad5c05e442e5750731e7011056012

On Sat, Oct 1, 2016 at 11:44 AM Chas. Owens  wrote:

> Poking around in the source, it does not appear to be well tested WRT bind
> variables (see the test file below).  I will file a bug at
> https://rt.cpan.org/Public/Dist/Display.html?Name=DBD-mysql but I
> wouldn't hold my breath on seeing anything other than a documentation
> change.  There is probably too much code in the darkpan that counts on the
> current behavior (ie making it sensible would break existing code that
> expects it to be broken).
>
> use strict ;
> use warnings ;
>
> use Test::More ;
> use DBI ;
> use vars  qw($test_dsn $test_user
> $test_password);
> use lib  '.', 't';
> require 'lib.pl';
>
> sub VerifyBit ($) {
> }
>
> my $dbh;
> my $charset= 'DEFAULT CHARSET=utf8';
>
> eval {$dbh = DBI->connect($test_dsn, $test_user, $test_password,
> { RaiseError => 1, AutoCommit => 1}) or ServerError() ;};
>
> if ($@) {
> plan skip_all => "no database connection";
> }
> else {
> plan tests => 15;
> }
>
> if (!MinimumVersion($dbh, '4.1')) {
> $charset= '';
> }
>
> ok $dbh->do("DROP TABLE IF EXISTS dbd_mysql_b1"), "Drop table if exists
> dbd_mysql_b1";
>
> ok( $dbh->do('CREATE TABLE dbd_mysql_b1 (b BIT(8))') );
>
> ok ($dbh->do("insert into dbd_mysql_b1 set b = b''"));
> ok ($dbh->do("insert into dbd_mysql_b1 set b = b'1010'"));
> ok ($dbh->do("insert into dbd_mysql_b1 set b = b'0101'"));
>
> ok (my $sth = $dbh->prepare("select BIN(b+0) FROM dbd_mysql_b1"));
>
> ok ($sth->execute);
>
> ok (my $result = $sth->fetchall_arrayref);
>
> ok defined($result), "result returned defined";
>
> is $result->[0][0], , "should be ";
> is $result->[1][0], 1010, "should be 1010";
> is $result->[2][0], 101, "should be 101";
>
> ok ($sth->finish);
>
> ok $dbh->do("DROP TABLE dbd_mysql_b1"), "Drop table dbd_mysql_b1";
>
> ok $dbh->disconnect;
>
>
> On Sat, Oct 1, 2016 at 11:34 AM Chas. Owens  wrote:
>
> Whoops, meant to include links for the docs to those two functions:
>
> http://perldoc.perl.org/functions/pack.html
> http://perldoc.perl.org/functions/vec.html
>
> On Sat, Oct 1, 2016 at 11:31 AM Chas. Owens  wrote:
>
> DBD::mysql is treating 1 and 3 as their ASCII values on insert due to
> quoting.  You need to create values that are bit fields themselves.  This
> being Perl, there are lots of ways of doing that:
>
> $dbh->do("create table bittest (lilbits bit(8))");
>
> my $insert = $dbh->prepare("insert into bittest values (?)");
> my $select = $dbh->prepare("select * from bittest where lilbits = ?");
>
> $insert->execute(pack "n", 5);
> $insert->execute(pack "b", "101");
>
> vec(my $bitstring, 0, 8) = 5;
>
> $insert->execute($bitstring);
>
> $select->execute(5);
>
> while (my $row = $select->fetch) {
> printf "%08b\n", ord $row->[0];
> }
>
> The first two use the pack function to pack the input into a binary
> representation (n converts integers, b converts strings of 0s and 1s).  The
> third uses the vec function as an lvalue to build a bitstring.
> Interestingly, selecting with bitstrings doesn't seem to work and you have
> to use the number.  I am not sure if this is a bug or not.  The
> inconsistent behavior for select and insert is certainly surprising enough
> that I would expect it to be mentioned in the docs, but I didn't see it.
>
> On Sat, Oct 1, 2016 at 10:35 AM hw  wrote:
>
>
> Hi,
>
> what´s the correct way with DBI to update a field in a mysql database
> when the field type is 'bit'?
>
> I´m getting, for example, converted to integer, 53 instead of 3 into
> the field.
>
> It goes like this:
>
>
> my $sth = $dbh->prepare("INSERT INTO t (`status`) VALUES (?)
>   ON DUPLICATE KEY UPDATE `status` = ?");
>
> $sth->execute(($var eq 'x' ? 1 : 0), ($var eq 'x' ? 3 : 0));
>
>
> That should work just fine but doesn´t in that the wrong bits of the
> field are being set.
>
> Is this a bug or a feature?
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: DBI and field type 'bit'

2016-10-01 Thread Chas. Owens
Poking around in the source, it does not appear to be well tested WRT bind
variables (see the test file below).  I will file a bug at
https://rt.cpan.org/Public/Dist/Display.html?Name=DBD-mysql but I wouldn't
hold my breath on seeing anything other than a documentation change.  There
is probably too much code in the darkpan that counts on the current
behavior (ie making it sensible would break existing code that expects it
to be broken).

use strict ;
use warnings ;

use Test::More ;
use DBI ;
use vars  qw($test_dsn $test_user
$test_password);
use lib  '.', 't';
require 'lib.pl';

sub VerifyBit ($) {
}

my $dbh;
my $charset= 'DEFAULT CHARSET=utf8';

eval {$dbh = DBI->connect($test_dsn, $test_user, $test_password,
{ RaiseError => 1, AutoCommit => 1}) or ServerError() ;};

if ($@) {
plan skip_all => "no database connection";
}
else {
plan tests => 15;
}

if (!MinimumVersion($dbh, '4.1')) {
$charset= '';
}

ok $dbh->do("DROP TABLE IF EXISTS dbd_mysql_b1"), "Drop table if exists
dbd_mysql_b1";

ok( $dbh->do('CREATE TABLE dbd_mysql_b1 (b BIT(8))') );

ok ($dbh->do("insert into dbd_mysql_b1 set b = b''"));
ok ($dbh->do("insert into dbd_mysql_b1 set b = b'1010'"));
ok ($dbh->do("insert into dbd_mysql_b1 set b = b'0101'"));

ok (my $sth = $dbh->prepare("select BIN(b+0) FROM dbd_mysql_b1"));

ok ($sth->execute);

ok (my $result = $sth->fetchall_arrayref);

ok defined($result), "result returned defined";

is $result->[0][0], , "should be ";
is $result->[1][0], 1010, "should be 1010";
is $result->[2][0], 101, "should be 101";

ok ($sth->finish);

ok $dbh->do("DROP TABLE dbd_mysql_b1"), "Drop table dbd_mysql_b1";

ok $dbh->disconnect;

On Sat, Oct 1, 2016 at 11:34 AM Chas. Owens  wrote:

> Whoops, meant to include links for the docs to those two functions:
>
> http://perldoc.perl.org/functions/pack.html
> http://perldoc.perl.org/functions/vec.html
>
> On Sat, Oct 1, 2016 at 11:31 AM Chas. Owens  wrote:
>
> DBD::mysql is treating 1 and 3 as their ASCII values on insert due to
> quoting.  You need to create values that are bit fields themselves.  This
> being Perl, there are lots of ways of doing that:
>
> $dbh->do("create table bittest (lilbits bit(8))");
>
> my $insert = $dbh->prepare("insert into bittest values (?)");
> my $select = $dbh->prepare("select * from bittest where lilbits = ?");
>
> $insert->execute(pack "n", 5);
> $insert->execute(pack "b", "101");
>
> vec(my $bitstring, 0, 8) = 5;
>
> $insert->execute($bitstring);
>
> $select->execute(5);
>
> while (my $row = $select->fetch) {
> printf "%08b\n", ord $row->[0];
> }
>
> The first two use the pack function to pack the input into a binary
> representation (n converts integers, b converts strings of 0s and 1s).  The
> third uses the vec function as an lvalue to build a bitstring.
> Interestingly, selecting with bitstrings doesn't seem to work and you have
> to use the number.  I am not sure if this is a bug or not.  The
> inconsistent behavior for select and insert is certainly surprising enough
> that I would expect it to be mentioned in the docs, but I didn't see it.
>
> On Sat, Oct 1, 2016 at 10:35 AM hw  wrote:
>
>
> Hi,
>
> what´s the correct way with DBI to update a field in a mysql database
> when the field type is 'bit'?
>
> I´m getting, for example, converted to integer, 53 instead of 3 into
> the field.
>
> It goes like this:
>
>
> my $sth = $dbh->prepare("INSERT INTO t (`status`) VALUES (?)
>   ON DUPLICATE KEY UPDATE `status` = ?");
>
> $sth->execute(($var eq 'x' ? 1 : 0), ($var eq 'x' ? 3 : 0));
>
>
> That should work just fine but doesn´t in that the wrong bits of the
> field are being set.
>
> Is this a bug or a feature?
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: DBI and field type 'bit'

2016-10-01 Thread Chas. Owens
Whoops, meant to include links for the docs to those two functions:

http://perldoc.perl.org/functions/pack.html
http://perldoc.perl.org/functions/vec.html

On Sat, Oct 1, 2016 at 11:31 AM Chas. Owens  wrote:

> DBD::mysql is treating 1 and 3 as their ASCII values on insert due to
> quoting.  You need to create values that are bit fields themselves.  This
> being Perl, there are lots of ways of doing that:
>
> $dbh->do("create table bittest (lilbits bit(8))");
>
> my $insert = $dbh->prepare("insert into bittest values (?)");
> my $select = $dbh->prepare("select * from bittest where lilbits = ?");
>
> $insert->execute(pack "n", 5);
> $insert->execute(pack "b", "101");
>
> vec(my $bitstring, 0, 8) = 5;
>
> $insert->execute($bitstring);
>
> $select->execute(5);
>
> while (my $row = $select->fetch) {
> printf "%08b\n", ord $row->[0];
> }
>
> The first two use the pack function to pack the input into a binary
> representation (n converts integers, b converts strings of 0s and 1s).  The
> third uses the vec function as an lvalue to build a bitstring.
> Interestingly, selecting with bitstrings doesn't seem to work and you have
> to use the number.  I am not sure if this is a bug or not.  The
> inconsistent behavior for select and insert is certainly surprising enough
> that I would expect it to be mentioned in the docs, but I didn't see it.
>
> On Sat, Oct 1, 2016 at 10:35 AM hw  wrote:
>
>
> Hi,
>
> what´s the correct way with DBI to update a field in a mysql database
> when the field type is 'bit'?
>
> I´m getting, for example, converted to integer, 53 instead of 3 into
> the field.
>
> It goes like this:
>
>
> my $sth = $dbh->prepare("INSERT INTO t (`status`) VALUES (?)
>   ON DUPLICATE KEY UPDATE `status` = ?");
>
> $sth->execute(($var eq 'x' ? 1 : 0), ($var eq 'x' ? 3 : 0));
>
>
> That should work just fine but doesn´t in that the wrong bits of the
> field are being set.
>
> Is this a bug or a feature?
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: DBI and field type 'bit'

2016-10-01 Thread Chas. Owens
DBD::mysql is treating 1 and 3 as their ASCII values on insert due to
quoting.  You need to create values that are bit fields themselves.  This
being Perl, there are lots of ways of doing that:

$dbh->do("create table bittest (lilbits bit(8))");

my $insert = $dbh->prepare("insert into bittest values (?)");
my $select = $dbh->prepare("select * from bittest where lilbits = ?");

$insert->execute(pack "n", 5);
$insert->execute(pack "b", "101");

vec(my $bitstring, 0, 8) = 5;

$insert->execute($bitstring);

$select->execute(5);

while (my $row = $select->fetch) {
printf "%08b\n", ord $row->[0];
}

The first two use the pack function to pack the input into a binary
representation (n converts integers, b converts strings of 0s and 1s).  The
third uses the vec function as an lvalue to build a bitstring.
Interestingly, selecting with bitstrings doesn't seem to work and you have
to use the number.  I am not sure if this is a bug or not.  The
inconsistent behavior for select and insert is certainly surprising enough
that I would expect it to be mentioned in the docs, but I didn't see it.

On Sat, Oct 1, 2016 at 10:35 AM hw  wrote:

>
> Hi,
>
> what´s the correct way with DBI to update a field in a mysql database
> when the field type is 'bit'?
>
> I´m getting, for example, converted to integer, 53 instead of 3 into
> the field.
>
> It goes like this:
>
>
> my $sth = $dbh->prepare("INSERT INTO t (`status`) VALUES (?)
>   ON DUPLICATE KEY UPDATE `status` = ?");
>
> $sth->execute(($var eq 'x' ? 1 : 0), ($var eq 'x' ? 3 : 0));
>
>
> That should work just fine but doesn´t in that the wrong bits of the
> field are being set.
>
> Is this a bug or a feature?
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: DBI interaction with postgres

2011-01-04 Thread Brandon McCaig
On Tue, Jan 4, 2011 at 8:12 AM, jankes jankes...@gmail.com wrote:
 my $nowe = $generuj-fetchrow_array;

I haven't had the pleasure of using DBI yet, but CPAN says to exercise
caution when using fetchrow_array in scalar context. Perhaps you
should switch to list context. Either way, check the status of
$generuj-err afterward to see if an error occurred, which should be
truthy (is that terminology used with Perl?) if an error occurred.
Apparently if an error occurs then fetchrow_array should return an
empty list in list context or undef in scalar context, which might
explain your result.

# I have no idea what language your variables are in so I just
# added an 's'. ;) I'm not in a position to say if that's correct or
# not.
my @nowes = $generuj-fetchrow_array;

die DBI error: $generuj-err: $generuj-errstr if $generuj-err;

???


-- 
Brandon McCaig http://www.bamccaig.com bamcc...@gmail.com
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software http://www.castopulence.org/ bamcc...@castopulence.org

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: DBI - bind_param_inout

2010-10-25 Thread Shlomi Fish
Hi Nora,

On Monday 25 October 2010 10:05:05 HACKER Nora wrote:
 Hi list,
 
 I have a sql package which returns a value after execution. I figured
 out that, when calling this package from Perl, I need a bind parameter
 (http://search.cpan.org/~timb/DBI-1.615/DBI.pm#bind_param_inout) that
 this return can be saved into so that I can use it afterwards in my Perl
 program. Is my assumption correct? If so, could please somebody explain
 to me how to do that? I read the passage from the above URL again and
 again but I just don't get it :-/ What is $p_num? What is the
 \$bind_value? And of which unit is $max_len?

1. $p_num is the position of the parameter in the query string (the index of 
the ? which you put there.).

2. $bind_value is the variable where you want to supply and receive the value. 
You need to take a reference to it so it can be modified.

3. $max_len is the maximal amount of memory (in bytes likely) that should be 
allocated for the value to be stored.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Stop Using MSIE - http://www.shlomifish.org/no-ie/

rindolf She's a hot chick. But she smokes.
go|dfish She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: DBI - bind_param_inout

2010-10-25 Thread Brandon McCaig
On Mon, Oct 25, 2010 at 3:27 PM, Shlomi Fish shlo...@iglu.org.il wrote:
 2. $bind_value is the variable where you want to supply and receive the value.
 You need to take a reference to it so it can be modified.

I imagine she knows this already, but I believe the stored procedure's
parameter will need to be marked as an OUTPUT parameter.

 3. $max_len is the maximal amount of memory (in bytes likely) that should be
 allocated for the value to be stored.

This confusing me too. It makes some sense in C (though if it's doing
the allocating I would expect it to just tell me how much total data
it received), but in Perl I would expect that to just be magically
handled for you. At the very least, how can you know how many bytes it
will take? That sounds like an arbitrary magic number or outright
guess. :P What are the best practices for such a thing? :-[

-- 
Brandon McCaig bamcc...@gmail.com
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software http://www.castopulence.org/ bamcc...@castopulence.org

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: DBI under SOAP/mod_perl

2010-07-20 Thread Dermot
Hi Octavian,

On 19 July 2010 06:07, Octavian Rasnita orasn...@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 @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 @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(0x9af7094)',
'?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 

Re: DBI under SOAP/mod_perl

2010-07-18 Thread Octavian Rasnita

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

--
Octavian

- Original Message - 
From: Dermot paik...@gmail.com

To: Perl Beginners beginners@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 = @_;
   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-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@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-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: DBI escape_string

2009-11-05 Thread jm
your last field included in the query ('msg') has an apostrophe in the
middle of the text, as well as not be closed with a single quote before the
entire string is closed with the double quote.  you can't include an
unescaped single quote inside a single-quoted string, nor can you include an
unescaped double quote inside a double-quoted string.  look into using
something like

... $dbh-prepare( qq{$query} ) ...

to correctly handle multiple quotes.  whatever actions the prepare()
function performs, cleaning up incorrect quotes is not included.


On Thu, Nov 5, 2009 at 1:18 PM, cerr ron.egg...@gmail.com wrote:

 Hi There,

 On http://www.codepedia.com/1/PerlDBITutorial I found that prepare()
 would escape a string.
 Now I have a query like this:
 INSERT INTO logs (source, date, time, program, msg, inserttime) VALUES
 ('NovaxPRG-T0029', '2009-11-02', '09:51:11', 'NovaxPRG', 'NovaxPRG
 [931]: T0029: CRITICAL: couldn't establish connection with INIT
 Priority=-1 Position=0:0 Speed=0 Heading=0 Intersection= Approach=
 and mysql tells me
 execute failed: You have an error in your SQL syntax; check the
 manual that corresponds to your MySQL server version for the right
 syntax to use near 't establish connection with INIT Priority=-1
 Position=0:0 Speed=0 Heading=0 Inte' at line 1 at /root/cron/
 log_parser.pl line 143.

 even tho my code I pass the query  to prepare() first. Why that? A
 code snippet:
print Query: .$query.\n;
$pre = $dbh-prepare($query) || die Error: .$dbh-
 errstr.\n;
$pre-execute || Error: .$dbh-errstr.\n;

 Why is that? What am i doing wrong? The apostrophy in my query
 apparently is messing it all up.
 Thanks for help and suggestions!
 Ron


 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/





-- 
since this is a gmail account, please verify the mailing list is included in
the reply to addresses


Re: DBI driving me nuts ... !

2009-10-29 Thread Pau Marc Munoz Torres
Have you tried to print @row?


#!/usr/bin/perl

use Mysql;

$dbh = Mysql-connect(localhost,

 mailscanner,root,c0nc3pt) or
 die (Error  . Mysql-errno .  -  . Mysql-errstr);
 $sql = SELECT to_address FROM maillog LIMIT 10;;
 $sth = $dbh-query($sql) or die (Error  . Mysql-errno .  -  .
 Mysql-errstr);
 while (@row = $sth-fetchrow){
print @row /n;
 }


$dbh-disconnect();

2009/10/6 Gregory Machin g...@linuxpro.co.za

 Hi
 Please can you advise ?

 #!/usr/bin/perl

 use Mysql;

 $dbh = Mysql-connect(localhost,mailscanner,root,c0nc3pt) or
 die (Error  . Mysql-errno .  -  . Mysql-errstr);
 $sql = SELECT to_address FROM maillog LIMIT 10;;
 $sth = $dbh-query($sql) or die (Error  . Mysql-errno .  -  .
 Mysql-errstr);
 while (@row = $sth-fetchrow){
print $row /n;
 }

 which gives this

 [r...@mail10 ~]# perl addressrep2.pl
  /n /n /n /n /n /n /n /n /n /n[r...@mail10 ~]#

 when it should give the same output as

 Database changed
 mysql SELECT to_address FROM maillog LIMIT 10
- ;
 ++
 | to_address |
 ++
 | iv...@systems.xxx|
 | tkek...@stpeters.xxx |
 | dfou...@howden.xxx   |
 | melan...@mdlulisharp.xxx |
 | er...@mdlulisharp.xxx|
 | desi...@oas.xxx  |
 | dbalakis...@multivid.xxx |
 | bhar...@webb.xxx |
 | jcven...@multivid.xxx|
 | ad...@troika-iw.xxx|
 ++
 10 rows in set (0.00 sec)

 mysql



 what am I doing wrong ?

 Thanks

 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/





-- 
Pau Marc Muñoz Torres

Laboratori de Biologia Computacional
Institut de  Biotecnologia   i Biomedicina Vicent Villar

Universitat Autonoma de Barcelona
E-08193 Bellaterra (Barcelona)

telèfon: 93 5812807
Email : paumarc.mu...@bioinf.uab.cat


Re: DBI driving me nuts ... !

2009-10-07 Thread Jenda Krynicky
 Please can you advise ?
 
 #!/usr/bin/perl
 
 use Mysql;
 
 $dbh = Mysql-connect(localhost,mailscanner,root,c0nc3pt) or
 die (Error  . Mysql-errno .  -  . Mysql-errstr);
 ...

I do not see any DBI in here.

Though ... http://search.cpan.org/~capttofu/DBD-mysql-
3.0008/lib/Mysql.pm says M(y)sqlPerl is no longer a separate module. 
Instead it is emulated using the DBI drivers. You are strongly 
encouraged to implement new code with DBI directly. ...


In either case you put the data for the row into @row and then 
attempt to print $row. Those are two different variables.

Jenda
= je...@krynicky.cz === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: DBI driving me nuts ... !

2009-10-06 Thread Shawn H Corey
Gregory Machin wrote:
 Hi
 Please can you advise ?
 
 #!/usr/bin/perl

use strict;
use warnings;

 
 use Mysql;
 
 $dbh = Mysql-connect(localhost,mailscanner,root,c0nc3pt) or
 die (Error  . Mysql-errno .  -  . Mysql-errstr);

my $dbh = ...

 $sql = SELECT to_address FROM maillog LIMIT 10;;

my $sql = ...

 $sth = $dbh-query($sql) or die (Error  . Mysql-errno .  -  .
 Mysql-errstr);

my $sth = ...

 while (@row = $sth-fetchrow){

while( my @row = ...

 print $row /n;

print @row\n;

 }


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: DBI fetchall_arrayref

2009-02-27 Thread Chas. Owens
On Fri, Feb 27, 2009 at 08:43, David Shere dsh...@steelerubber.com wrote:
 The following sub uses fetchall_arrayref in the DBI module to put the
 results of an SQL command into an array, where each element of the array
 is a hash of that records name/value pairs.  The documentation says to
 pass it a reference to a hash.  My interpretation of that requirement is
 below.  Did I miss something?

 sub SQLCom { # Issues a command to the MySQL database.
    my $dbh           = shift; # Database object (from DBI)
    my $CommandString = shift; # SQL Command
    my $Query         = $dbh-prepare($CommandString);

    $Query-execute() or (print Can't execute database command
 \$CommandString\\n\n and return undef);
    if ($CommandString =~ m/SELECT/i) {
        my @return = @{$Query-fetchall_arrayref(\%asfd)};
        return @return;
    }
    return true;
 }

Where does %asdf come from?  Anyway, there are four ways to call
fetchall_arrayref.

You can call it with an empty arrayref or not arguments at all:

my $AoA = $sth-fetchall_arrayref([]);
my $AoA = $sth-fetchall_arrayref();

$AoA contains a reference to an array of arrays, so, if the data in
the data base looked like this:

foo|bar|baz
1|2|3
4|5|6
7|8|9

then the $AoA would look like this

my $AoA = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ],
];

You can call it with an empty hashref:

my $AoH = $sth-fetchall_arrayref({});

$AoH contains a reference to an array of hashes, so, if the data in
the data base looked like this:

foo|bar|baz
1|2|3
4|5|6
7|8|9

then the $AoH would look like this

my $AoH = [
[ foo = 1, bar = 2, baz = 3 ],
[ foo = 4, bar = 5, baz = 6 ],
[ foo = 7, bar = 8, baz = 9 ],
];

You can call it with a hashref of the names columns:

my $AoH = $sth-fetchall_arrayref({foo = 1, baz = 1});

$AoH contains a reference to an array of hashes, so, if the data in
the data base looked like this:

foo|bar|baz
1|2|3
4|5|6
7|8|9

then the $AoH would look like this

my $AoH = [
[ foo = 1, baz = 3 ],
[ foo = 4, baz = 6 ],
[ foo = 7, baz = 9 ],
];


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: DBI fetchall_arrayref

2009-02-27 Thread John W. Krahn

Chas. Owens wrote:

On Fri, Feb 27, 2009 at 08:43, David Shere dsh...@steelerubber.com wrote:

The following sub uses fetchall_arrayref in the DBI module to put the
results of an SQL command into an array, where each element of the array
is a hash of that records name/value pairs.  The documentation says to
pass it a reference to a hash.  My interpretation of that requirement is
below.  Did I miss something?

sub SQLCom { # Issues a command to the MySQL database.
   my $dbh   = shift; # Database object (from DBI)
   my $CommandString = shift; # SQL Command
   my $Query = $dbh-prepare($CommandString);

   $Query-execute() or (print Can't execute database command
\$CommandString\\n\n and return undef);
   if ($CommandString =~ m/SELECT/i) {
   my @return = @{$Query-fetchall_arrayref(\%asfd)};
   return @return;
   }
   return true;
}


Where does %asdf come from?  Anyway, there are four ways to call
fetchall_arrayref.

You can call it with an empty arrayref or not arguments at all:

my $AoA = $sth-fetchall_arrayref([]);
my $AoA = $sth-fetchall_arrayref();

$AoA contains a reference to an array of arrays, so, if the data in
the data base looked like this:

foo|bar|baz
1|2|3
4|5|6
7|8|9

then the $AoA would look like this

my $AoA = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ],
];

You can call it with an empty hashref:

my $AoH = $sth-fetchall_arrayref({});

$AoH contains a reference to an array of hashes, so, if the data in
the data base looked like this:

foo|bar|baz
1|2|3
4|5|6
7|8|9

then the $AoH would look like this

my $AoH = [
[ foo = 1, bar = 2, baz = 3 ],
[ foo = 4, bar = 5, baz = 6 ],
[ foo = 7, bar = 8, baz = 9 ],
];


ITYM:

my $AoH = [
{ foo = 1, bar = 2, baz = 3 },
{ foo = 4, bar = 5, baz = 6 },
{ foo = 7, bar = 8, baz = 9 },
];



You can call it with a hashref of the names columns:

my $AoH = $sth-fetchall_arrayref({foo = 1, baz = 1});

$AoH contains a reference to an array of hashes, so, if the data in
the data base looked like this:

foo|bar|baz
1|2|3
4|5|6
7|8|9

then the $AoH would look like this

my $AoH = [
[ foo = 1, baz = 3 ],
[ foo = 4, baz = 6 ],
[ foo = 7, baz = 9 ],
];


ITYM:

my $AoH = [
{ foo = 1, baz = 3 },
{ foo = 4, baz = 6 },
{ foo = 7, baz = 9 },
];



John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: DBI and SQLite efficiency

2009-01-13 Thread Jenda Krynicky
From: Southworth, Harry harry.southwo...@astrazeneca.com
 I have a database with several tables in it, and each table contains
 data on lots of people. From one run of my program to the next, the
 tables could change, so my code needs to be fairly general. 
 
 I want to pull the data for each person from each table, and create an
 XML report - one report for each person. 
 
 The problem I'm having is that my code is very inefficient. Although
 I've read that putting prepare inside a loop is slow, I have failed to
 make anything else work at all (I tried putting the connections into
 an array, but either I did something wrong or that is not supposed to
 work). 
 
 I would be very grateful if someone were able to tell me how to
 rewrite this in order to make if more efficient. 
 
 
 use DBI;
 use IO::File;
 use XML::Writer;
 
   my $dbh = DBI-connect( 'DBI:SQLite:myDB' )
   or die Couldn't connect to database: . DBI-errstr;
   my $sth = $dbh-prepare( 'SELECT id FROM demography' ) 
  or die Couldn't prepare statement:  . $dbh-errstr;

   my $id;
   my @tables = $dbh-tables();
 
   # Get the IDs
   $sth-execute();
 
   while( $id = $sth-fetchrow_array() ){
 # Open report for writing and add top-matter here:
 # code not shown
 
 for (0..$#tables){
   $theTable = $tables[$_];
   $qid = $dbh-quote( $id );
 
   # Do stuff to make the next line produce the correct SQL:
   # code not shown
   $sql = SELECT * FROM $theTable WHERE usubjid = $id;

I don't know how's your XML supposed to be structured, but could you 
swith the loops around? That way you could prepare

  SELECT * FROM $theTable WHERE usubjid = ?;

in the outer loop and then just $cnx-execute($id) in the inner.

If you can't do this, prepare the statement for each table first and 
then use that:

my %sth;
for (0..$#tables){
  $sth{$tables[$_]} = $dbh-prepare(
   SELECT * FROM $theTable WHERE usubjid = ?
  );
}
...
while( $id = $sth-fetchrow_array() ){
   for (0..$#tables){
 $sth{$tables[$_]}-execute($id) ...
...


It's possible that the prepares are not the reason of the slowness. 
Do you have indexes on the usubjid column in all tables?

Jenda
= je...@krynicky.cz === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: DBI and SQLite efficiency

2009-01-13 Thread Southworth, Harry
Thanks.

I think that if I append (rather than overwrite) each report with each table, I 
could restructure the code like you suggest. Thanks for pointing that out - it 
hadn't occurred to me.

 my %sth;
 for (0..$#tables){
   $sth{$tables[$_]} = $dbh-prepare(
SELECT * FROM $theTable WHERE usubjid = ?
   );
 }

I already tried something like that, but using an array rather than a hash. Is 
there a reason why an array wouldn't work?

 Do you have indexes on the usubjid column in all tables?

Yes, and indexing made a huge speed improvement, so I know it worked.

Thanks again for all your suggestions.
Harry

--
AstraZeneca UK Limited is a company incorporated in England and Wales with 
registered number: 03674842 and a registered office at 15 Stanhope Gate, London 
W1K 1LN.
Confidentiality Notice: This message is private and may contain confidential, 
proprietary and legally privileged information. If you have received this 
message in error, please notify us and remove it from your system and note that 
you must not copy, distribute or take any action in reliance on it. Any 
unauthorised use or disclosure of the contents of this message is not permitted 
and may be unlawful.
Disclaimer: Email messages may be subject to delays, interception, non-delivery 
and unauthorised alterations. Therefore, information expressed in this message 
is not given or endorsed by AstraZeneca UK Limited unless otherwise notified by 
an authorised representative independent of this message. No contractual 
relationship is created by this message by any person unless specifically 
indicated by agreement in writing other than email.
Monitoring: AstraZeneca UK Limited may monitor email traffic data and content 
for the purposes of the prevention and detection of crime, ensuring the 
security of our computer systems and checking Compliance with our Code of 
Conduct and Policies.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: DBI and SQLite efficiency

2009-01-13 Thread Jenda Krynicky
From: Southworth, Harry harry.southwo...@astrazeneca.com
 I think that if I append (rather than overwrite) each report with each
 table, I could restructure the code like you suggest. Thanks for
 pointing that out - it hadn't occurred to me. 
 
  my %sth;
  for (0..$#tables){
$sth{$tables[$_]} = $dbh-prepare(
 SELECT * FROM $theTable WHERE usubjid = ?
);
  }
 
 I already tried something like that, but using an array rather than a
 hash. Is there a reason why an array wouldn't work? 

Nope. Not sure why I used a hash. an array and $sth[$_] would work 
just as well.

If this did not help then most likely the problem is elsewhere.

Jenda
= je...@krynicky.cz === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: DBI and SQLite efficiency

2009-01-13 Thread Rob Dixon
Southworth, Harry wrote:
 I have a database with several tables in it, and each table contains data on 
 lots of people. From one run of my program to the next, the tables could 
 change, so my code needs to be fairly general.
 
 I want to pull the data for each person from each table, and create an XML 
 report - one report for each person.
 
 The problem I'm having is that my code is very inefficient. Although I've 
 read that putting prepare inside a loop is slow, I have failed to make 
 anything else work at all (I tried putting the connections into an array, but 
 either I did something wrong or that is not supposed to work).
 
 I would be very grateful if someone were able to tell me how to rewrite this 
 in order to make if more efficient.
 
 
 use DBI;
 use IO::File;
 use XML::Writer;
 
   my $dbh = DBI-connect( 'DBI:SQLite:myDB' )
   or die Couldn't connect to database: . DBI-errstr;
   my $sth = $dbh-prepare( 'SELECT id FROM demography' ) 
  or die Couldn't prepare statement:  . $dbh-errstr;

   my $id;
   my @tables = $dbh-tables();
 
   # Get the IDs
   $sth-execute();
 
   while( $id = $sth-fetchrow_array() ){
 # Open report for writing and add top-matter here:
 # code not shown
 
 for (0..$#tables){
   $theTable = $tables[$_];
   $qid = $dbh-quote( $id );
 
   # Do stuff to make the next line produce the correct SQL:
   # code not shown
   $sql = SELECT * FROM $theTable WHERE usubjid = $id;
 
   # Next lines are inefficient. Please help!
 $cnx = $dbh-prepare($sql);
 $cnx-execute()
 or die Failed execution;
 
   # Code omitted here
   } # Close while
 
   # Tidy up and close down here

I suggest that there is probably no need to extract a list of IDs from the
demography table and then access the records one at a time. The program below
gives a hint of what I mean, but I clearly can't test it for you.

  use strict;
  use warnings;

  use DBI;
  use IO::File;
  use XML::Writer;

  my $dbh = DBI-connect( 'DBI:SQLite:myDB' )
  or die Couldn't connect to database: . DBI-errstr;

  foreach my $theTable ($dbh-tables) {

my $sth = $dbh-prepare(SELECT * FROM $theTable ORDER BY usubjid);

while (my @data = $sth-fetchrow_array) {

  # Open report file for append here according to usubjid field. If
  # file doesn't exist then open for output and add top-matter.
  # Keep note of all new files created.

}
  }

  # Add any tail data to all files created



HTH,

Rob

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: DBI: Add column to mysql table

2008-12-07 Thread Chas. Owens
On Sat, Dec 6, 2008 at 20:23, hotkitty [EMAIL PROTECTED] wrote:
 Hi,

 I am using DBI to add a column to my existing table, goodtable. W/ a
 phpmyadmin I can add a column w/ a numeric or nonnumeric label. Using
 perl DBI, I can only add a column w/ a nonnumeric label, as follows:

 $dbh-do(ALTER TABLE goodtable ADD testname VARCHAR( 250 ) NULL);
 is a non-numeric column label and works fine.

 However, changing testname to a number results in an error..
 $dbh-do(ALTER TABLE goodtable ADD 546 VARCHAR( 250 ) NULL);
 is a numeric column label and throwsback the following
 error:

 DBD::mysql::db do failed: You have an error in your SQL syntax; check
 the manual that corresponds to your MySQL server version for the right
 syntax to use near '451 VARCHAR( 250 ) NULL'

 Again, everything works fine doing it in a non-perl way. I've tried
 using quotes, escape characters, $sql = $dbh-quote($value), etc.
 (Obviously, I could do this in a web interface but this project
 requires creating columns on the fly, so to speak, so I must use perl
 for this.)
snip

To my knowledge MySQL doesn't allow numeric only column names:

mysql alter table foo add column 123 int;
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '123 int' at line 1

If phpadmin is letting you add them then it is most likely adding a
different name and showing you a numeric label.  Try checking the
actual database to see what the column is named.

Also, I must warn you that a numeric column name is an incredibly bad
idea (I would go so far as to say any numbers at all in a column name
is generally* a sign off a bad design**).  Column names should reflect
their contents and numbers alone just don't have the descriptive
power.

* the best counter-example I can think of is something like
supports_sql92 where the number is a part of the term, but in my
experience those cases are rare.
** here I am mostly talking about things like address1, address2, etc.
 This is better handled with another table with a one-to-many
relationship with the first table.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: DBI equivalent of Oraperl ora_titles function !

2008-08-06 Thread Amit Saxena
On Tue, Aug 5, 2008 at 6:06 PM, Peter Scott [EMAIL PROTECTED] wrote:

 On Tue, 05 Aug 2008 09:38:41 +0530, Amit Saxena wrote:

  What's the DBI equivalent of Oraperl ora_titles function ?
 
  I need it because I want to get the titles (column names) of a select
 query
  into an array without fetching the row values from the database.

 I believe you want the NAME statement handle attribute:

 http://search.cpan.org/~timb/DBI-1.607/DBI.pm#NAME_(array-ref,_read-only)http://search.cpan.org/%7Etimb/DBI-1.607/DBI.pm#NAME_%28array-ref,_read-only%29

 --
 Peter Scott
 http://www.perlmedic.com/
 http://www.perldebugged.com/


 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/


Hi Peter,

Thanks, it worked for me !

Regards,
Amit Saxena


Re: DBI equivalent of Oraperl ora_titles function !

2008-08-05 Thread Peter Scott
On Tue, 05 Aug 2008 09:38:41 +0530, Amit Saxena wrote:

 What's the DBI equivalent of Oraperl ora_titles function ?
 
 I need it because I want to get the titles (column names) of a select query
 into an array without fetching the row values from the database.

I believe you want the NAME statement handle attribute:

http://search.cpan.org/~timb/DBI-1.607/DBI.pm#NAME_(array-ref,_read-only)

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: DBI error

2008-07-22 Thread Rob Dixon

Panda-X wrote:

 I've got this error, anything I can do ?
 
   Can't locate auto/DBI/data_source.al in @INC 
 
 Code :
 
use DBI;
my @dataSource = DBI - data_source ( mysql ) ;

The method call is

  DBI-data_sources('mysql');

 and if I change the as this :
 
 use DBI;
 my $dbh = DBI - connect ( dbi:mysql, $adm, $pass ) ;

the data source should look like

  dbi:drivername:database name

so

  dbi:mysql:database name

in your case.

[snip]

HTH,

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: DBI error

2008-07-22 Thread Panda-X
Ah! Yes!! Thank you very much!!

Problem fixed now =)


2008/7/22 Rob Dixon [EMAIL PROTECTED]:


 Panda-X wrote:
 
  I've got this error, anything I can do ?
 
Can't locate auto/DBI/data_source.al in @INC 
 
  Code :
 
 use DBI;
 my @dataSource = DBI - data_source ( mysql ) ;

 The method call is

  DBI-data_sources('mysql');

  and if I change the as this :
 
  use DBI;
  my $dbh = DBI - connect ( dbi:mysql, $adm, $pass ) ;

 the data source should look like

  dbi:drivername:database name

 so

  dbi:mysql:database name

 in your case.

 [snip]

 HTH,

 Rob



Re: DBI error

2008-07-21 Thread Amit Saxena
On Tue, Jul 22, 2008 at 9:18 AM, Panda-X [EMAIL PROTECTED] wrote:

 Hi,

 I've got this error, anything I can do ?

  Can't locate auto/DBI/data_source.al in @INC 

 Code :

   use DBI;
   my @dataSource = DBI - data_source ( mysql ) ;

 and if I change the as this :

use DBI;
my $dbh = DBI - connect ( dbi:mysql, $adm, $pass ) ;

 I got this error :
 Can't connect to data source 'dbi:mysql' 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 quickPerl.pl line 8

 I have MySQL server installed and it works well with other applications.

 Thanks for help!


Is it because you have not specified the database name in the following
connect statement :-

   use DBI;
   my $dbh = DBI - connect ( dbi:mysql, $adm, $pass ) ;


Regards,
Amit Saxena


Re: DBI install

2008-07-01 Thread Jeff Peng
On Tue, Jul 1, 2008 at 8:39 PM,  [EMAIL PROTECTED] wrote:
 Can any one help me out in Installing DBI in a standalone box. There is no 
 internet connetion. I tried downloading DBI-1.48 module and tried using ppm 
 and makefile.PL its not working. I am doing it correct or missing something?


Posting the error messages here is helpful.
Otherwise the people on the list don't know what happened to you.

-- 
Regards,
Jeff. - [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: DBI install

2008-07-01 Thread Francisco Valladolid
Hi,

if you don't have internet connection, the easy form is downloading
the module via cpan.

http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBI-1.605.tar.gz

later you have to decompress it with :

$ tar -xzvf DBI-1.605.tar.gz
# cd DBI...
# perl Makefile.PL
# make  make install

can do the work.

Regards.


On Tue, Jul 1, 2008 at 5:09 PM,  [EMAIL PROTECTED] wrote:
 Can any one help me out in Installing DBI in a standalone box. There is no 
 internet connetion. I tried downloading DBI-1.48 module and tried using ppm 
 and makefile.PL its not working. I am doing it correct or missing something?




-- 
Francisco Valladolid H.
 -- http://bsdguy.net - Jesus Christ follower.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: DBI Integrated Security

2008-05-29 Thread Jenda Krynicky
From: HESTER, CHRISTOPHER [EMAIL PROTECTED]
 I'm trying to connect to a MSSQL 2000 database using integrated security
 and am not having any success. My understanding is that you only need to
 call DBSETLSECURE before you call dblogin, as in my example below, but
 it doesn't even attempt to be reaching the SQL server. If I uncomment
 the commented line of code (and vice versa for the dblogin line) it then
 tries to login with the 'test' user, which should be ignored. Any help
 would be greatly appreciated!
 
  
 
 DBSETLSECURE;
 
 #$dbh = MSSQL::DBlib-dblogin('test', 'test', $server);
 
 $dbh = MSSQL::DBlib-dblogin($server);

use DBI; # and DBD::ODBC

Jenda


= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: DBI question

2008-05-21 Thread Ken Foskey
On Wed, 2008-05-21 at 23:53 +1000, Ken Foskey wrote:
 I have a program that will run literally for days and days.  It monitors
 logs by file tail.  Problem is that I think the DBI is causing problems.
 It is constantly connecting and reconnecting to DB2 for every
 transaction.

The original did not make much sense reading it back.

I want to redesign the application to have an open connection
permanently.  Problem is that I don't trust it,  what happens if DB2 is
shutdown for instance.   I have to recover the connection.  Problem is I
cannot figure out how to check the connection is still OK without
calling something an have it fail.

What I would like to do is replace my connect subroutine with a grab a
cached DBI handle,  check it is still connected and if it is not
'actually' connected,  ie crashed,  then reconnect it an return the new
DBI handle.

Anyone know of a way to tell that a handle is still valid?

Ken


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: DBI question

2008-05-21 Thread Rob Dixon
Ken Foskey wrote:
 On Wed, 2008-05-21 at 23:53 +1000, Ken Foskey wrote:
 I have a program that will run literally for days and days.  It monitors
 logs by file tail.  Problem is that I think the DBI is causing problems.
 It is constantly connecting and reconnecting to DB2 for every
 transaction.
 
 The original did not make much sense reading it back.
 
 I want to redesign the application to have an open connection
 permanently.  Problem is that I don't trust it,  what happens if DB2 is
 shutdown for instance.   I have to recover the connection.  Problem is I
 cannot figure out how to check the connection is still OK without
 calling something an have it fail.
 
 What I would like to do is replace my connect subroutine with a grab a
 cached DBI handle,  check it is still connected and if it is not
 'actually' connected,  ie crashed,  then reconnect it an return the new
 DBI handle.
 
 Anyone know of a way to tell that a handle is still valid?

Any database operation will tell you whether the handle is still valid.

I suggest you do a SELECT on one of your chosen database's system tables. In
SQLite, for example, you could write

  SELECT * FROM sqlite_master

and a success would indicate that the database is on line.

It might be nice to make sure that the tables you're going to access are in the
list of those that the database knows about. In SQLite you would execute

  SELECT name FROM sqlite_master WHERE type = 'table'

and check that the names of your tables are in the list.

HTH,

Rob


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: DBI prepare syntax

2007-11-08 Thread Mike
That was a rookie mistake :). Double quotes works, thanks Beginner!

Beginner [EMAIL PROTECTED] wrote: On 8 Nov 2007 at 8:59, Mike wrote:

 Hi,

 
 #Update override_exclude set th_flag=N to indicate that thesaurus entries
 #have been added to sierra2_thesaurus.xml
 
 use DBI;
 my $dbh = DBI-connect(dbi:mysql:endeca_tracking,$user,$password);
 my $sth = $dbh-prepare('update override_exclude set th_flag=N 
 where pid=$pid') or die Couldn't prepare statement .$dbh-errstr;
 $sth-execute;

I'm no guru but shouldn't you be double quoting the prepare 
statement:

my $sth = $dbh-prepare(update override_exclude set th_flag='N' 
where pid=$pid)

or better still

my $sth = $dbh-prepare('update override_exclude set th_flag=N 
where pid=?)
$sth-execute($pid);

HTH,
Dp.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




 __
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: DBI prepare syntax

2007-11-08 Thread Douglas Hunter

Mike wrote:

Hi,

I have a variable setup as $pid and i've tried to call this in the prepare part of the DBI module but  i'm  get an Unknown  column $pid syntax error. Probably $pid was passed as a string instead of a variable inside the prepare (''). Anyone has an idea of how i can fix this?   Thanks. 


DBD::mysql::st execute failed: Unknown column '$pid' in 'where clause' at 
createThesaurus.pl line 33,

---

while ( NEW ) {
next if $. == 1;  # exclude header
chomp;
my ($pid,$thesaurus_from,$thesaurus_to,$thesaurus_type) = split /\|/;

#Update override_exclude set th_flag=N to indicate that thesaurus entries
#have been added to sierra2_thesaurus.xml

use DBI;
my $dbh = DBI-connect(dbi:mysql:endeca_tracking,$user,$password);
my $sth = $dbh-prepare('update override_exclude set th_flag=N where pid=$pid') or 
die Couldn't prepare statement .$dbh-errstr;


The prepare statement here is inside single quotes, inside of which Perl 
doesn't interpolate variables (it does inside double quotes).  But DBI 
has a mechanism called placeholders that allow you to not worry about 
quoting and interpolation of variables, documented under the section 
Placeholders and Bind Values in the DBI documentation.


You can change your prepare statement to:

$dbh-prepare('update override_exclude set th_flag=? where pid=?')

(the question marks denote the placeholder)



$sth-execute;



And then change your execute to:

$sth-execute( N, $pid );

to pass along the list of values meant to take the place of your 
placeholders.  This is generally safer than passing variables directly 
to your prepare statement.  For instance, if $pid held a nasty string 
that terminated the original statement and then followed up with 
something destructive, such as 5; truncate table_foo;, bad things 
could happen.  With placeholders you don't have to worry about that, as 
the database driver fixes that up by quoting it properly (not to say you 
shouldn't still validate input to a database!)


Hope that helps a bit,

-- Douglas

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: DBI prepare syntax

2007-11-08 Thread Beginner
On 8 Nov 2007 at 8:59, Mike wrote:

 Hi,

 
 #Update override_exclude set th_flag=N to indicate that thesaurus entries
 #have been added to sierra2_thesaurus.xml
 
 use DBI;
 my $dbh = DBI-connect(dbi:mysql:endeca_tracking,$user,$password);
 my $sth = $dbh-prepare('update override_exclude set th_flag=N 
 where pid=$pid') or die Couldn't prepare statement .$dbh-errstr;
 $sth-execute;

I'm no guru but shouldn't you be double quoting the prepare 
statement:

my $sth = $dbh-prepare(update override_exclude set th_flag='N' 
where pid=$pid)

or better still

my $sth = $dbh-prepare('update override_exclude set th_flag=N 
where pid=?)
$sth-execute($pid);

HTH,
Dp.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: DBI prepare syntax

2007-11-08 Thread Mike
Perl is Awsome!  Thanks for explaining that basic concept to me Douglas!

Douglas Hunter [EMAIL PROTECTED] wrote: Mike wrote:
 Hi,
 
 I have a variable setup as $pid and i've tried to call this in the prepare 
 part of the DBI module but  i'm  get an Unknown  column $pid syntax error. 
 Probably $pid was passed as a string instead of a variable inside the prepare 
 (''). Anyone has an idea of how i can fix this?   Thanks. 
 
 DBD::mysql::st execute failed: Unknown column '$pid' in 'where clause' at 
 createThesaurus.pl line 33,
 
 ---
 
 while (  ) {
 next if $. == 1;  # exclude header
 chomp;
 my ($pid,$thesaurus_from,$thesaurus_to,$thesaurus_type) = split /\|/;
 
 #Update override_exclude set th_flag=N to indicate that thesaurus entries
 #have been added to sierra2_thesaurus.xml
 
 use DBI;
 my $dbh = DBI-connect(dbi:mysql:endeca_tracking,$user,$password);
 my $sth = $dbh-prepare('update override_exclude set th_flag=N 
 where pid=$pid') or die Couldn't prepare statement .$dbh-errstr;

The prepare statement here is inside single quotes, inside of which Perl 
doesn't interpolate variables (it does inside double quotes).  But DBI 
has a mechanism called placeholders that allow you to not worry about 
quoting and interpolation of variables, documented under the section 
Placeholders and Bind Values in the DBI documentation.

You can change your prepare statement to:

$dbh-prepare('update override_exclude set th_flag=? where pid=?')

(the question marks denote the placeholder)


 $sth-execute;
 

And then change your execute to:

$sth-execute( N, $pid );

to pass along the list of values meant to take the place of your 
placeholders.  This is generally safer than passing variables directly 
to your prepare statement.  For instance, if $pid held a nasty string 
that terminated the original statement and then followed up with 
something destructive, such as 5; truncate table_foo;, bad things 
could happen.  With placeholders you don't have to worry about that, as 
the database driver fixes that up by quoting it properly (not to say you 
shouldn't still validate input to a database!)

Hope that helps a bit,

-- Douglas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




 __
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: DBI, postgresql and large table

2007-06-27 Thread Chas Owens

On 6/27/07, Andrej Kastrin [EMAIL PROTECTED] wrote:

Dear all,

I need to process postgresql table with DBI module. The script below
works well for small tables, but when I want to process larger tables
(10 rows) out-of-memory occurs.

Any suggestion? Thanks in advance,
Andrej

use strict;
use warnings;
use DBI;

my $dbh = DBI-connect(DBI:Pg:dbname=medline;host=localhost,
postgres, secret, {'RaiseError' = 1});
my $sth = $dbh-prepare(SELECT text_a, text_b FROM tmp_table);
$sth-execute();

while (my $ref = $sth-fetchrow_hashref()) {
my $field_a = $ref-{'text_a'};
my $field_b = $ref-{'text_b'};
print $field_a \t $field_b\n;
}


* When does it fail and what is the exact error message?
* Have you tried to execute this command in an SQL editor (psql if I
remember correctly)?
* How much memory do you have on that box?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: DBI, postgresql and large table

2007-06-27 Thread Andrej Kastrin

Chas Owens wrote:

On 6/27/07, Andrej Kastrin [EMAIL PROTECTED] wrote:

Dear all,

I need to process postgresql table with DBI module. The script below
works well for small tables, but when I want to process larger tables
(10 rows) out-of-memory occurs.

Any suggestion? Thanks in advance,
Andrej

use strict;
use warnings;
use DBI;

my $dbh = DBI-connect(DBI:Pg:dbname=medline;host=localhost,
postgres, secret, {'RaiseError' = 1});
my $sth = $dbh-prepare(SELECT text_a, text_b FROM tmp_table);
$sth-execute();

while (my $ref = $sth-fetchrow_hashref()) {
my $field_a = $ref-{'text_a'};
my $field_b = $ref-{'text_b'};
print $field_a \t $field_b\n;
}


* When does it fail and what is the exact error message?
* Have you tried to execute this command in an SQL editor (psql if I
remember correctly)?
* How much memory do you have on that box?

1. The error message: DBD::Pg::st execute failed: out of memory for 
query result

2. Everything works fine, when I execute the command in psql
3. 4GB RAM on Linux box

Andrej


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: DBI::execute(): how to evade quoting identifier names

2007-01-02 Thread D. Bolliger
Bram Kuijper am Dienstag, 2. Januar 2007 18:07:
 Hi all,

Hello Bram Kuijper

 I try to execute the following SQL query in PostGreSQL 8.1. However, it
   gives errors since DBI::execute() automatically quotes when it inserts
 its arguments into the SQL query. Is there any way to change the quoting
 behavior of DBI::execute():

 my $qry = ALTER TABLE mytable ALTER COLUMN ? TYPE double precision;
 my $qry_sth = $dbh-prepare($qry);
 $qry_sth-execute($col_name);

 which results in the following query being executed:
 ALTER TABLE mytable ALTER COLUMN 'column_name' TYPE double precision

 The inserted variable, which is an identifier, will receive single
 quotes by DBI::execute(). PostGreSQL gives an error, since it only
 accepts unquoted identifiers. How can I change DBI::prepare() or
 DBI::execute default behavior, so that added values go unquoted?

 I have the idea that this should be done by adding some statement
 handling attribute to the $qry_sth object, but the DBI documentation is
 not very explicit about it.

It states:

Placeholders and Bind Values

With most drivers, placeholders can’t be used for any element of a statement 
that would prevent the database server from validating the statement and 
creating a query execution plan for it. For example:

 SELECT name, age FROM ? # wrong (will probably fail)
 SELECT name, ?   FROM people# wrong (but may not ’fail’)


I think since the alter table operation is not likely to be executed many 
times, and there's no execution plan to calculate, it's ok to simply:

# sanitize $column_name here to prevent sql injection

$dbh-do(
  ALTER TABLE mytable ALTER COLUMN $column_name TYPE double precision
) or die $dbh-errstr;

# see the do() method in perldoc DBI

Dani

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: dbi ^C handling

2006-10-07 Thread Jeff Pang

I killed my update script with the DBI and it left the DB2 connection
hanging so I could not rerun until the DBA killed the thread the next
working day.

What is the preferred handling for killing scripts like this so they
clean up connections?


It's a little strange that when you kill your script all file-handle or 
database-handle opened by this script should be shutdown.Or can you give a try 
to add the $dbh-disconnect statement in script's END {} block?

--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: dbi ^C handling

2006-10-07 Thread Robin Sheat
On Sunday 08 October 2006 13:51, Ken Foskey wrote:
 I killed my update script with the DBI and it left the DB2 connection
 hanging so I could not rerun until the DBA killed the thread the next
 working day.
Was it a long-running operation? I've found that if you issue a command that 
takes a long time (like 'create index' on a large table), then you pretty 
much have to wait until the database finishes up. Otherwise, I've not noted 
problems with hanging connections (not that I've used DB2).

-- 
Robin [EMAIL PROTECTED] JabberID: [EMAIL PROTECTED]

Hostes alienigeni me abduxerunt. Qui annus est?

PGP Key 0xA99CEB6D = 5957 6D23 8B16 EFAB FEF8  7175 14D3 6485 A99C EB6D


pgplYfewVzQJk.pgp
Description: PGP signature


Re: DBI - DB2 Perl Script ... TWiki

2006-09-28 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
 Hi all,

Hello,

 I have this script that am trying to use to connect to DB2.
 
 At the moment I cannot get the script to connect to DB2.
 
 In the UNIX prompt, if I run . /home/db2inst1/sqllib/db2profile first and then
 run the Perl script, then I can connect to DB2.
 
 Also, I can only do export DB2INSTANCE=db2inst1 and then run the Perl script,
 then I can connect to DB2.
 
 Can someone please advise how do I do an export DB2INSTANCE=db2inst1 or run 
 the
 . /home/db2inst1/sqllib/db2profile and that does not work? I tried to include
 the following lines within the Perl script and it does not work too ...

Inside your Perl program do this:

BEGIN {
$ENV{ DB2INSTANCE } = 'db2inst1';
}



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI

2006-08-03 Thread Bjørge Solli
On Tuesday 01 August 2006 17:04, Greg Sabino Mullane wrote:
 You need to tell DBI to import the SQL type constants. This is done by
 replacing 'use DBI;' above with:

 use DBI qw(:sql_types);

Do I have to do something similar to get the below to work?

use strict;
my $insertid;
...
eval {
  #some insertion
  $insertid = $dbh-{'mysql_insertid'};
};
...

At the moment $insertid is always set to 0.

Thanks!

-- 
Bjørge Solli - Office:+47 55205847
Mohn-Sverdrupsenteret, Nansensenteret, Høyteknologisenteret T47
Thormöhlensgate 47, 5006 Bergen, Norway - www.nersc.no
Google Earth: www.nersc.no/GE - TOPAZ: topaz.nersc.no

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: DBI type mismatch

2006-08-03 Thread Ken Foskey
On Tue, 2006-08-01 at 10:13 -0500, Charles K. Clarkson wrote:
 Bjørge Solli wrote:
  
 : I get an error message I don't understand. I've been following
 : what I thought was good practice when talking to a DB.
 
 Did you import those constants?
 
 use DBI qw(:sql_types);

I have a similar problem myself now.  I am getting a type mismatch
because they are strings.  I am doing a split on a csv input file.

I ran bind with SQL_NUMERIC or SQL_INTEGER or SQL_DECIMAL it still
fails. I did a $var +=0 and it worked.  This is an OK solution, not a
great one.

Problem is that there is a dollar value  1234.59 and I am worried that
this will convert to float and corrupt the value.

Is there a better way to do this?

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI

2006-08-02 Thread Bjørge Solli
On Tuesday 01 August 2006 17:04, Greg Sabino Mullane wrote:
  use strict;
  use DBI;
  $sth-bind_param( 1, \$insertid, SQL_INT); #insertid from other
  insertion $sth-bind_param( 2, \$ap, SQL_DOUBLE);

 You need to tell DBI to import the SQL type constants. This is done by
 replacing 'use DBI;' above with:

 use DBI qw(:sql_types);

 Note that SQL_INT is not a valid type: you want to use SQL_INTEGER
 instead. You can view all the available types with this bit of code,
 taken from the documentation for DBI:

Thanks, that helped.

-- 
Bjørge Solli - Office:+47 55205847
Mohn-Sverdrupsenteret, Nansensenteret, Høyteknologisenteret T47
Thormöhlensgate 47, 5006 Bergen, Norway - www.nersc.no
Google Earth: www.nersc.no/GE - TOPAZ: topaz.nersc.no

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI

2006-08-01 Thread Greg Sabino Mullane
 use strict;
 use DBI;
   $sth-bind_param( 1, \$insertid, SQL_INT); #insertid from other 
 insertion
   $sth-bind_param( 2, \$ap, SQL_DOUBLE);

You need to tell DBI to import the SQL type constants. This is done by
replacing 'use DBI;' above with:

use DBI qw(:sql_types);

Note that SQL_INT is not a valid type: you want to use SQL_INTEGER
instead. You can view all the available types with this bit of code,
taken from the documentation for DBI:

no strict 'refs';
for (sort @{ $DBI::EXPORT_TAGS{sql_types} }) {
  printf %s=%d\n, $_, {DBI::$_};
}

In addition, whichever database driver you are using may have its own
type constants available. For example, if you are using Postgres, you
can specify:

use DBD::Pg (:pg_types);

Hope that helps.

--
Greg Sabino Mullane [EMAIL PROTECTED]  [EMAIL PROTECTED]
End Point Corporation http://www.endpoint.com/
PGP Key: 0x14964AC8 200608011102
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8



signature.asc
Description: This is a digitally signed message part


RE: DBI

2006-08-01 Thread Charles K. Clarkson
Bjørge Solli wrote:
 
: I get an error message I don't understand. I've been following
: what I thought was good practice when talking to a DB.

Did you import those constants?

use DBI qw(:sql_types);


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI

2006-08-01 Thread rahed
[EMAIL PROTECTED] (Bjørge Solli) writes:

 Hi,

 I get an error message I don't understand. I've been following what I
 thought was good practice when talking to a DB.

 use DBI;

Import :sql_types tag.
use DBI qw/:sql_types/;

-- 
Radek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI::AnyData problem

2006-03-26 Thread Stephen Day
On Sunday 26 March 2006 18:58, Stephen Day wrote:
 I have perl, v5.8.7 built for i686-linux running on gentoo.
 I've installed the DBI::AnyData modules ( DBI, SQL::Statement, DBD::CSV,
 AnyData, DBD::AnyData ) with perl -e  'use CPAN; install  whatever'

 I have the following script more or less copied from the CPAN example:
 -- Start
 #!/usr/bin/perl
 use DBI;

 my $dbh = DBI-connect('dbi:AnyData(RaiseError=1):');
 $dbh-func( 'users', 'Passwd', '/etc/passwd', 'ad_catalog');
 my $sth = $dbh-prepare(SELECT username FROM users);
 $sth-execute();

 while (my $row = $sth-fetch) {
 print @$row\n;
 }

 $sth-finish();
 $dbh-disconnect();
 -- End

 The script works ( lists all usernames from /etc/passwd ) but always
 returns the following warning at the end:

 DBI handle 0x8529630 cleared whilst still active.
 dbih_clearcom (sth 0x8529630, com 0x85452e8, imp DBD::AnyData::st):
FLAGS 0x182195: COMSET Active Warn RaiseError PrintError PrintWarn
 ShowErrorStatement
PARENT DBI::db=HASH(0x8529504)
KIDS 0 (0 Active)
IMP_DATA undef
NUM_OF_FIELDS 1
NUM_OF_PARAMS 0

 The only help I can find on google says do '$sth-finish()', Well I did and
 it didn't help.


 Any idea what is going wrong here?


 Stephen

A clearer example of this is as follows:

--Start script
#!/usr/bin/perl
use DBI;

my $dbh = DBI-connect('dbi:AnyData(RaiseError=1):');
$dbh-func('mytable','CSV','data.csv','ad_catalog');
my $sth = $dbh-prepare(SELECT some FROM mytable);

$sth-execute();

while ( my $row = $sth-fetch ) {
  print @$row\n;
}

$sth-finish();
$dbh-disconnect();
-- End

--Start data.csv
some,csv,data,not,a,lot,but,enough,to,test,with
some1,csv1,data1,not1,a1,lot1,but1,enough1,to1,test1,with1
some2,csv2,data2,not2,a2,lot2,but2,enough2,to2,test2,with2
some3,csv3,data3,not3,a3,lot3,but3,enough3,to3,test3,with3
--End

Result:
$ ./t1.pl
some1
some2
some3
DBI handle 0x85fa9dc cleared whilst still active.
dbih_clearcom (sth 0x85fa9dc, com 0x85fbb48, imp DBD::AnyData::st):
   FLAGS 0x182195: COMSET Active Warn RaiseError PrintError PrintWarn 
ShowErrorStatement
   PARENT DBI::db=HASH(0x85fa8b0)
   KIDS 0 (0 Active)
   IMP_DATA undef
   NUM_OF_FIELDS 1
   NUM_OF_PARAMS 0


Stephen

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI/SQL question

2006-03-15 Thread Robert Hicks

Robert Hicks wrote:
I have a large array of numbers that I need to use in an update SQL 
statement using a like clause.


my @nums = ( 123 456 789 );

foreach my $num (@nums) {
$dbh-do(q{update table_name set item_desc1 = item_desc2 where equip 
like # I draw a blank here

}

I am not sure how to use the $num in a like since a like is '%' and it I 
do '%$num' that won't be ierpolated.


Help...

Robert
Never mind...I was mixing my SQL thoughts with my Perl thoughts and 
coming up blank.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: DBI problem

2005-12-16 Thread Charles K. Clarkson
john mailto:[EMAIL PROTECTED] wrote:

: Thanks, Charles, for your suggestions. I think I've incorporated
: most of them.

You're welcome.


: Your regex is a lot more practical than what I was using.

I wouldn't have used it a year ago. Perhaps I'm getting
better. :)


: Here is the improved script. I can live with the one warning
: Newline in left-justified string for printf at ./describe_skus.pl
: line 29.

That's strange, there doesn't seem to be a new line in that
format string. Try adding this to the top of the script and see if
you can track down the problem. You might get a better idea of how
to correct this problem. Did you leave it wrapped like it is in the
email perhaps? The format should all be on one line.

: #!/usr/bin/perl -w
: use strict;
: use DBI;

use diagnostics;

===

I indented and wrapped this to make it easier to read.

: while ( my $columns = $sth2-fetchrow_arrayref() ) {
: printf OUTFILE (%-4d %-40s %-22s %d,
  @$columns[0],
  @$columns[1],
  @$columns[2],
  @$columns[3]
  );
: print OUTFILE \n;
: }

I assume you chose fetchrow_arrayref() over fetchrow_array()
because it's more efficient. Good. Now we need to break
you of this double-quoting variables habit. :)

The code above can be written without the double quotes. The
only warning is from the printf.

while ( my $columns = $sth2-fetchrow_arrayref() ) {
printf OUTFILE (
'%-4d %-40s %-22s %d',
@$columns[0],
@$columns[1],
@$columns[2],
@$columns[3],
);
print OUTFILE \n;
}

You can play along at home with this test code (no database
needed).

while ( my $columns = [0..3] ) {
printf (
'%-4d %-40s %-22s %d',
@$columns[0],
@$columns[1],
@$columns[2],
@$columns[3],
);
print \n;
last;
}

When I run this, I get the following error. We can avoid this
by dropping the parenthesis. See code below.

printf (...) interpreted as function at a.pl line 10.


while ( my $columns = [0..3] ) {
printf
'%-4d %-40s %-22s %d',
@$columns[0],
@$columns[1],
@$columns[2],
@$columns[3];

print \n;
last;
}


The new line (\n) can be added into the format and allow us to
eliminate the second print statement. Special characters like this
and \t are the only reasons for putting formats in double quotes.
Only single quoted strings are normally needed.

while ( my $columns = [0..3] ) {
printf
%-4d %-40s %-22s %d\n,
@$columns[0],
@$columns[1],
@$columns[2],
@$columns[3];

last;
}

While this code does not give any errors, it is more common to
use the - operator.

while ( my $columns = [0..3] ) {
printf
%-4d %-40s %-22s %d\n,
$columns-[0],
$columns-[1],
$columns-[2],
$columns-[3];

last;
}

There is another way to go. In this example we deference the
array reference with the @{} operator.

while ( my $columns = [0..3] ) {
printf
%-4d %-40s %-22s %d\n,
@{ $columns };

last;
}

As a shortcut we can use @$columns.

while ( my $columns = [0..3] ) {
printf
%-4d %-40s %-22s %d\n,
@$columns;

last;
}

Taking this back to the database example, we end up with this.

while ( my $columns = $sth2-fetchrow_arrayref() ) {
printf %-4d %-40s %-22s %d\n, @$columns;
}


Or, if you are feeling lucky, this might do.

printf %-4d %-40s %-22s %d\n, @$_ while $sth2-fetchrow_arrayref();


If the sku column is unique, only one row is returned and
this will do the trick.

printf %-4d %-40s %-22s %d\n, @{ $sth2-fetchrow_arrayref() };

# or (maybe):

printf %-4d %-40s %-22s %d\n, $sth2-fetchrow_array();


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI problem

2005-12-15 Thread john
Thanks, Charles, for your suggestions. I think I've incorporated most of 
them.

Your regex is a lot more practical than what I was using.
Here is the improved script. I can live with the one warning
Newline in left-justified string for printf at ./describe_skus.pl line 29.
John

#!/usr/bin/perl -w
use strict;
use DBI;

# purpose: To take sku numbers from a text file, no-imgs.txt,
# and print out their database descriptions, to a separate text file, 
need-images.txt.


open INFILE, no-imgs.txt or die Input file failed to open: $!;
chomp( my @skus = map /^\s*(\d*)\s*$/, INFILE );
close INFILE;

open OUTFILE,  need-images.txt or die Output filehandle not open: $!;
print OUTFILESKU \t TITLE \t\t\t\t VENDOR_STOCK_NO \t VENDOR_ID \n;
print OUTFILE - - - - - - - - - - - - - - - - - - - - - - - - - - -\n;

my $dbh=DBI-connect('dbi:mysql:productdb','script','') ||
die Error connecting to database: $DBI::errstr;

my $query2 = q{select sku, title, vendor_stock_no, vendor_id
FROM products
WHERE sku=?
};

for my $sku (@skus) {
my $sth2= $dbh-prepare($query2) || die Prepare failed: $DBI::errstr;
$sth2-execute ($sku) || die Couldn't execute query: $DBI::errstr;

while ( my $columns = $sth2-fetchrow_arrayref() ) {
printf OUTFILE (%-4d %-40s %-22s 
%d,@$columns[0],@$columns[1],@$columns[2],@$columns[3]);

print OUTFILE \n;
}
$sth2-finish ();
}

$dbh-disconnect || die Failed to disconnect\n;
close OUTFILE or die Cannot close output file: $!;


Charles K. Clarkson wrote:


john mailto:[EMAIL PROTECTED] wrote:

: Yes, you're right. I changed this line:
: while ((my $ref) = $sth2 -fetchrow_hashref($num)) {...
: by removing the parameter, and quotes around 'my $ref' :
: while (my $ref = $sth2 -fetchrow_hashref()) {...
: and the script works now.

   For the archives: Those were parenthesis, not quotes, which
were replaced around my $ref.


John,

   I'm glad you solved this problem, but there are some other
items in your code that need mentioning. To save some line
wrapping I'm going to delete two levels of email indentation. I'm
also going to leave the new lines off the end of my die
statements. This gives a better idea of where problems originated.
Read the perl docs for die for details on why.


: open INFILE, no-imgs.txt or die Input file failed to open: $!\n;
: open OUTFILE,  need-images.txt or die Output filehandle not open:
$!\n;
: my @nums = INFILE;

   This is the first section that I wanted to comment on. When
programming, we are writing a story. We often introduce some
characters at the beginning, describe the setting, and bring in
more characters as the story unfolds.

When writing a script it becomes important to keep the reader
in mind. Program readers are the people who come behind: code
maintainers and such. I often program for the only one maintainer,
my future self. I know that in six months or a year, I will not be
the same programmer I am now and that some of the things I do may
look very odd. I try to keep my utterly confused future self in
mind while I write.

I mention this because I want other script authors to grasp
the importance of the timeline in a story. In perl, we generally
wait to the last moment to bring out new characters, like lexical
variables. Sometimes we want to introduce a character and then
remove them as soon as possible, like I/O operations.

So, several things struck me as odd about these there lines.
First, we don't close INFILE. We're finished with it, why leave it
open? Second, why open a file, do something unrelated (though
similar) and then suck in the open file? Why not open the file,
suck in the file, and close the file then move to the next task?
Third, is $nums really a descriptive name for a variable? How
about @skus, @sku_numbers, or @stock_keeping_unts.

Fourth, why do only this very limited processing of the file?
Later on, we strip line endings and white space to end up with
just sku numbers. Why not just start with those? The approach used
in the script to obtain sku numbers was exclusionary. Exclude the
characters we don't want, the rest are sku numbers.

In a thread on email regular expressions last month, one guru
mentioned that a safer regular expression for that subject was
one in which we only include valid characters for a field. Let's
do the same for these sku numbers.

   I don't know how your sku numbers are formatted, so I'll just
make a format up. You can modify that to meet your needs. I'll use
a simple 6 digit number, like 123456 or 024569.

   (I use the three argument open and tend to recycle file
handles. Unless it is already open I just keep using $fh for every
file I open.)

my $file = 'no-imgs.txt';
open my $fh, '', $file or die qq(Cannot open $file: $!);
chomp( my @sku_numbers = map /^\s*(\d{6})\s*$/, $fh );
close $fh;

Wow, that's a mouthful!

You can chomp an array all at once.

chomp( @sku_numbers );

You can chomp an array as it is assigned.

chomp( 

RE: DBI problem

2005-12-14 Thread Charles K. Clarkson
john mailto:[EMAIL PROTECTED] wrote:

: I can't see it in emacs.
: What do you mean by dump the last line of the file in binary?

I don't use emacs, but if you open the file in a hex editor you
can view each character and see how your lines and files end.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI problem

2005-12-14 Thread Frank Bax

At 11:07 PM 12/13/05, john wrote:

I can't see it in emacs.


Then my guess was off-base.

What do you mean by dump the last line of the file in binary? Sounds 
like something I need to learn about.



 tail -2 filename | cat -v

-v  Displays non-printing characters so they are visible.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: DBI problem

2005-12-14 Thread Charles K. Clarkson
john mailto:[EMAIL PROTECTED] wrote:

: Yes, you're right. I changed this line:
: while ((my $ref) = $sth2 -fetchrow_hashref($num)) {...
: by removing the parameter, and quotes around 'my $ref' :
: while (my $ref = $sth2 -fetchrow_hashref()) {...
: and the script works now.

For the archives: Those were parenthesis, not quotes, which
were replaced around my $ref.


John,

I'm glad you solved this problem, but there are some other
items in your code that need mentioning. To save some line
wrapping I'm going to delete two levels of email indentation. I'm
also going to leave the new lines off the end of my die
statements. This gives a better idea of where problems originated.
Read the perl docs for die for details on why.


: open INFILE, no-imgs.txt or die Input file failed to open: $!\n;
: open OUTFILE,  need-images.txt or die Output filehandle not open:
$!\n;
: my @nums = INFILE;

This is the first section that I wanted to comment on. When
programming, we are writing a story. We often introduce some
characters at the beginning, describe the setting, and bring in
more characters as the story unfolds.

When writing a script it becomes important to keep the reader
in mind. Program readers are the people who come behind: code
maintainers and such. I often program for the only one maintainer,
my future self. I know that in six months or a year, I will not be
the same programmer I am now and that some of the things I do may
look very odd. I try to keep my utterly confused future self in
mind while I write.

I mention this because I want other script authors to grasp
the importance of the timeline in a story. In perl, we generally
wait to the last moment to bring out new characters, like lexical
variables. Sometimes we want to introduce a character and then
remove them as soon as possible, like I/O operations.

So, several things struck me as odd about these there lines.
First, we don't close INFILE. We're finished with it, why leave it
open? Second, why open a file, do something unrelated (though
similar) and then suck in the open file? Why not open the file,
suck in the file, and close the file then move to the next task?
Third, is $nums really a descriptive name for a variable? How
about @skus, @sku_numbers, or @stock_keeping_unts.

Fourth, why do only this very limited processing of the file?
Later on, we strip line endings and white space to end up with
just sku numbers. Why not just start with those? The approach used
in the script to obtain sku numbers was exclusionary. Exclude the
characters we don't want, the rest are sku numbers.

In a thread on email regular expressions last month, one guru
mentioned that a safer regular expression for that subject was
one in which we only include valid characters for a field. Let's
do the same for these sku numbers.

I don't know how your sku numbers are formatted, so I'll just
make a format up. You can modify that to meet your needs. I'll use
a simple 6 digit number, like 123456 or 024569.

(I use the three argument open and tend to recycle file
handles. Unless it is already open I just keep using $fh for every
file I open.)

my $file = 'no-imgs.txt';
open my $fh, '', $file or die qq(Cannot open $file: $!);
chomp( my @sku_numbers = map /^\s*(\d{6})\s*$/, $fh );
close $fh;

Wow, that's a mouthful!

You can chomp an array all at once.

chomp( @sku_numbers );

You can chomp an array as it is assigned.

chomp( my @sku_numbers = $fh );

And since map is just another assignment, you can chomp an
array while you map it into a nicer form.

chomp( my @sku_numbers = map /blah/, $fh );


The regex can be broken down as follows.

/   # open match - same as m/
^   # Anchor this match to the beginning
of the line.
\s* # match 0 or more white space
characters.
(   # begin capture.
\d{6}   # capture six digits in a row. 
)   # end capture.
\s* # match 0 or more white space
characters.
$   # Anchor this match to the end of
the line.
/   # close match

If there is no match, map moves on to the next line. The
result is only valid sku numbers remain @sku_numbers.
 

: my $dbh=DBI-connect('dbi:mysql:productdb','script','') ||
:   die Error connecting to database: $DBI::errstr\n;
: 
: my $query2 = qq{SELECT `sku`, `title`, `vendor_stock_no`,
: `vendor_id` FROM `products` WHERE `sku`=?};

I assume the back ticks are needed in the mySQL admin script
you use, but they are not required by the DBI (AFAIK).

my $query2 = qq{SELECT sku, title, vendor_stock_no, vendor_id
FROM

Re: DBI problem

2005-12-13 Thread Octavian Rasnita
Hi,

As far as I know, the method fetchrow_hashref doesn't require a parameter
(like fetchall_hashref).

Teddy

- Original Message - 
From: john [EMAIL PROTECTED]
To: beginners@perl.org
Sent: Tuesday, December 13, 2005 09:30 AM
Subject: DBI problem


 Hi all-
 I'm attempting to loop thru an input file,  executing a SELECT query
 with the value from each line.
 The script works for the first iteration, and then gives these error
 messages:

 DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at
 ./describe_skus.pl line 27, INFILE line 2190.
 Use of uninitialized value in print at ./describe_skus.pl line 27,
 INFILE line 2190.
 Use of uninitialized value in print at ./describe_skus.pl line 27,
 INFILE line 2190.
 Use of uninitialized value in print at ./describe_skus.pl line 27,
 INFILE line 2190.
 Use of uninitialized value in print at ./describe_skus.pl line 27,
 INFILE line 2190.

 (INFILE line 2190 is the last line.)
 Here's my script:

 #!/usr/bin/perl -w
 use strict;
 use DBI;

 # purpose: To take sku numbers from a text file, no-imgs.txt,
 # and print out their database descriptions, to a separate text file,
 need-images.txt.

 open INFILE, no-imgs.txt or die Input file failed to open: $!\n;
 open OUTFILE,  need-images.txt or die Output filehandle not open:
 $!\n;
 my @nums = INFILE;

 my $dbh=DBI-connect('dbi:mysql:productdb','script','') ||
die Error connecting to database: $DBI::errstr\n;

 my $query2 = qq{SELECT `sku`, `title`, `vendor_stock_no`, `vendor_id`
 FROM `products` WHERE `sku`=?};

 for my $num (@nums) {
 last unless $num; #exit at end-of-input-file
 next if $num =~ /^\s*\t*\n$/;  # to skip over blank lines
 $num =~ s/^\s+//; # delete leading spaces
 chomp $num;

 my $sth2= $dbh-prepare($query2) || die Prepare failed:
 $DBI::errstr\n;
 $sth2-execute ($num) || die Couldn't execute query:
$DBI::errstr\n;

 while ((my $ref) = $sth2 -fetchrow_hashref($num)) {
 print OUTFILE sku, \t title, \t vendor_stock_no, \t vendor_id
\n,
  $ref-{sku}, $ref-{title}, $ref-{vendor_stock_no},
 $ref-{vendor_id};
 }
 $sth2-finish ();
 }

 $dbh-disconnect || die Failed to disconnect\n;
 close OUTFILE or die cannot close output file need-imgs.txt: $!;
 #End

 Thanks in advance for your suggestions.
 John



 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI problem

2005-12-13 Thread Frank Bax

At 02:30 AM 12/13/05, john wrote:
I'm attempting to loop thru an input file,  executing a SELECT query with 
the value from each line.

The script works for the first iteration, and then gives these error messages:

DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at 
./describe_skus.pl line 27, INFILE line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27, 
INFILE line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27, 
INFILE line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27, 
INFILE line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27, 
INFILE line 2190.


(INFILE line 2190 is the last line.)



Are you saying your input file contains 2190 lines?  If so, dump the last 
line of the file in binary - my guess is that the last character in the 
file is Ctrl-Z - an EOF marker on some systems; and that it follows a newline. 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI problem

2005-12-13 Thread john

Teddy,
Yes, you're right. I changed this line:
   while ((my $ref) = $sth2 -fetchrow_hashref($num)) {...
by removing the parameter, and quotes around 'my $ref' :
   while (my $ref = $sth2 -fetchrow_hashref()) {...
and the script works now.

Thanks for your help.
John


Octavian Rasnita wrote:


Hi,

As far as I know, the method fetchrow_hashref doesn't require a parameter
(like fetchall_hashref).

Teddy

- Original Message - 
From: john [EMAIL PROTECTED]

To: beginners@perl.org
Sent: Tuesday, December 13, 2005 09:30 AM
Subject: DBI problem


 


Hi all-
I'm attempting to loop thru an input file,  executing a SELECT query
with the value from each line.
The script works for the first iteration, and then gives these error
messages:

DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at
./describe_skus.pl line 27, INFILE line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27,
INFILE line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27,
INFILE line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27,
INFILE line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27,
INFILE line 2190.

(INFILE line 2190 is the last line.)
Here's my script:

#!/usr/bin/perl -w
use strict;
use DBI;

# purpose: To take sku numbers from a text file, no-imgs.txt,
# and print out their database descriptions, to a separate text file,
need-images.txt.

open INFILE, no-imgs.txt or die Input file failed to open: $!\n;
open OUTFILE,  need-images.txt or die Output filehandle not open:
$!\n;
my @nums = INFILE;

my $dbh=DBI-connect('dbi:mysql:productdb','script','') ||
  die Error connecting to database: $DBI::errstr\n;

my $query2 = qq{SELECT `sku`, `title`, `vendor_stock_no`, `vendor_id`
FROM `products` WHERE `sku`=?};

for my $num (@nums) {
   last unless $num; #exit at end-of-input-file
   next if $num =~ /^\s*\t*\n$/;  # to skip over blank lines
   $num =~ s/^\s+//; # delete leading spaces
   chomp $num;

   my $sth2= $dbh-prepare($query2) || die Prepare failed:
$DBI::errstr\n;
   $sth2-execute ($num) || die Couldn't execute query:
   


$DBI::errstr\n;
 


   while ((my $ref) = $sth2 -fetchrow_hashref($num)) {
   print OUTFILE sku, \t title, \t vendor_stock_no, \t vendor_id
   


\n,
 


$ref-{sku}, $ref-{title}, $ref-{vendor_stock_no},
$ref-{vendor_id};
   }
   $sth2-finish ();
}

$dbh-disconnect || die Failed to disconnect\n;
close OUTFILE or die cannot close output file need-imgs.txt: $!;
#End

Thanks in advance for your suggestions.
John



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response


   




 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI problem

2005-12-13 Thread john

Frank,
I can't see it in emacs.
What do you mean by dump the last line of the file in binary? 
Sounds like something I need to learn about.

John


Frank Bax wrote:


At 02:30 AM 12/13/05, john wrote:

I'm attempting to loop thru an input file,  executing a SELECT query 
with the value from each line.
The script works for the first iteration, and then gives these error 
messages:


DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at 
./describe_skus.pl line 27, INFILE line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27, 
INFILE line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27, 
INFILE line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27, 
INFILE line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27, 
INFILE line 2190.


(INFILE line 2190 is the last line.)




Are you saying your input file contains 2190 lines?  If so, dump the 
last line of the file in binary - my guess is that the last character 
in the file is Ctrl-Z - an EOF marker on some systems; and that it 
follows a newline.




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI fetch

2005-09-29 Thread Tom Allison

Peter Scott wrote:
On Sat, 27 Aug 2005 14:07:09 +0300, Octavian Rasnita wrote: 


What do you think, if the most important is the speed, which method is
recommended to get the results of a DBI query?

fetchrow_arrayref
or
fetchrow_array

(I guess that fetchrow_hashref has the lowest speed).



That wasn't one of your choices.

Don't guess, measure.  perldoc Benchmark.



Peters right.  Measure it.  And I would love to know your findings.  But 
you probably need to include the database (pgsql, mysql, oracle...) 
because of the different backends.


Be careful that your first SQL doesn't become cached giving you 
artificially fast returns on subsequent queries.  In Oracle I typically 
can run a SQL statement in say 3 seconds and run it again right away and 
get 0.2 seconds.  But you'll see that on the first two runs.


One thing that Perl has a lot of (and doesn't get enough coverage) are 
the tools for development.  Benchmark, Test::More, Devel::Size, 
Devel::Cover, Data::Dumper -- these are all wonderful tools at your 
disposal and well worth spending some serious time learning how to use.


As an anectdote, my brother has fallen in favor with Python while I'm a 
Perl fan.  Tools like this are either unavailable or unknown to him (I 
honestly don't know which).  In either case it's apparent that he has a 
lot of work to do in validating and testing code that I don't have to 
experience.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




More re: DBI::Proxy failure

2005-09-12 Thread Mason Loring Bliss
It seems that when I have dbiproxy log to the terminal, it gives more
information, which hopefully will be of some use:

Mon Sep 12 12:37:03 2005 err, 1, Error while connecting to DBI:Pg:dbname=oracle 
as mason: DBI::ProxyServer connect('dbname=oracle','mason',...) failed: FATAL:  
IDENT authentication failed for user mason
 [err=1,state=S1000] at /usr/lib/perl5/DBI.pm line 604 thread 1
DBI::__ANON__('undef', 'undef') called at /usr/lib/perl5/DBI.pm line 
660 thread 1
DBI::connect('DBI::ProxyServer', 'DBI:Pg:dbname=oracle', 'mason', 
'testing', 'HASH(0x85947e8)') called at /usr/lib/perl5/DBI/ProxyServer.pm line 
200 thread 1   
eval {...} called at /usr/lib/perl5/DBI/ProxyServer.pm line 189 thread 1
DBI::ProxyServer::AcceptUser('DBI::ProxyServer=HASH(0x839f69c)', 
'mason', 'testing') called at /usr/share/perl5/RPC/PlServer.pm line 171 thread 1
RPC::PlServer::Accept('DBI::ProxyServer=HASH(0x839f69c)') called at 
/usr/share/perl5/Net/Daemon.pm line 506 thread 1
eval {...} called at /usr/share/perl5/Net/Daemon.pm line 505 thread 1
Net::Daemon::HandleChild('DBI::ProxyServer=HASH(0x839f69c)') called at 
/usr/share/perl5/Net/Daemon.pm line 466 thread 1
Net::Daemon::__ANON__('DBI::ProxyServer=HASH(0x839f69c)', 
'HandleChild') called at /usr/share/perl5/Net/Daemon.pm line 468 thread 1
eval {...} called at /usr/share/perl5/Net/Daemon.pm line 468 thread 1

Mon Sep 12 12:37:03 2005 err, 1, Refusing client


Thanks in advance for clues!

-- 
 Mason Loring Bliss [EMAIL PROTECTED]http://blisses.org/  
I am a brother of jackals, and a companion of ostriches.  (Job 30 : 29)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




SOLUTION (was Re: More re: DBI::Proxy failure)

2005-09-12 Thread Mason Loring Bliss
On Mon, Sep 12, 2005 at 12:44:43PM -0400, Mason Loring Bliss wrote:

 Mon Sep 12 12:37:03 2005 err, 1, Refusing client

So, this was, indeed, PostgreSQL refusing the connection, and not a DBI
issue at all. This was masked by DBI::ProxyServer returning a user could
not authenticate error even without the database running, which was
weird, but when I tweaked PostgreSQL's access specifiers to not require
connectors and account names to match, I was able to get in.

Thanks, all, for the assistance! Tricky, tricky.

-- 
  Mason Loring Bliss  [EMAIL PROTECTED]   I m m a n e n t i z e
awake ? sleep : dream;http://blisses.org/ t h e E s c h a t o n


pgpWFcy6AxUmF.pgp
Description: PGP signature


Re: DBI fetch

2005-08-27 Thread Peter Scott
On Sat, 27 Aug 2005 14:07:09 +0300, Octavian Rasnita wrote: 
 What do you think, if the most important is the speed, which method is
 recommended to get the results of a DBI query?
 
 fetchrow_arrayref
 or
 fetchrow_array
 
 (I guess that fetchrow_hashref has the lowest speed).

That wasn't one of your choices.

Don't guess, measure.  perldoc Benchmark.

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI insert vs update question

2005-07-10 Thread Octavian Rasnita
Can't you use the replace sql query?

Use it like you use insert. It will insert new rows where there are no
rows, and do an update where there are rows...

Teddy


- Original Message - 
From: Peter Rabbitson [EMAIL PROTECTED]
To: beginners@perl.org
Sent: Sunday, July 10, 2005 18:09 PM
Subject: DBI insert vs update question


 Hello everyone,
 I want someone to share his expertise on the following:
 Suppose we have a table with some data that periodically must be synced
 with an external source, which provides only partial information (e.g.
 it might provide all the fields for a new record, but might provide
 only a single field difference for an already existing record). This
 obviously will involve a series of UPDATE and INSERT statements, mostly
 in random order. As most RDBMS can hold only one prepared statement at a
 time (including MySQL) I have 2 ways to do this that look somewhat
 efficient:

 1. Sweep the pre-existing table into a hash, DELETE all the records from
 it and INSERT the new data, using the hash as a source for missing
 fields.

 2. Create 3 connections to the database, have the first one hold a
 SELECT statement that will replace the hash above, have the second
 connection be an INSERT for nonexisting records and the third connection
 be an UPDATE for existing ones

 From reading on DBI I understood that moving lots of data with do()
 statements is pretty slow (e.g. constantly re-preparing the same
 statement), so I think scenario 2 with a single connection is even
 worse.

 The reason I am elaborating on this is that I am afraid the dataset will
 stop fitting in memory at some point of time if I go with scenario 1
 (which is easier and cleaner to implement). Also I have no idea how
 resource intensive scenario 2 would be, although I have proper
 indexing and stuff so the UPDATES should be fast enough...

 Thanks

 Peter

 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI insert vs update question

2005-07-10 Thread Peter Rabbitson
On Sun, Jul 10, 2005 at 06:23:19PM +0300, Octavian Rasnita wrote:
 Can't you use the replace sql query?
 
 Use it like you use insert. It will insert new rows where there are no
 rows, and do an update where there are rows...
 

Negative. REPLACE is just a shortcut for DELETE FROM... INESERT INTO (at 
least in MySQL) with some pretty neat gimmicks to find out what exactly 
to DELETE. Performance is the same but you have less control.

Peter

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI insert vs update question

2005-07-10 Thread Peter Rabbitson
 I'm sure others will give you more informed answers..  But why can't
 you create multiple statement handlers under the same connection?
 

Because you can't. One connection holds only one prepared statement (at 
least in MySQL). If you prepare $statement2 on the same $dbh, 
$statement1 automatically gets invalidated. Clinically proven :)

Peter


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI insert vs update question

2005-07-10 Thread Mads N. Vestergaard

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hey Peter,

Are you sure about that?
As far as I understand, what you say you can't do, is to have two
prepares  for example:

my $dbh = DBI-connect(dbi:mysql:database,user,pass);
my $foo = $dbh-prepare(SELECT * FROM .);
my $bar = $dbh-prepare(INSERT INTO .);
$foo-execute();
$foo-finish();
$bar-execute();
$bar-finish();

At least that works for me.

Sorry if I misunderstood you.


Mads

Peter Rabbitson wrote:
|I'm sure others will give you more informed answers..  But why can't
|you create multiple statement handlers under the same connection?
|
|
|
| Because you can't. One connection holds only one prepared statement (at
| least in MySQL). If you prepare $statement2 on the same $dbh,
| $statement1 automatically gets invalidated. Clinically proven :)
|
| Peter
|
|

- --
Mads N. Vestergaard - http://rwxr-xr-x.dk
Interested in Open Source, and web application development
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFC0Ukt7WOaPMd53OMRAvcCAJ0Y/kCn1Oh67D3AUrCfpq7ihBOu8QCeO/SC
JMvYjVK+8naZfgReXn13AQU=
=psBJ
-END PGP SIGNATURE-

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI insert vs update question

2005-07-10 Thread David Van Ginneken
Below is taken from: http://search.cpan.org/dist/DBD-mysql/lib/DBD/mysql.pm

Also look at: 
http://dev.mysql.com/tech-resources/articles/4.1/prepared-statements.html


Prepared statement support (server side prepare)

To use server side prepared statements, all you need to do is set
the variable mysql_server_prepare in the connect:

$dbh = DBI-connect(
DBI:mysql:database=test;host=localhost:mysql_server_prepare=1, ,
, { RaiseError = 1, AutoCommit = 1 } );

To make sure that the 'make test' step tests whether server
prepare works, you just need to export the env variable
MYSQL_SERVER_PREPARE:

export MYSQL_SERVER_PREPARE=1

Test first without server side prepare, then with.


On 7/10/05, Mads N. Vestergaard [EMAIL PROTECTED] wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 Hey Peter,
 
 Are you sure about that?
 As far as I understand, what you say you can't do, is to have two
 prepares  for example:
 
 my $dbh = DBI-connect(dbi:mysql:database,user,pass);
 my $foo = $dbh-prepare(SELECT * FROM .);
 my $bar = $dbh-prepare(INSERT INTO .);
 $foo-execute();
 $foo-finish();
 $bar-execute();
 $bar-finish();
 
 At least that works for me.
 
 Sorry if I misunderstood you.
 
 
 Mads
 
 Peter Rabbitson wrote:
 |I'm sure others will give you more informed answers..  But why can't
 |you create multiple statement handlers under the same connection?
 |
 |
 |
 | Because you can't. One connection holds only one prepared statement (at
 | least in MySQL). If you prepare $statement2 on the same $dbh,
 | $statement1 automatically gets invalidated. Clinically proven :)
 |
 | Peter
 |
 |
 
 - --
 Mads N. Vestergaard - http://rwxr-xr-x.dk
 Interested in Open Source, and web application development
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.1 (GNU/Linux)
 
 iD8DBQFC0Ukt7WOaPMd53OMRAvcCAJ0Y/kCn1Oh67D3AUrCfpq7ihBOu8QCeO/SC
 JMvYjVK+8naZfgReXn13AQU=
 =psBJ
 -END PGP SIGNATURE-
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI insert vs update question

2005-07-10 Thread Wiggins d'Anconia
Peter Rabbitson wrote:
 Hello everyone,
 I want someone to share his expertise on the following:
 Suppose we have a table with some data that periodically must be synced 
 with an external source, which provides only partial information (e.g. 
 it might provide all the fields for a new record, but might provide 
 only a single field difference for an already existing record). This 
 obviously will involve a series of UPDATE and INSERT statements, mostly 
 in random order. As most RDBMS can hold only one prepared statement at a 
 time (including MySQL) I have 2 ways to do this that look somewhat 
 efficient:


What version of MySQL? Generally this would be handled with a
transaction, but only newer MySQLs support them. And I suspect Randal
(if he is listening) will pop in with a comment about using PostgreSQL
right about now :-). And now, having used both I would agree with him.

 1. Sweep the pre-existing table into a hash, DELETE all the records from 
 it and INSERT the new data, using the hash as a source for missing 
 fields.
 

Yeh this sounds like a nightmare.

 2. Create 3 connections to the database, have the first one hold a 
 SELECT statement that will replace the hash above, have the second 
 connection be an INSERT for nonexisting records and the third connection 
 be an UPDATE for existing ones
 

As the other posters said, and to my knowledge, you should double check
that you can't prepare multiple statements.  From the DBI docs:

http://search.cpan.org/~timb/DBI-1.48/DBI.pm#prepare

Portable applications should not assume that a new statement can be
prepared and/or executed while still fetching results from a previous
statement.

That is a should not assume rather than a can't do it, and that is
specifically geared towards portable applications which generally
means when dealing with multiple different db backends. You might also
want to have a read through the 'prepare_cached' section following the
above. It appears to be a way in DBI to handle the same if the backend
doesn't support it.

From reading on DBI I understood that moving lots of data with do()
 statements is pretty slow (e.g. constantly re-preparing the same 
 statement), so I think scenario 2 with a single connection is even 
 worse.
 

Slow is still only meaningful in your context until you benchmark
whether it really is too slow you won't know.

 The reason I am elaborating on this is that I am afraid the dataset will 
 stop fitting in memory at some point of time if I go with scenario 1 
 (which is easier and cleaner to implement). Also I have no idea how 
 resource intensive scenario 2 would be, although I have proper 
 indexing and stuff so the UPDATES should be fast enough...


Easier I would agree with, cleaner I definitely wouldn't, at least not
if we are talking about enterprise level stuff. There are all kinds of
issues you can run into when trying to do a DELETE/INSERT instead of the
more appropriate UPDATE, especially when there is an intermediary (your
Perl hash) involved.

 Thanks
 
 Peter
 

HTH some,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI, duplicates

2005-06-14 Thread Ing. Branislav Gerzo
Ing. Branislav Gerzo [IBG], on Tuesday, June 14, 2005 at 21:10 (+0200)
thinks about:


IBG my ($id) = $dbh-selectrow_array(select id from
IBG db_url where id = ?, {}, $url);

ahm, maybe I'm too tired or blind, don't see that - I have error in
select statement :)

-- 

 ...m8s, cu l8r, Brano.

[But captain, can't we just give the Borg Windows '95?]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI + XML::Twig conflict (?)

2005-06-06 Thread Wiggins d'Anconia
Peter Rabbitson wrote:
Thank you. No guarantees, but try setting 'InactiveDestroy' when you
create the DB handle. XML::Twig uses a fork/exec call in 'parseurl' to
retrieve the URL in one process and to parse the XML in the other. When
the retrieval is complete one of the processes closes with an 'exit'. I
think because the $dbh is shared (because it just is) you are getting
the above result. The switch I mentioned appears to be designed for this
specific case.

For more info see InactiveDestroy here:

http://search.cpan.org/~timb/DBI-1.48/DBI.pm#ATTRIBUTES_COMMON_TO_ALL_HANDLES

This attribute is specifically designed for use in Unix applications
that fork child processes. Either the parent or the child process, but
not both, should set InactiveDestroy on all their shared handles.

HTH,
 
 
 
 Hm... I get it and I don't get it... Who keeps the sub _dummy - the parent
 or the child? I need to use DBI in it so I guess InactiveDestroy must be set
 to true there. How do I find out who is who not at the time but after the
 fork? Is this portable to win32? (the final version must run on win32 as
 well).
 Actually from the little I know about forks I thought that both parent and
 child get copies of the very same stuff. So both get a hot DBI and
 DBD::Mysql tied to the same socket... if this is at all possible. On the
 other hand I am not using DBI anymore while in the reader (child?), just the
 parser, so it shouldn't matter... Wow I am even more confused now :)
 

Ah, fun with IPC :-). The sub _dummy is the parent, because that is what
you are controlling, technically you aren't even supposed to be aware
that there is a fork (and weren't, really, until I told you :-)).  Yes
you are correct, everything is shared across the fork, the $dbh being
one of those things. Normally if you were controlling the fork/exec
model then you could decide to set InactiveDestroy in whichever place it
was needed, it would actually be the child as that is what is exiting
early (it does the retrieval). But in this case since the fork/exec is
encapsulated in a module you didn't write, you will likely want to set
it at connection time so that it is set on both of the handles. The key
in this case is that you have to do your explicit commit/disconnect
(which you were already). Theoretically another option would be to set
it during construction, then unset it in the parent after the fork,
assuming this works as I am thinking (caveat), then that might be better
as it should make sure to do the normal DBI cleanup. Of course back to
my caveat, since you don't really have control of when the fork is going
to exit this might be trickier. Though *I think* (no guarantee) that the
parser is reading from the pipe created for the fork, so as long as the
parser isn't finished the pipe and child should be active. Sorry if I am
confusing you again, the route I would take would be to set it during
construction because that is the simplest, then test, test, and test
some more. Try it different ways and see which works the best in the
tests. See if you can get it to break again.

Whether or not this works correctly on Windows I have no idea, and
wouldn't even venture to guess. You may want to read up on IPC on
windows and fork/exec for that platform.

 All above considered - I guess I would be safer downloading the file 
 somewhere and doing safe_parsefile to avoid any forking altogether. 


Possibly, but then that is more code you have to write, which can be
buggy, doesn't likely have as many people looking at and testing it,
etc.  Watch out for the slippery slope with this argument, I mean, you
could just write it all without modules, you could write it all in C,
you could write it in assembly! Boy what fun that would be.

 Thanks for the hint
 
HTH, Good luck (and test some more),

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI + XML::Twig conflict (?)

2005-06-05 Thread Wiggins d'Anconia
Please don't cross post.

Peter Rabbitson wrote:
 I have a strange problem where a database handle is being destroyed for no 
 apparent reason. My initial idea was to parse some xml, and translate it 
 into a database. Deleting line after line of code I came up with this short 
 meaningles program which exhibits the same behavior as its real-life 
 sibling (tested against two different mysql instalations on different 
 machines):
 
 use warnings;
 use strict;
 use DBI;
 use XML::Twig;
 
 ++$|; #so I can see the progress in _dummy ()
 
 my $dbh = DBI-connect ( dbi:mysql:$random_db:localhost,
  $user,
  $pass, 
  {AutoCommit = 0,
 RaiseError = 1,
 PrintError = 0,
  }
);
 
 unless ($dbh) {
 print Unable to connect:\n$DBI::errstr\n;
 exit 1;
 };
 
 eval { $dbh-do (DROP TABLE IF EXISTS some_nonexistant_table) };
 die ($@) if $@;
 
 my $objinfo_parser = XML::Twig-new (
   twig_handlers = {
  'Products/Product' = \_dummy 
   }
);
 $objinfo_parser-parseurl ('http://www.3btech.net/3btech/objinfo.xml');
 
 $dbh-commit;
 $dbh-disconnect;
 
 exit 0;
 
 sub _dummy {
 my ($twig, $child) = @_;
 print '.';
 $twig-purge();
 return 'dummy';
 }
 
 Note that I am not even doing any real operations on the MySQL side, thus I 
 don't care what database I connect to. I put the DROP TABLE there just to 
 make sure that commands are reaching the server, and yes I can see that in 
 the logs.
 If I run the real program I end up stuffing about 480 out of roughly 510
 products into a designated table and then the handle goes out to lunch with
 the same error message.

What's the error message?

http://danconia.org

 I use the very same XML::Twig setup in another script that packs results 
 into a hash and returns it, and everything works flawlessly. Any help is 
 priceless, as after nearly two days playing with this I am totally lost...
 
 Thanks
 
 Peter
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI + XML::Twig conflict (?)

2005-06-05 Thread Peter Rabbitson
  If I run the real program I end up stuffing about 480 out of roughly 510
  products into a designated table and then the handle goes out to lunch with
  the same error message.
 
 What's the error message?
 

Ups... I guess I missed that:

~$ ./test  /dev/null
Issuing rollback() for database handle being DESTROY'd without explicit 
disconnect().
DBD::mysql::db commit failed: MySQL server has gone away at ./test line 27.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI + XML::Twig conflict (?)

2005-06-05 Thread Wiggins d'Anconia
Peter Rabbitson wrote:
If I run the real program I end up stuffing about 480 out of roughly 510
products into a designated table and then the handle goes out to lunch with
the same error message.

What's the error message?

 
 
 Ups... I guess I missed that:
 
 ~$ ./test  /dev/null
 Issuing rollback() for database handle being DESTROY'd without explicit 
 disconnect().
 DBD::mysql::db commit failed: MySQL server has gone away at ./test line 27.
 
 

Thank you. No guarantees, but try setting 'InactiveDestroy' when you
create the DB handle. XML::Twig uses a fork/exec call in 'parseurl' to
retrieve the URL in one process and to parse the XML in the other. When
the retrieval is complete one of the processes closes with an 'exit'. I
think because the $dbh is shared (because it just is) you are getting
the above result. The switch I mentioned appears to be designed for this
specific case.

For more info see InactiveDestroy here:

http://search.cpan.org/~timb/DBI-1.48/DBI.pm#ATTRIBUTES_COMMON_TO_ALL_HANDLES

This attribute is specifically designed for use in Unix applications
that fork child processes. Either the parent or the child process, but
not both, should set InactiveDestroy on all their shared handles.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI + XML::Twig conflict (?)

2005-06-05 Thread Peter Rabbitson
 Thank you. No guarantees, but try setting 'InactiveDestroy' when you
 create the DB handle. XML::Twig uses a fork/exec call in 'parseurl' to
 retrieve the URL in one process and to parse the XML in the other. When
 the retrieval is complete one of the processes closes with an 'exit'. I
 think because the $dbh is shared (because it just is) you are getting
 the above result. The switch I mentioned appears to be designed for this
 specific case.
 
 For more info see InactiveDestroy here:
 
 http://search.cpan.org/~timb/DBI-1.48/DBI.pm#ATTRIBUTES_COMMON_TO_ALL_HANDLES
 
 This attribute is specifically designed for use in Unix applications
 that fork child processes. Either the parent or the child process, but
 not both, should set InactiveDestroy on all their shared handles.
 
 HTH,


Hm... I get it and I don't get it... Who keeps the sub _dummy - the parent
or the child? I need to use DBI in it so I guess InactiveDestroy must be set
to true there. How do I find out who is who not at the time but after the
fork? Is this portable to win32? (the final version must run on win32 as
well).
Actually from the little I know about forks I thought that both parent and
child get copies of the very same stuff. So both get a hot DBI and
DBD::Mysql tied to the same socket... if this is at all possible. On the
other hand I am not using DBI anymore while in the reader (child?), just the
parser, so it shouldn't matter... Wow I am even more confused now :)

All above considered - I guess I would be safer downloading the file 
somewhere and doing safe_parsefile to avoid any forking altogether. 

Thanks for the hint

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI - SELECT by Date

2005-05-06 Thread John Doe
Am Donnerstag, 5. Mai 2005 22.46 schrieb Diogo Nunes de Oliveira:
 Hi all,

Hi Diogo

 I´m having quite a problem here... My script works with postgree. Now i
 want to get a result from a date range... But I just can´t get it done...
 Explaining... Let´s supose I want to get all registers from 05/01/2005 to
 05/05/2005. How do I do that?
 I´m trying SELECT * FROM table WHERE date BETWEEN $inicial AND $final;
 and
 SELECT * FROM table WHERE (date  $inicial) AND (date  $final);
 But I just can´t get it done... Thanks in advance...

See chapter 11.3 of the mysql online documentation 
http://dev.mysql.com/doc/mysql/en/date-and-time-types.html
about date format. It states for instance:

 Although MySQL tries to interpret values in several formats, dates always 
must be given in year-month-day order (for example, '98-09-04'), rather than 
in the month-day-year or day-month-year orders commonly used elsewhere (for 
example, '09-04-98', '04-09-98').

(your question is not perl related, the mysql list would be appropriate)

hth, joe

 --
 Diogo N Oliveira - Instrutor EAD - Senai CEDESG

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI object version 1.32 does not match $DBI::VERSION 1.48

2005-04-06 Thread Chris Devers
On Wed, 6 Apr 2005 [EMAIL PROTECTED] wrote:

 I have upgraded DBI to version 1.48 and I am now having issues and 
 errors with my scripts. The error that I am getting is :

How did you do the upgrade?

It looks like you have remnants of the old version still installed.
 


-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: DBI object version 1.32 does not match $DBI::VERSION 1.48

2005-04-06 Thread christopher . l . hood
I did the install via CPAN, and I found that I DID have 2 versions
installed. I also found that the permissions that the modules and
subsequent directories had were not allowing anyone but ROOT to see the
modules.

So after renaming the old DBI.pm files to .old and changing the
permissions so that my non-root user could see the module, everything
worked fine.

The 2 questions that this brings  up is :
1. Why does CPAN only make the module directories accessible only by root
? (permissions set to 700 )
2. Why doesn't CPAN overwrite or remove the older version of DBI when the
new version is installed?

Chris Hood 


-Original Message-
From: Chris Devers [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 06, 2005 8:42 AM
To: Christopher L. Hood
Cc: Perl Beginners List
Subject: Re: DBI object version 1.32 does not match $DBI::VERSION 1.48

On Wed, 6 Apr 2005 [EMAIL PROTECTED] wrote:

 I have upgraded DBI to version 1.48 and I am now having issues and 
 errors with my scripts. The error that I am getting is :

How did you do the upgrade?

It looks like you have remnants of the old version still installed.
 


-- 
Chris Devers



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: DBI object version 1.32 does not match $DBI::VERSION 1.48

2005-04-06 Thread Bob Showalter
[EMAIL PROTECTED] wrote:
 1. Why does CPAN only make the module directories accessible only by
 root ? (permissions set to 700 )

It's probably just respecting your umask. Is your umask 077? It needs to be
something like 022 instead.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: DBI object version 1.32 does not match $DBI::VERSION 1.48

2005-04-06 Thread christopher . l . hood
Ok , I thought I had it fixed, but it is still causing problems, what is
the BEST way to solve this, what is the BEST way to remove all the old
versions and ensure that the latest (1.48) is installed?

Chris Hood 


-Original Message-
From: Chris Devers [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 06, 2005 8:42 AM
To: Christopher L. Hood
Cc: Perl Beginners List
Subject: Re: DBI object version 1.32 does not match $DBI::VERSION 1.48

On Wed, 6 Apr 2005 [EMAIL PROTECTED] wrote:

 I have upgraded DBI to version 1.48 and I am now having issues and 
 errors with my scripts. The error that I am getting is :

How did you do the upgrade?

It looks like you have remnants of the old version still installed.
 


-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI query

2005-03-15 Thread John Doe
Hi mike

Am Montag, 14. März 2005 18.38 schrieb mike:
 Anyone got any any idea what is happening here

Apart from your actual problem, it happens that the coding below will give big 
chances to have undetected or hard to find errors.

- use use strict; use warnings; at the top of the code
- declare your variables (as local to the first usage as possible)
- check the results of methods/functions


I did not run your (and my) code; just some annotations:

 $dbh=DBI-connect(dbi:Pg:dbname=data_cc,$user,$pw);

my $dbh=DBI-connect(dbi:Pg:dbname=data_cc,$user,$pw) or die $DBI::errstr;
(an example for declaring $dbh and checking the result of connect())

 $dump_dir='/home/data_cc/dump';
 @names=$dbh-tables();
 #$dbh-execute;
 #print @names;
 foreach $names(@names){

sidenote: since $names contains a scalar, $name would be a better name for 
this variable.

 if (substr($names,0,9) eq public.tb)
 {
 $file1= $dump_dir\/$names;
 $dbh-prepare(COPY $names TO ? WITH DELIMITER AS #);

The prepare method returns a statement handle for further usage, check the 
manual of DBI.

my $sth=$dbh-prepare(COPY $names TO ? WITH DELIMITER AS #) 
   or die  $DBI::errstr

 $dbh-bind_param(1,$file1);
 $dbh-execute();

and the statement handle has the bind_param and execute methods:

$sth-bind_param(1,$file1) or die $DBI::errstr;
$sth-execute() or die $DBI::errstr;

There are several methods to retrieve the results from the statement handle 
(see man DBI) - at this place in the code, not outside of the foreach loop.

 } 
 }

 results in output


 [Mon Mar 14 17:30:10 2005] [error] [client 127.0.0.1] Can't locate
 object method bind_param via package DBI::db at /home/www/cgi-
 bin/dump_all.pl line 25.

This is correct, since the database handle has no such methods.

 confused - it seems to be losing the connection to the db

No, this would not result in an object dropping a method.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: DBI query

2005-03-15 Thread Bob Showalter
mike wrote:
 Anyone got any any idea what is happening here
 
 $dbh=DBI-connect(dbi:Pg:dbname=data_cc,$user,$pw);
 $dump_dir='/home/data_cc/dump';
 @names=$dbh-tables();
 #$dbh-execute;
 #print @names;
 foreach $names(@names){
 if (substr($names,0,9) eq public.tb)
 {
 $file1= $dump_dir\/$names;
 $dbh-prepare(COPY $names TO ? WITH DELIMITER AS #);
 $dbh-bind_param(1,$file1);
 $dbh-execute();
 }
 }
 
 results in output
 
 
 [Mon Mar 14 17:30:10 2005] [error] [client 127.0.0.1] Can't locate
 object method bind_param via package DBI::db at /home/www/cgi-
 bin/dump_all.pl line 25.

bind_param and execute are *statement* handle method, and you're applying
them
to a *database* handle. You need to save the return value from prepare()
and call bind_param() and execute() on that.

Or, you can combine the prepare/bind/execute all into one call to do():

   $dbh-do(COPY $names TO ? WITH DELIMITER AS #, undef, $file);

 
 confused - it seems to be losing the connection to the db

No, the error message is a Perl error telling you that the package
that $dbh belongs to (DBI::db) doesn't have or inherit a method called
bind_param.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: DBI problem

2005-02-09 Thread Bob Showalter
mike wrote:
 I have the following query which works in psql
 
 SELECT to_char('05 Feb 2005'::date,'-MM-DD')
 
 However when I run it in DBI I get
 
 $row6=$dbh-prepare(SELECT
 to_char('2005-02-05'::date,'-MM-DD'));
 #$row6-bind_param(1,'2005-02-05'); $row6-execute();
 
 
 Can't call method prepare on an undefined value at /home/www/cgi-
 bin/times_upd_multi.pl line 46., referer: http://localhost/cgi-
 bin/times_input_mult.pl

This is telling you that $dbh is undefined. Your query is OK. (I assume
you have RaiseError turned on since you aren't checking for errors.)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI hashref with multiple db rows

2004-10-05 Thread jason_normandin
Steve

You may want to think of this from a DB perspective. 

Is there a unique key associated with each of these lookups that could prevent 
duplicate rows being returned? If you are looking up info for a particular person, I 
would assume you would only want 1 returned and you would want a key within the table 
to ensure this uniqueness.

HPH
-Jason
 
 From: Steve Bertrand [EMAIL PROTECTED]
 Date: 2004/10/05 Tue PM 05:14:41 GMT
 To: [EMAIL PROTECTED]
 Subject: DBI hashref with multiple db rows
 
 I have created a module, and inside one of the Package methods, I have
 the following code:
 
 $href = $getPlanInfo-fetchrow_hashref();
 foreach my $key (keys %$href) {
 print $key : $href-{$key}\n;
 $name = $key;
 $self-{$name} = $href-{$key};
 }
 
 Now, in the main program that calls this method, I have the following:
 
 my ($user) = new Accounting::EagleUser();
 $user-getPlanInfo(steveb);
 print $user-{'plan'} $user-{'username'}\n;
 
 
 What is happening, is that getPlanInfo() takes a single param, (a
 username). It then performs a fetchrow_hashref, creating the keys for
 the user object with the table field names from the db, and the values
 are the actual data from the table row.
 
 However, my problem is that some users have more than one row. I have
 tried for days, playing, reading, etc and you guys(gals) feel like my
 last hope. I can't figure out a way to give the user object multiple
 values for a single key. The output when print only shows the fetched
 row that it got first, and it appears the second is never looked at.
 
 I was thinking that if I implemented something like $self-{$key$i},
 where $i could be an incremented integer, I'd have what I was looking
 for, but how do I iterate through the DB to the next row using
 fetchrow_hashref to do this?
 
 I really appreciate any insight at all that will help clarify this for
 me, or at least put me back on a path I feel I have wandered waaay off
 of.
 
 Tks!
 
 Steve
 
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI hashref with multiple db rows

2004-10-05 Thread Steve Bertrand
 Steve

 You may want to think of this from a DB perspective.

 Is there a unique key associated with each of these lookups that could
 prevent duplicate rows being returned? If you are looking up info for
 a particular person, I would assume you would only want 1 returned and
 you would want a key within the table to ensure this uniqueness.

Thanks Jason,

I'll have to extract info prior to using the hashref function that
will return me the unique key for all of the rows, and I'll have to
mod my queries to return each row seperately, work with it, then call
the routine again with the next query.

A little more back and forth to the db than I had hoped, but your
solution sounds very viable.

Tks again,

Steve


 HPH
 -Jason

 From: Steve Bertrand [EMAIL PROTECTED]
 Date: 2004/10/05 Tue PM 05:14:41 GMT
 To: [EMAIL PROTECTED]
 Subject: DBI hashref with multiple db rows

 I have created a module, and inside one of the Package methods, I
 have
 the following code:

 $href = $getPlanInfo-fetchrow_hashref();
 foreach my $key (keys %$href) {
 print $key : $href-{$key}\n;
 $name = $key;
 $self-{$name} = $href-{$key};
 }

 Now, in the main program that calls this method, I have the
 following:

 my ($user) = new Accounting::EagleUser();
 $user-getPlanInfo(steveb);
 print $user-{'plan'} $user-{'username'}\n;


 What is happening, is that getPlanInfo() takes a single param, (a
 username). It then performs a fetchrow_hashref, creating the keys
 for
 the user object with the table field names from the db, and the
 values
 are the actual data from the table row.

 However, my problem is that some users have more than one row. I
 have
 tried for days, playing, reading, etc and you guys(gals) feel like
 my
 last hope. I can't figure out a way to give the user object multiple
 values for a single key. The output when print only shows the
 fetched
 row that it got first, and it appears the second is never looked at.

 I was thinking that if I implemented something like $self-{$key$i},
 where $i could be an incremented integer, I'd have what I was
 looking
 for, but how do I iterate through the DB to the next row using
 fetchrow_hashref to do this?

 I really appreciate any insight at all that will help clarify this
 for
 me, or at least put me back on a path I feel I have wandered waaay
 off
 of.

 Tks!

 Steve



 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response





 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI hashref with multiple db rows

2004-10-05 Thread Wiggins d Anconia
Please bottom post

 Steve
 
 You may want to think of this from a DB perspective. 
 
 Is there a unique key associated with each of these lookups that could
prevent duplicate rows being returned? If you are looking up info for a
particular person, I would assume you would only want 1 returned and you
would want a key within the table to ensure this uniqueness.
 
 HPH
 -Jason

It is reasonable to have a set of data rows for a particular object. 

  
  From: Steve Bertrand [EMAIL PROTECTED]
  Date: 2004/10/05 Tue PM 05:14:41 GMT
  To: [EMAIL PROTECTED]
  Subject: DBI hashref with multiple db rows
  
  I have created a module, and inside one of the Package methods, I have
  the following code:
  
  $href = $getPlanInfo-fetchrow_hashref();
  foreach my $key (keys %$href) {
  print $key : $href-{$key}\n;
  $name = $key;
  $self-{$name} = $href-{$key};
  }

So in the above you want to loop over the result set storing them to the
object, this sounds like the perfect use of an array reference stored to
the object. Something like:

while (my $href = $getPlanInfo-fetchrow_hashref) {
   push @{$self-{$name}}, $href;
}

Now $self-{$name} contains a list, similar to what you mention with the
indexes below, but let Perl handle that for you.  Then you can loop over
the list as with any array reference, or index into it similar to any array.

foreach my $element (@{$self-{$name}}) {
foreach my $key (keys %$element) {
 print $key: $element-{$name}\n;
}
}

HTH,

http://danconia.org

  
  Now, in the main program that calls this method, I have the following:
  
  my ($user) = new Accounting::EagleUser();
  $user-getPlanInfo(steveb);
  print $user-{'plan'} $user-{'username'}\n;
  
  
  What is happening, is that getPlanInfo() takes a single param, (a
  username). It then performs a fetchrow_hashref, creating the keys for
  the user object with the table field names from the db, and the values
  are the actual data from the table row.
  
  However, my problem is that some users have more than one row. I have
  tried for days, playing, reading, etc and you guys(gals) feel like my
  last hope. I can't figure out a way to give the user object multiple
  values for a single key. The output when print only shows the fetched
  row that it got first, and it appears the second is never looked at.
  
  I was thinking that if I implemented something like $self-{$key$i},
  where $i could be an incremented integer, I'd have what I was looking
  for, but how do I iterate through the DB to the next row using
  fetchrow_hashref to do this?
  
  I really appreciate any insight at all that will help clarify this for
  me, or at least put me back on a path I feel I have wandered waaay off
  of.
  
  Tks!
  
  Steve
  
  
  
  -- 
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  http://learn.perl.org/ http://learn.perl.org/first-response
  
  
  
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 
 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI hashref with multiple db rows

2004-10-05 Thread Steve Bertrand

  I have created a module, and inside one of the Package methods, I
 have
  the following code:
 
  $href = $getPlanInfo-fetchrow_hashref();
  foreach my $key (keys %$href) {
  print $key : $href-{$key}\n;
  $name = $key;
  $self-{$name} = $href-{$key};
  }

 So in the above you want to loop over the result set storing them to
 the
 object, this sounds like the perfect use of an array reference stored
 to
 the object. Something like:

 while (my $href = $getPlanInfo-fetchrow_hashref) {
push @{$self-{$name}}, $href;
 }

 Now $self-{$name} contains a list, similar to what you mention with
 the
 indexes below, but let Perl handle that for you.  Then you can loop
 over
 the list as with any array reference, or index into it similar to any
 array.

 foreach my $element (@{$self-{$name}}) {
 foreach my $key (keys %$element) {
  print $key: $element-{$name}\n;
 }
 }

Wow! ...and I *almost* understand how it works! Admittedly, I'm just
begun familiarizing myself with references the last few days, but this
looks so far like what I need. I am going to research how, and why
this works, but am I correct with this?:

(based on your code above, assuming 2 rows in db for user)

@{$self-{$name}}[0] == %hash (name  val)   # from db row 1
@{$self-{$name}}[1] == %hash2 (name  val) # from db row 2

I truly was never aware the true flexibility of Perl before. Wow...if
I had of researched this stuff before...I don't want to even imagine
the time I would of saved myself ;o)

Steve

 HTH,

 http://danconia.org

 
  Now, in the main program that calls this method, I have the
 following:
 
  my ($user) = new Accounting::EagleUser();
  $user-getPlanInfo(steveb);
  print $user-{'plan'} $user-{'username'}\n;
 
 
  What is happening, is that getPlanInfo() takes a single param, (a
  username). It then performs a fetchrow_hashref, creating the keys
 for
  the user object with the table field names from the db, and the
 values
  are the actual data from the table row.
 
  However, my problem is that some users have more than one row. I
 have
  tried for days, playing, reading, etc and you guys(gals) feel like
 my
  last hope. I can't figure out a way to give the user object
 multiple
  values for a single key. The output when print only shows the
 fetched
  row that it got first, and it appears the second is never looked
 at.
 
  I was thinking that if I implemented something like
 $self-{$key$i},
  where $i could be an incremented integer, I'd have what I was
 looking
  for, but how do I iterate through the DB to the next row using
  fetchrow_hashref to do this?
 
  I really appreciate any insight at all that will help clarify this
 for
  me, or at least put me back on a path I feel I have wandered waaay
 off
  of.
 
  Tks!
 
  Steve
 
 
 
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  http://learn.perl.org/ http://learn.perl.org/first-response
 
 
 


 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response









-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI hashref with multiple db rows

2004-10-05 Thread Wiggins d Anconia
   I have created a module, and inside one of the Package methods, I
  have
   the following code:
  
   $href = $getPlanInfo-fetchrow_hashref();
   foreach my $key (keys %$href) {
   print $key : $href-{$key}\n;
   $name = $key;
   $self-{$name} = $href-{$key};
   }
 
  So in the above you want to loop over the result set storing them to
  the
  object, this sounds like the perfect use of an array reference stored
  to
  the object. Something like:
 
  while (my $href = $getPlanInfo-fetchrow_hashref) {
 push @{$self-{$name}}, $href;
  }
 
  Now $self-{$name} contains a list, similar to what you mention with
  the
  indexes below, but let Perl handle that for you.  Then you can loop
  over
  the list as with any array reference, or index into it similar to any
  array.
 
  foreach my $element (@{$self-{$name}}) {
  foreach my $key (keys %$element) {
   print $key: $element-{$name}\n;
  }
  }
 
 Wow! ...and I *almost* understand how it works! Admittedly, I'm just
 begun familiarizing myself with references the last few days, but this
 looks so far like what I need. I am going to research how, and why
 this works, but am I correct with this?:


perldoc perlreftut
perldoc perlref
perldoc perllol
perldoc perldsc

Are excellent resources. If you are into the whole book thing then I
would highly suggest the Learning PORM book from O'Reilly[1].
 
 (based on your code above, assuming 2 rows in db for user)
 
 @{$self-{$name}}[0] == %hash (name  val)   # from db row 1
 @{$self-{$name}}[1] == %hash2 (name  val) # from db row 2
 

I think you are thinking about them correctly

$self-{$name} contains an array reference as its value. So the above
slices into that array reference to retreive a particular indexes value,
which happens to be a hash reference.  To make things easier and
generally better looking, Perl provides a simpler access syntax, so for
the first element of the array above you would write,

$self-{$name}-[0]

And the second becomes,

$self-{$name}-[1],

So then to access into the next level, aka to get specific information
from a record you could issue,

$self-{$name}-[0]-{'license_number'};

(Obviously I am making up the names of the fields, but hopefully you get
the point.)  The listed docs should provide much more thorough,
accurate, and readable examples/descriptions.

 I truly was never aware the true flexibility of Perl before. Wow...if
 I had of researched this stuff before...I don't want to even imagine
 the time I would of saved myself ;o)
 
 Steve

Yep, welcome to a whole new world.  References often take some time to
just get, but once you just get them, they make things significantly
easier.

snip

http://danconia.org

[1] http://www.oreilly.com/catalog/lrnperlorm/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI for FireBird

2004-08-20 Thread David Dorward
On 20 Aug 2004, at 11:03, Cristi Ocolisan wrote:
Can anybody tell me something about a DBI for FireBird?
I looked on CPAN, but didn't find any.
When I go to http://search.cpan.org/search?query=firebirdmode=all 
the second hit is subtitled DBI driver for Firebird (then it goes on 
to mention InterBase).

--
David Dorward
 http://dorward.me.uk/
http://blog.dorward.me.uk/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: DBI Install

2004-08-04 Thread NYIMI Jose \(BMB\)


 -Original Message-
 From: Witzke, Rob [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, August 04, 2004 3:30 PM
 To: [EMAIL PROTECTED]
 Subject: DBI Install
 
 ...
 /bin/sh: /opt/SUNWspro/bin/cc: not found
 make: *** [Perl.o] Error 1

Your compiler was not found ...

José.



 DISCLAIMER 

This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer.

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI Install

2004-08-04 Thread Chris Devers
On Wed, 4 Aug 2004, Witzke, Rob wrote:
I am trying to install DBI on a Sun Solaris box but am running into 
problems.
Have you tried using the CPAN shell? If you have it available, it's 
*much* easier than the way you're trying it.

$ sudo perl -MCPAN -e shell
cpan shell -- CPAN exploration and modules installation (v1.76)
ReadLine support enabled
cpan install DBI
And you're done.
Actually, that's a gentle lie -- if you haven't used the CPAN shell 
before, you'll be asked a series of configuration questions before you 
get to the 'cpan' prompt, but most of them are straightforward and you 
can usually just accept the defaults.

Once you're done setting up the shell, you get the 'cpan' prompt and 
from there it's one line to install any module: install My::Module.

That said...
/opt/SUNWspro/bin/cc -c   -I/usr/local/include -O   -DVERSION=\1.42\ -DXS_VERSION=\1.42\ 
-KPIC -I/usr/local/sirsi/lib/perl5/5.8.0/sun4-solaris/CORE  -DDBI_NO_THREADS Perl.c
/bin/sh: /opt/SUNWspro/bin/cc: not found
make: *** [Perl.o] Error 1
...do you actually have a C compiler at /opt/SUNWspro/bin/cc ?
The message said that I had perl version 5.008 installed but I actuall 
have the following:

DEVELOP 66% perl -v
This is perl, v5.8.0 built for sun4-solaris
Perl 5.008 *is* 5.8.0.
The reasons for this are old  boring, but basically Perl 5 just kept 
having micro .00x releases for a few years before people got around to 
making the numbers more sensible by masking over a couple of the zeroes. 
Hence, 5.006x is 5.6.x, and 5.8.x is 5.008x. You're more likely to see 
the version represented as 5.x.y these days, but some things will still 
present it as 5.00xy like it used to be. Don't worry about it.


--
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/
np: 'Moon River'
 by Henry Mancini
 from 'The Best Of Mancini'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: DBI Install

2004-08-04 Thread Witzke, Rob
Chris,

Thank you very much for you help.

I ran your command $ perl -MDBI -e '1' and got no results so I guess that is a good 
thing.

I will be looking into getting a c compiler.  Any suggestions?

Rob

-Original Message-
From: Chris Devers [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 04, 2004 10:29 AM
To: Witzke, Rob
Cc: PerlBeginners (E-mail)
Subject: RE: DBI Install


On Wed, 4 Aug 2004, Witzke, Rob wrote:

 Well, it seems that I don't have a c compiler loaded.  (I thought that 
 I did)

That'll slow you down :-)

 Is is possible to get the DBI stuff pre-compiled?

Maybe, but DBI is often available with Perl itself. Have you verified 
that you don't already have it? What happens if you run this:

 $ perl -MDBI -e '1'
 $

You should get no output, no errors, if it's installed. If you don't 
have it, you should get something like this:

 $ perl -MFictionalModule -e '1'
 Can't locate FictionalModule.pm in @INC (@INC contains:
 /System/Library/Perl/5.8.1/darwin-thread-multi-2level
 /System/Library/Perl/5.8.1
 /Library/Perl/5.8.1/darwin-thread-multi-2level /Library/Perl/5.8.1
 /Library/Perl /Network/Library/Perl/5.8.1/darwin-thread-multi-2level
 /Network/Library/Perl/5.8.1 /Network/Library/Perl .).
 BEGIN failed--compilation aborted.
 $

The paths will be different, but the error will be similar.

 Where can I get the CPAN shell?  I looked for it on the CPAN web site 
 but I don't see it. If I do find it, will it do any good without a C 
 compiler?

Again, it's frequently available with recent versions of Perl -- you 
mentioned 5.8.0, which really ought to have it by default. Try this:

 $ perl -MCPAN -e '1'

If that gives no errors, you've got it -- run it by doing a

 $ perl -MCPAN -e 'shell'

As noted before, you have to set it up the first time, but after that it 
should Just Work.


Note though that a lot of CPAN modules depend on a C compiler, and using 
the CPAN shell doesn't get you around that requirement. The CPAN shell 
just automates the process of finding, downloading, building, testing, 
and installing modules, but if you're missing the system tools needed to 
do any of those steps -- such as a C compiler -- then CPAN can't help.


-- 
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/

np: 'Baby Elephant Walk'
  by Henry Mancini
  from 'The Best Of Mancini'

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: DBI Install

2004-08-04 Thread Chris Devers
On Wed, 4 Aug 2004, Witzke, Rob wrote:
Well, it seems that I don't have a c compiler loaded.  (I thought that 
I did)
That'll slow you down :-)
Is is possible to get the DBI stuff pre-compiled?
Maybe, but DBI is often available with Perl itself. Have you verified 
that you don't already have it? What happens if you run this:

$ perl -MDBI -e '1'
$
You should get no output, no errors, if it's installed. If you don't 
have it, you should get something like this:

$ perl -MFictionalModule -e '1'
Can't locate FictionalModule.pm in @INC (@INC contains:
/System/Library/Perl/5.8.1/darwin-thread-multi-2level
/System/Library/Perl/5.8.1
/Library/Perl/5.8.1/darwin-thread-multi-2level /Library/Perl/5.8.1
/Library/Perl /Network/Library/Perl/5.8.1/darwin-thread-multi-2level
/Network/Library/Perl/5.8.1 /Network/Library/Perl .).
BEGIN failed--compilation aborted.
$
The paths will be different, but the error will be similar.
Where can I get the CPAN shell?  I looked for it on the CPAN web site 
but I don't see it. If I do find it, will it do any good without a C 
compiler?
Again, it's frequently available with recent versions of Perl -- you 
mentioned 5.8.0, which really ought to have it by default. Try this:

$ perl -MCPAN -e '1'
If that gives no errors, you've got it -- run it by doing a
$ perl -MCPAN -e 'shell'
As noted before, you have to set it up the first time, but after that it 
should Just Work.

Note though that a lot of CPAN modules depend on a C compiler, and using 
the CPAN shell doesn't get you around that requirement. The CPAN shell 
just automates the process of finding, downloading, building, testing, 
and installing modules, but if you're missing the system tools needed to 
do any of those steps -- such as a C compiler -- then CPAN can't help.

--
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/
np: 'Baby Elephant Walk'
 by Henry Mancini
 from 'The Best Of Mancini'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: DBI Install

2004-08-04 Thread NYIMI Jose \(BMB\)
 -Original Message-
 From: Witzke, Rob [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, August 04, 2004 4:32 PM
 To: Chris Devers
 Cc: PerlBeginners (E-mail)
 Subject: RE: DBI Install
 
 
 Chris,
 
 Thank you very much for you help.
 
 I ran your command $ perl -MDBI -e '1' and got no results so 
 I guess that is a good thing.
 
 I will be looking into getting a c compiler.  Any suggestions?

Have a look to DBI FAQs
http://dev.isystek.com/dbi/fom-serve/cache/12.html
From
http://dbi.perl.org

HTH,

José.


 DISCLAIMER 

This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer.

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: DBI Install

2004-08-04 Thread Johnson, Shaunn
--howdy:

--wouldn't it be better if you went to http://www.sunfreeware.com
--and snagged a compiler (gcc works, i believe) - i'm sure you'll use it
--for other stuff in the future anyways ...

--*shrug*

--just my $0.02 cents ...

-X


-Original Message-
From: Witzke, Rob [mailto:[EMAIL PROTECTED]



Well, it seems that I don't have a c compiler loaded.  (I 
thought that I did)

Is is possible to get the DBI stuff pre-compiled?

Where can I get the CPAN shell?  I looked for it on the CPAN 
web site but I don't see it.
If I do find it, will it do any good without a C compiler?

[snip]


RE: DBI Install

2004-08-04 Thread Chris Devers
On Wed, 4 Aug 2004, Witzke, Rob wrote:
I ran your command $ perl -MDBI -e '1' and got no results so I guess 
that is a good thing.
Yeah, that means you already have DBI.
Now you just need DBD drivers for the database[s] you need.
I will be looking into getting a c compiler.  Any suggestions?
GCC is probably a good bet if Sun doesn't make one of their own 
available. As someone else noted, try http://www.sunfreeware.com
for things like this.

--
Chris Devers  [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/
np: 'Experiment In Terror'
 by Henry Mancini
 from 'The Best Of Mancini'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: DBI Install

2004-08-04 Thread Bob Showalter
Witzke, Rob wrote:
 Well, it seems that I don't have a c compiler loaded.  (I thought
 that I did) 

As others have pointed out, you need a C compiler to install some modules.

However, I'm pretty sure you can't just grab gcc and start installing DBI.
You need to build modules with the same compiler that Perl was built with.
If you don't have that compiler, best be would be to a) get gcc, b) rebuild
Perl itself with gcc, c) then build DBI and other modules.

I may be wrong about this, so somebody correct me if I am.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: DBI Install

2004-08-04 Thread Witzke, Rob
Unfortunately, this does indeed seem to be the case and I can't rebuild perl without 
jeopardizing our primary system

Thanks for all of the suggestions,

Rob

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 04, 2004 12:20 PM
To: Witzke, Rob; PerlBeginners (E-mail)
Subject: RE: DBI Install


Witzke, Rob wrote:
 Well, it seems that I don't have a c compiler loaded.  (I thought
 that I did) 

As others have pointed out, you need a C compiler to install some modules.

However, I'm pretty sure you can't just grab gcc and start installing DBI.
You need to build modules with the same compiler that Perl was built with.
If you don't have that compiler, best be would be to a) get gcc, b) rebuild
Perl itself with gcc, c) then build DBI and other modules.

I may be wrong about this, so somebody correct me if I am.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




  1   2   3   >