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"; }
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); }

Can anyone spot anything?

In reply to SQLite UPDATE table lock by packetstormer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.