summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--database.h6
-rw-r--r--unscoop.c18
2 files changed, 6 insertions, 18 deletions
diff --git a/database.h b/database.h
index eec6cb6..485791b 100644
--- a/database.h
+++ b/database.h
@@ -150,13 +150,9 @@ static inline int dbVersion(sqlite3 *db) {
 
 static const char *InitSQL = {
 	"BEGIN TRANSACTION;"
-	"CREATE TABLE networks ("
-		"network INTEGER PRIMARY KEY,"
-		"name TEXT NOT NULL UNIQUE"
-	");"
 	"CREATE TABLE contexts ("
 		"context INTEGER PRIMARY KEY,"
-		"network INTEGER NOT NULL REFERENCES networks,"
+		"network TEXT NOT NULL,"
 		"name TEXT NOT NULL,"
 		"query BOOLEAN NOT NULL,"
 		"UNIQUE (network, name)"
diff --git a/unscoop.c b/unscoop.c
index 8017f35..fa3a5a2 100644
--- a/unscoop.c
+++ b/unscoop.c
@@ -233,21 +233,14 @@ int main(int argc, char *argv[]) {
 		errx(EX_SOFTWARE, "regcomp: %s: %s", buf, matcher->pattern);
 	}
 
-	sqlite3_stmt *insertNetwork = dbPrepare(
-		db, 0, "INSERT OR IGNORE INTO networks (name) VALUES ($network);"
-	);
-	dbBindText(insertNetwork, 1, network, -1);
-	dbStep(insertNetwork);
-	sqlite3_finalize(insertNetwork);
-
 	sqlite3_stmt *insertContext = dbPrepare(
 		db, 0,
 		"INSERT OR IGNORE INTO contexts (network, name, query)"
-		"SELECT network, $context, $query FROM networks WHERE name = $network;"
+		"VALUES ($network, $context, $query);"
 	);
-	dbBindText(insertContext, 1, context, -1);
-	dbBindInt(insertContext, 2, context[0] != '#' && context[0] != '&');
-	dbBindText(insertContext, 3, network, -1);
+	dbBindText(insertContext, 1, network, -1);
+	dbBindText(insertContext, 2, context, -1);
+	dbBindInt(insertContext, 3, context[0] != '#' && context[0] != '&');
 	dbStep(insertContext);
 	sqlite3_finalize(insertContext);
 
@@ -255,8 +248,7 @@ int main(int argc, char *argv[]) {
 	sqlite3_stmt *selectContext = dbPrepare(
 		db, 0,
 		"SELECT context FROM contexts"
-		" JOIN networks USING (network)"
-		" WHERE networks.name = $network AND contexts.name = $context;"
+		" WHERE network = $network AND name = $context;"
 	);
 	dbBindText(selectContext, 1, network, -1);
 	dbBindText(selectContext, 2, context, -1);