[Freeswitch-svn] [commit] r4921 - in freeswitch/trunk/src: . include mod/languages/mod_spidermonkey_core_db

Freeswitch SVN mikej at freeswitch.org
Thu Apr 12 14:22:09 EDT 2007


Author: mikej
Date: Thu Apr 12 14:22:09 2007
New Revision: 4921

Modified:
   freeswitch/trunk/src/include/switch_core_db.h
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c
   freeswitch/trunk/src/switch_core_db.c

Log:
MODLANG-10 Modify Javascript exec function to return number of changed rows, thanks Dale.

Modified: freeswitch/trunk/src/include/switch_core_db.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core_db.h	(original)
+++ freeswitch/trunk/src/include/switch_core_db.h	Thu Apr 12 14:22:09 2007
@@ -457,6 +457,11 @@
  */
 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 */

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c	Thu Apr 12 14:22:09 2007
@@ -117,7 +117,7 @@
 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 @@
 		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;

Modified: freeswitch/trunk/src/switch_core_db.c
==============================================================================
--- freeswitch/trunk/src/switch_core_db.c	(original)
+++ freeswitch/trunk/src/switch_core_db.c	Thu Apr 12 14:22:09 2007
@@ -142,6 +142,10 @@
 	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;



More information about the Freeswitch-svn mailing list