/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

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