Professional Web Applications Themes

#25503 [Bgs]: SQLite_query() returning NULL, not FALSE - PHP Development

ID: 25503 User updated by: o_gangrel at hotmail dot com Reported By: o_gangrel at hotmail dot com Status: Bogus Bug Type: SQLite related Operating System: Windows 98 PHP Version: 5.0.0b1 (beta1) New Comment: From the [url]http://www.php.net/sqlite_query[/url] "Regardless of the query type, this function will return FALSE if the query failed." Return NULL is a wrong return value. Previous Comments: ------------------------------------------------------------------------ [2003-09-11 20:07:04] [email]wezphp.net[/email] Thank you for taking the time to write to us, but this is not a bug. Please double-check the doentation available at [url]http://www.php.net/manual/[/url] and the instructions on how to report a bug at [url]http://bugs.php.net/how-to-report.php[/url] You gave a ...

  1. #1

    Default #25503 [Bgs]: SQLite_query() returning NULL, not FALSE

    ID: 25503
    User updated by: o_gangrel at hotmail dot com
    Reported By: o_gangrel at hotmail dot com
    Status: Bogus
    Bug Type: SQLite related
    Operating System: Windows 98
    PHP Version: 5.0.0b1 (beta1)
    New Comment:

    From the [url]http://www.php.net/sqlite_query[/url]

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

    Return NULL is a wrong return value.


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-09-11 20:07:04] [email]wezphp.net[/email]

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the doentation available at
    [url]http://www.php.net/manual/[/url] and the instructions on how to report
    a bug at [url]http://bugs.php.net/how-to-report.php[/url]

    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 19:08:39] 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


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=25503&edit=1[/url]
    o_gangrel at hotmail dot com Guest

  2. #2

    Default #25503 [Bgs]: SQLite_query() returning NULL, not FALSE

    ID: 25503
    Updated by: [email]wezphp.net[/email]
    Reported By: o_gangrel at hotmail dot com
    Status: Bogus
    Bug Type: SQLite related
    Operating System: Windows 98
    PHP Version: 5.0.0b1 (beta1)
    New Comment:

    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 :)


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-09-11 20:32:12] o_gangrel at hotmail dot com

    From the [url]http://www.php.net/sqlite_query[/url]

    "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:07:04] [email]wezphp.net[/email]

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the doentation available at
    [url]http://www.php.net/manual/[/url] and the instructions on how to report
    a bug at [url]http://bugs.php.net/how-to-report.php[/url]

    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 19:08:39] 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


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=25503&edit=1[/url]
    wez@php.net Guest

Similar Threads

  1. #25503 [Opn->Bgs]: SQLite_query() returning NULL, not FALSE
    By wez@php.net in forum PHP Development
    Replies: 0
    Last Post: September 12th, 12:08 AM
  2. #25503 [NEW]: SQLite_query() returning NULL, not FALSE
    By o_gangrel at hotmail dot com in forum PHP Development
    Replies: 0
    Last Post: September 11th, 11:10 PM
  3. set_error_handler() returning false
    By Andy Hassall in forum PHP Development
    Replies: 1
    Last Post: July 25th, 01:56 AM
  4. OnEditCommand - .FindControl Returning Null
    By George Durzi in forum ASP.NET General
    Replies: 0
    Last Post: July 14th, 09:54 PM
  5. OnEditCommand - FindControl returning Null
    By George Durzi in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: July 14th, 09:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139