Good day Monks. I have a small sub that fetches a value from mysql:
sub getsqlvalue { my @results = (); my ($dbh,$sqlstatement)= @_; my $sth = $dbh->prepare($sqlstatement); my @row; $sth->execute || die "Could not execute MySQL statement: $sqlstate +ment"; while (@row=$sth->fetchrow_array) { push(@results, [ @row ]); } $sth->finish(); return $results[0][0]; }
I am using this in a program that is accessing a MyISAM table in MySQL. I issue a write lock on several tables in the same schema, but not this table named "vocabulary." Then when I try to do a SELECT on vocabulary I get the error "DBD::mysql::st execute failed: Table 'vocabulary' was not locked with LOCK TABLES" on the $sth->execute line in the above sub. I have tested the SQL statement being executed and it is valid. I have no clue what the problem is, since it is correct that I have not locked that table! Anyone know what's going on?

Many TIA

Steve UPDATE I found the answer in the MySQL docs for lock tables: "When you use LOCK TABLES, you must lock all tables that you are going to use in your queries." So the problem was indeed that I had not locked the table.


In reply to DBD::Mysql Strange Locking error by cormanaz

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.