|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-10-13 11:08 UTC] aharvey@php.net
[2010-10-13 11:08 UTC] aharvey@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: aharvey
[2010-10-13 11:08 UTC] aharvey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 10 10:00:02 2026 UTC |
Description: ------------ The PHP documentation for SQLite3::querySingle states querySingle will return the value of the first column for the first row/entire first row for the query or FALSE otherwise. In reality, if the query returns an empty set, either NULL (in case $entire_row = false) or an empty array is returned (in case $entire_row = true). This should be clarified, since one may infer the boolean FALSE is always returned if the value of the first column/entire first row cannot be returned for some reason. This is not true. FALSE is only returned in case there is an error executing the query. Test script: --------------- $db = new SQLite3('./test.sqlite', SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); $db->exec('CREATE TABLE IF NOT EXISTS test (test1 TEXT, test2 TEXT, PRIMARY KEY(test1))'); $row = $db->querySingle('SELECT * FROM test'); echo "SELECT * FROM test\n"; echo 'gettype($row) : ' . gettype($row) . "\n"; echo '$row === FALSE?: ' . ($row === FALSE ? 'YES' : 'NO') . "\n"; echo '$row === NULL? : ' . ($row === NULL ? 'YES' : 'NO') . "\n\n"; $row = $db->querySingle('SELECT * FROM test', true); echo "SELECT * FROM test (entire_row = true)\n"; echo 'gettype($row) : ' . gettype($row) . "\n"; echo '$row === FALSE?: ' . ($row === FALSE ? 'YES' : 'NO') . "\n"; echo '$row === NULL? : ' . ($row === NULL ? 'YES' : 'NO') . "\n"; echo 'empty($row) : ' . (empty($row) ? 'YES' : 'NO') . "\n\n"; $row = $db->querySingle('SELECT * FROM footestbar'); echo "SELECT * FROM footestbar\n"; echo 'gettype($row) : ' . gettype($row) . "\n"; echo '$row === FALSE?: ' . ($row === FALSE ? 'YES' : 'NO') . "\n"; echo '$row === NULL? : ' . ($row === NULL ? 'YES' : 'NO') . "\n\n"; $row = $db->querySingle('SEL ECT * from test'); echo "SE LECT * FROM test\n"; echo 'gettype($row) : ' . gettype($row) . "\n"; echo '$row === FALSE?: ' . ($row === FALSE ? 'YES' : 'NO') . "\n"; echo '$row === NULL? : ' . ($row === NULL ? 'YES' : 'NO') . "\n"; Expected result: ---------------- Under " Return Values", the documentation should state: "Returns the value of the first column of results or an array of the entire first row (if entire_row is TRUE) or FALSE on failure. If the query doesn't return a result, either NULL (if entire_row is FALSE) or an empty array (if otherwise) is returned." or similar, to match the result of the script above. Actual result: -------------- SELECT * FROM test gettype($row) : NULL SELECT * FROM test (entire_row = true) gettype($row) : array empty($row) : YES Warning: SQLite3::querySingle(): Unable to prepare statement: 1, no such table: footestbar in /Users/mpontes/test.php on line 19 SELECT * FROM footestbar gettype($row) : boolean $row === FALSE?: YES Warning: SQLite3::querySingle(): Unable to prepare statement: 1, near "SEL": syntax error in /Users/mpontes/test.php on line 25 SE LECT * FROM test gettype($row) : boolean