/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-database.cpp

  • Committer: edam
  • Date: 2009-11-25 20:32:34 UTC
  • Revision ID: edam@waxworlds.org-20091125203234-24i7mzd60c7o46py
- initial commit
- basic support for: database, statements, commands, transactions, exceptions
- initial test app
- initial liscence and readme

Show diffs side-by-side

added added

removed removed

 
1
/*
 
2
 * test-database.cpp
 
3
 *
 
4
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
 
5
 *
 
6
 * This file is part of sqlitepp (hereafter referred to as "this program").
 
7
 * See http://www.waxworlds.org/edam/software/sqlitepp for more information.
 
8
 *
 
9
 * This program is free software: you can redistribute it and/or modify
 
10
 * it under the terms of the GNU Lesser General Public License as published
 
11
 * by the Free Software Foundation, either version 3 of the License, or
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU Lesser General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Lesser General Public License
 
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
 */
 
22
 
 
23
#include <sqlitepp.hpp>
 
24
#include <boost/filesystem.hpp>
 
25
 
 
26
 
 
27
#define DBFILE "test.db"
 
28
 
 
29
 
 
30
int main()
 
31
{
 
32
        // delete any existing test database
 
33
        if( boost::filesystem::exists( DBFILE ) )
 
34
                boost::filesystem::remove( DBFILE );
 
35
 
 
36
        // open database
 
37
        sqlite::database db( DBFILE );
 
38
 
 
39
        // test basic statement, via command class
 
40
        sqlite::command c1( db,
 
41
                "CREATE TABLE pets ( "
 
42
                        "name TEXT PRIMARY KEY, "
 
43
                        "age INTEGER "
 
44
                ")" );
 
45
        c1.step();
 
46
 
 
47
        // test statement bind() calls, via command
 
48
        sqlite::command c2( db, "INSERT INTO pets VALUES( ?, ? )" );
 
49
        c2.bind( 1, "billy" ); c2.bind( 2, 12 ); c2.exec();
 
50
        sqlite::command c3( db, "INSERT INTO pets VALUES( ?, ? )" );
 
51
        c3.bind( 2, 16 ); c3.bind( 1, "mopti" ); c3.exec();
 
52
        sqlite::command c6( db, "INSERT INTO pets VALUES( ?, ? )" );
 
53
        c6.bind_null( 1 ); c6.bind( 2, 123 ); c6.exec();
 
54
 
 
55
        // test binding via stream operator
 
56
        sqlite::command c4( db, "INSERT INTO pets VALUES( ?, ? )" );
 
57
        c4 << "tessa" << 16 << sqlite::exec;
 
58
        sqlite::command c5( db, "INSERT INTO pets VALUES( ?, ? )" );
 
59
        c5 << sqlite::null << sqlite::null <<
 
60
                sqlite::set_index( 1 ) << "tamara" << sqlite::exec;
 
61
 
 
62
        return 0;
 
63
}