bzr branch
http://bzr.ed.am/sqlite3cc
1
by edam
- initial commit |
1 |
/* |
2
by edam
- further initial development |
2 |
* command.h |
1
by edam
- initial commit |
3 |
* |
22
by edam
updated email and web addresses |
4 |
* Copyright (C) 2009 Tim Marston <tim@ed.am> |
1
by edam
- initial commit |
5 |
* |
2
by edam
- further initial development |
6 |
* This file is part of sqlite3cc (hereafter referred to as "this program"). |
22
by edam
updated email and web addresses |
7 |
* See http://ed.am/dev/sqlite3cc for more information. |
8 |
* |
|
9 |
* This program is free software: you can redistribute it and/or modify it under |
|
10 |
* the terms of the GNU Lesser General Public License as published by the Free |
|
11 |
* Software Foundation, either version 3 of the License, or (at your option) any |
|
12 |
* later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
15 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
16 |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
17 |
* details. |
|
1
by edam
- initial commit |
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 |
#ifndef SQLITE3CC_COMMAND_H_ |
24 |
#define SQLITE3CC_COMMAND_H_ |
|
25 |
||
26 |
||
27 |
#include <sqlite3cc/basic_statement.h> |
|
45
by Tim Marston
fixed some missing/incorrect includes |
28 |
#include <string> |
1
by edam
- initial commit |
29 |
|
30 |
||
31 |
namespace sqlite |
|
32 |
{ |
|
33 |
||
34 |
||
35 |
/** |
|
22
by edam
updated email and web addresses |
36 |
* The command class represents an SQL command. Since there is very little |
1
by edam
- initial commit |
37 |
* difference between a command an a statement, it is basically a shim around |
38 |
* the statement class with the addition of an exec() method to execute the |
|
39 |
* command. |
|
40 |
*/ |
|
41 |
class command |
|
42 |
: |
|
16
by edam
- renamed database to connection to better identify what it is (would database_connection be better though?) |
43 |
public detail::basic_statement |
1
by edam
- initial commit |
44 |
{ |
45 |
//______________________________________________________________________________ |
|
46 |
// instantiation |
|
47 |
public: |
|
48 |
||
49 |
/** |
|
16
by edam
- renamed database to connection to better identify what it is (would database_connection be better though?) |
50 |
* Constructor that provides a connection upon which to act and the SQL |
2
by edam
- further initial development |
51 |
* command to execute. |
22
by edam
updated email and web addresses |
52 |
* |
16
by edam
- renamed database to connection to better identify what it is (would database_connection be better though?) |
53 |
* @param connection a reference to a connection |
1
by edam
- initial commit |
54 |
* @param sql an SQL statement in UTF-8 |
55 |
*/ |
|
2
by edam
- further initial development |
56 |
explicit command( |
16
by edam
- renamed database to connection to better identify what it is (would database_connection be better though?) |
57 |
connection &connection, |
2
by edam
- further initial development |
58 |
const std::string &sql ); |
59 |
||
60 |
/** |
|
16
by edam
- renamed database to connection to better identify what it is (would database_connection be better though?) |
61 |
* Constructor that provides a connection upon which to act. |
22
by edam
updated email and web addresses |
62 |
* |
16
by edam
- renamed database to connection to better identify what it is (would database_connection be better though?) |
63 |
* @param connection a reference to a connection |
2
by edam
- further initial development |
64 |
*/ |
65 |
explicit command( |
|
16
by edam
- renamed database to connection to better identify what it is (would database_connection be better though?) |
66 |
connection &connection ); |
1
by edam
- initial commit |
67 |
|
68 |
//______________________________________________________________________________ |
|
69 |
// public interface |
|
70 |
public: |
|
71 |
||
72 |
/** |
|
2
by edam
- further initial development |
73 |
* Prepare an SQL statement. |
22
by edam
updated email and web addresses |
74 |
* |
2
by edam
- further initial development |
75 |
* @param sql an SQL statement in UTF-8 |
76 |
* @returns an sqlite error code |
|
77 |
* @see sqlite3_prepare_v2() |
|
78 |
*/ |
|
79 |
virtual int prepare( |
|
80 |
const std::string &sql ); |
|
81 |
||
82 |
/** |
|
22
by edam
updated email and web addresses |
83 |
* Step through one execution cycle of the SQL statement. If this is an SQL |
2
by edam
- further initial development |
84 |
* statement that doesn't return any rows, only one cycle is required, |
85 |
* otherwise, each cycle will return another row |
|
22
by edam
updated email and web addresses |
86 |
* |
2
by edam
- further initial development |
87 |
* @return an sqlite error code |
88 |
* @see sqlite3_step() |
|
89 |
*/ |
|
13
by edam
- made basic_statement::step() protected, for use by query and command only |
90 |
int step(); |
2
by edam
- further initial development |
91 |
|
92 |
/** |
|
22
by edam
updated email and web addresses |
93 |
* Execute the command. This is the same as doing a step(). |
94 |
* |
|
2
by edam
- further initial development |
95 |
* @return an sqlite error code |
1
by edam
- initial commit |
96 |
* @see sqlite3_step() |
97 |
*/ |
|
98 |
inline int exec() |
|
99 |
{ |
|
100 |
return step(); |
|
101 |
} |
|
102 |
||
2
by edam
- further initial development |
103 |
/** |
104 |
* Get the number of changes made by the last successful execution of this |
|
22
by edam
updated email and web addresses |
105 |
* command. This doesn't include changes made in trigger subcontexts. |
106 |
* |
|
2
by edam
- further initial development |
107 |
* @return the number of changed rows |
108 |
* @see sqlite3_changes() |
|
109 |
*/ |
|
110 |
inline int changes() |
|
111 |
{ |
|
112 |
return _changes; |
|
113 |
} |
|
114 |
||
115 |
/** |
|
116 |
* Get the number of changes made by the last successful execution of this |
|
22
by edam
updated email and web addresses |
117 |
* command. This includes changes made in all trigger subcontexts. |
118 |
* |
|
2
by edam
- further initial development |
119 |
* @return the number of changed rows |
120 |
* @see sqlite3_total_changes() |
|
121 |
*/ |
|
122 |
inline int total_changes() |
|
123 |
{ |
|
124 |
return _total_changes; |
|
125 |
} |
|
126 |
||
127 |
/** |
|
128 |
* Get the rowid of the last row inserted via a successful INSERT command |
|
129 |
* (regardless of whether that is this command or not). |
|
22
by edam
updated email and web addresses |
130 |
* |
2
by edam
- further initial development |
131 |
* @return the last inserted rowid |
132 |
*/ |
|
133 |
inline long long last_insert_rowid() |
|
134 |
{ |
|
135 |
return _last_insert_rowid; |
|
136 |
} |
|
137 |
||
138 |
//______________________________________________________________________________ |
|
139 |
// implementation |
|
140 |
private: |
|
141 |
||
142 |
/** non-recursive number of changes made by the last execution */ |
|
143 |
int _changes; |
|
144 |
||
145 |
/** recursive number of changes made by the last execution */ |
|
146 |
int _total_changes; |
|
147 |
||
148 |
/** the rowid of the last successful insert command */ |
|
149 |
long long _last_insert_rowid; |
|
150 |
||
1
by edam
- initial commit |
151 |
}; |
152 |
||
153 |
||
16
by edam
- renamed database to connection to better identify what it is (would database_connection be better though?) |
154 |
namespace detail |
155 |
{ |
|
156 |
||
157 |
||
158 |
// template specialisations for detail::basic_statement::operator <<() |
|
14
by edam
- moved basic_statement::operator <<() back to basic_statement and just create another specialisation in command so that it can use sqlite::exec |
159 |
template< > |
160 |
basic_statement &basic_statement::operator << < detail::exec_t >( |
|
13
by edam
- made basic_statement::step() protected, for use by query and command only |
161 |
const detail::exec_t & ); |
162 |
||
163 |
||
16
by edam
- renamed database to connection to better identify what it is (would database_connection be better though?) |
164 |
} // namespace detail |
165 |
||
166 |
||
2
by edam
- further initial development |
167 |
} // namespace sqlite |
168 |
||
169 |
||
170 |
#endif /* SQLITE3CC_COMMAND_H_ */ |