From 50b5fe43a210b1a59d0c197eee656dc50befdb42 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 12 Apr 2007 18:22:09 +0000 Subject: [PATCH] MODLANG-10 Modify Javascript exec function to return number of changed rows, thanks Dale. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4921 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_core_db.h | 5 +++++ .../mod_spidermonkey_core_db/mod_spidermonkey_core_db.c | 8 ++++++-- src/switch_core_db.c | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/include/switch_core_db.h b/src/include/switch_core_db.h index 6fc3c79c00..ab5903b24a 100644 --- a/src/include/switch_core_db.h +++ b/src/include/switch_core_db.h @@ -457,6 +457,11 @@ SWITCH_DECLARE(void) switch_core_db_free_table(char **result); */ SWITCH_DECLARE(void) switch_core_db_free(char *z); +/** + * Call this routine to find the number of rows changed by the last statement. + */ +SWITCH_DECLARE(int) switch_core_db_changes(switch_core_db_t *db); + /** Return values for switch_core_db_exec() and switch_core_db_step()*/ #define SWITCH_CORE_DB_OK 0 /* Successful result */ /* beginning-of-error-codes */ diff --git a/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c b/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c index cc38165307..03e97ea384 100644 --- a/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c +++ b/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c @@ -117,7 +117,7 @@ static int db_callback(void *pArg, int argc, char **argv, char **columnNames) static JSBool db_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval) { struct db_obj *dbo = JS_GetPrivate(cx, obj); - *rval = BOOLEAN_TO_JSVAL(JS_TRUE); + *rval = INT_TO_JSVAL(0); if (argc > 0) { char *sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); @@ -137,7 +137,11 @@ static JSBool db_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, if (err) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", err); switch_core_db_free(err); - *rval = BOOLEAN_TO_JSVAL(JS_FALSE); + *rval = INT_TO_JSVAL(-1); + } else { + int count = switch_core_db_changes(dbo->db); + + *rval = INT_TO_JSVAL(count); } } return JS_TRUE; diff --git a/src/switch_core_db.c b/src/switch_core_db.c index 587928aee4..f0f4a28f3d 100644 --- a/src/switch_core_db.c +++ b/src/switch_core_db.c @@ -142,6 +142,10 @@ SWITCH_DECLARE(void) switch_core_db_free(char *z) sqlite3_free(z); } +SWITCH_DECLARE(int) switch_core_db_changes(switch_core_db_t *db) { + return sqlite3_changes(db); +} + SWITCH_DECLARE(char *) switch_mprintf(const char *zFormat, ...) { va_list ap;