[Freeswitch-svn] [commit] r9245 - freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc

Freeswitch SVN anthm at freeswitch.org
Mon Aug 11 15:21:22 EDT 2008


Author: anthm
Date: Mon Aug 11 15:21:21 2008
New Revision: 9245

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

Log:
fix MODLANG-75

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c	Mon Aug 11 15:21:21 2008
@@ -178,6 +178,8 @@
 		} else {
 			tf = JS_FALSE;
 		}
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database handle is not initialized!\n");
 	}
 
 	*rval = BOOLEAN_TO_JSVAL(tf);
@@ -196,7 +198,7 @@
 		goto done;
 	}
 
-	if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+	if (!odbc_obj || switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
 		goto done;
 	}
@@ -229,7 +231,7 @@
 		goto done;
 	}
 
-	if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+	if (!odbc_obj || switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
 		goto done;
 	}
@@ -261,7 +263,7 @@
 
 	SQLSMALLINT rows = 0;
 
-	if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+	if (!odbc_obj || switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
 		goto done;
 	}
@@ -285,7 +287,7 @@
 	int result = 0;
 	JSBool tf = JS_FALSE;
 
-	if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+	if (!odbc_obj || switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
 		goto done;
 	}
@@ -353,7 +355,7 @@
 	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
 	JSBool tf = JS_FALSE;
 
-	if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+	if (!odbc_obj || switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
 		goto done;
 	}
@@ -414,12 +416,35 @@
 	return JS_TRUE;
 }
 
+
+static JSBool odbc_disconnect(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+	odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
+
+	if (!odbc_obj) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database handle is not initialized!\n");
+		goto done;
+	}
+
+	if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
+		goto done;
+	}
+
+	switch_odbc_handle_disconnect(odbc_obj->handle);
+
+ done:
+
+	return JS_TRUE;
+}
+
 enum odbc_tinyid {
 	odbc_NAME
 };
 
 static JSFunctionSpec odbc_methods[] = {
 	{"connect", odbc_connect, 1},
+	{"disconnect", odbc_disconnect, 1},
 	{"exec", odbc_exec, 1},
 	{"query", odbc_exec, 1},
 	{"execute", odbc_execute, 1},



More information about the Freeswitch-svn mailing list