I decided to try DBD::SQLite and am getting no where fast. I create a new table, insert a record, then I cannot find the record again via SELECT. I don't get an error, I just get 0 records returned. (Actually, the object returns '0E0', which means zero records returned anyway.) Here's my code opening the db and creating the table.
Then I execute these statements in order. Every SQL statement is executed with the routine prepex().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
The final SELECT fails with no records found. Am I missing something about oddball characters in a string field? Is there something else going on I'm not seeing? I have no experience with SQL. I've been going over this for about 3 hours trying different things, to no avail.###################################################################### +##### # 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 re +cs returned
Thank you.
EDIT. We are using ampersands in the SQL statement data (and other odd characters) to indicate formatting like bold and italic. They will later be put into a text file, then put into Word, and formatted appropriately. We might also us caret (^), pound (#), dollar sign ($), or others.
In reply to DBD::SQLite select fails by bulrush
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |