/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

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