php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28246 sqlite_query("ATTACH...") returns FALSE even when it succeeds
Submitted: 2004-05-01 21:59 UTC Modified: 2004-07-10 15:18 UTC
From: derrell dot lipman at unwireduniverse dot com Assigned:
Status: Closed Package: SQLite related
PHP Version: 5.0.0RC2 OS: Linux 2.4
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: derrell dot lipman at unwireduniverse dot com
New email:
PHP Version: OS:

 

 [2004-05-01 21:59 UTC] derrell dot lipman at unwireduniverse dot com
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-10 15:18 UTC] wez@php.net
This bug has been fixed in CVS.

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 18:01:29 2024 UTC