/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:46:42 UTC
  • Revision ID: edam@waxworlds.org-20100727154642-1uxrjkpxhp7xl6hq
- moved null_t, exec_t and set_index_t to detail namespace so only their extern instantiations are in the main namespace
- added immediate transation

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" );
 
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" );
55
67
}
56
68
 
57
69
 
65
77
 
66
78
void sqlite::exclusive_transaction::begin()
67
79
{
68
 
        int error_code = _database.exec( "BEGIN EXCLUSIVE" );
69
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
80
        _database.exec( "BEGIN EXCLUSIVE" );
70
81
}
71
82
 
72
83
 
88
99
 
89
100
void sqlite::recursive_transaction::begin()
90
101
{
91
 
        int error_code = _database.exec( "SAVEPOINT " + _sp_name );
92
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
102
        _database.exec( "SAVEPOINT " + _sp_name );
93
103
}
94
104
 
95
105
 
96
106
void sqlite::recursive_transaction::commit()
97
107
{
98
 
        int error_code = _database.exec( "RELEASE " + _sp_name );
99
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
108
        _database.exec( "RELEASE " + _sp_name );
100
109
}
101
110
 
102
111
 
103
112
void sqlite::recursive_transaction::rollback()
104
113
{
105
 
        int error_code = _database.exec( "ROLLBACK TO " + _sp_name );
106
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
114
        _database.exec( "ROLLBACK TO " + _sp_name );
107
115
 
108
116
        // we have rolled back this transaction's savepoint, but the savepoint will
109
117
        // 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 );
 
118
        _database.exec( "RELEASE " + _sp_name );
112
119
}