bzr branch
http://bzr.ed.am/sqlite3cc
1
by edam
- initial commit |
1 |
/* |
2
by edam
- further initial development |
2 |
* query.cc |
1
by edam
- initial commit |
3 |
* |
4 |
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org> |
|
5 |
* |
|
2
by edam
- further initial development |
6 |
* This file is part of sqlite3cc (hereafter referred to as "this program"). |
7 |
* See http://www.waxworlds.org/edam/software/sqlite3cc for more information. |
|
1
by edam
- initial commit |
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 |
||
2
by edam
- further initial development |
23 |
#include <sqlite3cc/query.h> |
24 |
#include <sqlite3cc/row.h> |
|
25 |
#include <assert.h> |
|
26 |
||
27 |
||
28 |
sqlite::query::query( |
|
29 |
database &database, |
|
30 |
const std::string &sql ) |
|
31 |
: |
|
32 |
basic_statement( database, sql ) |
|
33 |
{ |
|
34 |
assert( sqlite3_column_count( _handle ) > 0 ); |
|
35 |
} |
|
36 |
||
37 |
||
38 |
sqlite::query::query( |
|
39 |
database &database ) |
|
40 |
: |
|
41 |
basic_statement( database ) |
|
42 |
{ |
|
43 |
} |
|
44 |
||
45 |
||
46 |
int sqlite::query::prepare( |
|
47 |
const std::string &sql ) |
|
48 |
{ |
|
49 |
int error_code = basic_statement::prepare( sql ); |
|
50 |
assert( error_code != SQLITE_OK || sqlite3_column_count( _handle ) > 0 ); |
|
51 |
return error_code; |
|
52 |
} |
|
53 |
||
54 |
||
55 |
sqlite::row sqlite::query::step() |
|
56 |
{ |
|
57 |
int error_code = basic_statement::step(); |
|
58 |
if( error_code == SQLITE_ROW ) |
|
59 |
return row( *this ); |
|
60 |
if( error_code == SQLITE_DONE ) |
|
61 |
return row( *this, false ); |
|
62 |
throw sqlite_error( error_code ); |
|
63 |
} |
|
64 |
||
65 |
||
66 |
unsigned int sqlite::query::column_count() |
|
67 |
{ |
|
68 |
return sqlite3_column_count( _handle ); |
|
69 |
} |