[Freeswitch-svn] [commit] r9310 - in freeswitch/trunk/src: . mod/languages/mod_spidermonkey_odbc
Freeswitch SVN
anthm at freeswitch.org
Sat Aug 16 11:55:50 EDT 2008
Author: anthm
Date: Sat Aug 16 11:55:49 2008
New Revision: 9310
Modified:
freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c
freeswitch/trunk/src/switch_odbc.c
Log:
fix numRows and add numCols
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 Sat Aug 16 11:55:49 2008
@@ -260,8 +260,31 @@
static JSBool odbc_num_rows(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
+ SQLLEN row_count;
+
+ 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;
+ }
+
+ if (odbc_obj->stmt) {
+ SQLRowCount(odbc_obj->stmt, &row_count);
+ }
+
+ done:
+
+ *rval = INT_TO_JSVAL(row_count);
+
+ return JS_TRUE;
+
+}
+
+
+static JSBool odbc_num_cols(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+ odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
- SQLSMALLINT rows = 0;
+ SQLSMALLINT cols = 0;
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");
@@ -269,12 +292,12 @@
}
if (odbc_obj->stmt) {
- SQLNumResultCols(odbc_obj->stmt, &rows);
+ SQLNumResultCols(odbc_obj->stmt, &cols);
}
done:
- *rval = INT_TO_JSVAL(rows);
+ *rval = INT_TO_JSVAL(cols);
return JS_TRUE;
@@ -449,6 +472,7 @@
{"query", odbc_exec, 1},
{"execute", odbc_execute, 1},
{"numRows", odbc_num_rows, 1},
+ {"numCols", odbc_num_cols, 1},
{"nextRow", odbc_next_row, 1},
{"getData", odbc_get_data, 1},
{"close", odbc_close, 1},
Modified: freeswitch/trunk/src/switch_odbc.c
==============================================================================
--- freeswitch/trunk/src/switch_odbc.c (original)
+++ freeswitch/trunk/src/switch_odbc.c Sat Aug 16 11:55:49 2008
@@ -353,50 +353,49 @@
SQLNumResultCols(stmt, &c);
SQLRowCount(stmt, &m);
- if (m > 0) {
- for (t = 0; t < m; t++) {
- int name_len = 256;
- char **names;
- char **vals;
- int y = 0;
-
- if (!(result = SQLFetch(stmt)) == SQL_SUCCESS) {
- goto error;
- }
-
- names = calloc(c, sizeof(*names));
- vals = calloc(c, sizeof(*vals));
-
- switch_assert(names && vals);
-
- for (x = 1; x <= c; x++) {
- SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
- SQLULEN ColumnSize;
- names[y] = malloc(name_len);
- memset(names[y], 0, name_len);
-
- SQLDescribeCol(stmt, x, (SQLCHAR *) names[y], (SQLSMALLINT) name_len, &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
- ColumnSize++;
-
- vals[y] = malloc(ColumnSize);
- memset(vals[y], 0, ColumnSize);
- SQLGetData(stmt, x, SQL_C_CHAR, (SQLCHAR *) vals[y], ColumnSize, NULL);
- y++;
- }
-
- if (callback(pdata, y, vals, names)) {
- break;
- }
-
- for (x = 0; x < y; x++) {
- free(names[x]);
- free(vals[x]);
- }
- free(names);
- free(vals);
+
+ for (t = 0 ;; t++) {
+ int name_len = 256;
+ char **names;
+ char **vals;
+ int y = 0;
+
+ if (!(result = SQLFetch(stmt)) == SQL_SUCCESS) {
+ break;
+ }
+
+ names = calloc(c, sizeof(*names));
+ vals = calloc(c, sizeof(*vals));
+
+ switch_assert(names && vals);
+
+ for (x = 1; x <= c; x++) {
+ SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
+ SQLULEN ColumnSize;
+ names[y] = malloc(name_len);
+ memset(names[y], 0, name_len);
+
+ SQLDescribeCol(stmt, x, (SQLCHAR *) names[y], (SQLSMALLINT) name_len, &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
+ ColumnSize++;
+
+ vals[y] = malloc(ColumnSize);
+ memset(vals[y], 0, ColumnSize);
+ SQLGetData(stmt, x, SQL_C_CHAR, (SQLCHAR *) vals[y], ColumnSize, NULL);
+ y++;
+ }
+
+ if (callback(pdata, y, vals, names)) {
+ break;
}
- }
+ for (x = 0; x < y; x++) {
+ free(names[x]);
+ free(vals[x]);
+ }
+ free(names);
+ free(vals);
+ }
+
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
return SWITCH_ODBC_SUCCESS;
More information about the Freeswitch-svn
mailing list