/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-01-23 17:37:17 UTC
  • Revision ID: edam@waxworlds.org-20120123173717-yj4zb1nv7d39va8d
Tags: 0.1
prep for release

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( ?, ? )" ) <<
74
74
                << sqlite::set_index( 1 ) << "bar" << "baz";
75
75
 
76
76
        // test connection command and query factory methods
77
 
        conn.make_command( "PRAGMA user_version = 12")->step();
78
 
        assert( conn.make_query( "PRAGMA user_version" )->step()
79
 
                .column< int >( 0 ) == 12 );
 
77
        *conn.make_command( "PRAGMA user_version = 1") << sqlite::exec;
 
78
        conn.make_query( "PRAGMA user_version")->step();
80
79
 
81
80
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82
81
 
91
90
 
92
91
        // test rows
93
92
        unsigned int age;
94
 
        double dblage;
95
93
        std::string name;
96
94
        q1.step().column( 0, age ); assert( age == 12 );
97
95
        name = q1.step().column< std::string >( 2 ); assert( name == "mopti" );
101
99
        r1 >> age; assert( age == 16 );
102
100
        r1 >> age; assert( age == 19 );
103
101
        r1 >> name; assert( name == "tessa" );
104
 
        q1.step() >> dblage >> sqlite::null >> name;
105
 
        assert( dblage == 22.5 && name == "foocat" );
 
102
        q1.step() >> age >> sqlite::null >> name;
 
103
        assert( age == 22 && name == "foocat" );
106
104
        sqlite::row row = q1.step();
107
105
        row >> age >> sqlite::null >> sqlite::null; assert( age == 123 );
108
106
        row >> sqlite::set_index( 1 ) >> age; assert( age == 126 );
169
167
        sqlite::query( conn, "SELECT age FROM pets ORDER BY age DESC LIMIT 1" )
170
168
                .step() >> age; assert( age == 123 );
171
169
 
172
 
        // test recursive transactions
 
170
        // text recursive transactions
173
171
        {
174
172
                sqlite::transaction_guard< sqlite::recursive_transaction > t1( conn );
175
173
                conn.exec( "UPDATE pets SET age = 66" );
185
183
        sqlite::query( conn, "SELECT age FROM pets ORDER BY age DESC LIMIT 1" )
186
184
                .step() >> age; assert( age == 123 );
187
185
 
188
 
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
189
 
 
190
186
        // ok
191
187
        return 0;
192
188
}