4
4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
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.
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
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/>.
23
#ifndef SQLITE3CC_COMMAND_H_
24
#define SQLITE3CC_COMMAND_H_
27
#include <sqlite3cc/basic_statement.h>
27
#include "statement.hpp"
42
public basic_statement
44
44
//______________________________________________________________________________
49
* Constructor that provides a database upon which to act and the SQL
51
* @param database a reference to a database
49
* Constructor that provides the SQL statement to execute
52
50
* @param sql an SQL statement in UTF-8
55
53
database &database,
56
const std::string &sql );
59
* Constructor that provides a database upon which to act.
60
* @param database a reference to a database
54
const std::string &sql )
56
statement( database, sql )
65
59
//______________________________________________________________________________
66
60
// public interface
70
* Prepare an SQL statement.
71
* @param sql an SQL statement in UTF-8
72
* @returns an sqlite error code
73
* @see sqlite3_prepare_v2()
76
const std::string &sql );
79
* Step through one execution cycle of the SQL statement. If this is an SQL
80
* statement that doesn't return any rows, only one cycle is required,
81
* otherwise, each cycle will return another row
82
* @return an sqlite error code
88
64
* Execute the command. This is the same as doing a step().
89
* @return an sqlite error code
90
65
* @see sqlite3_step()
98
* Get the number of changes made by the last successful execution of this
99
* command. This doesn't include changes made in trigger subcontexts.
100
* @return the number of changed rows
101
* @see sqlite3_changes()
109
* Get the number of changes made by the last successful execution of this
110
* command. This includes changes made in all trigger subcontexts.
111
* @return the number of changed rows
112
* @see sqlite3_total_changes()
114
inline int total_changes()
116
return _total_changes;
120
* Get the rowid of the last row inserted via a successful INSERT command
121
* (regardless of whether that is this command or not).
122
* @return the last inserted rowid
124
inline long long last_insert_rowid()
126
return _last_insert_rowid;
130
* Stream operator is used to bind values to parameters automatically, in
131
* ascending order. In addition, the null, set_index() and execute auto-
132
* binding manipulators can be used.
133
* @param value a value to bind
136
command &operator <<(
139
int code = bind( _bind_index, value );
140
if( code != SQLITE_OK ) throw sqlite_error( _database, code );
145
//______________________________________________________________________________
149
/** non-recursive number of changes made by the last execution */
152
/** recursive number of changes made by the last execution */
155
/** the rowid of the last successful insert command */
156
long long _last_insert_rowid;
161
// template specialisations for command::operator <<()
163
command &command::operator << < detail::null_t >(
164
const detail::null_t & );
166
command &command::operator << < detail::exec_t >(
167
const detail::exec_t & );
169
command &command::operator << < detail::set_index_t >(
170
const detail::set_index_t &t );
173
} // namespace sqlite
176
#endif /* SQLITE3CC_COMMAND_H_ */
78
#endif /* COMMAND_HPP_ */