use DBD::SQLite; my %attr; $attr{AutoCommit}=1; # Turn on AutoCommit. if (! -e $dbfile) { $dbh=DBI->connect("dbi:SQLite:$dbfile", undef, undef, \%attr) or die "Could not open $dbfile: $DBI::errstr"; # Now create table. $sql="CREATE TABLE data "; $sql.="(skey TEXT PRIMARY KEY, "; # Was varchar(30) $sql.="svalue TEXT)"; $sql.=";"; $ret=prepex($sql); } else { $dbh=DBI->connect("dbi:SQLite:$dbfile", undef, undef, undef) or die "Could not open $dbfile: $DBI::errstr"; } $s="SQLite version: ".$dbh->{sqlite_version}; writeerr($s); SQLite version: 3.8.4.1 #### ########################################################################### # Prepare then execute SQL statement. # In: SQL statement # Out: change global var $sth. Return rows affected. # See $DBI::rows: rows returned? # $DBI::errstr: error string sub prepex {my($sql)=@_; my(@a,@b,$i,$j,$procname,$s,$t); my($key,$data,$ret,$rows); $procname="prepex()"; $rows=0; $s="$procname: Runnning sql: $sql"; writeerr($s); eval { $sth=$dbh->prepare($sql); }; if ($@) { $s="$procname: ERROR on prepare: $@"; writeerr($s); } eval { $sth->execute(); $rows=$DBI::rows; # Also $sth->rows; #$ret=$ret+0; # Remove '0E0' code. #$dbh->commit or die $dbh->errstr; # Do not use with AutoCommit. }; if (($@) or ($DBI::errstr)) { $s="$procname: ERROR on execute: $@"; writeerr($s); } #$s="$procname: Rows returned: $DBI::rows"; #writeerr($s); if (len($DBI::errstr)>0) { $s="$procname ERROR from DBI: $DBI::errstr"; writeerr($s); } return $rows; # prepex } Then I execute these SQL statements. CREATE TABLE data (skey TEXT PRIMARY KEY, svalue TEXT); INSERT INTO data (skey, svalue) VALUES ('Stuff', 'Ge 1:1-more &stuff& here '); SELECT svalue FROM data WHERE skey='Stuff'; # This one fails with 0 recs returned