diff options
author | Shaun McCance <shaunm@gnome.org> | 2011-02-11 15:44:54 -0500 |
---|---|---|
committer | Shaun McCance <shaunm@gnome.org> | 2011-02-11 15:44:54 -0500 |
commit | c6b056db59bf38683543442b2601a20b32bf8301 (patch) | |
tree | 206b4cdff2756b4bfeb220b84325247e91ef92db /libyelp/yelp-sqlite-storage.c | |
parent | 4fcf2b3d0139bf78a32574068fd566da8027203d (diff) | |
download | yelp-c6b056db59bf38683543442b2601a20b32bf8301.tar.gz |
Store and retrieve root title in storage for search results
Diffstat (limited to 'libyelp/yelp-sqlite-storage.c')
-rw-r--r-- | libyelp/yelp-sqlite-storage.c | 88 |
1 files changed, 78 insertions, 10 deletions
diff --git a/libyelp/yelp-sqlite-storage.c b/libyelp/yelp-sqlite-storage.c index 57ad1884..f2e6619f 100644 --- a/libyelp/yelp-sqlite-storage.c +++ b/libyelp/yelp-sqlite-storage.c @@ -40,16 +40,21 @@ static void yelp_sqlite_storage_set_property (GObject *obj const GValue *value, GParamSpec *pspec); -static void yelp_sqlite_storage_update (YelpStorage *storage, - const gchar *doc_uri, - const gchar *full_uri, - const gchar *title, - const gchar *desc, - const gchar *icon, - const gchar *text); -static GVariant * yelp_sqlite_storage_search (YelpStorage *storage, - const gchar *doc_uri, - const gchar *text); +static void yelp_sqlite_storage_update (YelpStorage *storage, + const gchar *doc_uri, + const gchar *full_uri, + const gchar *title, + const gchar *desc, + const gchar *icon, + const gchar *text); +static GVariant * yelp_sqlite_storage_search (YelpStorage *storage, + const gchar *doc_uri, + const gchar *text); +static gchar * yelp_sqlite_storage_get_root_title (YelpStorage *storage, + const gchar *doc_uri); +static void yelp_sqlite_storage_set_root_title (YelpStorage *storage, + const gchar *doc_uri, + const gchar *title); typedef struct _YelpSqliteStoragePrivate YelpSqliteStoragePrivate; struct _YelpSqliteStoragePrivate { @@ -115,7 +120,14 @@ yelp_sqlite_storage_constructed (GObject *object) -1, &stmt, NULL); if (status != SQLITE_OK) return; + sqlite3_step (stmt); + sqlite3_finalize (stmt); + status = sqlite3_prepare_v2 (priv->db, + "create table titles (doc_uri text, lang text, title text);", + -1, &stmt, NULL); + if (status != SQLITE_OK) + return; sqlite3_step (stmt); sqlite3_finalize (stmt); } @@ -147,6 +159,8 @@ yelp_sqlite_storage_iface_init (YelpStorageInterface *iface) { iface->update = yelp_sqlite_storage_update; iface->search = yelp_sqlite_storage_search; + iface->get_root_title = yelp_sqlite_storage_get_root_title; + iface->set_root_title = yelp_sqlite_storage_set_root_title; } YelpStorage * @@ -274,3 +288,57 @@ yelp_sqlite_storage_search (YelpStorage *storage, return ret; } + +static gchar * +yelp_sqlite_storage_get_root_title (YelpStorage *storage, + const gchar *doc_uri) +{ + gchar *ret = NULL; + sqlite3_stmt *stmt = NULL; + YelpSqliteStoragePrivate *priv = GET_PRIV (storage); + + g_mutex_lock (priv->mutex); + + sqlite3_prepare_v2 (priv->db, + "select title from titles where doc_uri = ? and lang = ?;", + -1, &stmt, NULL); + sqlite3_bind_text (stmt, 1, doc_uri, -1, SQLITE_TRANSIENT); + sqlite3_bind_text (stmt, 2, g_get_language_names()[0], -1, SQLITE_STATIC); + if (sqlite3_step (stmt) == SQLITE_ROW) + ret = g_strdup (sqlite3_column_text (stmt, 0)); + sqlite3_finalize (stmt); + + g_mutex_unlock (priv->mutex); + return ret; +} + +static void +yelp_sqlite_storage_set_root_title (YelpStorage *storage, + const gchar *doc_uri, + const gchar *title) +{ + sqlite3_stmt *stmt = NULL; + YelpSqliteStoragePrivate *priv = GET_PRIV (storage); + + g_mutex_lock (priv->mutex); + + sqlite3_prepare_v2 (priv->db, + "delete from titles where doc_uri = ? and lang = ?;", + -1, &stmt, NULL); + sqlite3_bind_text (stmt, 1, doc_uri, -1, SQLITE_TRANSIENT); + sqlite3_bind_text (stmt, 2, g_get_language_names()[0], -1, SQLITE_STATIC); + sqlite3_step (stmt); + sqlite3_finalize (stmt); + + sqlite3_prepare_v2 (priv->db, + "insert into titles (doc_uri, lang, title)" + " values (?, ?, ?);", + -1, &stmt, NULL); + sqlite3_bind_text (stmt, 1, doc_uri, -1, SQLITE_TRANSIENT); + sqlite3_bind_text (stmt, 2, g_get_language_names()[0], -1, SQLITE_STATIC); + sqlite3_bind_text (stmt, 3, title, -1, SQLITE_TRANSIENT); + sqlite3_step (stmt); + sqlite3_finalize (stmt); + + g_mutex_unlock (priv->mutex); +} |