Hello
I am struggling with this SQLite problem. I have a small table that I read from and depending on the results I may shoot off into another function to INSERT/UPDATE the table.
The problem is the SQLite table seems to be locked by the SELECT statement and won't let the update occur. Strangly, the INSERT works fine? The two bits of code is below. I have read the DBD docs and tried to set "sqlite_use_immediate_transaction => 1" but this has no effect.
The error I get is: "DBD::SQLite::st execute failed: database is locked at......."
sub new_dbh { my $dbfile = "shows.db"; my $dbh= DBI->connect("DBI:SQLite:dbname=$dbfile","","",{sqlite_us +e_immediate_transaction => 1,}) or die $DBI::errstr; return $dbh; } sub check_episode_exists { my @s_and_e = @_; my $return; my $dbh = new_dbh(); my ($ins,$skip) = (0,0); foreach my $sh(@s_and_e) { my ($id,$format_name,$title,$overview,$s +how) = split(/\|/,$sh); $show =~ s/-/ /g; print ucfirst($show) . " $format_name - + $title \n"; my $sth = $dbh->prepare("SELECT * from s +easons WHERE id = ? and format_name +=?"); $sth->execute($id,$format_name); my $row = $sth->rows(); if($row == "0") {insert_seasons($id,$for +mat_name,$title,$overview);$ins++;} if($row > 0) {$skip++;update_overview($i +d,$format_name,$overview)} } print "We added $ins\nWe skipped $skip\n"; }
Can anyone spot anything?sub update_overview { my $dbh = new_dbh(); my ($id,$format_name,$overview) = @_; my $season = substr($format_name,0,3); my $episode = substr($format_name,3); my $sth = $dbh->prepare("UPDATE seasons SET overview = ? WHERE id = ? AND season = ? AND episode = ?"); $sth->execute($overview,$id,$season,$episode); }
In reply to SQLite UPDATE table lock by packetstormer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |