in reply to Re^2: DBD::ODBC and FreeTDS / limited to one statement handle
in thread DBD::ODBC and FreeTDS / limited to one statement handle

Yeah, OK -- it looks like it's not DBD::ODBC.

The FreeTDS file freetds/src/tds/mem.c has a routine tds_alloc_lookup_sqlstate(TDSSOCKET * tds, int msgno) with a switch statement that appears to map a couple of errors to 24000; the first one is SQLS_ENTRY(16999, "24000"); /* Invalid cursor state */.

In the file freetds/src/odbc/error.c I see a line that appears to report an ODBC error of 24000 with the same text: ODBCERR("24000", "Invalid cursor state"),

So I've ansered my own question.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Replies are listed 'Best First'.
Re^4: DBD::ODBC and FreeTDS / limited to one statement handle
by talexb (Chancellor) on May 15, 2024 at 02:08 UTC

    So it turns out I'm a goof (this is not surprising), and after posting here, ruminating, and digging through the FreeTDS code, my brain proposed another solution. If I can't have multiple statement handles for a single database handle, can I have multiple database handles, each with its own statement handle? I should try that, right? The solution couldn't be that obvious, right? RIGHT?

    Good grief. I just tried it, and it works. I just created two $dbh guys, each with their own $sth; they each called my good friend fetchrow_hashref, and it all went swimmingly.

    I understand this is called Rubber Duck Debugging. Now it's time for some Scotch to celebrate. You goofball.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      Many database connections don't like more than a single active statement handle that hasn't been completely fetched ("cursor"). I know that SQLite dislikes this.

      My usual approach is to either convert the two parallel SQL statements into a single SQL statement, likely with a JOIN, or to use ->fetchall_arrayref to first read all of the rows of the first statement and then process the second statement. My machines usually have enough memory for the second approach.

      So it turns out I'm a goof (this is not surprising)

      Bolding emphasis mine, which is what I'm responding to here. That's absolute hogwash. You are one of the most methodical, logical and practical thinkers here on Perlmonks, and I've felt that for what, two plus decades.

      You hit, as you said, a de-facto situation of Rubber Duck Debugging. You're not the Maple Leafs... you're a Perl Hacker ;)

      I know what it's like to have that "sigh, I'm an idiot" moment. Awesome feeling, isn't it!