[Freeswitch-svn] [commit] r8914 - in freeswitch/trunk/src: . mod/languages/mod_spidermonkey_odbc

Freeswitch SVN mikej at freeswitch.org
Mon Jul 7 23:06:08 EDT 2008


Author: mikej
Date: Mon Jul  7 23:06:07 2008
New Revision: 8914

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

Log:
fix Misuse of SQLRowCount, issues with MSSQL (MODAPP-105)

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 Jul  7 23:06:07 2008
@@ -359,46 +359,45 @@
 	}
 
 	if (odbc_obj->stmt) {
-		SQLSMALLINT c = 0, x = 0;
-		SQLLEN m = 0;
+		SQLSMALLINT nColumns = 0, x = 0;
 
 		eval_some_js("~var _oDbC_dB_RoW_DaTa_ = {}", cx, obj, rval);
 		if (*rval == JS_FALSE) {
 			return JS_TRUE;
 		}
 
-		SQLNumResultCols(odbc_obj->stmt, &c);
-		SQLRowCount(odbc_obj->stmt, &m);
-		if (m > 0) {
-			for (x = 1; x <= c; x++) {
-				SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
-				SQLULEN ColumnSize;
-				SQLCHAR name[1024] = "";
-				SQLCHAR *data = odbc_obj->colbuf;
-				SQLCHAR *esc = NULL;
-
-				SQLDescribeCol(odbc_obj->stmt, x, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
-				SQLGetData(odbc_obj->stmt, x, SQL_C_CHAR, odbc_obj->colbuf, odbc_obj->cblen, NULL);
-
-				if (strchr((char *) odbc_obj->colbuf, '"')) {	/* please don't */
-					esc = (SQLCHAR *) escape_data((char *) odbc_obj->colbuf, '\\');
-					data = esc;
-				}
-
-				switch_snprintf((char *) odbc_obj->code, odbc_obj->codelen, "~_oDbC_dB_RoW_DaTa_[\"%s\"] = \"%s\"", name, data);
-				switch_safe_free(esc);
-
-				eval_some_js((char *) odbc_obj->code, cx, obj, rval);
-
-				if (*rval == JS_FALSE) {
-					return JS_TRUE;
-				}
+		if ( SQLNumResultCols( odbc_obj->stmt, &nColumns ) != SQL_SUCCESS )
+			return JS_FALSE;
+
+		for (x = 1; x <= nColumns; x++) {
+			SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
+			SQLULEN ColumnSize;
+			SQLCHAR name[1024] = "";
+			SQLCHAR *data = odbc_obj->colbuf;
+			SQLCHAR *esc = NULL;
+
+			SQLDescribeCol(odbc_obj->stmt, x, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
+			SQLGetData(odbc_obj->stmt, x, SQL_C_CHAR, odbc_obj->colbuf, odbc_obj->cblen, NULL);
+
+			if (strchr((char *) odbc_obj->colbuf, '"')) {	/* please don't */
+				esc = (SQLCHAR *) escape_data((char *) odbc_obj->colbuf, '\\');
+				data = esc;
 			}
 
-			JS_GetProperty(cx, obj, "_oDbC_dB_RoW_DaTa_", rval);
-			return JS_TRUE;
+			switch_snprintf((char *) odbc_obj->code, odbc_obj->codelen, "~_oDbC_dB_RoW_DaTa_[\"%s\"] = \"%s\"", name, data);
+			switch_safe_free(esc);
+
+			eval_some_js((char *) odbc_obj->code, cx, obj, rval);
+
+			if (*rval == JS_FALSE) {
+				return JS_TRUE;
+			}
 		}
 
+		JS_GetProperty(cx, obj, "_oDbC_dB_RoW_DaTa_", rval);
+		return JS_TRUE;
+		
+
 	}
 
   done:

Modified: freeswitch/trunk/src/switch_odbc.c
==============================================================================
--- freeswitch/trunk/src/switch_odbc.c	(original)
+++ freeswitch/trunk/src/switch_odbc.c	Mon Jul  7 23:06:07 2008
@@ -196,6 +196,9 @@
 	SQLCHAR sql[255] = "";
 	int max_tries = 120;
 
+	SQLRETURN rc;
+	SQLSMALLINT nresultcols;
+
   top:
 
 	if (!handle) {
@@ -219,10 +222,15 @@
 
 	result = SQLExecute(stmt);
 
-	SQLRowCount(stmt, &m);
-	ret = (int) m;
-
-	if (result < 0 || m < 0) {
+	SQLRowCount (stmt, &m);
+	rc = SQLNumResultCols (stmt, &nresultcols);
+	if (rc != SQL_SUCCESS){
+		goto error;
+	}
+	ret = (int) nresultcols;
+	/* determine statement type */
+	if (nresultcols <= 0) {
+		/* statement is not a select statement */
 		goto error;
 	}
 



More information about the Freeswitch-svn mailing list