[Xfce4-commits] <midori:master> Switch to prepared statements when adding/ updating history
Christian Dywan
noreply at xfce.org
Thu Feb 4 22:10:01 CET 2010
Updating branch refs/heads/master
to db334e2921678ebe078c70401cd1b6161cbc4fdc (commit)
from c2e828269673b10a105c5cad2020f4b67cd201e9 (commit)
commit db334e2921678ebe078c70401cd1b6161cbc4fdc
Author: Alexander Butenko <a.butenka at gmail.com>
Date: Thu Feb 4 19:13:16 2010 +0100
Switch to prepared statements when adding/ updating history
midori/midori-browser.c | 55 +++++++++++++++++++++++++---------------------
1 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 864bc13..7a9d5c9 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -465,22 +465,24 @@ midori_browser_update_history_title (MidoriBrowser* browser,
{
#if HAVE_SQLITE
sqlite3* db;
- gchar* sqlcmd;
- char* errmsg = NULL;
+ static sqlite3_stmt* stmt = NULL;
db = g_object_get_data (G_OBJECT (browser->history), "db");
- sqlcmd = sqlite3_mprintf ("UPDATE history SET title='%q' WHERE"
- " uri = '%q' and date=%d",
- katze_item_get_name (item),
- katze_item_get_uri (item),
- katze_item_get_added (item));
-
- if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
+ if (!stmt)
{
- g_printerr (_("Failed to insert new history item: %s\n"), errmsg);
- sqlite3_free (errmsg);
+ const gchar* sqlcmd;
+
+ sqlcmd = "UPDATE history SET title=? WHERE uri = ? and date=?";
+ sqlite3_prepare_v2 (db, sqlcmd, -1, &stmt, NULL);
}
- sqlite3_free (sqlcmd);
+ sqlite3_bind_text (stmt, 1, katze_item_get_name (item), -1, 0);
+ sqlite3_bind_text (stmt, 2, katze_item_get_uri (item), -1, 0);
+ sqlite3_bind_int64 (stmt, 3, katze_item_get_added (item));
+
+ if (sqlite3_step (stmt) != SQLITE_DONE)
+ g_printerr (_("Failed to update title: %s\n"), sqlite3_errmsg (db));
+ sqlite3_reset (stmt);
+ sqlite3_clear_bindings (stmt);
#endif
}
@@ -5597,8 +5599,7 @@ midori_browser_new_history_item (MidoriBrowser* browser,
gint64 day;
#if HAVE_SQLITE
sqlite3* db;
- gchar* sqlcmd;
- char* errmsg = NULL;
+ static sqlite3_stmt* stmt = NULL;
#endif
now = time (NULL);
@@ -5607,19 +5608,23 @@ midori_browser_new_history_item (MidoriBrowser* browser,
#if HAVE_SQLITE
db = g_object_get_data (G_OBJECT (browser->history), "db");
- sqlcmd = sqlite3_mprintf ("INSERT INTO history (uri, title, date, day) VALUES "
- "('%q', '%q', %d, %d)",
- katze_item_get_uri (*item),
- katze_item_get_name (*item),
- katze_item_get_added (*item),
- day);
-
- if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
+ if (!stmt)
{
- g_printerr (_("Failed to insert new history item: %s\n"), errmsg);
- sqlite3_free (errmsg);
+ const gchar* sqlcmd;
+
+ sqlcmd = "INSERT INTO history (uri, title, date, day) VALUES (?,?,?,?)";
+ sqlite3_prepare_v2 (db, sqlcmd, -1, &stmt, NULL);
}
- sqlite3_free (sqlcmd);
+ sqlite3_bind_text (stmt, 1, katze_item_get_uri (*item), -1, 0);
+ sqlite3_bind_text (stmt, 2, katze_item_get_name (*item), -1, 0);
+ sqlite3_bind_int64 (stmt, 3, katze_item_get_added (*item));
+ sqlite3_bind_int64 (stmt, 4, day);
+
+ if (sqlite3_step (stmt) != SQLITE_DONE)
+ g_printerr (_("Failed to insert new history item: %s\n"),
+ sqlite3_errmsg (db));
+ sqlite3_reset (stmt);
+ sqlite3_clear_bindings (stmt);
#endif
}
More information about the Xfce4-commits
mailing list