/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: 2012-04-23 18:40:10 UTC
  • Revision ID: tim@ed.am-20120423184010-3zaiqkhxwequfaey
Removed an optimisation in command::step() (calling finalize() here prevents
the command from being reset() and reused), and added a wrapper for a
transaction's begin() method to transaction_guard (both thanks to Ron Wilson).

Show diffs side-by-side

added added

removed removed

1
1
/*
2
 
 * test-main.cc
 
2
 * test-database.cc
3
3
 *
4
4
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
5
5
 *
56
56
        sqlite::command c6( conn, "INSERT INTO pets VALUES( ?, ? )" );
57
57
        c6.bind_null( 1 ); c6.bind( 2, 123 ); c6.exec();
58
58
        sqlite::command c7( conn, "INSERT INTO pets VALUES( :foo, :bar )" );
59
 
        c7.bind( ":foo", "foocat" ); c7.bind( ":bar", 22.5 ); c7.exec();
 
59
        c7.bind( ":foo", "foocat" ); c7.bind( ":bar", 22 ); c7.exec();
60
60
 
61
61
        // test command binding via stream operator
62
62
        sqlite::command( conn, "INSERT INTO pets VALUES( ?, ? )" ) <<
91
91
 
92
92
        // test rows
93
93
        unsigned int age;
94
 
        double dblage;
95
94
        std::string name;
96
95
        q1.step().column( 0, age ); assert( age == 12 );
97
96
        name = q1.step().column< std::string >( 2 ); assert( name == "mopti" );
101
100
        r1 >> age; assert( age == 16 );
102
101
        r1 >> age; assert( age == 19 );
103
102
        r1 >> name; assert( name == "tessa" );
104
 
        q1.step() >> dblage >> sqlite::null >> name;
105
 
        assert( dblage == 22.5 && name == "foocat" );
 
103
        q1.step() >> age >> sqlite::null >> name;
 
104
        assert( age == 22 && name == "foocat" );
106
105
        sqlite::row row = q1.step();
107
106
        row >> age >> sqlite::null >> sqlite::null; assert( age == 123 );
108
107
        row >> sqlite::set_index( 1 ) >> age; assert( age == 126 );
185
184
        sqlite::query( conn, "SELECT age FROM pets ORDER BY age DESC LIMIT 1" )
186
185
                .step() >> age; assert( age == 123 );
187
186
 
188
 
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
189
 
 
190
187
        // ok
191
188
        return 0;
192
189
}