]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dbtable.cpp
Give wxListBox a GetClassDefaultAttributes so wxCalendarCtrl (and
[wxWidgets.git] / src / common / dbtable.cpp
index c5482f8a694e14fd559d1f9e105b34ae2d67561e..bfa0dd10c8238a73e1a3003b1a0c141b40fbc5f6 100644 (file)
 // Notice:      This class library and its intellectual design are free of charge for use,
 //              modification, enhancement, debugging under the following conditions:
 //              1) These classes may only be used as part of the implementation of a
 // Notice:      This class library and its intellectual design are free of charge for use,
 //              modification, enhancement, debugging under the following conditions:
 //              1) These classes may only be used as part of the implementation of a
-//                 wxWindows-based application
-//              2) All enhancements and bug fixes are to be submitted back to the wxWindows
-//                 user groups free of all charges for use with the wxWindows library.
+//                 wxWidgets-based application
+//              2) All enhancements and bug fixes are to be submitted back to the wxWidgets
+//                 user groups free of all charges for use with the wxWidgets library.
 //              3) These classes may not be distributed as part of any other class library,
 //                 DLL, text (written or electronic), other than a complete distribution of
 //              3) These classes may not be distributed as part of any other class library,
 //                 DLL, text (written or electronic), other than a complete distribution of
-//                 the wxWindows GUI development toolkit.
+//                 the wxWidgets GUI development toolkit.
 ///////////////////////////////////////////////////////////////////////////////
 
 /*
 ///////////////////////////////////////////////////////////////////////////////
 
 /*
@@ -321,18 +321,17 @@ void wxDbTable::cleanup()
 #ifdef __WXDEBUG__
     if (tableID)
     {
 #ifdef __WXDEBUG__
     if (tableID)
     {
-        TablesInUse.DeleteContents(TRUE);
         bool found = FALSE;
 
         bool found = FALSE;
 
-        wxNode *pNode;
+        wxList::compatibility_iterator pNode;
         pNode = TablesInUse.GetFirst();
         while (pNode && !found)
         {
             if (((wxTablesInUse *)pNode->GetData())->tableID == tableID)
             {
                 found = TRUE;
         pNode = TablesInUse.GetFirst();
         while (pNode && !found)
         {
             if (((wxTablesInUse *)pNode->GetData())->tableID == tableID)
             {
                 found = TRUE;
-                if (!TablesInUse.DeleteNode(pNode))
-                    wxLogDebug (s,wxT("Unable to delete node!"));
+                delete (wxTablesInUse *)pNode->GetData();
+                TablesInUse.Erase(pNode);
             }
             else
                 pNode = pNode->GetNext();
             }
             else
                 pNode = pNode->GetNext();
@@ -410,6 +409,46 @@ ODBC 3.0 says to use this form
 /***************************** PRIVATE FUNCTIONS *****************************/
 
 
 /***************************** PRIVATE FUNCTIONS *****************************/
 
 
+void wxDbTable::setCbValueForColumn(int columnIndex)
+{
+    switch(colDefs[columnIndex].DbDataType)
+    {
+        case DB_DATA_TYPE_VARCHAR:
+            if (colDefs[columnIndex].Null)
+                colDefs[columnIndex].CbValue = SQL_NULL_DATA;
+            else
+                colDefs[columnIndex].CbValue = SQL_NTS;
+            break;
+        case DB_DATA_TYPE_INTEGER:
+            if (colDefs[columnIndex].Null)
+                colDefs[columnIndex].CbValue = SQL_NULL_DATA;
+            else
+                colDefs[columnIndex].CbValue = 0;
+            break;
+        case DB_DATA_TYPE_FLOAT:
+            if (colDefs[columnIndex].Null)
+                colDefs[columnIndex].CbValue = SQL_NULL_DATA;
+            else
+                colDefs[columnIndex].CbValue = 0;
+            break;
+        case DB_DATA_TYPE_DATE:
+            if (colDefs[columnIndex].Null)
+                colDefs[columnIndex].CbValue = SQL_NULL_DATA;
+            else
+                colDefs[columnIndex].CbValue = 0;
+            break;
+        case DB_DATA_TYPE_BLOB:
+            if (colDefs[columnIndex].Null)
+                colDefs[columnIndex].CbValue = SQL_NULL_DATA;
+            else
+                if (colDefs[columnIndex].SqlCtype == SQL_C_CHAR)
+                    colDefs[columnIndex].CbValue = SQL_NTS;
+                else
+                    colDefs[columnIndex].CbValue = SQL_LEN_DATA_AT_EXEC(colDefs[columnIndex].SzDataObj);
+            break;
+    }
+}
+
 /********** wxDbTable::bindParams() **********/
 bool wxDbTable::bindParams(bool forUpdate)
 {
 /********** wxDbTable::bindParams() **********/
 bool wxDbTable::bindParams(bool forUpdate)
 {
@@ -445,19 +484,11 @@ bool wxDbTable::bindParams(bool forUpdate)
                 fSqlType = pDb->GetTypeInfVarchar().FsqlType;
                 precision = colDefs[i].SzDataObj;
                 scale = 0;
                 fSqlType = pDb->GetTypeInfVarchar().FsqlType;
                 precision = colDefs[i].SzDataObj;
                 scale = 0;
-                if (colDefs[i].Null)
-                    colDefs[i].CbValue = SQL_NULL_DATA;
-                else
-                    colDefs[i].CbValue = SQL_NTS;
                 break;
             case DB_DATA_TYPE_INTEGER:
                 fSqlType = pDb->GetTypeInfInteger().FsqlType;
                 precision = pDb->GetTypeInfInteger().Precision;
                 scale = 0;
                 break;
             case DB_DATA_TYPE_INTEGER:
                 fSqlType = pDb->GetTypeInfInteger().FsqlType;
                 precision = pDb->GetTypeInfInteger().Precision;
                 scale = 0;
-                if (colDefs[i].Null)
-                    colDefs[i].CbValue = SQL_NULL_DATA;
-                else
-                    colDefs[i].CbValue = 0;
                 break;
             case DB_DATA_TYPE_FLOAT:
                 fSqlType = pDb->GetTypeInfFloat().FsqlType;
                 break;
             case DB_DATA_TYPE_FLOAT:
                 fSqlType = pDb->GetTypeInfFloat().FsqlType;
@@ -468,30 +499,21 @@ bool wxDbTable::bindParams(bool forUpdate)
                 // I check for this here and set the scale = precision.
                 //if (scale < 0)
                 // scale = (short) precision;
                 // I check for this here and set the scale = precision.
                 //if (scale < 0)
                 // scale = (short) precision;
-                if (colDefs[i].Null)
-                    colDefs[i].CbValue = SQL_NULL_DATA;
-                else
-                    colDefs[i].CbValue = 0;
                 break;
             case DB_DATA_TYPE_DATE:
                 fSqlType = pDb->GetTypeInfDate().FsqlType;
                 precision = pDb->GetTypeInfDate().Precision;
                 scale = 0;
                 break;
             case DB_DATA_TYPE_DATE:
                 fSqlType = pDb->GetTypeInfDate().FsqlType;
                 precision = pDb->GetTypeInfDate().Precision;
                 scale = 0;
-                if (colDefs[i].Null)
-                    colDefs[i].CbValue = SQL_NULL_DATA;
-                else
-                    colDefs[i].CbValue = 0;
                 break;
             case DB_DATA_TYPE_BLOB:
                 fSqlType = pDb->GetTypeInfBlob().FsqlType;
                 break;
             case DB_DATA_TYPE_BLOB:
                 fSqlType = pDb->GetTypeInfBlob().FsqlType;
-                precision = -1;
+                precision = colDefs[i].SzDataObj;
                 scale = 0;
                 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;
         }
                 break;
         }
+
+        setCbValueForColumn(i);
+
         if (forUpdate)
         {
             if (SQLBindParameter(hstmtUpdate, colNo++, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
         if (forUpdate)
         {
             if (SQLBindParameter(hstmtUpdate, colNo++, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
@@ -505,7 +527,7 @@ bool wxDbTable::bindParams(bool forUpdate)
         {
             if (SQLBindParameter(hstmtInsert, colNo++, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
                                  fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj,
         {
             if (SQLBindParameter(hstmtInsert, colNo++, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
                                  fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj,
-                                 precision+1,&colDefs[i].CbValue) != SQL_SUCCESS)
+                                 precision+1, &colDefs[i].CbValue) != SQL_SUCCESS)
             {
                 return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
             }
             {
                 return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
             }
@@ -667,6 +689,7 @@ bool wxDbTable::execUpdate(const wxString &pSqlStmt)
                     break;
                 }
             }
                     break;
                 }
             }
+            retcode = SQLParamData(hstmtUpdate, &pParmID);
         }
         if (retcode == SQL_SUCCESS ||
             retcode == SQL_NO_DATA_FOUND ||
         }
         if (retcode == SQL_SUCCESS ||
             retcode == SQL_NO_DATA_FOUND ||
@@ -842,7 +865,7 @@ bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists)
                 return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
         }
         else
                 return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
         }
         else
-            insertable= FALSE;
+            insertable = FALSE;
     }
 
     // Completed successfully
     }
 
     // Completed successfully
