2
* Copyright (C) 2011 Jens Georg <mail@jensge.org>.
4
* Author: Jens Georg <mail@jensge.org>
6
* This file is part of Rygel.
8
* Rygel is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU Lesser General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* Rygel is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public License
19
* along with this program; if not, write to the Free Software Foundation,
20
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
internal class Rygel.MediaExport.SqliteWrapper : Object {
26
private Sqlite.Database database = null;
27
private Sqlite.Database *reference = null;
30
* Property to access the wrapped database
32
protected unowned Sqlite.Database db {
33
get { return reference; }
37
* Wrap an existing SQLite Database object.
39
* The SqliteWrapper doesn't take ownership of the passed db
41
public SqliteWrapper.wrap (Sqlite.Database db) {
46
* Create or open a new SQLite database in path.
48
* @note: Path may also be ":memory:" for temporary databases
50
public SqliteWrapper (string path) throws DatabaseError {
51
Sqlite.Database.open (path, out this.database);
52
this.reference = this.database;
53
this.throw_if_db_has_error ();
57
* Convert a SQLite return code to a DatabaseError
59
protected void throw_if_code_is_error (int sqlite_error)
60
throws DatabaseError {
61
switch (sqlite_error) {
67
throw new DatabaseError.SQLITE_ERROR
68
("SQLite error %d: %s",
70
this.reference->errmsg ());
75
* Check if the last operation on the database was an error
77
protected void throw_if_db_has_error () throws DatabaseError {
78
this.throw_if_code_is_error (this.reference->errcode ());