summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/SQL.h4
-rw-r--r--lib/SQL.cc14
2 files changed, 17 insertions, 1 deletions
diff --git a/include/SQL.h b/include/SQL.h
index 4385a6d..5cccd1c 100644
--- a/include/SQL.h
+++ b/include/SQL.h
@@ -15,10 +15,12 @@ class SQLConnection : public Base {
int numrows();
int numfields();
AssocArray fetchrow();
+ int numaffectedrows();
+ int insertid();
private:
MYSQL con;
MYSQL_RES * res;
- int nr, nf;
+ int nr, nf, na, ii;
MYSQL_FIELD * fields;
};
diff --git a/lib/SQL.cc b/lib/SQL.cc
index 26620e4..e599f95 100644
--- a/lib/SQL.cc
+++ b/lib/SQL.cc
@@ -34,6 +34,8 @@ void SQLConnection::query(String q) throw(GeneralException) {
mysql_free_result(res);
}
+ res = 0;
+
if (mysql_real_query(&con, ((ugly_string)q).p, q.strlen())) {
throw GeneralException(String("Couldn't run query ") + q);
}
@@ -44,10 +46,14 @@ void SQLConnection::query(String q) throw(GeneralException) {
nr = mysql_num_rows(res);
nf = mysql_num_fields(res);
fields = mysql_fetch_fields(res);
+ na = mysql_affected_rows(res);
+ ii = mysql_insert_id(res);
} else {
nr = 0;
nf = 0;
fields = 0;
+ na = 0;
+ ii = -1;
}
}
@@ -73,4 +79,12 @@ AssocArray SQLConnection::fetchrow() {
return r;
}
+int SQLConnection::numaffectedrows() {
+ return na;
+}
+
+int SQLConnection::insertid() {
+ return ii;
+}
+
#endif