gboolean ephy_sqlite_statement_bind_blob (EphySQLiteStatement *self, int column, const void *value, int length, GError **error) { if (sqlite3_bind_blob (self->priv->prepared_statement, column + 1, value, length, SQLITE_TRANSIENT) != SQLITE_OK) { ephy_sqlite_connection_get_error (self->priv->connection, error); return FALSE; } return TRUE; }
gboolean ephy_sqlite_statement_step (EphySQLiteStatement *self, GError **error) { int error_code = sqlite3_step (self->priv->prepared_statement); if (error_code != SQLITE_OK && error_code != SQLITE_ROW && error_code != SQLITE_DONE) { ephy_sqlite_connection_get_error (self->priv->connection, error); } return error_code == SQLITE_ROW; }
gboolean ephy_sqlite_statement_bind_string (EphySQLiteStatement *self, int column, const char *value, GError **error) { if (sqlite3_bind_text (self->priv->prepared_statement, column + 1, value, -1, SQLITE_TRANSIENT) != SQLITE_OK) { ephy_sqlite_connection_get_error (self->priv->connection, error); return FALSE; } return TRUE; }
gboolean ephy_sqlite_statement_bind_double (EphySQLiteStatement *self, int column, double value, GError **error) { if (sqlite3_bind_double (self->priv->prepared_statement, column + 1, value) != SQLITE_OK) { ephy_sqlite_connection_get_error (self->priv->connection, error); return FALSE; } return TRUE; }
gboolean ephy_sqlite_statement_bind_null (EphySQLiteStatement *self, int column, GError **error) { if (sqlite3_bind_null (self->prepared_statement, column) != SQLITE_OK) { ephy_sqlite_connection_get_error (self->connection, error); return FALSE; } return TRUE; }
gboolean ephy_sqlite_connection_execute (EphySQLiteConnection *self, const char *sql, GError **error) { if (self->database == NULL) { set_error_from_string ("Connection not open.", error); return FALSE; } if (sqlite3_exec (self->database, sql, NULL, NULL, NULL) != SQLITE_OK) { ephy_sqlite_connection_get_error (self, error); return FALSE; } return TRUE; }
gboolean ephy_sqlite_connection_open (EphySQLiteConnection *self, const gchar *filename, GError **error) { if (self->database) { set_error_from_string ("Connection already open.", error); return FALSE; } if (sqlite3_open (filename, &self->database) != SQLITE_OK) { ephy_sqlite_connection_get_error (self, error); self->database = NULL; return FALSE; } return TRUE; }
EphySQLiteStatement * ephy_sqlite_connection_create_statement (EphySQLiteConnection *self, const char *sql, GError **error) { sqlite3_stmt *prepared_statement; if (self->database == NULL) { set_error_from_string ("Connection not open.", error); return NULL; } if (sqlite3_prepare_v2 (self->database, sql, -1, &prepared_statement, NULL) != SQLITE_OK) { ephy_sqlite_connection_get_error (self, error); return NULL; } return EPHY_SQLITE_STATEMENT (g_object_new (EPHY_TYPE_SQLITE_STATEMENT, "prepared-statement", prepared_statement, "connection", self, NULL)); }
gboolean ephy_sqlite_connection_open (EphySQLiteConnection *self, GError **error) { if (self->database) { set_error_from_string ("Connection already open.", error); return FALSE; } if (sqlite3_open_v2 (self->database_path, &self->database, self->mode == EPHY_SQLITE_CONNECTION_MODE_READ_ONLY ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) != SQLITE_OK) { ephy_sqlite_connection_get_error (self, error); self->database = NULL; return FALSE; } return TRUE; }