[epiphany] ephy-history-service: trim query strings to avoid reaching sqlite limit



commit 936e759536705b22218afaceff4d81d348021402
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Fri Apr 27 16:11:00 2012 +0300

    ephy-history-service: trim query strings to avoid reaching sqlite limit
    
    Sqlite limits the length of a LIKE pattern to 50000 bytes, therefore
    we need to make sure that longer strings are not used as queries.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674848

 lib/ephy-sqlite-statement.c                     |   12 ++++++++++++
 lib/ephy-sqlite-statement.h                     |    2 ++
 lib/ephy-sqlite.h                               |    2 ++
 lib/history/ephy-history-service-hosts-table.c  |    2 +-
 lib/history/ephy-history-service-urls-table.c   |    2 +-
 lib/history/ephy-history-service-visits-table.c |    2 +-
 6 files changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/lib/ephy-sqlite-statement.c b/lib/ephy-sqlite-statement.c
index f95518a..6ff2454 100644
--- a/lib/ephy-sqlite-statement.c
+++ b/lib/ephy-sqlite-statement.c
@@ -267,3 +267,15 @@ ephy_sqlite_statement_get_column_as_blob (EphySQLiteStatement *self, int column)
 {
   return sqlite3_column_blob (self->priv->prepared_statement, column);
 }
+
+char *
+ephy_sqlite_create_match_pattern (const char *match_string)
+{
+  char *string, *pattern;
+
+  string = g_strndup (match_string, EPHY_SQLITE_LIMIT_LIKE_PATTERN_LENGTH - 2);
+  pattern = g_strdup_printf ("%%%s%%", string);
+  g_free (string);
+
+  return pattern;
+}
diff --git a/lib/ephy-sqlite-statement.h b/lib/ephy-sqlite-statement.h
index c88947f..abf6ac4 100644
--- a/lib/ephy-sqlite-statement.h
+++ b/lib/ephy-sqlite-statement.h
@@ -68,6 +68,8 @@ double                   ephy_sqlite_statement_get_column_as_double  (EphySQLite
 const char*              ephy_sqlite_statement_get_column_as_string  (EphySQLiteStatement *statement, int column);
 const void*              ephy_sqlite_statement_get_column_as_blob    (EphySQLiteStatement *statement, int column);
 
+char*                    ephy_sqlite_create_match_pattern (const char *match_string);
+
 G_END_DECLS
 
 #endif /* EPHY_SQLITE_STATEMENT_H */
diff --git a/lib/ephy-sqlite.h b/lib/ephy-sqlite.h
index dc151ec..e2ad297 100644
--- a/lib/ephy-sqlite.h
+++ b/lib/ephy-sqlite.h
@@ -29,6 +29,8 @@ typedef enum {
   EPHY_SQLITE_COLUMN_TYPE_BLOB
 } EphySQLiteColumnType;
 
+#define EPHY_SQLITE_LIMIT_LIKE_PATTERN_LENGTH 50000
+
 G_END_DECLS
 
 #endif /* EPHY_SQLITE_H */
diff --git a/lib/history/ephy-history-service-hosts-table.c b/lib/history/ephy-history-service-hosts-table.c
index 9312d73..eb64e46 100644
--- a/lib/history/ephy-history-service-hosts-table.c
+++ b/lib/history/ephy-history-service-hosts-table.c
@@ -318,7 +318,7 @@ ephy_history_service_find_host_rows (EphyHistoryService *self, EphyHistoryQuery
   }
   for (substring = query->substring_list; substring != NULL; substring = substring->next) {
     int j = 4;
-    char *string = g_strdup_printf ("%%%s%%", (char*)substring->data);
+    char *string = ephy_sqlite_create_match_pattern ((char*)substring->data);
     while (j--)
       if (ephy_sqlite_statement_bind_string (statement, i++, string, &error) == FALSE) {
         g_error ("Could not build hosts table query statement: %s", error->message);
diff --git a/lib/history/ephy-history-service-urls-table.c b/lib/history/ephy-history-service-urls-table.c
index 9bcb5f6..1e0a9c1 100644
--- a/lib/history/ephy-history-service-urls-table.c
+++ b/lib/history/ephy-history-service-urls-table.c
@@ -311,7 +311,7 @@ ephy_history_service_find_url_rows (EphyHistoryService *self, EphyHistoryQuery *
     }
   }
   for (substring = query->substring_list; substring != NULL; substring = substring->next) {
-    char *string = g_strdup_printf ("%%%s%%", (char*)substring->data);
+    char *string = ephy_sqlite_create_match_pattern ((char*)substring->data);
     if (ephy_sqlite_statement_bind_string (statement, i++, string, &error) == FALSE) {
       g_error ("Could not build urls table query statement: %s", error->message);
       g_error_free (error);
diff --git a/lib/history/ephy-history-service-visits-table.c b/lib/history/ephy-history-service-visits-table.c
index 5b88b0f..d480175 100644
--- a/lib/history/ephy-history-service-visits-table.c
+++ b/lib/history/ephy-history-service-visits-table.c
@@ -182,7 +182,7 @@ ephy_history_service_find_visit_rows (EphyHistoryService *self, EphyHistoryQuery
     }
   }
   for (substring = query->substring_list; substring != NULL; substring = substring->next) {
-    char *string = g_strdup_printf ("%%%s%%", (char*)substring->data);
+    char *string = ephy_sqlite_create_match_pattern ((char*)substring->data);
     if (ephy_sqlite_statement_bind_string (statement, i++, string, &error) == FALSE) {
       g_error ("Could not build urls table query statement: %s", error->message);
       g_error_free (error);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]