/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc

« back to all changes in this revision

Viewing changes to src/query.cc

  • Committer: edam
  • Date: 2010-01-28 12:21:03 UTC
  • Revision ID: edam@waxworlds.org-20100128122103-v3gs6hro5h7ffnhb
- further initial development
- basic support for: queries, rows (query results)
- filename, comment header and project name consistency

Show diffs side-by-side

added added

removed removed

1
1
/*
2
 
 * query.cpp
 
2
 * query.cc
3
3
 *
4
4
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
5
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.
 
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.
8
8
 *
9
9
 * This program is free software: you can redistribute it and/or modify
10
10
 * it under the terms of the GNU Lesser General Public License as published
20
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
21
 */
22
22
 
23
 
#include <sqlitepp/query.hpp>
24
 
 
25
 
 
 
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
}