@@ -1047,7 +1070,7 @@ void wxDbTable::BuildSelectStmt(wxString &pSqlStmt, int typeOfSelect, bool disti
     {
         tStr = colDefs[i].ColName;
         // If joining tables, the base table column names must be qualified to avoid ambiguity
     {
         tStr = colDefs[i].ColName;
         // If joining tables, the base table column names must be qualified to avoid ambiguity
-        if ((appendFromClause || pDb->Dbms() == dbmsACCESS) && !tStr.Find(wxT('.')))
+        if ((appendFromClause || pDb->Dbms() == dbmsACCESS) && tStr.Find(wxT('.')) == wxNOT_FOUND)
         {
             pSqlStmt += pDb->SQLTableName(queryTableName.c_str());
             pSqlStmt += wxT(".");
         {
             pSqlStmt += pDb->SQLTableName(queryTableName.c_str());
             pSqlStmt += wxT(".");
@@ -1260,7 +1283,7 @@ void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere,
             // Concatenate where phrase for the column
             wxString tStr = colDefs[colNo].ColName;
 
             // Concatenate where phrase for the column
             wxString tStr = colDefs[colNo].ColName;
 
-            if (qualTableName.Length() && !tStr.Find(wxT('.')))
+            if (qualTableName.Length() && tStr.Find(wxT('.')) == wxNOT_FOUND)
             {
                 pWhereClause += pDb->SQLTableName(qualTableName);
                 pWhereClause += wxT(".");
             {
                 pWhereClause += pDb->SQLTableName(qualTableName);
                 pWhereClause += wxT(".");
@@ -1277,12 +1300,14 @@ void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere,
                 case SQL_C_CHAR:
                     colValue.Printf(wxT("'%s'"), (UCHAR FAR *) colDefs[colNo].PtrDataObj);
                     break;
                 case SQL_C_CHAR:
                     colValue.Printf(wxT("'%s'"), (UCHAR FAR *) colDefs[colNo].PtrDataObj);
                     break;
+                case SQL_C_SHORT:
                 case SQL_C_SSHORT:
                     colValue.Printf(wxT("%hi"), *((SWORD *) colDefs[colNo].PtrDataObj));
                     break;
                 case SQL_C_USHORT:
                     colValue.Printf(wxT("%hu"), *((UWORD *) colDefs[colNo].PtrDataObj));
                     break;
                 case SQL_C_SSHORT:
                     colValue.Printf(wxT("%hi"), *((SWORD *) colDefs[colNo].PtrDataObj));
                     break;
                 case SQL_C_USHORT:
                     colValue.Printf(wxT("%hu"), *((UWORD *) colDefs[colNo].PtrDataObj));
                     break;
+                case SQL_C_LONG:
                 case SQL_C_SLONG:
                     colValue.Printf(wxT("%li"), *((SDWORD *) colDefs[colNo].PtrDataObj));
                     break;
                 case SQL_C_SLONG:
                     colValue.Printf(wxT("%li"), *((SDWORD *) colDefs[colNo].PtrDataObj));
                     break;
@@ -1295,6 +1320,14 @@ void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere,
                 case SQL_C_DOUBLE:
                     colValue.Printf(wxT("%.6f"), *((SDOUBLE *) colDefs[colNo].PtrDataObj));
                     break;
                 case SQL_C_DOUBLE:
                     colValue.Printf(wxT("%.6f"), *((SDOUBLE *) colDefs[colNo].PtrDataObj));
                     break;
+                default:
+                    {
+                        wxString strMsg;
+                        strMsg.Printf(wxT("wxDbTable::bindParams(): Unknown column type for colDefs %d colName %s"),
+                                    colNo,colDefs[colNo].ColName);
+                        wxFAIL_MSG(strMsg.c_str());
+                    }
+                    break;
             }
             pWhereClause += colValue;
         }
             }
             pWhereClause += colValue;
         }
@@ -1911,6 +1944,15 @@ int wxDbTable::Insert(void)
                     break;
                 }
             }
                     break;
                 }
             }
