4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
4
* Copyright (C) 2009 Tim Marston <tim@ed.am>
6
6
* This file is part of sqlite3cc (hereafter referred to as "this program").
7
* See http://www.waxworlds.org/edam/software/sqlite3cc for more information.
9
* This program is free software: you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published
11
* by the Free Software Foundation, either version 3 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Lesser General Public License for more details.
7
* See http://ed.am/dev/sqlite3cc for more information.
9
* This program is free software: you can redistribute it and/or modify it under
10
* the terms of the GNU Lesser General Public License as published by the Free
11
* Software Foundation, either version 3 of the License, or (at your option) any
14
* This program is distributed in the hope that it will be useful, but WITHOUT
15
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19
19
* You should have received a copy of the GNU Lesser General Public License
20
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include <sqlite3cc/database.h>
23
#include <sqlite3cc/connection.h>
24
24
#include <sqlite3cc/exception.h>
27
sqlite::database::database(
25
#include <sqlite3cc/command.h>
26
#include <sqlite3cc/query.h>
29
sqlite::connection::mutex_guard::mutex_guard(
30
connection &connection )
32
_mutex( sqlite3_db_mutex( connection._handle ) )
34
if( _mutex ) sqlite3_mutex_enter( _mutex );
38
sqlite::connection::mutex_guard::~mutex_guard()
43
void sqlite::connection::mutex_guard::leave()
46
sqlite3_mutex_leave( _mutex );
52
sqlite::connection::connection(
28
53
const std::string &filename )
32
int error_code = open( filename );
33
if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
57
int code = open( filename );
58
if( code != SQLITE_OK ) throw sqlite_error( *this, code );
37
sqlite::database::database()
62
sqlite::connection::connection()
44
sqlite::database::~database() throw( )
69
sqlite::connection::~connection()
50
int sqlite::database::open(
75
int sqlite::connection::open(
51
76
const std::string &filename,
68
int sqlite::database::exec(
93
void sqlite::connection::exec(
69
94
const std::string &sql )
71
return sqlite3_exec( _handle, sql.c_str(), NULL, NULL, NULL );
96
int code = sqlite3_exec( _handle, sql.c_str(), NULL, NULL, NULL );
97
if( code != SQLITE_OK ) throw sqlite_error( *this, code );
75
int sqlite::database::busy_timeout(
101
int sqlite::connection::busy_timeout(
78
104
return sqlite3_busy_timeout( _handle, duration );
108
boost::shared_ptr< sqlite::command > sqlite::connection::make_command(
111
return boost::shared_ptr< sqlite::command >(
112
new sqlite::command( *this, sql ) );
116
boost::shared_ptr< sqlite::query > sqlite::connection::make_query(
119
return boost::shared_ptr< sqlite::query >(
120
new sqlite::query( *this, sql ) );