[Xfce4-commits] <midori:master> Get rid of exec_query_with_try_create_table

Christian Dywan noreply at xfce.org
Sun Feb 19 20:24:01 CET 2012


Updating branch refs/heads/master
         to c6b15ff4dcac0b432f081d45e8eb8d85354fc239 (commit)
       from 63d7df5a0acef44b593cd90ee509a1be6cc7e3d4 (commit)

commit c6b15ff4dcac0b432f081d45e8eb8d85354fc239
Author: Alexander Butenko <a.butenka at gmail.com>
Date:   Sun Feb 19 20:08:16 2012 +0100

    Get rid of exec_query_with_try_create_table

 katze/katze-http-cookies-sqlite.c |   46 +++++++-----------------------------
 1 files changed, 9 insertions(+), 37 deletions(-)

diff --git a/katze/katze-http-cookies-sqlite.c b/katze/katze-http-cookies-sqlite.c
index 4066407..d97dc32 100644
--- a/katze/katze-http-cookies-sqlite.c
+++ b/katze/katze-http-cookies-sqlite.c
@@ -27,7 +27,7 @@
 #include <sqlite3.h>
 
 #define QUERY_ALL "SELECT id, name, value, host, path, expiry, lastAccessed, isSecure, isHttpOnly FROM moz_cookies;"
-#define CREATE_TABLE "CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHttpOnly INTEGER)"
+#define CREATE_TABLE "CREATE TABLE IF NOT EXISTS moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHttpOnly INTEGER)"
 #define QUERY_INSERT "INSERT INTO moz_cookies VALUES(NULL, %Q, %Q, %Q, %Q, %d, NULL, %d, %d);"
 #define QUERY_DELETE "DELETE FROM moz_cookies WHERE name=%Q AND host=%Q;"
 
@@ -71,39 +71,6 @@ G_DEFINE_TYPE_WITH_CODE (KatzeHttpCookiesSqlite, katze_http_cookies_sqlite, G_TY
    Copyright (C) 2009 Collabora Ltd.
    Mostly copied from libSoup 2.30, coding style retained */
 
-static void
-try_create_table (sqlite3 *db)
-{
-    char *error = NULL;
-
-    if (sqlite3_exec (db, CREATE_TABLE, NULL, NULL, &error)) {
-        g_warning ("Failed to execute query: %s", error);
-        sqlite3_free (error);
-    }
-}
-
-static void
-exec_query_with_try_create_table (sqlite3*    db,
-                                  const char* sql)
-{
-    char *error = NULL;
-    gboolean try_create = TRUE;
-
-try_exec:
-    if (sqlite3_exec (db, sql, NULL, NULL, &error)) {
-        if (try_create) {
-            try_create = FALSE;
-            try_create_table (db);
-            sqlite3_free (error);
-            error = NULL;
-            goto try_exec;
-        } else {
-            g_warning ("Failed to execute query: %s", error);
-            sqlite3_free (error);
-        }
-    }
-}
-
 /* Follows sqlite3 convention; returns TRUE on error */
 static gboolean
 katze_http_cookies_sqlite_open_db (KatzeHttpCookiesSqlite* http_cookies)
@@ -116,6 +83,11 @@ katze_http_cookies_sqlite_open_db (KatzeHttpCookiesSqlite* http_cookies)
         return TRUE;
     }
 
+    if (sqlite3_exec (http_cookies->db, CREATE_TABLE, NULL, NULL, &error)) {
+        g_warning ("Failed to execute query: %s", error);
+        sqlite3_free (error);
+    }
+
     if (sqlite3_exec (http_cookies->db, "PRAGMA secure_delete = 1;",
         NULL, NULL, &error)) {
         g_warning ("Failed to execute query: %s", error);
@@ -173,7 +145,7 @@ katze_http_cookies_sqlite_load (KatzeHttpCookiesSqlite* http_cookies)
         {
             /* Cookie expired, remove it from database */
             query = sqlite3_mprintf (QUERY_DELETE, name, host);
-            exec_query_with_try_create_table (http_cookies->db, query);
+            sqlite3_exec (http_cookies->db, QUERY_DELETE, NULL, NULL, NULL);
             sqlite3_free (query);
             result = sqlite3_step (stmt);
             continue;
@@ -241,7 +213,7 @@ katze_http_cookies_sqlite_jar_changed_cb (SoupCookieJar*    jar,
         query = sqlite3_mprintf (QUERY_DELETE,
                      old_cookie->name,
                      old_cookie->domain);
-        exec_query_with_try_create_table (http_cookies->db, query);
+        sqlite3_exec (http_cookies->db, query, NULL, NULL, NULL);
         sqlite3_free (query);
     }
 
@@ -255,7 +227,7 @@ katze_http_cookies_sqlite_jar_changed_cb (SoupCookieJar*    jar,
                      expires,
                      new_cookie->secure,
                      new_cookie->http_only);
-        exec_query_with_try_create_table (http_cookies->db, query);
+        sqlite3_exec (http_cookies->db, query, NULL, NULL, NULL);
         sqlite3_free (query);
     }
 }


More information about the Xfce4-commits mailing list