php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52997 SQLite3::querySingle omits return type information
Submitted: 2010-10-06 01:47 UTC Modified: 2010-10-13 11:08 UTC
From: miguelpontes at gmail dot com Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.3 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: miguelpontes at gmail dot com
New email:
PHP Version: OS:

 

 [2010-10-06 01:47 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-13 11:08 UTC] 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-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
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.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 07:00:01 2026 UTC