1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  *  Copyright © 2011 Igalia S.L.
4  *
5  *  This file is part of Epiphany.
6  *
7  *  Epiphany is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  Epiphany is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with Epiphany.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #pragma once
22 
23 #include <glib-object.h>
24 #include "ephy-sqlite-statement.h"
25 
26 #include <sqlite3.h>
27 
28 G_BEGIN_DECLS
29 
30 #define EPHY_TYPE_SQLITE_CONNECTION (ephy_sqlite_connection_get_type ())
31 
32 G_DECLARE_FINAL_TYPE (EphySQLiteConnection, ephy_sqlite_connection, EPHY, SQLITE_CONNECTION, GObject)
33 
34 typedef enum {
35   EPHY_SQLITE_CONNECTION_MODE_MEMORY,
36   EPHY_SQLITE_CONNECTION_MODE_READWRITE
37 } EphySQLiteConnectionMode;
38 
39 EphySQLiteConnection *  ephy_sqlite_connection_new                     (EphySQLiteConnectionMode  mode, const char *database_path);
40 
41 gboolean                ephy_sqlite_connection_open                    (EphySQLiteConnection *self, GError **error);
42 void                    ephy_sqlite_connection_close                   (EphySQLiteConnection *self);
43 void                    ephy_sqlite_connection_delete_database         (EphySQLiteConnection *self);
44 
45 void                    ephy_sqlite_connection_get_error               (EphySQLiteConnection *self, GError **error);
46 
47 gboolean                ephy_sqlite_connection_execute                 (EphySQLiteConnection *self, const char *sql, GError **error);
48 EphySQLiteStatement *   ephy_sqlite_connection_create_statement        (EphySQLiteConnection *self, const char *sql, GError **error);
49 gint64                  ephy_sqlite_connection_get_last_insert_id      (EphySQLiteConnection *self);
50 void                    ephy_sqlite_connection_enable_foreign_keys     (EphySQLiteConnection *self);
51 
52 gboolean                ephy_sqlite_connection_begin_transaction       (EphySQLiteConnection *self, GError **error);
53 gboolean                ephy_sqlite_connection_commit_transaction      (EphySQLiteConnection *self, GError **error);
54 
55 gboolean                ephy_sqlite_connection_table_exists            (EphySQLiteConnection *self, const char *table_name);
56 
57 GQuark                  ephy_sqlite_error_quark                        (void);
58 
59 #define EPHY_SQLITE_ERROR ephy_sqlite_error_quark ()
60 
61 G_END_DECLS
62