Doc #52997 [Opn->Csd]: SQLite3::querySingle omits return type information

From: Date: Wed, 13 Oct 2010 09:08:48 +0000
Subject: Doc #52997 [Opn->Csd]: SQLite3::querySingle omits return type information
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5198@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52997&edit=1 ID: 52997 Updated by: aharvey@php.net Reported by: miguelpontes at gmail dot com Summary: SQLite3::querySingle omits return type information -Status: Open +Status: Closed Type: Documentation Problem Package: Documentation problem PHP Version: 5.3.3 -Assigned To: +Assigned To: aharvey Block user comment: N New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2010-10-13 11:08:45] aharvey@php.net Automatic comment from SVN on behalf of aharvey Revision: http://svn.php.net/viewvc/?view=revision&revision=304366 Log: Fix doc bug #52997 (SQLite3::querySingle omits return type information). ------------------------------------------------------------------------ [2010-10-06 01:47:34] miguelpontes at gmail dot com 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52997&edit=1

« previous php.doc.bugs (#5198) next »