FW: [sqlite] Reading Blob data using Perl

2007-10-16 Thread Brian Rowlands (Greymouth High School)
Magic Kishor

I'm learning a lot as I study Perl and now SQLite and your invaluable
assistance did the trick.

The key lines now read:

my $newdata = $ref->{icon};
binmode OUTPUT;
print OUTPUT $newdata;

Many thanks. 

-Original Message-
From: P Kishor [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, 17 October 2007 3:07 p.m.
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] Reading Blob data using Perl

can't help you all the way, but below are a few comments --

On 10/16/07, Brian Rowlands  (Greymouth High School)
<[EMAIL PROTECTED]> wrote:
> Hi
> I'm hoping someone can help me explain how to fix a problem I have 
> with reading a Blob field from a SQLite DB using Perl. My long term 
> aim is to not save it to a file but use it within my application and 
> store it as a label bitmap. However, first things first.
>
> This code reads the Blob but when I view the bmp file created it is 
> distorted - as though the bits have been wrapped around and ones I'd 
> expect on the right are on the left of the image in the prevw. Looking

> at the icon in the SQLite DB all is well.
>
> #!/usr/bin/perl -w
> use strict;
> use DBI;
> use Cwd;
> use Win32::GUI::BitmapInline ();
> our $datafile   = getdcwd()."\\mydatabase.db";
>
> # suck icon from SQLite database,
> my @array;
> my $dbh = DBI-> connect("dbi:SQLite:dbname=$datafile","","",{});#
> database handle
> my $sql = "SELECT icon FROM icons WHERE name = 'logo'";
> my $sth = $dbh-> prepare($sql);   # statement handle
>
> # must have this next line but DONT KNOW WHY my $numrows = 
> $sth->execute;

The line above is where you actually make your program do some work.
After all those declarations, you have to execute the statement, and
that is precisely what you are doing above. That is why you need the
above line, and without it nothing will work.

>
> open OUTPUT, ">output.bmp";
> my $ref = $sth->fetchrow_hashref;
> my $newdata = $$ref{'icon'};

I would write the above line as

my $newdata = $ref->{icon};

now, somewhere here, don't you require some binmode magic like so,
particularly on Windows

binmode OUTPUT;
> print OUTPUT $newdata;
> close OUTPUT;
>
> $sth->finish;
> undef $sth;
> $dbh->disconnect();
>
>
> Q1. Why is the line my $numrows = $sth->execute; essential? If it is 
> not present I can't view the image file at all and I get a message 
> that preview is not available.
> Q2. How do I fix it so the bmp file displays perfectly?
>
>
> Thanks
> Brian Rowlands
> We must accept finite disappointment, but we must never lose infinite 
> hope.
> Martin Luther King Jr. 
>
>
>
>


--
Puneet Kishor


-
To unsubscribe, send email to [EMAIL PROTECTED]

-


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] Reading Blob data using Perl

2007-10-16 Thread Brian Rowlands (Greymouth High School)
Hi
I'm hoping someone can help me explain how to fix a problem I have with
reading a Blob field from a SQLite DB using Perl. My long term aim is to
not save it to a file but use it within my application and store it as a
label bitmap. However, first things first.

This code reads the Blob but when I view the bmp file created it is
distorted - as though the bits have been wrapped around and ones I'd
expect on the right are on the left of the image in the prevw. Looking
at the icon in the SQLite DB all is well.

#!/usr/bin/perl -w
use strict;
use DBI;
use Cwd;
use Win32::GUI::BitmapInline ();
our $datafile   = getdcwd()."\\mydatabase.db";

# suck icon from SQLite database, 
my @array;
my $dbh = DBI-> connect("dbi:SQLite:dbname=$datafile","","",{});#
database handle
my $sql = "SELECT icon FROM icons WHERE name = 'logo'";
my $sth = $dbh-> prepare($sql); #
statement handle

# must have this next line but DONT KNOW WHY
my $numrows = $sth->execute;

open OUTPUT, ">output.bmp";
my $ref = $sth->fetchrow_hashref;
my $newdata = $$ref{'icon'};
print OUTPUT $newdata;
close OUTPUT;

$sth->finish;
undef $sth;
$dbh->disconnect(); 


Q1. Why is the line my $numrows = $sth->execute; essential? If it is not
present I can't view the image file at all and I get a message that
preview is not available.
Q2. How do I fix it so the bmp file displays perfectly?


Thanks
Brian Rowlands
We must accept finite disappointment, but we must never lose infinite
hope.
Martin Luther King Jr.   





RE: [sqlite] Most basic of questions

2007-10-10 Thread Brian Rowlands (Greymouth High School)
Nice one Clark. Worked a treat.

 

-Original Message-
From: Clark Christensen [mailto:[EMAIL PROTECTED] 
Sent: Thursday, 11 October 2007 5:47 a.m.
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] Most basic of questions

As you've discovered, $sth->finish doesn't quite do the job.  I've found
if I simply

undef $sth;

before disconnecting, it eliminates the message about closing $dbh with
active statement handles.

 -Clark


- Original Message 
From: Brian Rowlands (Greymouth High School)
<[EMAIL PROTECTED]>
To: sqlite-users@sqlite.org
Sent: Wednesday, October 10, 2007 1:48:49 AM
Subject: [sqlite] Most basic of questions


Hi
I'm absolutely new to sqlite which I'm using with a perl project. I did
a test script:

use strict;
use DBI;

my $dbfile = 'H:\trythis.s3db';

my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","",{RaiseError =>
1}); my $sql = "SELECT name FROM Fields ORDER BY name";

my $sth = $dbh->prepare($sql);

if (defined($sth)) {
$sth-> execute();
my @row;
while (@row = $sth->fetchrow_array()) {
print "$row[0]\n";
}
}

sth->finish();

$dbh->disconnect(); 

Can someone kindly tell me why I get displayed: "closing dbh with
active statement handles at H:\Testing sql.pl line 25? By that I mean
which it is necessary to have it displayed? Does it have to be so or can
I somehow cause it not to appear?

I'm awaiting a book "The definitive guide to SQLite" to study but in
the meantime I'd appreciate the help from some kind soul.

Thanks
Brian Rowlands
We must accept finite disappointment, but we must never lose infinite
hope.
Martin Luther King Jr.   








-
To unsubscribe, send email to [EMAIL PROTECTED]

-


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] Most basic of questions

2007-10-10 Thread Brian Rowlands (Greymouth High School)

Hi
I'm absolutely new to sqlite which I'm using with a perl project. I did
a test script:

use strict;
use DBI;

my $dbfile = 'H:\trythis.s3db';

my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","",{RaiseError =>
1});
my $sql = "SELECT name FROM Fields ORDER BY name";

my $sth = $dbh->prepare($sql);

if (defined($sth)) {
$sth-> execute();
my @row;
while (@row = $sth->fetchrow_array()) {
print "$row[0]\n";
}
}

sth->finish();

$dbh->disconnect(); 

Can someone kindly tell me why I get displayed: "closing dbh with active
statement handles at H:\Testing sql.pl line 25? By that I mean which it
is necessary to have it displayed? Does it have to be so or can I
somehow cause it not to appear?

I'm awaiting a book "The definitive guide to SQLite" to study but in the
meantime I'd appreciate the help from some kind soul.

Thanks
Brian Rowlands
We must accept finite disappointment, but we must never lose infinite
hope.
Martin Luther King Jr.