gboolean
ephy_sqlite_connection_commit_transaction (EphySQLiteConnection *self, GError **error)
{
  if (self->mode == EPHY_SQLITE_CONNECTION_MODE_READ_ONLY)
    return TRUE;
  return ephy_sqlite_connection_execute (self, "COMMIT", error);
}
gboolean
ephy_sqlite_connection_begin_transaction (EphySQLiteConnection *self, GError **error)
{
  if (self->mode == EPHY_SQLITE_CONNECTION_MODE_READ_ONLY)
    return TRUE;
  return ephy_sqlite_connection_execute (self, "BEGIN TRANSACTION", error);
}
gboolean
ephy_history_service_initialize_hosts_table (EphyHistoryService *self)
{
  EphyHistoryServicePrivate *priv = EPHY_HISTORY_SERVICE (self)->priv;
  GError *error = NULL;

  if (ephy_sqlite_connection_table_exists (priv->history_database, "hosts")) {
    return TRUE;
  }
  ephy_sqlite_connection_execute (priv->history_database,
    "CREATE TABLE hosts ("
    "id INTEGER PRIMARY KEY,"
    "url LONGVARCAR,"
    "title LONGVARCAR,"
    "visit_count INTEGER DEFAULT 0 NOT NULL,"
    "zoom_level REAL DEFAULT 1.0)", &error);

  if (error) {
    g_error("Could not create hosts table: %s", error->message);
    g_error_free (error);
    return FALSE;
  }
  ephy_history_service_schedule_commit (self);
  return TRUE;
}
gboolean
ephy_history_service_initialize_urls_table (EphyHistoryService *self)
{
  GError *error = NULL;

  if (ephy_sqlite_connection_table_exists (self->history_database, "visits")) {
    return TRUE;
  }
  ephy_sqlite_connection_execute (self->history_database,
                                  "CREATE TABLE urls ("
                                  "id INTEGER PRIMARY KEY,"
                                  "host INTEGER NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,"
                                  "url LONGVARCAR,"
                                  "title LONGVARCAR,"
                                  "sync_id LONGVARCAR,"
                                  "visit_count INTEGER DEFAULT 0 NOT NULL,"
                                  "typed_count INTEGER DEFAULT 0 NOT NULL,"
                                  "last_visit_time INTEGER,"
                                  "thumbnail_update_time INTEGER DEFAULT 0," /* this column is legacy, unused */
                                  "hidden_from_overview INTEGER DEFAULT 0)", &error);

  if (error) {
    g_warning ("Could not create urls table: %s", error->message);
    g_error_free (error);
    return FALSE;
  }
  return TRUE;
}
void
ephy_sqlite_connection_enable_foreign_keys (EphySQLiteConnection *self)
{
  GError *error = NULL;

  g_assert (EPHY_IS_SQLITE_CONNECTION (self));

  ephy_sqlite_connection_execute (self, "PRAGMA foreign_keys=ON", &error);
  if (error) {
    g_warning ("Failed to enable foreign keys pragma: %s", error->message);
    g_error_free (error);
  }
}
static void
ephy_history_service_clear_all (EphyHistoryService *self)
{
  EphyHistoryServicePrivate *priv = EPHY_HISTORY_SERVICE (self)->priv;
  GError *error = NULL;

  if (NULL == priv->history_database)
    return;

  ephy_sqlite_connection_execute (priv->history_database,
                                  "DELETE FROM hosts;", &error);
  if (error) {
    g_error ("Couldn't clear history database: %s", error->message);
    g_error_free(error);
  }
}
static void
ephy_history_service_enable_foreign_keys (EphyHistoryService *self)
{
  EphyHistoryServicePrivate *priv = EPHY_HISTORY_SERVICE (self)->priv;
  GError *error = NULL;

  if (NULL == priv->history_database)
    return;

  ephy_sqlite_connection_execute (priv->history_database,
                                  "PRAGMA foreign_keys = ON", &error);

  if (error) {
    g_error ("Could not enable foreign keys pragma: %s", error->message);
    g_error_free (error);
  }
}
void
ephy_history_service_delete_orphan_hosts (EphyHistoryService *self)
{
  GError *error = NULL;

  g_assert (self->history_thread == g_thread_self ());
  g_assert (self->history_database != NULL);

  /* Where a JOIN would give us all hosts with urls associated, a LEFT
     JOIN also gives us those hosts for which there are no urls.  By
     means of urls.host == NULL we filter out anything else and
     retrieve only the ids of the hosts without associated urls. Then,
     we delete all these rows from the hosts table. */
  ephy_sqlite_connection_execute (self->history_database,
                                  "DELETE FROM hosts WHERE hosts.id IN "
                                  "  (SELECT hosts.id FROM hosts LEFT JOIN urls "
                                  "    ON hosts.id = urls.host WHERE urls.host is NULL);",
                                  &error);
  if (error) {
    g_warning ("Couldn't remove orphan hosts from database: %s", error->message);
    g_error_free (error);
  }
}
gboolean
ephy_history_service_initialize_hosts_table (EphyHistoryService *self)
{
  GError *error = NULL;

  if (ephy_sqlite_connection_table_exists (self->history_database, "hosts")) {
    return TRUE;
  }
  ephy_sqlite_connection_execute (self->history_database,
                                  "CREATE TABLE hosts ("
                                  "id INTEGER PRIMARY KEY,"
                                  "url LONGVARCAR,"
                                  "title LONGVARCAR,"
                                  "visit_count INTEGER DEFAULT 0 NOT NULL,"
                                  "zoom_level REAL DEFAULT 0.0)", &error);

  if (error) {
    g_warning ("Could not create hosts table: %s", error->message);
    g_error_free (error);
    return FALSE;
  }
  return TRUE;
}
gboolean
ephy_history_service_initialize_visits_table (EphyHistoryService *self)
{
  GError *error = NULL;

  if (ephy_sqlite_connection_table_exists (self->history_database, "visits"))
    return TRUE;

  ephy_sqlite_connection_execute (self->history_database,
                                  "CREATE TABLE visits ("
                                  "id INTEGER PRIMARY KEY,"
                                  "url INTEGER NOT NULL REFERENCES urls(id) ON DELETE CASCADE,"
                                  "visit_time INTEGER NOT NULL,"
                                  "visit_type INTEGER NOT NULL,"
                                  "referring_visit INTEGER)", &error);

  if (error) {
    g_warning ("Could not create visits table: %s", error->message);
    g_error_free (error);
    return FALSE;
  }

  return TRUE;
}
Beispiel #11
0
gboolean
ephy_sqlite_connection_commit_transaction (EphySQLiteConnection *self, GError **error)
{
  return ephy_sqlite_connection_execute (self, "COMMIT", error);
}
Beispiel #12
0
gboolean
ephy_sqlite_connection_rollback_transaction (EphySQLiteConnection *self, GError **error)
{
  return ephy_sqlite_connection_execute (self, "ROLLBACK", error);
}
Beispiel #13
0
gboolean
ephy_sqlite_connection_begin_transaction (EphySQLiteConnection *self, GError **error)
{
  return ephy_sqlite_connection_execute (self, "BEGIN TRANSACTION", error);
}