On Tue, Sep 15, 2015 at 12:43 PM, Simon Slavin <slavins at bigfraud.org> wrote:
> > On 15 Sep 2015, at 5:01pm, Nicolas J?ger <jagernicolas at legtux.org> wrote: > > > I also would like to know how can I check if an entry exists,(or not > > exists), in a table. Like, > > > > IF (exists) THEN (doSomething) END > > Here's another alternative to add to those in Ryan's excellent post. With > your schema > > > create table Tags > > ( > > id integer primary key, > > name text collate nocase unique, > > count integer not null > > ); > > You can do things like > > SELECT total(count) FROM Tags WHERE id=234; > SELECT total(count) FROM Tags WHERE name='biology'; > > You will definitely get a reply from this since 'total()' returns 0.0 even > if there are no rows which satisfy the WHERE clause. > Might not work. I'd use count() sqlite> create table x(a int); sqlite> select total(a) from x; 0.0 sqlite> select count(a) from x; 0 sqlite> insert into x values(1); sqlite> insert into x values(-1); sqlite> select count(a) from x; 2 sqlite> select total(a) from x; 0.0 sqlite> > > So you can submit this query and know that there is definitely an answer > which is definitely a floating point value. And then in your programming > language you can do your equivalent of > > IF (theanswer) > 0.0 THEN (doSomething) END > > Warning: although SQLite also has the function sum() it does not produce > the same result to total() when no lines satisfy the WHERE clause. Sorting > out the possibilities is more complicated. > > Simon. > -- Schrodinger's backup: The condition of any backup is unknown until a restore is attempted. Yoda of Borg, we are. Futile, resistance is, yes. Assimilated, you will be. He's about as useful as a wax frying pan. 10 to the 12th power microphones = 1 Megaphone Maranatha! <>< John McKown