Hello Richard !

I just found that the changes I made to sqlite3 to allow reference objects on attached databases does not work properly, it does work when the tables/views from more than one database are not equal but if they are equal even with qualification it seems to always try to find first in the "main" database without qualification or always discard qualification.

Where in the view execution path the table/view qualifiers could be discarded ?

Cheers !

Example:

====

.open db1.db
create table if not exists t(id integer, count1 integer, count2 integer);
insert or ignore into t values(1, 5, 5);
create table if not exists t1(id integer, count1 integer, count2 integer);
insert or ignore into t1 values(1, 1, 1);

.open db2.db
create table if not exists t(id integer, count1 integer, count2 integer);
insert or ignore into t values(1, 10, 10);
create table if not exists t2(id integer, count1 integer, count2 integer);
insert or ignore into t2 values(1, 2, 2);

.open db1.db
pragma use_attached_dbs=ON;
attach database 'db2.db' as db2;

select a.count1+b.count1, a.count2+b.count2
from t1 a
join t2 b on a.id=b.id;
--3|3

create view if not exists v1 as
select a.count1+b.count1, a.count2+b.count2
from t1 a
join t2 b on a.id=b.id;

select * from v1;
--3|3

select a.count1+b.count1, a.count2+b.count2
from t a
join db2.t b on a.id=b.id;
--15|15

create view if not exists v2 as
select a.count1+b.count1, a.count2+b.count2
from t a
join db2.t b on a.id=b.id;

select * from v2;
--10|10
====

On 04/10/16 17:30, Richard Hipp wrote:
On 10/4/16, Domingo Alvarez Duarte <mingo...@gmail.com> wrote:
The problem is I didn't found yet the point where I should intercept the
"openDatabase" where I plan to check if there is a table named for
example "use_attached_dbs" and then attach the databases on that table
and then reread the schema to make the views work.

The place to do so probably is at the end of "openDatabase", can someone
shed some light here ?

The sqlite3Init() routine found at
https://www.sqlite.org/src/artifact/b1140c3d0cf59bc8?ln=355


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to