php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53466 sqlite3 columnType() returns SQLITE3_NULL when not in fetch loop
Submitted: 2010-12-03 18:28 UTC Modified: 2011-01-06 01:11 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: danielc at analysisandsolutions dot com Assigned: scottmac (profile)
Status: Closed Package: SQLite related
PHP Version: 5.3SVN-2010-12-03 (SVN) OS: linux
Private report: No CVE-ID: None
 [2010-12-03 18:28 UTC] danielc at analysisandsolutions dot com
Description:
------------
The SQLite3Result::columnType() method returns SQLITE3_NULL (5) if not looping over results.  This is done because the data type is unknown.  But this leads to confusion, because SQLITE3_NULL is a legitimate answer in some cases when inside the loop.  It would be clearer if PHP returned NULL or FALSE instead.


Test script:
---------------
$db = new SQLite3(':memory:');

$db->exec('CREATE TABLE test (whatever INTEGER)');
$db->exec('INSERT INTO test (whatever) VALUES (1)');

$result = $db->query('SELECT * FROM test');
while ($row = $result->fetchArray(SQLITE3_NUM)) {
    var_dump($result->columnType(0));  // int(1)  [SQLITE3_INTEGER]
}

// Seems returning null or false is more appropriate.
var_dump($result->columnType(0));  // int(5)  [SQLITE3_NULL]

$result->finalize();
$db->close();

echo "Done\n";


Expected result:
----------------
int(1)
bool(false)
Done


Actual result:
--------------
int(1)
int(5)
Done


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-06 01:09 UTC] scottmac@php.net
Automatic comment from SVN on behalf of scottmac
Revision: http://svn.php.net/viewvc/?view=revision&revision=307143
Log: Implemented FR #53466 (SQLite3Result::columnType() should return false after all of the rows have been fetched).
 [2011-01-06 01:11 UTC] scottmac@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: scottmac
 [2011-01-06 01:11 UTC] scottmac@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC