Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do inserts into sqlite views work?

I have a database schema which is identical in files 1.sqlitedb through n.sqlitedb. I use a view to 'merge' all of the databases. My question is: when i insert into the view, into which database does the data get inserted into? Is there any way to control which gets the data? The way that i need to split the data depends on the data itself. Essentially, i use the first letter of a field to determine the file that it gets inserted into. Any help would be appreciated. Thanks!

like image 812
chacham15 Avatar asked Apr 14 '11 09:04

chacham15


2 Answers

Writing to views is NOT supported for SQLite like it is with other dbs.

http://www.sqlite.org/omitted.html

In order to achieve similar functionality, one must create triggers to do the necessary work.

like image 56
chacham15 Avatar answered Oct 05 '22 06:10

chacham15


We need to implement instead of trigger on the view (VIEW_NAME) . So when insert/update happens view . we can insert update underlying object (TABLE_NAME) in the trigger body.

CREATE TRIGGER trigger_name instead of INSERT on VIEW_NAME BEGIN insert into TABLE_NAME ( col1 ,col2 ) values ( :new.col1, :new.col2); END;

like image 33
Tanmay Patil Avatar answered Oct 05 '22 06:10

Tanmay Patil