static EphyHistoryPageVisit * create_page_visit_from_statement (EphySQLiteStatement *statement) { EphyHistoryPageVisit *visit = ephy_history_page_visit_new (NULL, ephy_sqlite_statement_get_column_as_int64 (statement, 1), ephy_sqlite_statement_get_column_as_int (statement, 2)); visit->url->id = ephy_sqlite_statement_get_column_as_int (statement, 0); return visit; }
static EphyHistoryHost * create_host_from_statement (EphySQLiteStatement *statement) { EphyHistoryHost *host = ephy_history_host_new (ephy_sqlite_statement_get_column_as_string (statement, 1), ephy_sqlite_statement_get_column_as_string (statement, 2), ephy_sqlite_statement_get_column_as_int (statement, 3), ephy_sqlite_statement_get_column_as_double (statement, 4)); host->id = ephy_sqlite_statement_get_column_as_int (statement, 0); return host; }
gboolean ephy_sqlite_connection_table_exists (EphySQLiteConnection *self, const char *table_name) { GError *error = NULL; gboolean table_exists = FALSE; EphySQLiteStatement *statement = ephy_sqlite_connection_create_statement (self, "SELECT COUNT(type) FROM sqlite_master WHERE type='table' and name=?", &error); if (error) { g_warning ("Could not detect table existence: %s", error->message); g_error_free (error); return FALSE; } ephy_sqlite_statement_bind_string (statement, 0, table_name, &error); if (error) { g_object_unref (statement); g_warning ("Could not detect table existence: %s", error->message); g_error_free (error); return FALSE; } ephy_sqlite_statement_step (statement, &error); if (error) { g_object_unref (statement); g_warning ("Could not detect table existence: %s", error->message); g_error_free (error); return FALSE; } table_exists = ephy_sqlite_statement_get_column_as_int (statement, 0); g_object_unref (statement); return table_exists; }
static EphyHistoryURL * create_url_from_statement (EphySQLiteStatement *statement) { EphyHistoryURL *url = ephy_history_url_new (ephy_sqlite_statement_get_column_as_string (statement, 1), ephy_sqlite_statement_get_column_as_string (statement, 2), ephy_sqlite_statement_get_column_as_int (statement, 3), ephy_sqlite_statement_get_column_as_int (statement, 4), ephy_sqlite_statement_get_column_as_int64 (statement, 5)); url->id = ephy_sqlite_statement_get_column_as_int (statement, 0); url->host = ephy_history_host_new (NULL, NULL, 0, 0.0); url->hidden = ephy_sqlite_statement_get_column_as_int (statement, 6); url->host->id = ephy_sqlite_statement_get_column_as_int (statement, 7); url->sync_id = g_strdup (ephy_sqlite_statement_get_column_as_string (statement, 8)); return url; }
EphyHistoryHost * ephy_history_service_get_host_row (EphyHistoryService *self, const gchar *host_string, EphyHistoryHost *host) { EphySQLiteStatement *statement = NULL; GError *error = NULL; g_assert (self->history_thread == g_thread_self ()); g_assert (self->history_database != NULL); if (host_string == NULL && host != NULL) host_string = host->url; g_assert (host_string || (host != NULL && host->id != -1)); if (host != NULL && host->id != -1) { statement = ephy_sqlite_connection_create_statement (self->history_database, "SELECT id, url, title, visit_count, zoom_level FROM hosts " "WHERE id=?", &error); } else { statement = ephy_sqlite_connection_create_statement (self->history_database, "SELECT id, url, title, visit_count, zoom_level FROM hosts " "WHERE url=?", &error); } if (error) { g_warning ("Could not build hosts query statement: %s", error->message); g_error_free (error); return NULL; } if (host != NULL && host->id != -1) ephy_sqlite_statement_bind_int (statement, 0, host->id, &error); else ephy_sqlite_statement_bind_string (statement, 0, host_string, &error); if (error) { g_warning ("Could not build hosts table query statement: %s", error->message); g_error_free (error); g_object_unref (statement); return NULL; } if (ephy_sqlite_statement_step (statement, &error) == FALSE) { if (error) g_error_free (error); g_object_unref (statement); return NULL; } if (host == NULL) { host = ephy_history_host_new (NULL, NULL, 0, 0.0); } else { if (host->url) g_free (host->url); if (host->title) g_free (host->title); } host->id = ephy_sqlite_statement_get_column_as_int (statement, 0); host->url = g_strdup (ephy_sqlite_statement_get_column_as_string (statement, 1)); host->title = g_strdup (ephy_sqlite_statement_get_column_as_string (statement, 2)); host->visit_count = ephy_sqlite_statement_get_column_as_int (statement, 3); host->zoom_level = ephy_sqlite_statement_get_column_as_double (statement, 4); g_object_unref (statement); return host; }
int ephy_sqlite_statement_get_column_as_boolean (EphySQLiteStatement *self, int column) { return ephy_sqlite_statement_get_column_as_int (self, column); }
EphyHistoryURL * ephy_history_service_get_url_row (EphyHistoryService *self, const char *url_string, EphyHistoryURL *url) { EphySQLiteStatement *statement = NULL; GError *error = NULL; g_assert (self->history_thread == g_thread_self ()); g_assert (self->history_database != NULL); if (url_string == NULL && url != NULL) url_string = url->url; g_assert (url_string || (url != NULL && url->id != -1)); if (url != NULL && url->id != -1) { statement = ephy_sqlite_connection_create_statement (self->history_database, "SELECT id, url, title, visit_count, typed_count, last_visit_time, hidden_from_overview, sync_id FROM urls " "WHERE id=?", &error); } else { statement = ephy_sqlite_connection_create_statement (self->history_database, "SELECT id, url, title, visit_count, typed_count, last_visit_time, hidden_from_overview, sync_id FROM urls " "WHERE url=?", &error); } if (error) { g_warning ("Could not build urls table query statement: %s", error->message); g_error_free (error); return NULL; } if (url != NULL && url->id != -1) { ephy_sqlite_statement_bind_int (statement, 0, url->id, &error); } else { ephy_sqlite_statement_bind_string (statement, 0, url_string, &error); } if (error) { g_warning ("Could not build urls table query statement: %s", error->message); g_error_free (error); g_object_unref (statement); return NULL; } if (ephy_sqlite_statement_step (statement, &error) == FALSE) { g_object_unref (statement); return NULL; } if (url == NULL) { url = ephy_history_url_new (NULL, NULL, 0, 0, 0); } url->id = ephy_sqlite_statement_get_column_as_int (statement, 0); /* Only get the URL and page title if we don't know it yet, as the version in the history could be outdated. */ if (url->url == NULL) url->url = g_strdup (ephy_sqlite_statement_get_column_as_string (statement, 1)); if (url->title == NULL) url->title = g_strdup (ephy_sqlite_statement_get_column_as_string (statement, 2)); url->visit_count = ephy_sqlite_statement_get_column_as_int (statement, 3), url->typed_count = ephy_sqlite_statement_get_column_as_int (statement, 4), url->last_visit_time = ephy_sqlite_statement_get_column_as_int64 (statement, 5); url->hidden = ephy_sqlite_statement_get_column_as_int (statement, 6); url->sync_id = g_strdup (ephy_sqlite_statement_get_column_as_string (statement, 7)); g_object_unref (statement); return url; }