diff options
Diffstat (limited to 'src/npassd/db.c')
| -rw-r--r-- | src/npassd/db.c | 29 | 
1 files changed, 18 insertions, 11 deletions
| diff --git a/src/npassd/db.c b/src/npassd/db.c index 5afa45e..f55bede 100644 --- a/src/npassd/db.c +++ b/src/npassd/db.c @@ -7,17 +7,23 @@  #define DB_NAME "secret_service.sqlite" -const char sql_stmt_init[] = "CREATE TABLE IF NOT EXISTS store (" -			     "	storeid INTEGER PRIMARY KEY," -			     "	name TEXT NOT NULL UNIQUE" -			     ");" -			     "CREATE TABLE IF NOT EXISTS lookup (" -			     "	key TEXT NOT NULL," -			     "	value TEXT NOT NULL," -			     "	storeid INTEGER," -			     "	UNIQUE(storeid, key)," -			     "	FOREIGN KEY(storeid) REFERENCES store(storeid)" -			     ");"; +const char sql_stmt_init[] = +	"CREATE TABLE IF NOT EXISTS collections (" +	"	id INTEGER PRIMARY KEY," +	"	root TEXT NOT NULL UNIQUE," +	"	label TEXT UNIQUE," +	"	alias TEXT UNIQUE," +	"	created INTEGER," +	"	modified INTEGER" +	");" +	"CREATE TABLE IF NOT EXISTS collection_attrs (" +	"	id INTEGER PRIMARY KEY," +	"	key TEXT NOT NULL," +	"	value TEXT NOT NULL," +	"	collectionid INTEGER," +	"	UNIQUE(key, collectionid)" +	"	FOREIGN KEY(collectionid) REFERENCES collections(id)" +	");";  int db_init(const char *store_path, struct sqlite3 **db)  { @@ -41,6 +47,7 @@ int db_init(const char *store_path, struct sqlite3 **db)  	ret = sqlite3_exec(*db, sql_stmt_init, NULL, NULL, NULL);  	if (ret != SQLITE_OK) { +		sqlite3_close(*db);  		print_err("Failed to create tables: %s", sqlite3_errmsg(*db));  		return -EPERM;  	} | 
