Newbie: Statement handle inactive after successful execute of SELECT

From: Alan M. Carroll (amc_at_thought-mesh.net)
Date: 11/04/03

  • Next message: Michael A Chase: "Re: Newbie: Statement handle inactive after successful execute of SELECT"
    To: dbi-users@perl.org
    Date: Tue, 4 Nov 2003 14:24:35 -0600
    
    

    I'm working with a problem in Movable Type (a PERL web application) where
    certain operations fail. One place where it fails is in some code to create
    an iterator which walks a set of rows in a MySQL 3.23.58 DB using DBI 1.21.
    The code looks like this:

        my $sth = $dbh->prepare($sql) or return sub { };
        $sth->execute(@$bind) or return sub { };
        $sth->bind_columns(undef, @bind);

    What happens is the "bind_columns" fails with "Statement has no result
    columns to bind". I've put in some additional debugging code after the
    execute and before the bind_columns. Both "$sth->err" and "$sth->errstr" are
    undefined. The statement is *not* active. NUM_OF_FIELDS is zero. The execute
    returned "-1". The text of the statement (the contents of $sql) are

    select entry_id, entry_blog_id, entry_status, entry_author_id,
    entry_allow_comments, entry_title, entry_excerpt, entry_text,
    entry_text_more, entry_convert_breaks, entry_to_ping_urls,
    entry_pinged_urls, entry_allow_pings, entry_keywords, entry_tangent_cache,
    entry_category_id, entry_created_on, entry_created_by, entry_modified_on,
    entry_modified_by
    from mt_entry
    where (entry_status = ?)
    order by entry_created_on desc

    The entry_status has been bound to "2" (this was presumably done correctly
    or the execute would have failed, and I've verified that @$bind is correct
    via my debugging code). If I use PHPMyAdmin to do this directly it works
    (although PHPMyAdmin puts a LIMIT on the statement which may have an
    effect).

    This exact same code on the same host works correctly on a different
    database instance in the same MySQL process. Sometimes the code works on the
    problem database in other situations although I don't have any good criteria
    for distinguishing the working from non-working cases. As best I can tell,
    there are certain rows which, if they are in the result set, cause this
    failure. OTOH it may be size related (in this failure case, there are 16,792
    rows, while in the non-problem DB there are about 2800 rows). I've used all
    of the MySQL table repair options, none of which indicated any error in the
    tables.

    My question is, what can I look at to discover more information? I don't
    have access to the MySQL logs. I tried "DBI->trace(4)" but it had no visible
    effect. As far as I can tell from reading the documentation, this situation
    should be impossible, i.e. if the execute succeeds on a SELECT then the
    statement should be Active, even if no rows were selected (although in this
    case it should select all of the rows). Has anyone else seen this? What
    might cause that to happen? The statement handle isn't being re-used, it's
    created on the spot from the prepare. Are there any other methods I can call
    on the database or statement handle to get additional diagnostic
    information? If anyone has a handy DBI info script I can run I'd be happy to
    do that. Thanks.


  • Next message: Michael A Chase: "Re: Newbie: Statement handle inactive after successful execute of SELECT"

    Relevant Pages

    • Re: INSERT statements not INSERTING when using mysql from python
      ... Well, I've checked the SQL log, and my insert statements are certainly ... But then again when I execute the problematic command manually nothing ... and after that the original tables and database is used. ... It occured to me that if I could access the mysql query log that might ...
      (comp.lang.python)
    • Re: INSERT statements not INSERTING when using mysql from python
      ... One partial explanation might be that for some reason it is recreating ... a PSP script that makes many calls to populate a database. ... Then I execute many insert statements in various different loops on ... It occured to me that if I could access the mysql query log that might ...
      (comp.lang.python)
    • Re: error in inserting a longblob data
      ... 'abc'xyz' - a string with an embedded '. ... > gets stored in the database but for other files it gives a MySql ... > in _execute ...
      (comp.lang.python)
    • MySQLdb returns "ValueError: invalid literal for float():" for cursor.execute(show databas
      ... I'm trying to write a simple python program to access a MySQL ... database. ... When I try the same thing in Python 2.3.2 using MySQLdb I get: ... line 114, in _execute ...
      (comp.lang.python)
    • RE: FreeBSD 5.3 MySQL Performance
      ... versions of Linux and FreeBSD for most tests. ... > popular with the ATA disk drive manufacturers. ... > Many companies have used FreeBSD and MySQL for years and years. ... it is not often that you have such a small database and such a large ...
      (freebsd-questions)