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;