+/********** wxDb::ExecSql() with column info **********/
+bool wxDb::ExecSql(const wxString &pSqlStmt, wxDbColInf** columns, short& numcols)
+{
+ //execute the statement first
+ if (!ExecSql(pSqlStmt))
+ return false;
+
+ SWORD noCols;
+ if (SQLNumResultCols(hstmt, &noCols) != SQL_SUCCESS)
+ {
+ DispAllErrors(henv, hdbc, hstmt);
+ return false;
+ }
+
+ if (noCols == 0)
+ return false;
+ else
+ numcols = noCols;
+
+ // Get column information
+ short colNum;
+ wxChar name[DB_MAX_COLUMN_NAME_LEN+1];
+ SWORD Sword;
+ SDWORD Sdword;
+ wxDbColInf* pColInf = new wxDbColInf[noCols];
+
+ // Fill in column information (name, datatype)
+ for (colNum = 0; colNum < noCols; colNum++)
+ {
+ if (SQLColAttributes(hstmt, (UWORD)(colNum+1), SQL_COLUMN_NAME,
+ name, sizeof(name),
+ &Sword, &Sdword) != SQL_SUCCESS)
+ {
+ DispAllErrors(henv, hdbc, hstmt);
+ delete[] pColInf;
+ return false;
+ }
+
+ wxStrncpy(pColInf[colNum].colName, name, DB_MAX_COLUMN_NAME_LEN);
+ pColInf[colNum].colName[DB_MAX_COLUMN_NAME_LEN] = 0; // Prevent buffer overrun
+
+ if (SQLColAttributes(hstmt, (UWORD)(colNum+1), SQL_COLUMN_TYPE,
+ NULL, 0, &Sword, &Sdword) != SQL_SUCCESS)
+ {
+ DispAllErrors(henv, hdbc, hstmt);
+ delete[] pColInf;
+ return false;
+ }
+
+ switch (Sdword)
+ {
+ case SQL_WCHAR:
+ case SQL_WVARCHAR:
+ case SQL_VARCHAR:
+ case SQL_CHAR:
+ pColInf[colNum].dbDataType = DB_DATA_TYPE_VARCHAR;
+ break;
+ case SQL_TINYINT:
+ case SQL_SMALLINT:
+ case SQL_INTEGER:
+ case SQL_BIT:
+ pColInf[colNum].dbDataType = DB_DATA_TYPE_INTEGER;
+ break;
+ case SQL_DOUBLE:
+ case SQL_DECIMAL:
+ case SQL_NUMERIC:
+ case SQL_FLOAT:
+ case SQL_REAL:
+ pColInf[colNum].dbDataType = DB_DATA_TYPE_FLOAT;
+ break;
+ case SQL_DATE:
+ case SQL_TIMESTAMP:
+ pColInf[colNum].dbDataType = DB_DATA_TYPE_DATE;
+ break;
+ case SQL_BINARY:
+ pColInf[colNum].dbDataType = DB_DATA_TYPE_BLOB;
+ break;
+#ifdef __WXDEBUG__
+ default:
+ wxString errMsg;
+ errMsg.Printf(wxT("SQL Data type %ld currently not supported by wxWidgets"), (long)Sdword);
+ wxLogDebug(errMsg,wxT("ODBC DEBUG MESSAGE"));
+#endif
+ }
+ }
+
+ *columns = pColInf;
+ return true;
+} // wxDb::ExecSql()
+