]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Lets not error on a query that returns 0 rows
authorKen Rice <krice@freeswitch.org>
Tue, 17 Feb 2009 04:29:50 +0000 (04:29 +0000)
committerKen Rice <krice@freeswitch.org>
Tue, 17 Feb 2009 04:29:50 +0000 (04:29 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12081 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/switch_odbc.c

index 6af24f234b9176684914c39052fbffddf3efe031..134d957926cb6b28ce47dd3b80be3c768864103d 100644 (file)
@@ -366,56 +366,57 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c
        SQLNumResultCols(stmt, &c);
        SQLRowCount(stmt, &m);
 
-
-       for (t = 0 ;; t++) {
-               int name_len = 256;
-               char **names;
-               char **vals;
-               int y = 0;
-               int done = 0;
-
-               result = SQLFetch(stmt);
-
-               if (result != SQL_SUCCESS) {
-                       if (result != SQL_NO_DATA){
-                               err++;
+       if (m > 0) {
+               for (t = 0 ;; t++) {
+                       int name_len = 256;
+                       char **names;
+                       char **vals;
+                       int y = 0;
+                       int done = 0;
+       
+                       result = SQLFetch(stmt);
+       
+                       if (result != SQL_SUCCESS) {
+                               if (result != SQL_NO_DATA){
+                                       err++;
+                               }
+                               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++;
                        }
-                       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)) {
-                       done = 1;
-               }
 
-               for (x = 0; x < y; x++) {
-                       free(names[x]);
-                       free(vals[x]);
-               }
-               free(names);
-               free(vals);
+                       if (callback(pdata, y, vals, names)) {
+                               done = 1;
+                       }
+       
+                       for (x = 0; x < y; x++) {
+                               free(names[x]);
+                               free(vals[x]);
+                       }
+                       free(names);
+                       free(vals);
 
-               if (done) {
+                       if (done) {
                        break;
+                       }
                }
        }