]> git.saurik.com Git - wxWidgets.git/commitdiff
[ 955006 ] wxDb query with column information (modded to overload instead of creating...
authorRyan Norton <wxprojects@comcast.net>
Sat, 6 Nov 2004 20:32:34 +0000 (20:32 +0000)
committerRyan Norton <wxprojects@comcast.net>
Sat, 6 Nov 2004 20:32:34 +0000 (20:32 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30321 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/db.h
src/common/db.cpp

index 795b7912f5a6cfd5dd14cf68bce95372489d8f27..e923002979621af34f88b73a4fd74ae71b78228d 100644 (file)
@@ -624,6 +624,7 @@ public:
     bool         CreateView(const wxString &viewName, const wxString &colList, const wxString &pSqlStmt, bool attemptDrop=true);
     bool         DropView(const wxString &viewName);
     bool         ExecSql(const wxString &pSqlStmt);
+    bool         ExecSql(const wxString &pSqlStmt, wxDbColInf** columns, short& numcols);
     bool         GetNext(void);
     bool         GetData(UWORD colNo, SWORD cType, PTR pData, SDWORD maxLen, SDWORD FAR *cbReturned);
     bool         Grant(int privileges, const wxString &tableName, const wxString &userList = wxT("PUBLIC"));
index da7698256d406799a89615c12d48e4fb0b54807d..f99e9cff2cab07413c0a5f8d165be2f469bced0f 100644 (file)
@@ -2163,6 +2163,91 @@ bool wxDb::ExecSql(const wxString &pSqlStmt)
 }  // wxDb::ExecSql()
 
 
+/********** wxDb::ExecSql() with column info **********/ 
+bool wxDb::ExecSqlGetInf(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;
+    UCHAR 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,colNum+1, SQL_COLUMN_NAME,
+            name, sizeof(name),
+            &Sword, &Sdword) != SQL_SUCCESS)
+        {
+            DispAllErrors(henv, hdbc, hstmt);
+            delete[] pColInf;
+            return false;
+        }
+  
+        wxStrncpy(pColInf[colNum].colName, (const char*) name, DB_MAX_COLUMN_NAME_LEN);
+        
+        if (SQLColAttributes(hstmt,colNum+1, SQL_COLUMN_TYPE,
+            NULL, 0, &Sword, &Sdword) != SQL_SUCCESS)
+        {
+            DispAllErrors(henv, hdbc, hstmt);
+            delete[] pColInf;
+            return false;
+        }
+        
+        switch (Sdword)
+        {
+        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 %d currently not supported by wxWindows"), Sdword);
+            wxLogDebug(errMsg,wxT("ODBC DEBUG MESSAGE"));
+#endif
+        }
+    }
+    *columns = pColInf;
+    return true;
+}  // wxDb::ExecSqlGetInf()
+
 /********** wxDb::GetNext()  **********/
 bool wxDb::GetNext(void)
 {