PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » MDB » Bug #984

Error with 'DECLARE select_cursor CURSOR'

Details

Submitted2004-03-09 17:56 UTC
Fromk_julie at hotmail dot com
StatusBogus
PackageMDB
PHP Version4.3.3
OSSuse Linux 9.0
Roadmaps(Not assigned)

Comments

[2004-03-09 17:56 UTC] k_julie at hotmail dot com

Description:
------------
After upgrading to PostgreSQL 7.4, I recieve this error:

MDB Error: unknown error
SELECT id,string_date FROM issue [nativecode = ERROR: cursor
"select_cursor" already exists ]

It is happening because I am calling the function getRow twice within
one transaction. It makes sense that you can't re-declare a cursor until
after the transaction ends or the cursor is closed. I'm not sure why this
worked with PostgreSQL 7.3, but I know they changed some things
with cursors in the 7.4 release. This also happens when calling getOne
twice, but not with getAll or getCol. I assume this doesn't happen with
getAll or getCol because those reach to the end of the result set, where
getRow and getOne don't.

I tried with the latest version from CVS, but still didn't work.

I was able to stop the error by adding these lines to Common.php at
the end of function getRow (on line #4017). I don't know if this is the
best way, or if it is even compatible with other DB's.

if(!$this->autocommit) {
$this->query('CLOSE select_cursor');
}

Reproduce code:
---------------
$dbh->autocommit(false);

if(MDB::isError($row1 = $dbh->getRow('SELECT id,title FROM publication'))) {
print $row1->message . '<br>' . $row1->userinfo;
}
else {
print_r($row1);
}

print '<br><br>';

if(MDB::isError($row2 = $dbh->getRow('SELECT id,string_date FROM issue'))) {
print $row2->message . '<br>' . $row2->userinfo;
}
else {
print_r($row2);
}

$dbh->commit();

Expected result:
----------------
I would expect it to print out the array for the first row and then the
array for the second row.

Actual result:
--------------
It prints out the array for the first row, and then the error message.

Array ( [0] => 7 [1] => Annual Statistical Digest )

MDB Error: unknown error
SELECT id,string_date FROM issue [nativecode = ERROR: cursor
"select_cursor" already exists ]