Consider this piece of code:

<?php
    $db = new SQLiteDatabase("./crm.db", 0666, &$error)
        or die("Failed: $error");

    $create_query = "
CREATE TABLE document (
    id INTEGER PRIMARY KEY,
    title,
    intro,
    body
);

REATE TABLE dictionary (
    id INTEGER PRIMARY KEY,
    word
);

CREATE TABLE lookup (
    document_id INTEGER,
    word_id     INTEGER,
    position    INTEGER
);

REATE UNIQUE INDEX word ON dictionary(word);
";

    $ret = $db->query($create_query);
    if ($db->lastError() != SQLITE_OK) {
        echo $db->lastError();
    }
?>

As you can see there are two typoes (REATE instead of CREATE) so
obviously I expected to get a result value other than SQLITE_OK back,
but that didn't happen, and no php warnings either. Then I fixed those
two typoes, ran the script and to my surprise it only showed the *first*
table in the database. Making a typo in the first create table statement
did throw a warning (unexpected when $ret = is used) and the return
value was set to SQLITE_ERROR.

After some investigation I found that if I removed the "$ret = " before
the query() call, then all queries are run just fine, and throw also a
warning when I put back in the typoes.

I would have expected something else though:
1. Without the "$ret = " it should throw a PHP warning for each broken
   query. (That's current what it's doing).
2. With the "$ret = " it should NOT throw any warnings, and set the
   $db->lastError() value accordingly whether there were errors or not.

In the code I do see that there is a check for if the return value is
used, so this behavior is possible and definitely wanted IMO. The
current behavior is just wrong and uninituitive.


regards,
Derick

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to