note 92714 added to function.sqlite-query
| From: | bruce at causal dot com | Date: | Wed, 05 Aug 2009 06:11:44 +0000 |
| Subject: | note 92714 added to function.sqlite-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159121@lists.php.net to get a copy of this message | ||
In follow up to Csaba Gabor's function (see below) that allows for multi-statement queries to
be executed via sqlite_query() this alternative implementation avoids a problem with Csaba's
version (which prevents multi-statement constructs like CREATE TRIGGER from being parsed correctly).
<?php
function sqlite_query_multi ($db, $query) {
//
// sqlite_query() rewritten to support concatenated SQL statements.
//
// This method works around the sqlite_query() deficiency by splitting
// queries into two parts; the first part comprising all the statements
// except the last one (executed via sqlite_exec) and then the last
// statement (executed via sqlite_query).
//
// This allows the result of the last SELECT statement in a multi-statement
// query to be accessed regardless of the SQL statements that came before it.
// It also allows execution of arbitrary multi-statement programs regardless
// whether the result is needed, subject to the following constraint:
//
// This method requires that the last statement in a multi-statement query
// is a valid "stand-alone" SQL statement. If it is not (eg, the "END;" of
// a multi-statement construct such as CREATE TRIGGER) append an additional
// ";" (ie, a NULL statement). Normally this should not be needed because
// almost all the multi-statement constructs I can think of should have a
// stand-alone statement following them (ie, to makes use of the construct).
//
$pattern = '/^(.*;)(.*;)/s';
if ( preg_match($pattern,$query,$match) ) {
// multi-statement query
sqlite_exec($db,$match[1]);
$result = sqlite_query($db,$match[2]);
} else {
// single-statement query
$result = sqlite_query($db,$query);
}
return (@$result);
}
?>
----
Server IP: 117.55.229.1
Probable Submitter: 210.23.157.230
----
Manual Page -- http://www.php.net/manual/en/function.sqlite-query.php
Edit -- https://master.php.net/note/edit/92714
Del: integrated -- https://master.php.net/note/delete/92714/integrated
Del: useless -- https://master.php.net/note/delete/92714/useless
Del: bad code -- https://master.php.net/note/delete/92714/bad+code
Del: spam -- https://master.php.net/note/delete/92714/spam
Del: non-english -- https://master.php.net/note/delete/92714/non-english
Del: in docs -- https://master.php.net/note/delete/92714/in+docs
Del: other reasons-- https://master.php.net/note/delete/92714
Reject -- https://master.php.net/note/reject/92714
Search -- https://master.php.net/manage/user-notes.php