MCPcopy Create free account
hub / github.com/davisking/dlib / statement

Class statement

dlib/sqlite/sqlite.h:115–601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113// --------------------------------------------------------------------------------------------
114
115 class statement : noncopyable
116 {
117 public:
118 statement (
119 database& db_,
120 const std::string sql_statement
121 ) :
122 needs_reset(false),
123 step_status(SQLITE_DONE),
124 at_first_step(true),
125 db(db_.db),
126 stmt(0),
127 sql_string(sql_statement)
128 {
129 // make sure requires clause is not broken
130 DLIB_ASSERT(db_.is_open() == true,
131 "\t statement::statement()"
132 << "\n\t The database must be opened before calling this routine."
133 << "\n\t this: " << this
134 );
135
136 int status = sqlite3_prepare_v2(db.get(),
137 sql_string.c_str(),
138 sql_string.size()+1,
139 &stmt,
140 NULL);
141
142 if (status != SQLITE_OK)
143 {
144 sqlite3_finalize(stmt);
145 throw sqlite_error(sqlite3_errmsg(db.get()));
146 }
147 if (stmt == 0)
148 {
149 throw sqlite_error("Invalid SQL statement");
150 }
151 }
152
153 ~statement(
154 )
155 {
156 sqlite3_finalize(stmt);
157 }
158
159 void exec(
160 )
161 {
162 reset();
163
164 step_status = sqlite3_step(stmt);
165 needs_reset = true;
166 if (step_status != SQLITE_DONE && step_status != SQLITE_ROW)
167 {
168 if (step_status == SQLITE_ERROR)
169 throw sqlite_error(sqlite3_errmsg(db.get()));
170 else if (step_status == SQLITE_BUSY)
171 throw sqlite_error("statement::exec() failed. SQLITE_BUSY returned");
172 else

Callers 1

execMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected