[32911] in Perl-Users-Digest
Perl-Users Digest, Issue: 4189 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 9 14:09:29 2014
Date: Wed, 9 Apr 2014 11:09:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 9 Apr 2014 Volume: 11 Number: 4189
Today's topics:
Perl to SQLite bridge is not working, database connect vishwanathsen03@gmail.com
Re: Perl to SQLite bridge is not working, database conn <john@castleamber.com>
Re: Perl to SQLite bridge is not working, database conn <john@castleamber.com>
Re: Perl to SQLite bridge is not working, database conn <gravitalsun@hotmail.foo>
setting binmode for empty filehandle <hhr-m@web.de>
Re: setting binmode for empty filehandle <petergoATnetspace.net.au>
Re: setting binmode for empty filehandle <rweikusat@mobileactivedefense.com>
Re: setting binmode for empty filehandle <gravitalsun@hotmail.foo>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 8 Apr 2014 12:04:36 -0700 (PDT)
From: vishwanathsen03@gmail.com
Subject: Perl to SQLite bridge is not working, database connect fails ....
Message-Id: <6a924a3d-0c4c-4d4d-91f2-1832ac745f8f@googlegroups.com>
Hi,
I have installed the perl modules -
DBI
DBD::SQLite
Now I am running a simple perl script that calls sqlite database.
#!/usr/bin/perl
use DBI;
use strict;
my $driver = "SQLite";
my $database = "ex2.db";
my $dsn = "DBI:$driver:dbname=$database";
my $userid = "";
my $password = "";
my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 })
or die $DBI::errstr;
print "Opened database successfully\n";
Perl script fails on the line that does connect (DBI->connect) with the message -
DBI connect('dbname=ex2.db','',...) failed: database disk image is malformed at perl_sqllite_example1.pl line 11
SQLite and database seems to be fine, I could open/load the database using sqlite3 and I could do insert and select operations.
I could write a C program and I could use the C program to do an insert operation successfully in the database.
So it is the perl to sqlite bridge that has issues....
Kindly suggest.....
Regards,
Vishwanath
------------------------------
Date: Tue, 08 Apr 2014 15:36:07 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: Perl to SQLite bridge is not working, database connect fails ....
Message-Id: <87wqezblu0.fsf@castleamber.com>
vishwanathsen03@gmail.com writes:
> Hi,
>
> I have installed the perl modules -
> DBI
> DBD::SQLite
>
> Now I am running a simple perl script that calls sqlite database.
>
> #!/usr/bin/perl
>
> use DBI;
> use strict;
>
> my $driver = "SQLite";
> my $database = "ex2.db";
> my $dsn = "DBI:$driver:dbname=$database";
> my $userid = "";
> my $password = "";
> my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 })
> or die $DBI::errstr;
>
> print "Opened database successfully\n";
>
>
> Perl script fails on the line that does connect (DBI->connect) with the message -
>
> DBI connect('dbname=ex2.db','',...) failed: database disk image is malformed at perl_sqllite_example1.pl line 11
>
> SQLite and database seems to be fine, I could open/load the database using sqlite3 and I could do insert and select operations.
> I could write a C program and I could use the C program to do an insert operation successfully in the database.
>
> So it is the perl to sqlite bridge that has issues....
Which version did you use to create the database file (it sounds like
version 2)? You might have to pass legacy_file_format, see documentation
of DBD::SQLite.
--
John Bokma j3b
Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/
Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html
------------------------------
Date: Tue, 08 Apr 2014 20:00:50 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: Perl to SQLite bridge is not working, database connect fails ....
Message-Id: <87sipnb9kt.fsf@castleamber.com>
George Mpouras <gravitalsun@hotmail.foo> writes:
> $dbh->do('PRAGMA foreign_keys = OFF');
> $dbh->do('PRAGMA cache_size = 1000');
> $dbh->do('PRAGMA synchronous = OFF');
> $dbh->do('PRAGMA sqlite_allow_multiple_statements = OFF')
Which I probably would write as:
$dbh->do( "PRAGMA $_->[0] = $_->[1]" ) for (
[ foreign_keys => 'OFF' ],
[ cache_size => 1000 ],
[ synchonous => 'OFF' ],
[ sqlite_allow_multiple_statements => 'OFF' ]
);
But I am afraid your working example is not going to work as well, at
least if I am correct that it's an SQLite version issue.
--
John Bokma j3b
Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/
Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html
------------------------------
Date: Wed, 09 Apr 2014 01:29:14 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: Perl to SQLite bridge is not working, database connect fails ....
Message-Id: <li1t87$2sr6$1@news.ntua.gr>
# take a working sample from one of my scripts and adapt it ...
use strict;
use warnings;
use DBI qw(:sql_types); # για blobs
my $dbh = DBI->connect('dbi:SQLite:dbname=C:/Program
Files/WebApp/sites/database/sms.db', undef, undef, {AutoCommit=>1,
RaiseError=>1, sqlite_unicode=>1}) or die "$DBI::errstr\n";;
$dbh->do('PRAGMA foreign_keys = OFF');
$dbh->do('PRAGMA cache_size = 1000');
$dbh->do('PRAGMA synchronous = OFF');
$dbh->do('PRAGMA sqlite_allow_multiple_statements = OFF')
$dbh->{'sqlite_see_if_its_a_number'} = 1;
$dbh->{'sqlite_use_immediate_transaction'} = 0;
my $sth = $dbh->prepare('SELECT provider_name, account_username FROM
Account WHERE webapp_username == ?1 ORDER BY
provider_name,account_username') or die "$DBI::errstr\n";
$sth->bind_param(1, 'user1', SQL_VARCHAR);
$sth->execute() or die "$DBI::errstr\n";
my ($provider, $username);
$sth->bind_columns(\$provider,\$username);
while ( $sth->fetchrow_array )
{
print "$provider,$username\n";
}
$dbh->disconnect;
------------------------------
Date: Tue, 8 Apr 2014 22:28:30 +0200
From: Helmut Richter <hhr-m@web.de>
Subject: setting binmode for empty filehandle
Message-Id: <alpine.LNX.2.00.1404082218540.7143@badwlrz-clhri01.ws.lrz.de>
In an application, everything is Unicode. I though I would never have to
worry if I set
use utf8; # because the source is also UTF-8
binmode (STDIN, ':utf8');
binmode (STDOUT, ':utf8');
binmode (STDERR, ':utf8');
This would work for explicit usage of these filehandles and for implicit usage
of STDOUT via "print" without a filehandle. It has, however, no effect on <>.
Well between <> there is nothing, why not try
binmode ('', ':utf8');
but that does not help either.
There is an obvious work-around: find myself the command line parameter with
the file name and open it explicitly, or else use STDIN. Possible, but clumsy.
Perhaps, the recommended way of dealing with *all files are Unicode* is
something else. I am open to learn.
--
Helmut Richter
------------------------------
Date: 08 Apr 2014 20:45:49 GMT
From: Peter Gordon <petergoATnetspace.net.au>
Subject: Re: setting binmode for empty filehandle
Message-Id: <XnsA30A44CFFC3CCpetergonetspacenetau@216.151.153.138>
Helmut Richter <hhr-m@web.de> wrote in
news:alpine.LNX.2.00.1404082218540.7143@badwlrz-clhri01.ws.lrz.de:
> In an application, everything is Unicode. I though I would never have
> to worry if I set
>
> use utf8; # because the source is also UTF-8
> binmode (STDIN, ':utf8');
> binmode (STDOUT, ':utf8');
> binmode (STDERR, ':utf8');
>
> This would work for explicit usage of these filehandles and for
> implicit usage of STDOUT via "print" without a filehandle. It has,
> however, no effect on <>.
>
> Well between <> there is nothing, why not try
>
> binmode ('', ':utf8');
>
> but that does not help either.
>
> There is an obvious work-around: find myself the command line
> parameter with the file name and open it explicitly, or else use
> STDIN. Possible, but clumsy.
>
> Perhaps, the recommended way of dealing with *all files are Unicode*
> is something else. I am open to learn.
>
The below works fir me.
use open ":encoding(UTF-16le)";
binmode(STDOUT, "::encoding(UTF-16le)");
while( <> ) {
------------------------------
Date: Tue, 08 Apr 2014 22:04:15 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: setting binmode for empty filehandle
Message-Id: <87txa35y9c.fsf@sable.mobileactivedefense.com>
Helmut Richter <hhr-m@web.de> writes:
> In an application, everything is Unicode. I though I would never have to
> worry if I set
>
> use utf8; # because the source is also UTF-8
> binmode (STDIN, ':utf8');
> binmode (STDOUT, ':utf8');
> binmode (STDERR, ':utf8');
>
> This would work for explicit usage of these filehandles and for implicit usage
> of STDOUT via "print" without a filehandle. It has, however, no effect on <>.
>
> Well between <> there is nothing, why not try
>
> binmode ('', ':utf8');
>
> but that does not help either.
>
> There is an obvious work-around: find myself the command line parameter with
> the file name and open it explicitly, or else use STDIN. Possible, but clumsy.
>
> Perhaps, the recommended way of dealing with *all files are Unicode* is
> something else.
perl -CDS
could be used achieve the desired effect.
------------------------------
Date: Wed, 09 Apr 2014 01:24:13 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: setting binmode for empty filehandle
Message-Id: <li1suq$2sch$1@news.ntua.gr>
> use utf8; # because the source is also UTF-8
> binmode (STDIN, ':utf8');
> binmode (STDOUT, ':utf8');
> binmode (STDERR, ':utf8');
this will give double encoding strings
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4189
***************************************