summaryrefslogtreecommitdiff
path: root/libsqlitepp/sqlite-modifycommand.cpp
blob: d69516d7b7da5862006e7df7c4c6d45de560d8f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "sqlite-modifycommand.h"
#include "sqlite-connection.h"
#include "sqlite-error.h"
#include <cstdlib>

SQLite::ModifyCommand::ModifyCommand(const Connection * conn, const std::string & sql) :
	DB::Command(sql), DB::ModifyCommand(sql), SQLite::Command(conn, sql)
{
}

unsigned int
SQLite::ModifyCommand::execute(bool anc)
{
	if (sqlite3_step(stmt) != SQLITE_DONE) {
		sqlite3_reset(stmt);
		throw Error(c->db);
	}
	auto rows = static_cast<unsigned int>(sqlite3_changes(c->db));
	sqlite3_reset(stmt);
	if (rows == 0 && !anc) {
		throw DB::NoRowsAffected();
	}
	return rows;
}