########################################################################### # 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