]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dbtable.cpp
added (and documented) msw.xp-tab-ok option
[wxWidgets.git] / src / common / dbtable.cpp
index bfc966f81131f747a57fde358839cfeaa043c6da..3e3349915935a9a01bbc9c11e866c314818a3ee7 100644 (file)
@@ -116,6 +116,7 @@ wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const UWORD numColumn
 
 
 /***** DEPRECATED: use wxDbTable::wxDbTable() format above *****/
+#if WXWIN_COMPATIBILITY_2_4
 wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const UWORD numColumns,
                     const wxChar *qryTblName, bool qryOnly, const wxString &tblPath)
 {
@@ -124,6 +125,7 @@ wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const UWORD numColumn
     if (!initialize(pwxDb, tblName, numColumns, tempQryTblName, qryOnly, tblPath))
         cleanup();
 }  // wxDbTable::wxDbTable()
+#endif // WXWIN_COMPATIBILITY_2_4
 
 
 /********** wxDbTable::~wxDbTable() **********/
@@ -432,7 +434,7 @@ void wxDbTable::setCbValueForColumn(int columnIndex)
             if (colDefs[columnIndex].Null)
                 colDefs[columnIndex].CbValue = SQL_NULL_DATA;
             else
-                if (colDefs[columnIndex].SqlCtype == SQL_C_CHAR)
+                if (colDefs[columnIndex].SqlCtype == SQL_C_WXCHAR)
                     colDefs[columnIndex].CbValue = SQL_NTS;
                 else
                     colDefs[columnIndex].CbValue = SQL_LEN_DATA_AT_EXEC(colDefs[columnIndex].SzDataObj);
@@ -777,7 +779,7 @@ bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists)
         // reliable!
         if (// *(pDb->dbInf.accessibleTables) == 'N' &&
             !pDb->TablePrivileges(tableName,wxT("SELECT"), pDb->GetUsername(), pDb->GetUsername(), tablePath))
-            s = wxT("Current logged in user does not have sufficient privileges to access this table.\n");
+            s = wxT("Connecting user does not have sufficient privileges to access this table.\n");
     }
 
     if (!s.IsEmpty())
