/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc

« back to all changes in this revision

Viewing changes to test/test-main.cc

  • Committer: edam
  • Date: 2010-01-31 21:12:21 UTC
  • Revision ID: edam@waxworlds.org-20100131211221-5xtrhfrchozhk326
- rewrote transaction classes and added transaction_guard
- removed leftover code (sqlite_busy error)
- added tests for transactions

Show diffs side-by-side

added added

removed removed

59
59
        // test basic_statement binding via stream operator
60
60
        sqlite::command c4( db, "INSERT INTO pets VALUES( ?, ? )" );
61
61
        c4 << "tessa" << 16 << sqlite::exec;
62
 
        sqlite::command c5( db, "INSERT INTO pets VALUES( ?, ? )" );
63
 
        c5 << sqlite::null << sqlite::null <<
 
62
        sqlite::command( db, "INSERT INTO pets VALUES( ?, ? )" ) <<
 
63
                sqlite::null << sqlite::null <<
64
64
                sqlite::set_index( 1 ) << "tamara" << sqlite::exec;
65
65
 
66
66
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
96
96
        // test end of results
97
97
        assert( !q1.step() );
98
98
 
 
99
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
100
 
 
101
        // test transactions
 
102
        {       sqlite::transaction_guard< > t1( db ); }
 
103
        {       sqlite::transaction_guard< sqlite::exclusive_transaction > t1( db ); }
 
104
        {       sqlite::transaction_guard< sqlite::recursive_transaction > t1( db );
 
105
                sqlite::transaction_guard< sqlite::recursive_transaction > t2( db ); }
 
106
 
 
107
        // test transaction guard rollback
 
108
        {
 
109
                sqlite::transaction_guard< > t1( db );
 
110
                db.exec( "UPDATE pets SET age = 99" );
 
111
        }
 
112
        sqlite::query( db, "SELECT age FROM pets ORDER BY age DESC LIMIT 1" )
 
113
                .step() >> age; assert( age == 123 );
 
114
 
 
115
        // text recursive transactions
 
116
        {
 
117
                sqlite::transaction_guard< sqlite::recursive_transaction > t1( db );
 
118
                db.exec( "UPDATE pets SET age = 99" );
 
119
 
 
120
                {
 
121
                        sqlite::transaction_guard< sqlite::recursive_transaction > t2( db );
 
122
                        db.exec( "UPDATE pets SET age = 1" );
 
123
                }
 
124
 
 
125
                sqlite::query( db, "SELECT age FROM pets ORDER BY age DESC LIMIT 1" )
 
126
                        .step() >> age; assert( age == 99 );
 
127
 
 
128
                t1.commit();
 
129
        }
 
130
        sqlite::query( db, "SELECT age FROM pets ORDER BY age DESC LIMIT 1" )
 
131
                .step() >> age; assert( age == 99 );
 
132
 
99
133
        return 0;
100
134
}