From 44361901d3a0b3063c01d05899bdbfa26a8e5361 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 6 Dec 2019 16:18:42 -0500 Subject: Fold networks into contexts --- database.h | 6 +----- unscoop.c | 18 +++++------------- 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); -- cgit 1.4.1 in/dash?id=f3a3627f24d6644bbac13786621359561b5910a0&showmsg=1&follow=1'>dash/ChangeLog.O (unfollow)
Commit message (Collapse)Author
2021-01-31Add The Rosewater RedemptionJune McEnroe
Remembering how to read 2021.
2021-01-29Use int when checking for EOFJune McEnroe
2021-01-28Move gpl.c and agpl.c templates out of etcJune McEnroe
2021-01-27Set para and sect for mdocJune McEnroe
Copied from the OpenBSD defaults.
2021-01-26Use First state to match keyword at beginning of lineJune McEnroe
Otherwise keywords at the beginnings of lines with preceeding whitespace are not matched.
2021-01-25Install vi on Linux and nvi on macOSJune McEnroe
2021-01-25Use vi and lessJune McEnroe
I haven't used neovim in a couple weeks by now, so I may as well commit this.
2021-01-20Use mtags for sh in source-filterJune McEnroe
2021-01-20Generate tags for sh files in mtagsJune McEnroe
Only matches functions declared at the beginnings of lines, but I'm fine with that.
2021-01-20Add messy sh lexerJune McEnroe
Surprisingly seems to work for everything I looked at in my repos.
2021-01-20Add all target to git.causal.agency MakefileJune McEnroe
2021-01-20Remove Lua supportJune McEnroe
Lua support is unused and the dlsym fwrite/write hacks horrify me. Clean it up.
2021-01-20Fix tests for diff spansJune McEnroe
2021-01-20Avoid matching ':' in make tagsJune McEnroe
Otherwise a :: rule includes one of the ':'s in the tag name.
2021-01-19Prefer tag matches not preceded by [[:alnum:]]June McEnroe
Otherwise the "id" in "void" matches for "void id".
2021-01-19Escape \ and / in mtags search patternsJune McEnroe
2021-01-20Use mtags in source-filterJune McEnroe
2021-01-19Add mtags to generate tags for make and mdocJune McEnroe
2021-01-19Map tags to IDs using only [[:alnum:]-._]June McEnroe
2021-01-19Don't use a pager if reading standard inputJune McEnroe
2021-01-19Support BSD make syntax and match *.amJune McEnroe
These don't really go together, but...
2021-01-19Match tab following escaped newline in make assignmentsJune McEnroe
Otherwise it ends up going into Shell state.
2021-01-18Allow matching lexers using first input lineJune McEnroe