PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » MDB » Bug #1087

query limits in INSERT queries

Details

Submitted2004-03-28 12:38 UTC
Fromalexei at saveliev dot org
Assignedlsmith
StatusClosed
PackageMDB
PHP Version4.3.4
OSlinux
Roadmaps(Not assigned)

Comments

[2004-03-28 12:38 UTC] alexei at saveliev dot org

Description:
------------
MDB has wrong query generation in some circumstances

It seems that $this->selected_row_limit adds limit to query.

Reproduce code:
---------------
I've got it with following sequence of actions:

$langs=$db->getAll('SELECT ID,name FROM '.TABLE_PREFIX.'langs_avail ORDER BY ID');

//....

$sql='INSERT INTO '.TABLE_PREFIX.'i18n(ID,pageID'.$fld.') VALUES (?,?'.$val.')';
$sti=$db->prepareQuery($sql);
$res=$db->execute($sti,NULL,$data_ord);

Expected result:
----------------
INSERT INTO webshop_i18n(ID,pageID,en,ru) VALUES ('test','main','main','') on server input

Actual result:
--------------
INSERT INTO webshop_i18n(ID,pageID,en,ru) VALUES ('test','main','main','') LIMIT 1

My query does not have any LIMIT for sure.

[2004-03-28 18:27 UTC] alexei at saveliev dot org

I don't have any LIMIT in code.

Here are mysql logs for different code:

$sql='INSERT INTO '.TABLE_PREFIX.'i18n(ID,pageID'.$fld.') VALUES (?,?'.$val.')';
$sti=$db->prepareQuery($sql);
$res=$db->execute($sti,NULL,$data_ord);

/usr/local/mysql/libexec/mysqld, Version: 4.0.15a-log, started with:
Tcp port: 3306 Unix socket: /tmp/mysql.sock
Time Id Command Argument
040328 22:16:00 2 Connect root@localhost on
2 Query SELECT VERSION()
2 Init DB webshop
2 Query SELECT ID,name FROM webshop_langs_avail ORDER BY ID
2 Init DB webshop
2 Query INSERT INTO webshop_i18n(ID,pageID,en,ru) VALUES ('test','test','test','') LIMIT 1
2 Quit

$db->selected_row_limit=0;
$sql='INSERT INTO '.TABLE_PREFIX.'i18n(ID,pageID'.$fld.') VALUES (?,?'.$val.')';
$sti=$db->prepareQuery($sql);
$res=$db->execute($sti,NULL,$data_ord);

040328 22:18:56 6 Connect root@localhost on
6 Query SELECT VERSION()
6 Init DB webshop
6 Query SELECT ID,name FROM webshop_langs_avail ORDER BY ID
6 Init DB webshop
6 Query INSERT INTO webshop_i18n(ID,pageID,en,ru) VALUES ('test2','test2','test2','')
6 Quit

[2004-03-28 18:35 UTC] alexei at saveliev dot org

I use mysql driver

[2004-03-28 19:59 UTC] alexei at saveliev dot org

Sorry, I do have one statement that limits query. For some reason MySQL did not dump it to log.

I have getOne method call before prepareQuery (thanks to xdebug extension)

5 =>
array
'function' => 'checkmsgid'
'file' => '/usr/local/lib/php/HTML/QuickForm/Rule/Callback.php'
'line' => 73
'params' =>
array
6 =>
array
'function' => 'getone'
'class' => 'mdb_mysql'
'file' => '/.prj/.shop/admin/i18n/msg_edit.php'
'line' => 76
'params' =>
array
7 =>
array
'function' => 'setselectedrowrange'
'class' => 'mdb_mysql'
'file' => '/usr/local/lib/php/MDB/Common.php'
'line' => 3942
'params' =>
array

It seems that non zero $this->selected_row_limit is used for all subsequent queries.

[2004-03-28 21:16 UTC] alexei at saveliev dot org

getOne and others have two ways to execute queries - query() and executeQuery(). $this->selected_row_limit is reset in query() all time but executeQuery() may raise error without actual calling of query() and return. this leaves $this->selected_row_limit untouched. That was my case. I have courage to confirm that it was my error caused misbehavior of MDB.