Re: [sqlite] accessing multiple databases

2012-02-29 Thread Simon Slavin

On 29 Feb 2012, at 6:07pm, Rob Richardson  wrote:

> IIRC, there's a connection string option that will choose between creating an 
> empty database and throwing an exception if you try opening a database that 
> doesn't exist.

Arguments to sqlite3_open_v2():

http://sqlite.org/c3ref/open.html

But further down the same page you'll see a 'mode' string which can be used the 
same way.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] accessing multiple databases

2012-02-29 Thread Rob Richardson
IIRC, there's a connection string option that will choose between creating an 
empty database and throwing an exception if you try opening a database that 
doesn't exist.  Perhaps if that option is set to throw an exception, then the 
ATTACH command would fail.  Or not.  

RobR
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] accessing multiple databases

2012-02-29 Thread jwzumwalt

As a follow up...

Sqlite finds the first db fine useing a relative path but the ATTACH command
needs the FULL PATH. Ugg!



Are you sure it's really opening the DB you think it's opening?  I think
SQLite will create the file if it's not there, and you'll have nothing in
it.

Perhaps you should try it and specify the complete path, just in case.  I
don't know if the PDO object looks for the file before opening it.

Marc

-- 
View this message in context: 
http://old.nabble.com/accessing-multiple-databases-tp33410065p33415881.html
Sent from the SQLite mailing list archive at Nabble.com.

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] accessing multiple databases

2012-02-28 Thread Marc L. Allen
Are you sure it's really opening the DB you think it's opening?  I think SQLite 
will create the file if it's not there, and you'll have nothing in it.

Perhaps you should try it and specify the complete path, just in case.  I don't 
know if the PDO object looks for the file before opening it.

Marc

> -Original Message-
> From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> boun...@sqlite.org] On Behalf Of jwzumwalt
> Sent: Tuesday, February 28, 2012 5:05 PM
> To: sqlite-users@sqlite.org
> Subject: [sqlite] accessing multiple databases
> 
> 
> I'm attempting to do a test accessing multiple databases with the code
> listed below.
> It errors on the 2nd db select statement and says that the "table does
> not exist".
> I am using 2 identical db for the test with different names. Any idea
> what I am doing wrong? - Thanks, Jan Zumwalt
> 
>echo '';
>   echo 'Use Multiple Database';
> 
>   $db = new PDO("sqlite:db1.sqlite3"); // db connect
>   $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
> //enhanced error msg
> 
> # query using simple SELECT
>   $result = $db->query("SELECT * FROM 'sales'");
>   $rows   = $result->fetchall(PDO::FETCH_ASSOC);
>   echo ""; print_r($rows); echo "";
> 
> # attach second database
>   $result = $db->query("ATTACH database 'db2.sqlite3' AS lastyear");
> 
> # query 2nd database
>   $result = $db->query('SELECT * FROM lastyear.sales'); // <== ERRORS
>   $rows   = $result->fetchall(PDO::FETCH_ASSOC);
>   echo ""; print_r($rows); echo ""; ?>
> --
> View this message in context: http://old.nabble.com/accessing-multiple-
> databases-tp33410065p33410065.html
> Sent from the SQLite mailing list archive at Nabble.com.
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] accessing multiple databases

2012-02-28 Thread jwzumwalt

I'm attempting to do a test accessing multiple databases with the code listed
below.
It errors on the 2nd db select statement and says that the "table does not
exist".
I am using 2 identical db for the test with different names. Any idea what I
am
doing wrong? - Thanks, Jan Zumwalt

';
  echo 'Use Multiple Database';
 
  $db = new PDO("sqlite:db1.sqlite3"); // db connect
  $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //enhanced
error msg
 
# query using simple SELECT
  $result = $db->query("SELECT * FROM 'sales'");
  $rows   = $result->fetchall(PDO::FETCH_ASSOC);
  echo ""; print_r($rows); echo "";

# attach second database
  $result = $db->query("ATTACH database 'db2.sqlite3' AS lastyear");
 
# query 2nd database
  $result = $db->query('SELECT * FROM lastyear.sales'); // <== ERRORS
  $rows   = $result->fetchall(PDO::FETCH_ASSOC);
  echo ""; print_r($rows); echo ""; 
?>
-- 
View this message in context: 
http://old.nabble.com/accessing-multiple-databases-tp33410065p33410065.html
Sent from the SQLite mailing list archive at Nabble.com.

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users