From fac7fe86128718b6339a9a5942b99cbf5855a185 Mon Sep 17 00:00:00 2001 From: Yuanle Song Date: Fri, 5 Apr 2019 16:59:20 +0800 Subject: [PATCH] v0.3.1 extra select is required to do dedup. otherwise the group by command only applies to the 2nd SQL. --- meson.build | 2 +- test-sql.sh | 2 +- zero-pinyin-service.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 69212eb..2e0e49c 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ # -*- mode: conf -*- project('zero-pinyin-service', ['c', 'cpp'], - version: '0.3.0', + version: '0.3.1', license: 'GPL', default_options: [ 'warning_level=2', diff --git a/test-sql.sh b/test-sql.sh index eb487a3..7a616ce 100755 --- a/test-sql.sh +++ b/test-sql.sh @@ -2,5 +2,5 @@ sqlite3 -echo \ -cmd '.headers on' \ -cmd '.prompt "zerodb> " " ...> "' \ - -cmd 'attach "/usr/share/pyzy/db/open-phrase.db" as "maindb"; attach "/home/sylecn/.cache/ibus/pinyin/user-1.0.db" as "userdb";' \ + -cmd 'attach "/home/sylecn/.cache/ibus/pinyin/main.db" as "maindb"; attach "/home/sylecn/.cache/ibus/pinyin/user-1.0.db" as "userdb";' \ ':memory:' diff --git a/zero-pinyin-service.c b/zero-pinyin-service.c index 1754532..2cfdab5 100644 --- a/zero-pinyin-service.c +++ b/zero-pinyin-service.c @@ -88,7 +88,7 @@ build_sql_for_n_pinyin (GList* pylist, /* always keep one space after current term */ GString* sql = NULL; gchar* where_clause = NULL; - sql = g_string_new (NULL); + sql = g_string_new ("SELECT MAX(user_freq), phrase, MAX(freq) FROM ("); g_string_append_printf ( sql, "SELECT 0 AS user_freq, phrase, freq FROM " "maindb.py_phrase_%u WHERE ", n - 1); @@ -101,7 +101,7 @@ build_sql_for_n_pinyin (GList* pylist, sql, "SELECT user_freq, phrase, freq FROM " "userdb.py_phrase_%u WHERE ", n - 1); sql = g_string_append (sql, where_clause); - sql = g_string_append (sql, "GROUP BY phrase ORDER BY user_freq DESC, freq DESC "); + sql = g_string_append (sql, ") GROUP BY phrase ORDER BY user_freq DESC, freq DESC "); g_string_append_printf (sql, "LIMIT %u;", limit); char* result = sql->str; g_free (where_clause); -- GitLab