/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc

« back to all changes in this revision

Viewing changes to src/transaction.cc

  • Committer: edam
  • Date: 2010-02-07 15:28:23 UTC
  • Revision ID: edam@waxworlds.org-20100207152823-42k206h6gwy7vla4
- fixed .am files so the library gets built!

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <sqlite3cc/database.h>
25
25
#include <sqlite3cc/exception.h>
26
26
#include <boost/thread.hpp>
27
 
#include <boost/lexical_cast.hpp>
28
27
 
29
28
 
30
29
sqlite::basic_transaction::basic_transaction(
37
36
 
38
37
void sqlite::basic_transaction::begin()
39
38
{
40
 
        _database.exec( "BEGIN" );
 
39
        int error_code = _database.exec( "BEGIN" );
 
40
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
41
41
}
42
42
 
43
43
 
44
44
void sqlite::basic_transaction::commit()
45
45
{
46
 
        _database.exec( "COMMIT" );
 
46
        int error_code = _database.exec( "COMMIT" );
 
47
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
47
48
}
48
49
 
49
50
 
50
51
void sqlite::basic_transaction::rollback()
51
52
{
52
 
        _database.exec( "ROLLBACK" );
53
 
}
54
 
 
55
 
 
56
 
sqlite::immediate_transaction::immediate_transaction(
57
 
        database &database )
58
 
        :
59
 
        basic_transaction( database )
60
 
{
61
 
}
62
 
 
63
 
 
64
 
void sqlite::immediate_transaction::begin()
65
 
{
66
 
        _database.exec( "BEGIN IMMEDIATE" );
 
53
        int error_code = _database.exec( "ROLLBACK" );
 
54
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
67
55
}
68
56
 
69
57
 
77
65
 
78
66
void sqlite::exclusive_transaction::begin()
79
67
{
80
 
        _database.exec( "BEGIN EXCLUSIVE" );
 
68
        int error_code = _database.exec( "BEGIN EXCLUSIVE" );
 
69
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
81
70
}
82
71
 
83
72
 
99
88
 
100
89
void sqlite::recursive_transaction::begin()
101
90
{
102
 
        _database.exec( "SAVEPOINT " + _sp_name );
 
91
        int error_code = _database.exec( "SAVEPOINT " + _sp_name );
 
92
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
103
93
}
104
94
 
105
95
 
106
96
void sqlite::recursive_transaction::commit()
107
97
{
108
 
        _database.exec( "RELEASE " + _sp_name );
 
98
        int error_code = _database.exec( "RELEASE " + _sp_name );
 
99
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
109
100
}
110
101
 
111
102
 
112
103
void sqlite::recursive_transaction::rollback()
113
104
{
114
 
        _database.exec( "ROLLBACK TO " + _sp_name );
 
105
        int error_code = _database.exec( "ROLLBACK TO " + _sp_name );
 
106
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
115
107
 
116
108
        // we have rolled back this transaction's savepoint, but the savepoint will
117
109
        // remain on the transaction stack unless we also release it
118
 
        _database.exec( "RELEASE " + _sp_name );
 
110
        error_code = _database.exec( "RELEASE " + _sp_name );
 
111
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
119
112
}