@@ -996,7 +998,7 @@ void wxDbTable::BuildDeleteStmt(wxString &pSqlStmt, int typeOfDel, const wxStrin
                 // Get the ROWID value.  If not successful retreiving the ROWID,
                 // simply fall down through the code and build the WHERE clause
                 // based on the key fields.
-                if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS)
+                if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_WXCHAR, (UCHAR*) rowid, sizeof(rowid), &cb) == SQL_SUCCESS)
                 {
                     pSqlStmt += wxT("ROWID = '");
                     pSqlStmt += rowid;
@@ -1214,7 +1216,7 @@ void wxDbTable::BuildUpdateStmt(wxString &pSqlStmt, int typeOfUpd, const wxStrin
                 // Get the ROWID value.  If not successful retreiving the ROWID,
                 // simply fall down through the code and build the WHERE clause
                 // based on the key fields.
-                if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS)
+                if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_WXCHAR, (UCHAR*) rowid, sizeof(rowid), &cb) == SQL_SUCCESS)
                 {
                     pSqlStmt += wxT("ROWID = '");
                     pSqlStmt += rowid;
@@ -1260,7 +1262,7 @@ void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere,
     {
         // Determine if this column should be included in the WHERE clause
         if ((typeOfWhere == DB_WHERE_KEYFIELDS && colDefs[colNo].KeyField) ||
-             (typeOfWhere == DB_WHERE_MATCHING  && (!IsColNull(colNo))))
+             (typeOfWhere == DB_WHERE_MATCHING  && (!IsColNull((UWORD)colNo))))
         {
             // Skip over timestamp columns
             if (colDefs[colNo].SqlCtype == SQL_C_TIMESTAMP)
@@ -1281,7 +1283,7 @@ void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere,
             }
             pWhereClause += pDb->SQLColumnName(colDefs[colNo].ColName);
 
-            if (useLikeComparison && (colDefs[colNo].SqlCtype == SQL_C_CHAR))
+            if (useLikeComparison && (colDefs[colNo].SqlCtype == SQL_C_WXCHAR))
                 pWhereClause += wxT(" LIKE ");
             else
                 pWhereClause += wxT(" = ");
@@ -1289,6 +1291,8 @@ void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere,
             switch(colDefs[colNo].SqlCtype)
             {
                 case SQL_C_CHAR:
+                case SQL_C_WCHAR:
+                //case SQL_C_WXCHAR:  SQL_C_WXCHAR is covered by either SQL_C_CHAR or SQL_C_WCHAR
                     colValue.Printf(wxT("'%s'"), (UCHAR FAR *) colDefs[colNo].PtrDataObj);
                     break;
                 case SQL_C_SHORT:
@@ -1393,7 +1397,7 @@ bool wxDbTable::CreateTable(bool attemptDrop)
         switch(colDefs[i].DbDataType)
         {
             case DB_DATA_TYPE_VARCHAR:
-                cout << pDb->GetTypeInfVarchar().TypeName << wxT("(") << colDefs[i].SzDataObj << wxT(")");
+                cout << pDb->GetTypeInfVarchar().TypeName << wxT("(") << (int)(colDefs[i].SzDataObj / sizeof(wxChar)) << wxT(")");
                 break;
             case DB_DATA_TYPE_INTEGER:
                 cout << pDb->GetTypeInfInteger().TypeName;
@@ -1455,7 +1459,7 @@ bool wxDbTable::CreateTable(bool attemptDrop)
 //            colDefs[i].DbDataType == DB_DATA_TYPE_BLOB)
         {
             wxString s;
-            s.Printf(wxT("(%d)"), colDefs[i].SzDataObj);
+            s.Printf(wxT("(%d)"), (int)(colDefs[i].SzDataObj / sizeof(wxChar)));
             sqlStmt += s;
         }
 
@@ -1529,7 +1533,7 @@ bool wxDbTable::CreateTable(bool attemptDrop)
                     colDefs[i].DbDataType ==  DB_DATA_TYPE_VARCHAR)
                 {
                     wxString s;
-                    s.Printf(wxT("(%d)"), colDefs[i].SzDataObj);
+                    s.Printf(wxT("(%d)"), (int)(colDefs[i].SzDataObj / sizeof(wxChar)));
                     sqlStmt += s;
                 }
             }
@@ -1671,7 +1675,7 @@ bool wxDbTable::CreateIndex(const wxString &idxName, bool unique, UWORD noIdxCol
             if (found)
             {
                 ok = pDb->ModifyColumn(tableName, pIdxDefs[i].ColName,
-                                        colDefs[j].DbDataType, colDefs[j].SzDataObj,
+                                        colDefs[j].DbDataType, (int)(colDefs[j].SzDataObj / sizeof(wxChar)),
                                         wxT("NOT NULL"));
 
                 if (!ok)
@@ -1733,7 +1737,7 @@ bool wxDbTable::CreateIndex(const wxString &idxName, bool unique, UWORD noIdxCol
             if ( colDefs[j].DbDataType ==  DB_DATA_TYPE_VARCHAR)
             {
                 wxString s;
-                s.Printf(wxT("(%d)"), colDefs[i].SzDataObj);
+                s.Printf(wxT("(%d)"), (int)(colDefs[i].SzDataObj / sizeof(wxChar)));
                 sqlStmt += s;
             }
         }
@@ -2088,6 +2092,8 @@ bool wxDbTable::IsColNull(UWORD colNo) const
     switch(colDefs[colNo].SqlCtype)
     {
         case SQL_C_CHAR:
+        case SQL_C_WCHAR:
+        //case SQL_C_WXCHAR:  SQL_C_WXCHAR is covered by either SQL_C_CHAR or SQL_C_WCHAR
             return(((UCHAR FAR *) colDefs[colNo].PtrDataObj)[0] == 0);
         case SQL_C_SSHORT:
             return((  *((SWORD *) colDefs[colNo].PtrDataObj))   == 0);
@@ -2171,6 +2177,8 @@ void wxDbTable::ClearMemberVar(UWORD colNo, bool setToNull)
     switch(colDefs[colNo].SqlCtype)
     {
         case SQL_C_CHAR:
+        case SQL_C_WCHAR:
+        //case SQL_C_WXCHAR:  SQL_C_WXCHAR is covered by either SQL_C_CHAR or SQL_C_WCHAR
             ((UCHAR FAR *) colDefs[colNo].PtrDataObj)[0]    = 0;
             break;
         case SQL_C_SSHORT:
@@ -2179,6 +2187,7 @@ void wxDbTable::ClearMemberVar(UWORD colNo, bool setToNull)
         case SQL_C_USHORT:
             *((UWORD*) colDefs[colNo].PtrDataObj)           = 0;
             break;
+        case SQL_C_LONG:
         case SQL_C_SLONG:
             *((SDWORD *) colDefs[colNo].PtrDataObj)         = 0;
             break;
@@ -2216,7 +2225,7 @@ void wxDbTable::ClearMemberVars(bool setToNull)
 
     // Loop through the columns setting each member variable to zero
     for (i=0; i < noCols; i++)
-        ClearMemberVar(i,setToNull);
+        ClearMemberVar((UWORD)i,setToNull);
 
 }  // wxDbTable::ClearMemberVars()
 
@@ -2268,7 +2277,7 @@ void wxDbTable::SetColDefs(UWORD index, const wxString &fieldName, int dataType,
     colDefs[index].DbDataType       = dataType;
     colDefs[index].PtrDataObj       = pData;
     colDefs[index].SqlCtype         = cType;
-    colDefs[index].SzDataObj        = size;
+    colDefs[index].SzDataObj        = size;  //TODO: glt ??? * sizeof(wxChar) ???
     colDefs[index].KeyField         = keyField;
     colDefs[index].DerivedCol       = derivedCol;
     // Derived columns by definition would NOT be "Insertable" or "Updateable"
@@ -2306,13 +2315,13 @@ wxDbColDataPtr* wxDbTable::SetColDefs(wxDbColInf *pColInfs, UWORD numCols)
             switch (pColInfs[index].dbDataType)
             {
                 case DB_DATA_TYPE_VARCHAR:
-                   pColDataPtrs[index].PtrDataObj = new wxChar[pColInfs[index].bufferLength+1];
-                   pColDataPtrs[index].SzDataObj  = pColInfs[index].columnSize;
-                   pColDataPtrs[index].SqlCtype   = SQL_C_CHAR;
+                   pColDataPtrs[index].PtrDataObj = new wxChar[pColInfs[index].bufferSize+(1*sizeof(wxChar))];
+                   pColDataPtrs[index].SzDataObj  = pColInfs[index].bufferSize+(1*sizeof(wxChar));
+                   pColDataPtrs[index].SqlCtype   = SQL_C_WXCHAR;
                    break;
                 case DB_DATA_TYPE_INTEGER:
                     // Can be long or short
-                    if (pColInfs[index].bufferLength == sizeof(long))
+                    if (pColInfs[index].bufferSize == sizeof(long))
                     {
                       pColDataPtrs[index].PtrDataObj = new long;
                       pColDataPtrs[index].SzDataObj  = sizeof(long);
@@ -2327,7 +2336,7 @@ wxDbColDataPtr* wxDbTable::SetColDefs(wxDbColInf *pColInfs, UWORD numCols)
                     break;
                 case DB_DATA_TYPE_FLOAT:
                     // Can be float or double
-                    if (pColInfs[index].bufferLength == sizeof(float))
+                    if (pColInfs[index].bufferSize == sizeof(float))
                     {
                         pColDataPtrs[index].PtrDataObj = new float;
                         pColDataPtrs[index].SzDataObj  = sizeof(float);
@@ -2480,12 +2489,12 @@ bool wxDbTable::Refresh(void)
     if (CanUpdByROWID())
     {
         SDWORD cb;
-        wxChar   rowid[wxDB_ROWID_LEN+1];
+        wxChar rowid[wxDB_ROWID_LEN+1];
 
         // Get the ROWID value.  If not successful retreiving the ROWID,
         // simply fall down through the code and build the WHERE clause
         // based on the key fields.
-        if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS)
+        if (SQLGetData(hstmt, (UWORD)(noCols+1), SQL_C_WXCHAR, (UCHAR*) rowid, sizeof(rowid), &cb) == SQL_SUCCESS)
         {
             whereClause += pDb->SQLTableName(queryTableName);
 //            whereClause += queryTableName;
@@ -2557,7 +2566,7 @@ bool wxDbTable::SetColNull(const wxString &colName, bool set)
     {
         colDefs[colNo].Null = set;
         if (set)  // Blank out the values in the member variable
-           ClearMemberVar(colNo,false);  // Must call with false here, or infinite recursion will happen
+           ClearMemberVar((UWORD)colNo,false);  // Must call with false here, or infinite recursion will happen
 
         setCbValueForColumn(colNo);
 
@@ -2664,7 +2673,7 @@ void wxDbTable::SetRowMode(const rowmode_t rowmode)
 wxVariant wxDbTable::GetCol(const int colNo) const
 {
     wxVariant val;
-    if ((colNo < noCols) && (!IsColNull(colNo)))
+    if ((colNo < noCols) && (!IsColNull((UWORD)colNo)))
     {
         switch (colDefs[colNo].SqlCtype)
         {
@@ -2717,7 +2726,7 @@ void wxDbTable::SetCol(const int colNo, const wxVariant val)
     //FIXME: Add proper wxDateTime support to wxVariant..
     wxDateTime dateval;
 
-    SetColNull(colNo, val.IsNull());
+    SetColNull((UWORD)colNo, val.IsNull());
 
     if (!val.IsNull())
     {
@@ -2727,7 +2736,7 @@ void wxDbTable::SetCol(const int colNo, const wxVariant val)
         {
             //Returns null if invalid!
             if (!dateval.ParseDate(val.GetString()))
-                SetColNull(colNo, true);
+                SetColNull((UWORD)colNo, true);
         }
 
         switch (colDefs[colNo].SqlCtype)
@@ -2736,7 +2745,7 @@ void wxDbTable::SetCol(const int colNo, const wxVariant val)
             case SQL_VARCHAR:
                 csstrncpyt((wxChar *)(colDefs[colNo].PtrDataObj),
                            val.GetString().c_str(),
-                           colDefs[colNo].SzDataObj-1);
+                           colDefs[colNo].SzDataObj-1);  //TODO: glt ??? * sizeof(wxChar) ???
                 break;
             case SQL_C_LONG:
             case SQL_C_SLONG:
@@ -2744,7 +2753,7 @@ void wxDbTable::SetCol(const int colNo, const wxVariant val)
                 break;
             case SQL_C_SHORT:
             case SQL_C_SSHORT:
-                *(short *)(colDefs[colNo].PtrDataObj) = val.GetLong();
+                *(short *)(colDefs[colNo].PtrDataObj) = (short)val.GetLong();
                 break;
             case SQL_C_ULONG:
                 *(unsigned long *)(colDefs[colNo].PtrDataObj) = val.GetLong();
@@ -2756,7 +2765,7 @@ void wxDbTable::SetCol(const int colNo, const wxVariant val)
                 *(wxChar *)(colDefs[colNo].PtrDataObj) = val.GetChar();
                 break;
             case SQL_C_USHORT:
-                *(unsigned short *)(colDefs[colNo].PtrDataObj) = val.GetLong();
+                *(unsigned short *)(colDefs[colNo].PtrDataObj) = (unsigned short)val.GetLong();
                 break;
             //FIXME: Add proper wxDateTime support to wxVariant..
             case SQL_C_DATE:
@@ -2764,9 +2773,9 @@ void wxDbTable::SetCol(const int colNo, const wxVariant val)
                     DATE_STRUCT *dataptr =
                         (DATE_STRUCT *)colDefs[colNo].PtrDataObj;
 
-                    dataptr->year   = dateval.GetYear();
-                    dataptr->month  = dateval.GetMonth()+1;
-                    dataptr->day    = dateval.GetDay();
+                    dataptr->year   = (SWORD)dateval.GetYear();
+                    dataptr->month  = (UWORD)(dateval.GetMonth()+1);
+                    dataptr->day    = (UWORD)dateval.GetDay();
                 }
                 break;
             case SQL_C_TIME:
@@ -2783,9 +2792,9 @@ void wxDbTable::SetCol(const int colNo, const wxVariant val)
                 {
                     TIMESTAMP_STRUCT *dataptr =
                         (TIMESTAMP_STRUCT *)colDefs[colNo].PtrDataObj;
-                    dataptr->year   = dateval.GetYear();
-                    dataptr->month  = dateval.GetMonth()+1;
-                    dataptr->day    = dateval.GetDay();
+                    dataptr->year   = (SWORD)dateval.GetYear();
+                    dataptr->month  = (UWORD)(dateval.GetMonth()+1);
+                    dataptr->day    = (UWORD)dateval.GetDay();
 
                     dataptr->hour   = dateval.GetHour();
                     dataptr->minute = dateval.GetMinute();
@@ -2840,7 +2849,7 @@ void wxDbTable::SetKey(const GenericKey& k)
     {
         if (colDefs[i].KeyField)
         {
-            SetColNull(i, false);
+            SetColNull((UWORD)i, false);
             memcpy(colDefs[i].PtrDataObj, blkptr, colDefs[i].SzDataObj);
             blkptr += colDefs[i].SzDataObj;
         }