fix numRows and add numCols

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9310 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2008-08-16 15:55:49 +00:00
parent 05b01a6c03
commit a3f6e72f35
2 changed files with 67 additions and 44 deletions

View File

@@ -353,50 +353,49 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odb
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;