php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25503 SQLite_query() returning NULL, not FALSE
Submitted: 2003-09-11 19:08 UTC Modified: 2003-09-11 20:45 UTC
From: o_gangrel at hotmail dot com Assigned:
Status: Not a bug Package: SQLite related
PHP Version: 5.0.0b1 (beta1) OS: Windows 98
Private report: No CVE-ID: None
 [2003-09-11 19:08 UTC] o_gangrel at hotmail dot com
Description:
------------
I am using the configuration Apache/2.0.43 (Win32) PHP/5.0.0b1 with PHP as a module of Apache.

When I make a query on a SQLite database with a not valid SQL query, the the sqlite_query() produces an Warning, that's ok. But when the script continues the SQLite_fetch_array() returns a NULL and it is expected to return a FALSE.
The Warning message produced by the SQLite_fetch_array() is right, but the return value is not expected.

I found solutions to not hapen this erro, but this is not expected.
And I'm sorry, I didn't tested the CVS version and other vertion of the Apache.

Reproduce code:
---------------
$query1  = "SELECT * FROM sqlite_master";
$query2  = "foobar";
$db_file = "test.db";

$sqlite_connection = sqlite_open($db_file, 0666, $sqlite_error);
if($sqlite_connection === false) {
    die($sqlite_error);
}

$result = sqlite_query($sqlite_connection, $query1);
echo var_dump(sqlite_fetch_array($result, SQLITE_BOTH))."\n";

$result = sqlite_query($sqlite_connection, $query2);
echo var_dump(sqlite_fetch_array($result, SQLITE_BOTH))."\n";

sqlite_close($sqlite_connection);

Expected result:
----------------
array(10) {
  [0]=>
  string(5) "table"
  ["type"]=>
  string(5) "table"
  [1]=>
  string(4) "test"
  ["name"]=>
  string(4) "test"
  [2]=>
  string(4) "test"
  ["tbl_name"]=>
  string(4) "test"
  [3]=>
  string(1) "3"
  ["rootpage"]=>
  string(1) "3"
  [4]=>
  string(24) "CREATE TABLE test (test)"
  ["sql"]=>
  string(24) "CREATE TABLE test (test)"
}

bool(false)

Actual result:
--------------
array(10) {
  [0]=>
  string(5) "table"
  ["type"]=>
  string(5) "table"
  [1]=>
  string(4) "test"
  ["name"]=>
  string(4) "test"
  [2]=>
  string(4) "test"
  ["tbl_name"]=>
  string(4) "test"
  [3]=>
  string(1) "3"
  ["rootpage"]=>
  string(1) "3"
  [4]=>
  string(24) "CREATE TABLE test (test)"
  ["sql"]=>
  string(24) "CREATE TABLE test (test)"
}


Warning: sqlite_query(): near "foobar": syntax error in D:\internet\pages\sqlite\bugscript.php on line 16


Warning: sqlite_fetch_array() expects parameter 1 to be resource, boolean given in D:\internet\pages\sqlite\bugscript.php on line 17

NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-11 20:07 UTC] wez@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You gave a function the wrong arguments; PHP will return NULL in this case.
So this is not a bug in PHP, but in your script for not checking error returns correctly.
 [2003-09-11 20:32 UTC] o_gangrel at hotmail dot com
From the http://www.php.net/sqlite_query

"Regardless of the query type, this function will return FALSE if the query failed."

Return NULL is a wrong return value.
 [2003-09-11 20:45 UTC] wez@php.net
The parameter type checking is performed before the query is executed; PHP always returns NULL in this case, as it does for a very large number of other functions.

Just fix your script to use !$sqlite_connection and get over it :)
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Nov 27 19:03:46 2022 UTC