]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dbtable.cpp
a fix for the last fix
[wxWidgets.git] / src / common / dbtable.cpp
index 9dbeb6d0a2019b190021562c3a10d7699c127665..a1f0a15eaf1aab2604e347ab68e5f6900bb332c0 100644 (file)
@@ -102,7 +102,32 @@ ULONG lastTableID = 0;
 #endif
 
 
-/********** wxDbTable::wxDbTable() **********/
+/********** wxDbColDef::wxDbColDef() Constructor **********/
+wxDbColDef::wxDbColDef()
+{
+    Initialize();
+}  // Constructor
+
+
+bool wxDbColDef::Initialize()
+{
+    ColName[0]      = 0;
+    DbDataType      = DB_DATA_TYPE_INTEGER;
+    SqlCtype        = SQL_C_LONG;
+    PtrDataObj      = NULL;
+    SzDataObj       = 0;
+    KeyField        = FALSE;
+    Updateable      = FALSE;
+    InsertAllowed   = FALSE;
+    DerivedCol      = FALSE;
+    CbValue         = 0;
+    Null = FALSE;
+
+    return TRUE;
+}  // wxDbColDef::Initialize()
+
+
+/********** wxDbTable::wxDbTable() Constructor **********/
 wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const int nCols,
                     const wxString &qryTblName, bool qryOnly, const wxString &tblPath)
 {
@@ -462,6 +487,15 @@ bool wxDbTable::bindParams(bool forUpdate)
                 else
                     colDefs[i].CbValue = 0;
                 break;
+            case DB_DATA_TYPE_BLOB:
+                fSqlType = pDb->GetTypeInfBlob().FsqlType;
+                precision = 50000;
+                scale = 0;
+                if (colDefs[i].Null)
+                    colDefs[i].CbValue = SQL_NULL_DATA;
+                else
+                    colDefs[i].CbValue = SQL_LEN_DATA_AT_EXEC(colDefs[i].SzDataObj);
+                break;
         }
         if (forUpdate)
         {
@@ -1290,6 +1324,9 @@ bool wxDbTable::CreateTable(bool attemptDrop)
             case DB_DATA_TYPE_DATE:
                 cout << pDb->typeInfDate.TypeName;
                 break;
+            case DB_DATA_TYPE_BLOB:
+                cout << pDb->typeInfBlob.TypeName;
+                break;
         }
         cout << endl;
     }
@@ -1325,9 +1362,13 @@ bool wxDbTable::CreateTable(bool attemptDrop)
             case DB_DATA_TYPE_DATE:
                 sqlStmt += pDb->GetTypeInfDate().TypeName;
                 break;
+            case DB_DATA_TYPE_BLOB:
+                sqlStmt += pDb->GetTypeInfBlob().TypeName;
+                break;
         }
         // For varchars, append the size of the string
-        if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR)
+        if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR)// ||
+//            colDefs[i].DbDataType == DB_DATA_TYPE_BLOB)
         {
             wxString s;
             s.Printf(wxT("(%d)"), colDefs[i].SzDataObj);
@@ -2094,8 +2135,26 @@ wxDbColDataPtr* wxDbTable::SetColDefs(wxDbColInf *pColInfs, ULONG numCols)
                     pColDataPtrs[index].SzDataObj  = sizeof(TIMESTAMP_STRUCT);
                     pColDataPtrs[index].SqlCtype   = SQL_C_TIMESTAMP;
                     break;
+                case DB_DATA_TYPE_BLOB:
+                                                 int notSupportedYet = 0;
+                    wxASSERT_MSG(notSupportedYet, wxT("This form of ::SetColDefs() cannot be used with BLOB columns"));
+                    pColDataPtrs[index].PtrDataObj = /*BLOB ADDITION NEEDED*/NULL;
+                    pColDataPtrs[index].SzDataObj  = /*BLOB ADDITION NEEDED*/sizeof(void *);
+                    pColDataPtrs[index].SqlCtype   = SQL_VARBINARY;
+                    break;
+            }
+            if (pColDataPtrs[index].PtrDataObj != NULL)
+                SetColDefs (index,pColInfs[index].colName,pColInfs[index].dbDataType, pColDataPtrs[index].PtrDataObj, pColDataPtrs[index].SqlCtype, pColDataPtrs[index].SzDataObj);
+            else
+            {
+                // Unable to build all the column definitions, as either one of 
+                // the calls to "new" failed above, or there was a BLOB field
+                // to have a column definition for.  If BLOBs are to be used,
+                // the other form of ::SetColDefs() must be used, as it is impossible
+                // to know the maximum size to create the PtrDataObj to be.
+                delete [] pColDataPtrs;
+                return NULL;
             }
-            SetColDefs (index,pColInfs[index].colName,pColInfs[index].dbDataType, pColDataPtrs[index].PtrDataObj, pColDataPtrs[index].SqlCtype, pColDataPtrs[index].SzDataObj);
         }
     }