Re: [sqlite] What is the recommended way to write to views?

2019-02-22 Thread Rocky Ji
Thanks for the suggestion on `UNIQUE`, I should have done it. Based on this new schema I wrote (pseudoSQL code): create table dummy (d text); -- empty table to let us use case...when...then syntax create table variables( variable_id integer primary key autoincrement, name text not null,

Re: [sqlite] What is the recommended way to write to views?

2019-02-22 Thread Rocky Ji
Wow, that's some clever use. I tried doing it all in one go using a `vars` table (name, value, timestamp) and a `dummy` (empty table to enable access to case syntax) table, made a mess of case...when...then... only to realize that a then-expr can't contain insert clause. I guess I'll implement

Re: [sqlite] What is the recommended way to write to views?

2019-02-20 Thread Keith Medcalf
The insert sequence does not work in all cases. This fixes one particular problem of duplicate or changed linkage to parent in Alpha:Charlie ... create trigger trg_summary_insert instead of insert on summary for each row begin insert or ignore into Alpha (a_attribute) values

Re: [sqlite] What is the recommended way to write to views?

2019-02-20 Thread Keith Medcalf
Or as a trigger of course: create table Alpha ( id integer primary key, a_attribute text not null collate nocase unique ); create table Beta ( id integer primary key, b_attribute text not null collate nocase unique ); create table Charlie ( id integer primary

Re: [sqlite] What is the recommended way to write to views?

2019-02-20 Thread Keith Medcalf
Your constraints are logically inconsistent and incompletely specified. >Alpha has-many Beta,and >Beta has-many Alpha >Alpha has-many Charlie, while >Charlie has one Alpha Implies that: Alpha:Beta is N:M and Beta:Alpha is N:M. Fine. but you did not say whether the instant relationships are

Re: [sqlite] What is the recommended way to write to views?

2019-02-20 Thread David Raymond
Well, you _can_ with this specific simplified schema, but it's a little sketchy and most likely will not scale. So if at all possible this sort of thing should be done from the controlling program rather than by a trigger. Also as mentioned, if the a/b/c _attribute fields aren't unique in the

Re: [sqlite] What is the recommended way to write to views?

2019-02-20 Thread Simon Slavin
On 20 Feb 2019, at 11:14am, Rocky Ji wrote: > create view summary > as >select >a.a_attribute, >b.b_attribute, >c.c_attribute >from >m2mAlphaBeta m >inner join Alpha a on a.a_id = m.FK_a_id >inner join Beta b on b.b_id = m.FK_b_id >

Re: [sqlite] What is the recommended way to write to views?

2019-02-20 Thread Andy Bennett
Hi, Like how do I get ROWID of the "just inserted" record in A to insert into C properly. I am thinking "should I make transactions, but we don't have variables"... and going round-and-round without solution. Is last_insert_rowid what you're looking for?

[sqlite] What is the recommended way to write to views?

2019-02-20 Thread Rocky Ji
Hi everyone, I know the simple answer to be `instead of insert ...`. But consider a situation where: Alpha has-many Beta,and Beta has-many Alpha Alpha has-many Charlie, while Charlie has one Alpha So if my SQL looks like: -- PRAGMA fk ON; create table Alpha ( a_id integer primary key