PEAR is archived and read-only

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

Home » Database » DB » Bug #2864

Execution of multiple SQL statements with SQLite

Details

Request #2864Execution of multiple SQL statements with SQLite
Submitted2004-12-01 10:52 UTC
Frompriplatv at netscape dot net
Assigneddanielc
StatusWont fix
PackageDB
PHP Version5.0.1
OSWindows XP but irrelevant
Roadmaps(Not assigned)

Comments

[2004-12-01 10:52 UTC] priplatv at netscape dot net

Description:
------------
When the string containing the SQL statements contain more then one SQL statement, separated by colons, the query() probably uses internally the sqlite_query() function instead of the sqlite_exec() function.
This results in only the first SQL statement to be executed and the rest ignored, returning TRUE.
See the Warning text in the description of sqlite_query and sqlite_exec functions.

Reproduce code:
---------------
// Once you have a database object.
$dbres = $dbobj -> query("BEGIN;
/* Drop table and recreate it */
DROP TABLE log;
CREATE TABLE log (Action varchar(7) NOT NULL,
DBname NOT NULL default '',
Status varchar(4) NOT NULL default '',
DataAction timestamp(14) NULL);
INSERT INTO Log VALUES('Backup',
'Database1', 'Fail', '20041201113625');
INSERT INTO Log VALUES('Restore',
'Database2', 'OK', '20041201095000');
COMMIT;");
if (DB::isError($dbres)) die($dbres -> getMessage());
// It will continue here !

Expected result:
----------------
All SQL statements shall be executed (like with sqlite_exec() function).

Actual result:
--------------
Only the first SQL statement is executed. If that is DROP TABLE, the table is dropped and the database very likely be corrupted.

[2004-12-01 17:07 UTC] priplatv at netscape dot net

SQL statements are separated by semi-colons. Obviously!