summaryrefslogtreecommitdiff
path: root/libsqlitepp/modifycommand.cpp
blob: 1b44cf4eba7a747338767f438b6ecfab9cd25b95 (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
25
26
27
28
29
30
31
#include "modifycommand.h"
#include "error.h"
#include <stdlib.h>
#include "connection.h"

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

SQLite::ModifyCommand::~ModifyCommand()
{
}

unsigned int
SQLite::ModifyCommand::execute(bool anc)
{
	if (sqlite3_step(stmt) != SQLITE_DONE) {
		sqlite3_reset(stmt);
		throw Error(sqlite3_errmsg(c->db));
	}
	unsigned int rows = sqlite3_changes(c->db);
	sqlite3_reset(stmt);
	if (rows == 0 && !anc) {
		throw Error("No rows affected");
	}
	return rows;
}