MacOS Perl - sqlite behaviour

I have a sqlite DB, 1 table with 12 columns. From command-line I can execute a select statement and get proper / correct results.
In a Perl script using the same database and the same select statement, my results are missing the first record.
I've checked the DB for blank / null records - none.
Running Monterey (12.4) on a newish M1.
SQLite version 3.38.2 2022-03-26 13:51:10
This is perl 5, version 30, subversion 3 (v5.30.3) built for darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)

@trudge ,

  • share your code, both that run from the command line and the perl script (or the salient parts of it )
  • the query being executed and the accompanying output showing the discrepancies in results
  • sample table data that is supposed to be retrieved by the query

NB: please use MARKDOWN menu options when posting code / data

Command line:

sqlite> select year,month,anomM,anomMU from data where year=1951;
year  month  anomM   anomMU
----  -----  ------  ------
1951  1      -0.51   0.137 
1951  2      -0.914  0.14  
1951  3      -0.273  0.152 
1951  4      0.006   0.173 
1951  5      0.094   0.199 
1951  6      -0.287  0.241 
1951  7      -0.103  0.239 
1951  8      0.113   0.262 
1951  9      0.192   0.235 
1951  10     0.397   0.141 
1951  11     0.085   0.136 
1951  12     0.623   0.164 

Perl script:

$sth=$dbh->prepare(qq{select id,year,month,anomM,anomMU from data where year=1951;});
$sth->execute();
while (@records=$sth->fetchrow_array()) {
	$id=$records[0];
	$year=$records[1];
	$month=$records[2];
	$anomM=$records[3];
	$anomMU=$records[4];
	print (qq{$year : $month : $anomM : $anomMU<br/>});
#	$idx++;
}
$sth->finish();

Result:

1951 : 2 : -0.914 : 0.14
1951 : 3 : -0.273 : 0.152
1951 : 4 : 0.006 : 0.173
1951 : 5 : 0.094 : 0.199
1951 : 6 : -0.287 : 0.241
1951 : 7 : -0.103 : 0.239
1951 : 8 : 0.113 : 0.262
1951 : 9 : 0.192 : 0.235
1951 : 10 : 0.397 : 0.141
1951 : 11 : 0.085 : 0.136
1951 : 12 : 0.623 : 0.164

Well this is weird. When I add an HTML <ol> tag then a <li> tag for each print in the script, it now shows me all the data, including the missing month 1 ...

3265 Records

1951 : 1 : -0.51 : 0.137
1951 : 2 : -0.914 : 0.14
1951 : 3 : -0.273 : 0.152
1951 : 4 : 0.006 : 0.173
1951 : 5 : 0.094 : 0.199
1951 : 6 : -0.287 : 0.241
1951 : 7 : -0.103 : 0.239
1951 : 8 : 0.113 : 0.262
1951 : 9 : 0.192 : 0.235
1951 : 10 : 0.397 : 0.141
1951 : 11 : 0.085 : 0.136
1951 : 12 : 0.623 : 0.164

Sorry, the HTML list tags didn't appear in that but the list is numbered 1-12 on my screen.
Now I'm really confused.

More weirdness. I took the HTML list tags out of the print statements and the script runs correctly. Tried several different selects just to make sure. Apologies for wasting anyone's time on this. If I ever figure out what was going on I will let you know.

1 Like

np, sometime just having another set of :eyes: (even remote ones) is a good passive debugging aid

1 Like