/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-07-23 12:57:07 UTC
  • Revision ID: edam@waxworlds.org-20100723125707-qu9jk9vvg2uewx7t
- cleaned up test-main
- fixed comment type
- made sqlite::exec() throw instead of returning sqlite error code

Show diffs side-by-side

added added

removed removed

37
37
 
38
38
void sqlite::basic_transaction::begin()
39
39
{
40
 
        _database.exec( "BEGIN" );
 
40
        int error_code = _database.exec( "BEGIN" );
 
41
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
41
42
}
42
43
 
43
44
 
44
45
void sqlite::basic_transaction::commit()
45
46
{
46
 
        _database.exec( "COMMIT" );
 
47
        int error_code = _database.exec( "COMMIT" );
 
48
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
47
49
}
48
50
 
49
51
 
50
52
void sqlite::basic_transaction::rollback()
51
53
{
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" );
 
54
        int error_code = _database.exec( "ROLLBACK" );
 
55
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
67
56
}
68
57
 
69
58
 
77
66
 
78
67
void sqlite::exclusive_transaction::begin()
79
68
{
80
 
        _database.exec( "BEGIN EXCLUSIVE" );
 
69
        int error_code = _database.exec( "BEGIN EXCLUSIVE" );
 
70
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
81
71
}
82
72
 
83
73
 
99
89
 
100
90
void sqlite::recursive_transaction::begin()
101
91
{
102
 
        _database.exec( "SAVEPOINT " + _sp_name );
 
92
        int error_code = _database.exec( "SAVEPOINT " + _sp_name );
 
93
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
103
94
}
104
95
 
105
96
 
106
97
void sqlite::recursive_transaction::commit()
107
98
{
108
 
        _database.exec( "RELEASE " + _sp_name );
 
99
        int error_code = _database.exec( "RELEASE " + _sp_name );
 
100
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
109
101
}
110
102
 
111
103
 
112
104
void sqlite::recursive_transaction::rollback()
113
105
{
114
 
        _database.exec( "ROLLBACK TO " + _sp_name );
 
106
        int error_code = _database.exec( "ROLLBACK TO " + _sp_name );
 
107
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
115
108
 
116
109
        // we have rolled back this transaction's savepoint, but the savepoint will
117
110
        // remain on the transaction stack unless we also release it
118
 
        _database.exec( "RELEASE " + _sp_name );
 
111
        error_code = _database.exec( "RELEASE " + _sp_name );
 
112
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
119
113
}