diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-05-08 14:15:26 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-05-08 14:15:26 +0200 |
commit | 94b6276d5cf43c4eef6a3cd05a2ec5e09d9987a0 (patch) | |
tree | 9142cadbbcfe8d2cfc30f0c4e46ded22e0e80136 | |
parent | 55bc1ebe8ca3425cdec4bf24b9908e120f6c7fca (diff) |
db: Added foreign keys and cascade on delete.
Following db-changes will most likely be incompatible with old db's.
-rw-r--r-- | db.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -21,7 +21,7 @@ static int db_create_tables() { ");" "create table wallpaper (" " id integer not null," - " dirid integer not null," + " dirid integer not null references directory (id) on delete cascade," " date integer not null," " filepath text not null," " size integer not null," @@ -31,13 +31,13 @@ static int db_create_tables() { ");" "create table tag (" " id integer not null," - " parent integer null," + " parent integer null references tag (id) on delete cascade," " name varchar(100) not null," " primary key (id)" ");" "create table walltags (" - " wallid integer not null," - " tagid integer not null," + " wallid integer not null references wallpaper (id)," + " tagid integer not null references tag (id)," " primary key (wallid, tagid)" ");", NULL, NULL, &errmsg); @@ -73,6 +73,8 @@ int db_open() { return 0; } + sqlite3_exec(db, "PRAGMA foreign_keys = ON;", NULL, NULL, NULL); + if(!datafound && !db_create_tables()) { db_close(); return 0; |