[Freeswitch-svn] [commit] r5583 - freeswitch/trunk/src/mod/languages/mod_spidermonkey_core_db

Freeswitch SVN anthm at freeswitch.org
Fri Aug 10 10:27:26 EDT 2007


Author: anthm
Date: Fri Aug 10 10:27:25 2007
New Revision: 5583

Modified:
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c

Log:
add close method needs testing

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	Fri Aug 10 10:27:25 2007
@@ -73,17 +73,33 @@
 	return JS_FALSE;
 }
 
-static void db_destroy(JSContext * cx, JSObject * obj)
+static JSBool db_close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 {
 	struct db_obj *dbo = JS_GetPrivate(cx, obj);
-
+	
 	if (dbo) {
-		switch_memory_pool_t *pool = dbo->pool;
 		if (dbo->stmt) {
 			switch_core_db_finalize(dbo->stmt);
 			dbo->stmt = NULL;
 		}
-		switch_core_db_close(dbo->db);
+		if (dbo->db) {
+			switch_core_db_close(dbo->db);
+			dbo->db = NULL;
+		}
+	}
+
+	return JS_TRUE;
+}
+
+static void db_destroy(JSContext *cx, JSObject *obj)
+{
+	struct db_obj *dbo = JS_GetPrivate(cx, obj);
+
+	if (dbo) {
+		switch_memory_pool_t *pool = dbo->pool;
+		jsval rval = JS_TRUE;
+
+		db_close(cx, obj, 0, NULL, &rval);
 		switch_core_destroy_memory_pool(&pool);
 		pool = NULL;
 	}
@@ -119,6 +135,10 @@
 	struct db_obj *dbo = JS_GetPrivate(cx, obj);
 	*rval = INT_TO_JSVAL(0);
 
+	if (!dbo->db) {
+		return JS_FALSE;
+	}
+
 	if (argc > 0) {
 		char *sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
 		char *err = NULL;
@@ -153,6 +173,10 @@
 	struct db_obj *dbo = JS_GetPrivate(cx, obj);
 	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 
+	if (!dbo->db) {
+		return JS_FALSE;
+	}
+
 	if (dbo->stmt) {
 		int running = 1;
 		while (running < 5000) {
@@ -180,6 +204,10 @@
 	char code[1024];
 	int x;
 
+	if (!dbo->db) {
+		return JS_FALSE;
+	}
+
 	snprintf(code, sizeof(code), "~var _dB_RoW_DaTa_ = {}");
 	eval_some_js(code, dbo->cx, dbo->obj, rval);
 	if (*rval == JS_FALSE) {
@@ -207,6 +235,10 @@
 
 	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 
+	if (!dbo->db) {
+		return JS_FALSE;
+	}
+
 	if (dbo->stmt) {
 		switch_core_db_finalize(dbo->stmt);
 		dbo->stmt = NULL;
@@ -229,6 +261,7 @@
 
 static JSFunctionSpec db_methods[] = {
 	{"exec", db_exec, 1},
+	{"close", db_close, 0},
 	{"next", db_next, 0},
 	{"fetch", db_fetch, 1},
 	{"prepare", db_prepare, 0},



More information about the Freeswitch-svn mailing list