From:             derrell dot lipman at unwireduniverse dot com
Operating system: Linux 2.4
PHP version:      5.0.0RC2
PHP Bug Type:     SQLite related
Bug description:  sqlite_query("ATTACH...") returns FALSE even when it succeeds

Description:
------------
There is no way to ascertain whether an ATTACH command worked, as
sqlite_query() and sqlite_unbuffered_query() return FALSE whether it
worked or not.

HERE'S THE FIX:
Upgrading the embedded sqlite from 2.8.11 to 2.8.13 solved this problem
(as well as correcting the 2.8.11 bugs, of course).


Reproduce code:
---------------
<?php
/*
 * We assume that /tmp/test1.db and /tmp/test2.db exist and have the
following
 * schema and data:
 *
 * test1.db:
 *   CREATE TABLE t1 (i INTEGER PRIMARY KEY, t TEXT);
 *   INSERT INTO t1 VALUES (23, 'hello');
 *
 * test2.db:
 *   CREATE TABLE t2 (j INTEGER PRIMARY KEY, t TEXT);
 *   INSERT INTO t2 VALUES (42, 'world');
 *
 */

if (($dbConn = sqlite_open("/tmp/test1.db", 0666)) === false)
{
    echo "open test1.db failed<p>";
    exit;
}

if (($dbRC =
     sqlite_query($dbConn, "ATTACH '/tmp/test2.db' AS test_db;")) ===
false)
{
    echo "This should have returned TRUE, but returned FALSE.  See, it can
get data from t2...<br>";

    if (! $dbRC = sqlite_query($dbConn, "SELECT j, t FROM t2;"))
    {
        echo "Could not retrieve data from t2<br>";
    }
    else
    {
        while ($row = @sqlite_fetch_array($dbRC, SQLITE_ASSOC))
        {
            echo "Got j = " . $row["j"] . ", t = " . $row["t"] . "<br>";
        }
    }
    exit;
}

echo "ATTACH returned what it should have (this doesn't happen)<br>";
exit;

?>


Expected result:
----------------
TRUE

Actual result:
--------------
FALSE

-- 
Edit bug report at http://bugs.php.net/?id=28246&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=28246&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=28246&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=28246&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=28246&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=28246&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=28246&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=28246&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=28246&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=28246&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=28246&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=28246&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=28246&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28246&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=28246&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=28246&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=28246&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28246&r=float

Reply via email to