I am testing an application written in PHP, so all sqlite access is 
through PDO.

In a particular situation I am scanning a directory for filenames with a 
'.db' extension and attaching to each database in turn to do something 
with it. I am using a prepared statement ($astmt) to do the attach, 
binding it with each filename that matches the database type and 
executing the prepared statement.

Thus ...

$db=new PDO('sqlite:'.DATA_DIR.'football.ini');
...

        $astmt = $db->prepare("ATTACH ? AS comp");
        $fns = scandir(DATA_DIR);
        foreach ($fns as $filename) {
                if(filetype(DATA_DIR.$filename) == 'file') {
                        $split = splitFIlename($filename);
                        if($split[1] == 'db') {
                        // found a database file
                                $astmt->bindValue(1,DATA_DIR.$filename);
                                $astmt->execute(); //ATTACH
...
                                $astmt->closeCursor();
                                $db->exec("DETACH comp;");
                        }
                }
        }



The first time round the loop seems to work fine, but the second time 
round the loop, the $astmt->execute(); trying to attach to the file 
fails with SQLITE_SCHEMA

Reading the docs, it appears SQLITE_SCHEMA means I need to recompile the 
prepared statement each time round the loop.

WHY?

(I tried it and it works - but is inefficient).

PS = I suppose it may be a php bug that it is using the v1 version of 
prepare





-- 
Alan Chandler
http://www.chandlerfamily.org.uk
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to