[sqlite] Attach via prepared statement / Multiple attach

2015-03-11 Thread Fabian Stumpf
Thanks for your reply, James!

> Parameterized queries  in general let you replace any data value
> (and not metadata).  For instance, you can replace a column value, but
> not a column name.  Using that as a guide, I'm a little suprised that
>
> ATTACH DATABASE ? AS ?
>
> works, because the second parameter is metadata.

To be honest, by 'works' I currently mean "The statement prepares
alright, I can bind both parameters and execute it without ever being
presented with anything but SQLITE_OK or SQLITE_DONE". I have not
actually yet checked if the database was attached using the bound
name, so it might just have been attached with a name of '?'. I'll
check ASAP.

As for my second question (Attaching the same file multiple times
under different names), I found the answer in the documentation for
the DETACH statement[0].
It might be useful to also include that fact in the ATTACH documentation :)

Thanks for your time!

[0] https://www.sqlite.org/lang_detach.html

--
FJS


[sqlite] Attach via prepared statement / Multiple attach

2015-03-11 Thread James K. Lowden
On Mon, 9 Mar 2015 17:59:33 +0100
Fabian Stumpf  wrote:

> I am currently using
> > ATTACH DATABASE ? AS ?;
> to dynamically attach databases to a connection.
> In some cases, the same physical database file is attached under
> different names.
> 
> This all seems to work perfectly, although the documentation for the
> ATTACH statement specifies the name as type "database-name", not as
> "expr", so I'm not sure if specifying a bind parameter is "legal". 

I don't have a definitive answer for you, just a way to think about
it.  

Parameterized queries  in general let you replace any data value
(and not metadata).  For instance, you can replace a column value, but
not a column name.  Using that as a guide, I'm a little suprised that 

ATTACH DATABASE ? AS ?

works, because the second parameter is metadata.  But I would expect

ATTACH DATABASE ? AS db;

to be valid.  

So IMO you've been lucky so far, but the filename is fair game for
parameterization.  

--jkl



[sqlite] Attach via prepared statement / Multiple attach

2015-03-09 Thread Fabian Stumpf
Hi everyone,

I am currently using
> ATTACH DATABASE ? AS ?;
to dynamically attach databases to a connection.
In some cases, the same physical database file is attached under
different names.

This all seems to work perfectly, although the documentation for the
ATTACH statement specifies the name as type "database-name", not as
"expr", so I'm not sure if specifying a bind parameter is "legal". So
I'd like to know if this behaviour is intended and thus safe to rely
on (and will it continue to be supported)? Same goes for attaching the
same file multiple times (under different names).

--
Kind regards,
FJS