Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifdef WIN32
  2. int odbc_db_query(SQLHDBC hDbc, struct QUERY_RESULTS_STRUCT *result_info, volatile const char *sql, const unsigned long lengt)
  3. {
  4.     int ret = QUERY_OKAY;
  5.     SQLHSTMT    hStmt = NULL;
  6.     RETCODE     rc;
  7. //  SQLSMALLINT sNumResults;
  8.    
  9.     rc = SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt);
  10.     if (SQL_SUCCESS != rc)
  11.     {
  12.         odbc_db_error_status(hDbc, SQL_HANDLE_DBC, NULL, true);
  13.         return QUERY_ERROR;
  14.     }
  15.  
  16.     rc = SQLExecDirect(hStmt, (SQLCHAR*)sql, lengt);
  17.  
  18.     switch (rc)
  19.     {
  20.         case SQL_NO_DATA:
  21.         {
  22.             ret = QUERY_OKAY;
  23.             break;
  24.         }
  25.  
  26.         case SQL_SUCCESS_WITH_INFO:
  27.         {
  28.             ret = QUERY_OKAY;
  29.             odbc_db_error_status(hStmt, SQL_HANDLE_STMT, result_info, false);
  30.             // fall through
  31.         }
  32.        
  33.         case SQL_SUCCESS:
  34.         {
  35.             ret = QUERY_OKAY;
  36.             /*rc = SQLNumResultCols(hStmt, &sNumResults);
  37.             if (SQL_ERROR == rc)
  38.             {
  39.                 fetch_odbc_error_status(hStmt, SQL_HANDLE_STMT, result_info, false);
  40.                 break;
  41.             }
  42.                
  43.             if (sNumResults > 0)
  44.             {
  45.                 //DisplayResults(hStmt, sNumResults);
  46.             }
  47.             else
  48.             {
  49.                 SQLLEN cRowCount;
  50.                 rc = SQLRowCount(hStmt, &cRowCount);
  51.                 if (SQL_ERROR == rc)
  52.                 {
  53.                     fetch_odbc_error_status(hStmt, SQL_HANDLE_STMT, result_info, false);
  54.                     break;
  55.                 }
  56.             }
  57.             */
  58.             break;
  59.         }
  60.    
  61.         case SQL_ERROR:
  62.         {
  63.             ret = QUERY_ERROR;
  64.             odbc_db_error_status(hStmt, SQL_HANDLE_STMT, result_info, false);
  65.             break;
  66.         }
  67.  
  68.         default:
  69.         {
  70.             ret = QUERY_ERROR;
  71.             odbc_db_error_status(hStmt, SQL_HANDLE_STMT, result_info, false);
  72.         }
  73.         break;
  74.     }
  75.  
  76.     if (hStmt)
  77.     {
  78.  
  79.         rc = SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
  80.         if (SQL_ERROR == rc)
  81.         {
  82.             ret = QUERY_ERROR;//didn't really fail - the free failed, but still...
  83.             //fetch_odbc_error_status(hStmt, SQL_HANDLE_STMT, result_info, false);
  84.         }
  85.     }
  86.  
  87.     return ret;
  88.  
  89. }
  90. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement