/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-27 15:12:55 UTC
  • Revision ID: edam@waxworlds.org-20100727151255-goaqgdz4kj13q7gz
- update TODO
- added some missing includes for <string>
- changed usage of database::exec() to not require return code!
- prevented transaction_guard destructor from throwing an exception

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
void sqlite::basic_transaction::begin()
39
39
{
40
 
        int error_code = _database.exec( "BEGIN" );
41
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
40
        _database.exec( "BEGIN" );
42
41
}
43
42
 
44
43
 
45
44
void sqlite::basic_transaction::commit()
46
45
{
47
 
        int error_code = _database.exec( "COMMIT" );
48
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
46
        _database.exec( "COMMIT" );
49
47
}
50
48
 
51
49
 
52
50
void sqlite::basic_transaction::rollback()
53
51
{
54
 
        int error_code = _database.exec( "ROLLBACK" );
55
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
52
        _database.exec( "ROLLBACK" );
56
53
}
57
54
 
58
55
 
66
63
 
67
64
void sqlite::exclusive_transaction::begin()
68
65
{
69
 
        int error_code = _database.exec( "BEGIN EXCLUSIVE" );
70
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
66
        _database.exec( "BEGIN EXCLUSIVE" );
71
67
}
72
68
 
73
69
 
89
85
 
90
86
void sqlite::recursive_transaction::begin()
91
87
{
92
 
        int error_code = _database.exec( "SAVEPOINT " + _sp_name );
93
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
88
        _database.exec( "SAVEPOINT " + _sp_name );
94
89
}
95
90
 
96
91
 
97
92
void sqlite::recursive_transaction::commit()
98
93
{
99
 
        int error_code = _database.exec( "RELEASE " + _sp_name );
100
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
94
        _database.exec( "RELEASE " + _sp_name );
101
95
}
102
96
 
103
97
 
104
98
void sqlite::recursive_transaction::rollback()
105
99
{
106
 
        int error_code = _database.exec( "ROLLBACK TO " + _sp_name );
107
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
100
        _database.exec( "ROLLBACK TO " + _sp_name );
108
101
 
109
102
        // we have rolled back this transaction's savepoint, but the savepoint will
110
103
        // remain on the transaction stack unless we also release it
111
 
        error_code = _database.exec( "RELEASE " + _sp_name );
112
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
104
        _database.exec( "RELEASE " + _sp_name );
113
105
}