Module: sip-router
Branch: master
Commit: 9bd65819c8af6140f56f09fb891cc585dcb4badb
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9bd6581…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Thu Aug 18 10:32:37 2011 +0200
acc: new parameter to allow usage of insert delayed
- db_insert_mode can be set to 1 in order to use INSERT DELAYED when
adding the acc records to database
---
modules_k/acc/README | 747 +++++++++++++++++++++++++--------------
modules_k/acc/acc.c | 27 ++-
modules_k/acc/acc_mod.c | 2 +
modules_k/acc/doc/acc_admin.xml | 17 +
4 files changed, 526 insertions(+), 267 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=9bd…
Module: sip-router
Branch: master
Commit: 26f2169a0aef931b17b35e64a2aca580d82b6b1a
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=26f2169…
Author: Alex Hermann <alex(a)speakup.nl>
Committer: Alex Hermann <alex(a)speakup.nl>
Date: Tue Aug 9 11:56:21 2011 +0200
lib/srdb1: Add support for affected rows.
affected_rows is the number of rows affected by a query.
Primarily used after UPDATE, INSERT and DELETE queries,
to know how many rows were affected.
---
lib/srdb1/db.c | 7 +++++++
lib/srdb1/db.h | 11 +++++++++++
lib/srdb1/db_cap.h | 4 ++--
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/lib/srdb1/db.c b/lib/srdb1/db.c
index 0c4cb58..443e03d 100644
--- a/lib/srdb1/db.c
+++ b/lib/srdb1/db.c
@@ -139,6 +139,11 @@ int db_check_api(db_func_t* dbf, char *mname)
if (dbf->insert_delayed) {
dbf->cap |= DB_CAP_INSERT_UPDATE;
}
+
+ if (dbf->affected_rows) {
+ dbf->cap |= DB_CAP_AFFECTED_ROWS;
+ }
+
return 0;
error:
return -1;
@@ -229,6 +234,8 @@ int db_bind_mod(const str* mod, db_func_t* mydbf)
dbf.replace = (db_replace_f)find_mod_export(tmp, "db_replace", 2, 0);
dbf.last_inserted_id= (db_last_inserted_id_f)find_mod_export(tmp,
"db_last_inserted_id", 1, 0);
+ dbf.affected_rows = (db_affected_rows_f)find_mod_export(tmp,
+ "db_affected_rows", 1, 0);
dbf.insert_update = (db_insert_update_f)find_mod_export(tmp,
"db_insert_update", 2, 0);
dbf.insert_delayed = (db_insert_delayed_f)find_mod_export(tmp,
diff --git a/lib/srdb1/db.h b/lib/srdb1/db.h
index 21b9110..294488c 100644
--- a/lib/srdb1/db.h
+++ b/lib/srdb1/db.h
@@ -296,6 +296,16 @@ typedef int (*db_insert_delayed_f) (const db1_con_t* _h, const db_key_t* _k,
const db_val_t* _v, const int _n);
+/**
+ * \brief Retrieve the number of affected rows for the last query.
+ *
+ * The function returns the rows affected by the last query.
+ * If any other type of query was the last, it returns null.
+ * \param _h structure representing database connection
+ * \return returns the number of rows as integer or returns -1 on error
+ */
+typedef int (*db_affected_rows_f) (const db1_con_t* _h);
+
/**
* \brief Database module callbacks
@@ -321,6 +331,7 @@ typedef struct db_func {
in a table */
db_insert_update_f insert_update; /* Insert into table, update on duplicate key */
db_insert_delayed_f insert_delayed; /* Insert delayed into table */
+ db_affected_rows_f affected_rows; /* Numer of affected rows for last query */
} db_func_t;
diff --git a/lib/srdb1/db_cap.h b/lib/srdb1/db_cap.h
index 1bc4704..968f6f7 100644
--- a/lib/srdb1/db_cap.h
+++ b/lib/srdb1/db_cap.h
@@ -48,8 +48,8 @@ typedef enum db_cap {
DB_CAP_FETCH = 1 << 6, /*!< driver supports fetch result queries */
DB_CAP_LAST_INSERTED_ID = 1 << 7, /*!< driver can return the ID of the last insert operation */
DB_CAP_INSERT_UPDATE = 1 << 8, /*!< driver can insert data into database & update on duplicate */
- DB_CAP_INSERT_DELAYED = 1 << 9 /*!< driver can do insert delayed */
-
+ DB_CAP_INSERT_DELAYED = 1 << 9, /*!< driver can do insert delayed */
+ DB_CAP_AFFECTED_ROWS = 1 << 10 /*!< driver can return number of rows affected by the last query */
} db_cap_t;