4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
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.
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.
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.
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/>.
23
#include <sqlitepp.hpp>
24
#include <boost/filesystem.hpp>
27
#define DBFILE "test.db"
32
// delete any existing test database
33
if( boost::filesystem::exists( DBFILE ) )
34
boost::filesystem::remove( DBFILE );
37
sqlite::database db( DBFILE );
39
// test basic statement, via command class
40
sqlite::command c1( db,
41
"CREATE TABLE pets ( "
42
"name TEXT PRIMARY KEY, "
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();
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;