Skip Menu |
 

This queue is for tickets about the DBD-SQLite CPAN distribution.

Report information
The Basics
Id: 128121
Status: resolved
Priority: 0/
Queue: DBD-SQLite

People
Owner: Nobody in particular
Requestors: se_misc [...] hotmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: fetchrow_arrayref not returning fully compatible perl array ref
Date: Thu, 27 Dec 2018 19:42:37 +0000
To: "bug-DBD-SQLite [...] rt.cpan.org" <bug-DBD-SQLite [...] rt.cpan.org>
From: Stefan E <se_misc [...] hotmail.com>
Download (untitled) / with headers
text/plain 943b
Thx, Ishigaki San, for providing DBD::SQLite! Running the following code on Strawberry perl 5.26.1 (64 bit, Win 7) crashes at the line indicated. I'm currently porting some code from mySQL to SQLite; same code had no problem with DBD::mysql. Issue is reproduced with DBD::SQLite 1.54 and 1.60. use strict; use DBI; my($dbh, $sth, @data); $dbh = DBI->connect("DBI:SQLite:dbname=dummy1.sqlite", "", ""); $sth = $dbh->prepare("SELECT id, f_1397, f_1398, f_1399, f_1400 FROM myTable;"); $sth->execute(); while (my $row_ref = $sth->fetchrow_arrayref) {   splice @$row_ref, 1, 1;         # -- breaks if DBI:SQLite is used above   push @data, [ @$row_ref ];      # -- trying to copy array after splice kills perl (works without splice above)   #splice @{$data[-1]}, 1, 1;     # -- alternate (working) solution: splice on copy of array } Thx. for your consideration Kind regards, Stefan
Download (untitled) / with headers
text/plain 1.4k
On Fri Dec 28 04:43:05 2018, Stefan_E wrote: Show quoted text
> Thx, Ishigaki San, for providing DBD::SQLite! > > Running the following code on Strawberry perl 5.26.1 (64 bit, Win 7) > crashes at the line indicated. I'm currently porting some code from > mySQL to SQLite; same code had no problem with DBD::mysql. Issue is > reproduced with DBD::SQLite 1.54 and 1.60. > > use strict; > use DBI; > my($dbh, $sth, @data); > > $dbh = DBI->connect("DBI:SQLite:dbname=dummy1.sqlite", "", ""); > $sth = $dbh->prepare("SELECT id, f_1397, f_1398, f_1399, f_1400 FROM > myTable;"); > $sth->execute(); > > while (my $row_ref = $sth->fetchrow_arrayref) { >   splice @$row_ref, 1, 1;         # -- breaks if DBI:SQLite is used above >   push @data, [ @$row_ref ];      # -- trying to copy array after > splice kills perl (works without splice above) >   #splice @{$data[-1]}, 1, 1;     # -- alternate (working) solution: > splice on copy of array > } > > Thx. for your consideration > > Kind regards, Stefan >
Couldn't reproduce the issue under almost the same environment (64bit Win7 + strawberry 5.26.3) and a few other environments. Could you make the script above a little more complete? (create a table and insert necessary data, set proper attributes, etc; please let it reproduce the issue by just running it.) And what happens if you run the same script under other OSes (in other words, isn't it your environmental issue, rather than DBD::SQLite's)?
Subject: Re: [rt.cpan.org #128121] fetchrow_arrayref not returning fully compatible perl array ref
Date: Thu, 27 Dec 2018 21:46:53 +0000
To: "bug-DBD-SQLite [...] rt.cpan.org" <bug-DBD-SQLite [...] rt.cpan.org>
From: Stefan E <se_misc [...] hotmail.com>
Here is a self-contained script. Sorry, I don't have access to another environment (except for a VM with the same strawberry - btw., a portable installation; DBI is 1.637, but updating to 1.642 didn't help) use strict; use DBI; my($dbh, $sth, @data); unlink "test.sqlite" or warn "Can't erase test.sqlite"; $dbh = DBI->connect("DBI:SQLite:dbname=test.sqlite", "", ""); $dbh->do("CREATE TABLE test_table (             t1   REAL default 0,             t2   REAL default 0,             t3   REAL default 0,             t4   REAL default 0);"); $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (1.1, 1.2, 1.3, 1.4);"); $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (2.1, 2.2, 2.3, 2.4);"); $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (3.1, 3.2, 3.3, 3.4);"); $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (4.1, 4.2, 4.3, 4.4);"); $sth = $dbh->prepare("SELECT t1, t2, t3, t4 FROM test_table;"); $sth->execute(); while (my $row_ref = $sth->fetchrow_arrayref) {   splice @$row_ref, 1, 1;         # -- breaks if DBI:SQLite is used above   push @data, [ @$row_ref ];      # -- trying to copy array after splice kills perl   #splice @{$data[-1]}, 1, 1;     # -- alternate (working) solution: splice on copy of array } for (my $i = 0; $i < scalar @data; $i++) {   print join ", ", @{$data[$i]};   print "\n"; } On 27-Dec-18 22:05, Kenichi Ishigaki via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=128121 > > > On Fri Dec 28 04:43:05 2018, Stefan_E wrote:
>> Thx, Ishigaki San, for providing DBD::SQLite! >> >> Running the following code on Strawberry perl 5.26.1 (64 bit, Win 7) >> crashes at the line indicated. I'm currently porting some code from >> mySQL to SQLite; same code had no problem with DBD::mysql. Issue is >> reproduced with DBD::SQLite 1.54 and 1.60. >> >> use strict; >> use DBI; >> my($dbh, $sth, @data); >> >> $dbh = DBI->connect("DBI:SQLite:dbname=dummy1.sqlite", "", ""); >> $sth = $dbh->prepare("SELECT id, f_1397, f_1398, f_1399, f_1400 FROM >> myTable;"); >> $sth->execute(); >> >> while (my $row_ref = $sth->fetchrow_arrayref) { >>   splice @$row_ref, 1, 1;         # -- breaks if DBI:SQLite is used above >>   push @data, [ @$row_ref ];      # -- trying to copy array after >> splice kills perl (works without splice above) >>   #splice @{$data[-1]}, 1, 1;     # -- alternate (working) solution: >> splice on copy of array >> } >> >> Thx. for your consideration >> >> Kind regards, Stefan >>
> Couldn't reproduce the issue under almost the same environment (64bit Win7 + strawberry 5.26.3) and a few other environments. > > Could you make the script above a little more complete? (create a table and insert necessary data, set proper attributes, etc; please let it reproduce the issue by just running it.) > > And what happens if you run the same script under other OSes (in other words, isn't it your environmental issue, rather than DBD::SQLite's)? > > . >
Download (untitled) / with headers
text/plain 3.3k
On Fri Dec 28 06:47:21 2018, Stefan_E wrote: Show quoted text
> Here is a self-contained script. Sorry, I don't have access to another > environment (except for a VM with the same strawberry - btw., a > portable > installation; DBI is 1.637, but updating to 1.642 didn't help) > > use strict; > use DBI; > my($dbh, $sth, @data); > > unlink "test.sqlite" or warn "Can't erase test.sqlite"; > $dbh = DBI->connect("DBI:SQLite:dbname=test.sqlite", "", ""); > $dbh->do("CREATE TABLE test_table ( >             t1   REAL default 0, >             t2   REAL default 0, >             t3   REAL default 0, >             t4   REAL default 0);"); > $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (1.1, 1.2, > 1.3, > 1.4);"); > $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (2.1, 2.2, > 2.3, > 2.4);"); > $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (3.1, 3.2, > 3.3, > 3.4);"); > $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (4.1, 4.2, > 4.3, > 4.4);"); > > $sth = $dbh->prepare("SELECT t1, t2, t3, t4 FROM test_table;"); > > $sth->execute(); > while (my $row_ref = $sth->fetchrow_arrayref) { >   splice @$row_ref, 1, 1;         # -- breaks if DBI:SQLite is used > above >   push @data, [ @$row_ref ];      # -- trying to copy array after > splice kills perl >   #splice @{$data[-1]}, 1, 1;     # -- alternate (working) solution: > splice on copy of array > } > > for (my $i = 0; $i < scalar @data; $i++) { >   print join ", ", @{$data[$i]}; >   print "\n"; > } > > On 27-Dec-18 22:05, Kenichi Ishigaki via RT wrote:
> > <URL: https://rt.cpan.org/Ticket/Display.html?id=128121 > > > > > On Fri Dec 28 04:43:05 2018, Stefan_E wrote:
> >> Thx, Ishigaki San, for providing DBD::SQLite! > >> > >> Running the following code on Strawberry perl 5.26.1 (64 bit, Win 7) > >> crashes at the line indicated. I'm currently porting some code from > >> mySQL to SQLite; same code had no problem with DBD::mysql. Issue is > >> reproduced with DBD::SQLite 1.54 and 1.60. > >> > >> use strict; > >> use DBI; > >> my($dbh, $sth, @data); > >> > >> $dbh = DBI->connect("DBI:SQLite:dbname=dummy1.sqlite", "", ""); > >> $sth = $dbh->prepare("SELECT id, f_1397, f_1398, f_1399, f_1400 FROM > >> myTable;"); > >> $sth->execute(); > >> > >> while (my $row_ref = $sth->fetchrow_arrayref) { > >>   splice @$row_ref, 1, 1;         # -- breaks if DBI:SQLite is > >> used above > >>   push @data, [ @$row_ref ];      # -- trying to copy array after > >> splice kills perl (works without splice above) > >>   #splice @{$data[-1]}, 1, 1;     # -- alternate (working) > >> solution: > >> splice on copy of array > >> } > >> > >> Thx. for your consideration > >> > >> Kind regards, Stefan > >>
> > Couldn't reproduce the issue under almost the same environment (64bit > > Win7 + strawberry 5.26.3) and a few other environments. > > > > Could you make the script above a little more complete? (create a > > table and insert necessary data, set proper attributes, etc; please > > let it reproduce the issue by just running it.) > > > > And what happens if you run the same script under other OSes (in > > other words, isn't it your environmental issue, rather than > > DBD::SQLite's)? > > > > . > >
>
Now I can reproduce the issue under both Win and Debian. Will look at it. Thanks.
Download (untitled) / with headers
text/plain 4.1k
On Fri Dec 28 06:56:59 2018, ISHIGAKI wrote: Show quoted text
> On Fri Dec 28 06:47:21 2018, Stefan_E wrote:
> > Here is a self-contained script. Sorry, I don't have access to > > another > > environment (except for a VM with the same strawberry - btw., a > > portable > > installation; DBI is 1.637, but updating to 1.642 didn't help) > > > > use strict; > > use DBI; > > my($dbh, $sth, @data); > > > > unlink "test.sqlite" or warn "Can't erase test.sqlite"; > > $dbh = DBI->connect("DBI:SQLite:dbname=test.sqlite", "", ""); > > $dbh->do("CREATE TABLE test_table ( > >             t1   REAL default 0, > >             t2   REAL default 0, > >             t3   REAL default 0, > >             t4   REAL default 0);"); > > $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (1.1, 1.2, > > 1.3, > > 1.4);"); > > $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (2.1, 2.2, > > 2.3, > > 2.4);"); > > $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (3.1, 3.2, > > 3.3, > > 3.4);"); > > $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (4.1, 4.2, > > 4.3, > > 4.4);"); > > > > $sth = $dbh->prepare("SELECT t1, t2, t3, t4 FROM test_table;"); > > > > $sth->execute(); > > while (my $row_ref = $sth->fetchrow_arrayref) { > >   splice @$row_ref, 1, 1;         # -- breaks if DBI:SQLite is used > > above > >   push @data, [ @$row_ref ];      # -- trying to copy array after > > splice kills perl > >   #splice @{$data[-1]}, 1, 1;     # -- alternate (working) > > solution: > > splice on copy of array > > } > > > > for (my $i = 0; $i < scalar @data; $i++) { > >   print join ", ", @{$data[$i]}; > >   print "\n"; > > } > > > > On 27-Dec-18 22:05, Kenichi Ishigaki via RT wrote:
> > > <URL: https://rt.cpan.org/Ticket/Display.html?id=128121 > > > > > > > On Fri Dec 28 04:43:05 2018, Stefan_E wrote:
> > >> Thx, Ishigaki San, for providing DBD::SQLite! > > >> > > >> Running the following code on Strawberry perl 5.26.1 (64 bit, Win > > >> 7) > > >> crashes at the line indicated. I'm currently porting some code > > >> from > > >> mySQL to SQLite; same code had no problem with DBD::mysql. Issue > > >> is > > >> reproduced with DBD::SQLite 1.54 and 1.60. > > >> > > >> use strict; > > >> use DBI; > > >> my($dbh, $sth, @data); > > >> > > >> $dbh = DBI->connect("DBI:SQLite:dbname=dummy1.sqlite", "", ""); > > >> $sth = $dbh->prepare("SELECT id, f_1397, f_1398, f_1399, f_1400 > > >> FROM > > >> myTable;"); > > >> $sth->execute(); > > >> > > >> while (my $row_ref = $sth->fetchrow_arrayref) { > > >>   splice @$row_ref, 1, 1;         # -- breaks if DBI:SQLite is > > >> used above > > >>   push @data, [ @$row_ref ];      # -- trying to copy array > > >> after > > >> splice kills perl (works without splice above) > > >>   #splice @{$data[-1]}, 1, 1;     # -- alternate (working) > > >> solution: > > >> splice on copy of array > > >> } > > >> > > >> Thx. for your consideration > > >> > > >> Kind regards, Stefan > > >>
> > > Couldn't reproduce the issue under almost the same environment > > > (64bit > > > Win7 + strawberry 5.26.3) and a few other environments. > > > > > > Could you make the script above a little more complete? (create a > > > table and insert necessary data, set proper attributes, etc; please > > > let it reproduce the issue by just running it.) > > > > > > And what happens if you run the same script under other OSes (in > > > other words, isn't it your environmental issue, rather than > > > DBD::SQLite's)? > > > > > > . > > >
> >
> > Now I can reproduce the issue under both Win and Debian. Will look at > it. Thanks.
See DBI's document for fetchrow_arrayref. Note that the same array reference is returned for each fetch, so don't store the reference and then use it after a later fetch. Also, the elements of the array are also reused for each row, so take care if you want to take a reference to an element. See also "bind_columns". In this case, you splice the (readonly) row that will be reused for performance. The row to reuse has four elements at the first fetchrow, but it has only three at the second, which is roughly the reason of the breakage. So the solution here is don't use splice $row_ref itself.
Subject: Re: [rt.cpan.org #128121] fetchrow_arrayref not returning fully compatible perl array ref
Date: Fri, 28 Dec 2018 00:04:33 +0000
To: "bug-DBD-SQLite [...] rt.cpan.org" <bug-DBD-SQLite [...] rt.cpan.org>
From: Stefan E <se_misc [...] hotmail.com>
Download (untitled) / with headers
text/plain 4.5k
Thx - indeed, on closer inspection, it seems to be the second fetchrow_arrayref which breaks. On 27-Dec-18 23:56, Kenichi Ishigaki via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=128121 > > > On Fri Dec 28 06:56:59 2018, ISHIGAKI wrote:
>> On Fri Dec 28 06:47:21 2018, Stefan_E wrote:
>>> Here is a self-contained script. Sorry, I don't have access to >>> another >>> environment (except for a VM with the same strawberry - btw., a >>> portable >>> installation; DBI is 1.637, but updating to 1.642 didn't help) >>> >>> use strict; >>> use DBI; >>> my($dbh, $sth, @data); >>> >>> unlink "test.sqlite" or warn "Can't erase test.sqlite"; >>> $dbh = DBI->connect("DBI:SQLite:dbname=test.sqlite", "", ""); >>> $dbh->do("CREATE TABLE test_table ( >>>             t1   REAL default 0, >>>             t2   REAL default 0, >>>             t3   REAL default 0, >>>             t4   REAL default 0);"); >>> $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (1.1, 1.2, >>> 1.3, >>> 1.4);"); >>> $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (2.1, 2.2, >>> 2.3, >>> 2.4);"); >>> $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (3.1, 3.2, >>> 3.3, >>> 3.4);"); >>> $dbh->do("INSERT INTO test_table (t1, t2, t3, t4) VALUES (4.1, 4.2, >>> 4.3, >>> 4.4);"); >>> >>> $sth = $dbh->prepare("SELECT t1, t2, t3, t4 FROM test_table;"); >>> >>> $sth->execute(); >>> while (my $row_ref = $sth->fetchrow_arrayref) { >>>   splice @$row_ref, 1, 1;         # -- breaks if DBI:SQLite is used >>> above >>>   push @data, [ @$row_ref ];      # -- trying to copy array after >>> splice kills perl >>>   #splice @{$data[-1]}, 1, 1;     # -- alternate (working) >>> solution: >>> splice on copy of array >>> } >>> >>> for (my $i = 0; $i < scalar @data; $i++) { >>>   print join ", ", @{$data[$i]}; >>>   print "\n"; >>> } >>> >>> On 27-Dec-18 22:05, Kenichi Ishigaki via RT wrote:
>>>> <URL: https://rt.cpan.org/Ticket/Display.html?id=128121 > >>>> >>>> On Fri Dec 28 04:43:05 2018, Stefan_E wrote:
>>>>> Thx, Ishigaki San, for providing DBD::SQLite! >>>>> >>>>> Running the following code on Strawberry perl 5.26.1 (64 bit, Win >>>>> 7) >>>>> crashes at the line indicated. I'm currently porting some code >>>>> from >>>>> mySQL to SQLite; same code had no problem with DBD::mysql. Issue >>>>> is >>>>> reproduced with DBD::SQLite 1.54 and 1.60. >>>>> >>>>> use strict; >>>>> use DBI; >>>>> my($dbh, $sth, @data); >>>>> >>>>> $dbh = DBI->connect("DBI:SQLite:dbname=dummy1.sqlite", "", ""); >>>>> $sth = $dbh->prepare("SELECT id, f_1397, f_1398, f_1399, f_1400 >>>>> FROM >>>>> myTable;"); >>>>> $sth->execute(); >>>>> >>>>> while (my $row_ref = $sth->fetchrow_arrayref) { >>>>>   splice @$row_ref, 1, 1;         # -- breaks if DBI:SQLite is >>>>> used above >>>>>   push @data, [ @$row_ref ];      # -- trying to copy array >>>>> after >>>>> splice kills perl (works without splice above) >>>>>   #splice @{$data[-1]}, 1, 1;     # -- alternate (working) >>>>> solution: >>>>> splice on copy of array >>>>> } >>>>> >>>>> Thx. for your consideration >>>>> >>>>> Kind regards, Stefan >>>>>
>>>> Couldn't reproduce the issue under almost the same environment >>>> (64bit >>>> Win7 + strawberry 5.26.3) and a few other environments. >>>> >>>> Could you make the script above a little more complete? (create a >>>> table and insert necessary data, set proper attributes, etc; please >>>> let it reproduce the issue by just running it.) >>>> >>>> And what happens if you run the same script under other OSes (in >>>> other words, isn't it your environmental issue, rather than >>>> DBD::SQLite's)? >>>> >>>> . >>>>
>> Now I can reproduce the issue under both Win and Debian. Will look at >> it. Thanks.
> > See DBI's document for fetchrow_arrayref. > > Note that the same array reference is returned for each fetch, so don't > store the reference and then use it after a later fetch. Also, the > elements of the array are also reused for each row, so take care if you > want to take a reference to an element. See also "bind_columns". > > In this case, you splice the (readonly) row that will be reused for performance. The row to reuse has four elements at the first fetchrow, but it has only three at the second, which is roughly the reason of the breakage. So the solution here is don't use splice $row_ref itself. > . >
Closed. Thanks.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.