/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-02-08 22:08:57 UTC
  • Revision ID: edam@waxworlds.org-20100208220857-5up6fi4y6jh5bz4k
- removed "OK" from test-main when test is successful
- aranged for test/test-main to buld properly and be called from "make check"
- added include/Makefile.am to arrange for installation of library headers
- added project website to configure.ac
- added library interface configuration variable to configure.ac

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <sqlite3cc/database.h>
25
25
#include <sqlite3cc/exception.h>
26
26
#include <boost/thread.hpp>
27
 
#include <boost/lexical_cast.hpp>
28
27
 
29
28
 
30
29
sqlite::basic_transaction::basic_transaction(
37
36
 
38
37
void sqlite::basic_transaction::begin()
39
38
{
40
 
        _database.exec( "BEGIN" );
 
39
        int error_code = _database.exec( "BEGIN" );
 
40
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
41
41
}
42
42
 
43
43
 
44
44
void sqlite::basic_transaction::commit()
45
45
{
46
 
        _database.exec( "COMMIT" );
47
 
}
48
 
 
49
 
 
50
 
void sqlite::basic_transaction::invalidate_queries()
51
 
{
52
 
        while( sqlite3_stmt *handle = sqlite3_next_stmt( _database._handle, NULL ) )
53
 
                if( int code = sqlite3_finalize( handle ) )
54
 
                        throw sqlite_error( _database, code );
 
46
        int error_code = _database.exec( "COMMIT" );
 
47
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
55
48
}
56
49
 
57
50
 
58
51
void sqlite::basic_transaction::rollback()
59
52
{
60
 
        // we must invalidate any active queries when rolling back
61
 
        invalidate_queries();
62
 
        _database.exec( "ROLLBACK" );
63
 
}
64
 
 
65
 
 
66
 
sqlite::immediate_transaction::immediate_transaction(
67
 
        database &database )
68
 
        :
69
 
        basic_transaction( database )
70
 
{
71
 
}
72
 
 
73
 
 
74
 
void sqlite::immediate_transaction::begin()
75
 
{
76
 
        _database.exec( "BEGIN IMMEDIATE" );
 
53
        int error_code = _database.exec( "ROLLBACK" );
 
54
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
77
55
}
78
56
 
79
57
 
87
65
 
88
66
void sqlite::exclusive_transaction::begin()
89
67
{
90
 
        _database.exec( "BEGIN EXCLUSIVE" );
 
68
        int error_code = _database.exec( "BEGIN EXCLUSIVE" );
 
69
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
91
70
}
92
71
 
93
72
 
97
76
        basic_transaction( database )
98
77
{
99
78
        static unsigned long long i = 0;
 
79
        unsigned long long my_i;
100
80
        static boost::mutex mutex;
101
 
        unsigned long long my_i;
102
81
        {
103
82
                boost::lock_guard< boost::mutex > lock( mutex );
104
83
                my_i = i++;
109
88
 
110
89
void sqlite::recursive_transaction::begin()
111
90
{
112
 
        _database.exec( "SAVEPOINT " + _sp_name );
 
91
        int error_code = _database.exec( "SAVEPOINT " + _sp_name );
 
92
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
113
93
}
114
94
 
115
95
 
116
96
void sqlite::recursive_transaction::commit()
117
97
{
118
 
        _database.exec( "RELEASE " + _sp_name );
 
98
        int error_code = _database.exec( "RELEASE " + _sp_name );
 
99
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
119
100
}
120
101
 
121
102
 
122
103
void sqlite::recursive_transaction::rollback()
123
104
{
124
 
        // we must invalidate any active queries when rolling back
125
 
        invalidate_queries();
126
 
        _database.exec( "ROLLBACK TO " + _sp_name );
 
105
        int error_code = _database.exec( "ROLLBACK TO " + _sp_name );
 
106
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
127
107
 
128
108
        // we have rolled back this transaction's savepoint, but the savepoint will
129
109
        // remain on the transaction stack unless we also release it
130
 
        _database.exec( "RELEASE " + _sp_name );
 
110
        error_code = _database.exec( "RELEASE " + _sp_name );
 
111
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
131
112
}