+            retcode = SQLParamData(hstmtInsert, &pParmID);
+            if (retcode != SQL_SUCCESS &&
+                retcode != SQL_SUCCESS_WITH_INFO)
+            {
+                // record was not inserted
+                pDb->DispNextError();
+                pDb->DispAllErrors(henv, hdbc, hstmtInsert);
+                return(DB_FAILURE);
+            }
         }
     }
 
         }
     }
 
@@ -2498,10 +2540,10 @@ bool wxDbTable::SetColNull(UWORD colNo, bool set)
     {
         colDefs[colNo].Null = set;
         if (set)  // Blank out the values in the member variable
     {
         colDefs[colNo].Null = set;
         if (set)  // Blank out the values in the member variable
-        {
-           colDefs[colNo].CbValue = SQL_NULL_DATA; // SF PATCH#766404
-           ClearMemberVar(colNo,FALSE);  // Must call with FALSE, or infinite recursion will happen
-        }
+           ClearMemberVar(colNo, FALSE);  // Must call with FALSE here, or infinite recursion will happen
+
+        setCbValueForColumn(colNo);
+
         return(TRUE);
     }
     else
         return(TRUE);
     }
     else
@@ -2524,10 +2566,10 @@ bool wxDbTable::SetColNull(const wxString &colName, bool set)
     {
         colDefs[colNo].Null = set;
         if (set)  // Blank out the values in the member variable
     {
         colDefs[colNo].Null = set;
         if (set)  // Blank out the values in the member variable
-        {
-           colDefs[colNo].CbValue = SQL_NULL_DATA;  // SF PATCH#766404
-           ClearMemberVar(colNo,FALSE);  // Must call with FALSE, or infinite recursion will happen
-        }
+           ClearMemberVar(colNo,FALSE);  // Must call with FALSE here, or infinite recursion will happen
+
+        setCbValueForColumn(colNo);
+
         return(TRUE);
     }
     else
         return(TRUE);
     }
     else