X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/32a2907bd33438d2119d587aa9656c0d94e6e460..69659fd770f615210efac4b4fa741b3ad6223616:/src/common/dbgrid.cpp diff --git a/src/common/dbgrid.cpp b/src/common/dbgrid.cpp index 545d3072e8..634be020d8 100644 --- a/src/common/dbgrid.cpp +++ b/src/common/dbgrid.cpp @@ -1,9 +1,9 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: dbgrid.cpp +// Name: src/common/dbgrid.cpp // Purpose: Displays a wxDbTable in a wxGrid. // Author: Roger Gammans, Paul Gammans -// Modified by: -// Created: +// Modified by: +// Created: // RCS-ID: $Id$ // Copyright: (c) 1999 The Computer Surgery (roger@computer-surgery.co.uk) // Licence: wxWindows licence @@ -11,28 +11,26 @@ // Branched From : dbgrid.cpp,v 1.18 2000/12/19 13:00:58 /////////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ - #pragma implementation "dbgrid.h" -#endif - #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif - -#if wxUSE_ODBC -#if wxUSE_NEW_GRID +#if wxUSE_ODBC && wxUSE_GRID #ifndef WX_PRECOMP #include "wx/textctrl.h" #include "wx/dc.h" + #include "wx/app.h" #endif // WX_PRECOMP #include "wx/generic/gridctrl.h" #include "wx/dbgrid.h" +// DLL options compatibility check: +WX_CHECK_BUILD_OPTIONS("wxDbGrid") + wxDbGridCellAttrProvider::wxDbGridCellAttrProvider() { @@ -113,7 +111,7 @@ wxGridCellAttr *wxDbGridCellAttrProvider::GetAttr(int row, int col, break; } } - + } return attr; } @@ -125,7 +123,7 @@ void wxDbGridCellAttrProvider::AssignDbTable(wxDbTable *tab) wxDbGridTableBase::wxDbGridTableBase(wxDbTable *tab, wxDbGridColInfo* ColInfo, int count, bool takeOwnership) : - m_keys(), + m_keys(), m_data(tab), m_dbowner(takeOwnership), m_rowmodified(false) @@ -162,7 +160,7 @@ wxDbGridTableBase::wxDbGridTableBase(wxDbTable *tab, wxDbGridColInfo* ColInfo, if (i < m_nocols) { wxLogDebug(wxT("NoCols under length after traversing %i items"),i); - } + } #endif } } @@ -171,17 +169,18 @@ wxDbGridTableBase::~wxDbGridTableBase() { wxDbGridCellAttrProvider *provider; - //Can't check for update here as + //Can't check for update here as //FIXME: should i remove m_ColInfo and m_data from m_attrProvider if a wxDbGridAttrProvider // if ((provider = dynamic_cast(GetAttrProvider()))) - // Using C casting for now until we can support dynamic_cast with wxWindows - if ((provider = (wxDbGridCellAttrProvider *)(GetAttrProvider()))) + // Using C casting for now until we can support dynamic_cast with wxWidgets + provider = (wxDbGridCellAttrProvider *)(GetAttrProvider()); + if (provider) { provider->AssignDbTable(NULL); } delete [] m_ColInfo; - + Writeback(); if (m_dbowner) { @@ -204,11 +203,12 @@ bool wxDbGridTableBase::AssignDbTable(wxDbTable *tab, int count, bool takeOwners { wxDbGridCellAttrProvider *provider; + wxGridUpdateLocker locker(GetView()); + //Remove Information from grid about old data if (GetView()) { wxGrid *grid = GetView(); - grid->BeginBatch(); grid->ClearSelection(); if (grid->IsCellEditControlEnabled()) { @@ -226,14 +226,15 @@ bool wxDbGridTableBase::AssignDbTable(wxDbTable *tab, int count, bool takeOwners } m_keys.Empty(); m_data = tab; - //FIXME: Remove dynamic_cast before sumision to wxwin + //FIXME: Remove dynamic_cast before sumision to wxwin // if ((provider = dynamic_cast (GetAttrProvider()))) - // Using C casting for now until we can support dynamic_cast with wxWindows - if ((provider = (wxDbGridCellAttrProvider *)(GetAttrProvider()))) + // Using C casting for now until we can support dynamic_cast with wxWidgets + provider = (wxDbGridCellAttrProvider *)(GetAttrProvider()); + if (provider) { provider->AssignDbTable(m_data); } - + if (count == wxUSE_QUERY) { m_rowtotal = m_data ? m_data->Count() : 0; @@ -250,18 +251,14 @@ bool wxDbGridTableBase::AssignDbTable(wxDbTable *tab, int count, bool takeOwners wxGrid * grid = GetView(); wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rowtotal); grid->ProcessTableMessage(msg); - grid->EndBatch(); } m_dbowner = takeOwnership; m_rowmodified = false; return true; } -wxString wxDbGridTableBase::GetTypeName(int row, int col) +wxString wxDbGridTableBase::GetTypeName(int WXUNUSED(row), int col) { - if (col == 8) - int breakpoint = 1; - if (GetNumberCols() > col) { if (m_ColInfo[col].wxtypename == wxGRID_VALUE_DBAUTO) @@ -273,38 +270,32 @@ wxString wxDbGridTableBase::GetTypeName(int row, int col) switch(m_data->GetColDefs()[(m_ColInfo[col].DbCol)].SqlCtype) { case SQL_C_CHAR: +#ifdef SQL_C_WCHAR + case SQL_C_WCHAR: +#endif return wxGRID_VALUE_STRING; - break; + case SQL_C_SHORT: case SQL_C_SSHORT: return wxGRID_VALUE_NUMBER; - break; case SQL_C_USHORT: return wxGRID_VALUE_NUMBER; - break; + case SQL_C_LONG: case SQL_C_SLONG: return wxGRID_VALUE_NUMBER; - break; case SQL_C_ULONG: return wxGRID_VALUE_NUMBER; - break; case SQL_C_FLOAT: return wxGRID_VALUE_FLOAT; - break; case SQL_C_DOUBLE: return wxGRID_VALUE_FLOAT; - break; case SQL_C_DATE: return wxGRID_VALUE_DATETIME; - break; case SQL_C_TIME: return wxGRID_VALUE_DATETIME; - break; case SQL_C_TIMESTAMP: return wxGRID_VALUE_DATETIME; - break; default: return wxGRID_VALUE_STRING; - break; } } else @@ -328,23 +319,23 @@ bool wxDbGridTableBase::CanGetValueAs(int row, int col, const wxString& typeName return true; } - if (m_data->IsColNull(m_ColInfo[col].DbCol)) + if (m_data->IsColNull((UWORD)m_ColInfo[col].DbCol)) { return false; } if (m_data->GetNumberOfColumns() <= m_ColInfo[col].DbCol) { - //If a virtual column then we can't find it's type. we have to + //If a virtual column then we can't find it's type. we have to // return false to get using wxVariant. return false; } int sqltype = m_data->GetColDefs()[(m_ColInfo[col].DbCol)].SqlCtype; - + if (typeName == wxGRID_VALUE_DATETIME) { if ((sqltype == SQL_C_DATE) || - (sqltype == SQL_C_TIME) || + (sqltype == SQL_C_TIME) || (sqltype == SQL_C_TIMESTAMP)) { return true; @@ -354,7 +345,7 @@ bool wxDbGridTableBase::CanGetValueAs(int row, int col, const wxString& typeName if (typeName == wxGRID_VALUE_NUMBER) { if ((sqltype == SQL_C_SSHORT) || - (sqltype == SQL_C_USHORT) || + (sqltype == SQL_C_USHORT) || (sqltype == SQL_C_SLONG) || (sqltype == SQL_C_ULONG)) { @@ -365,7 +356,7 @@ bool wxDbGridTableBase::CanGetValueAs(int row, int col, const wxString& typeName if (typeName == wxGRID_VALUE_FLOAT) { if ((sqltype == SQL_C_SSHORT) || - (sqltype == SQL_C_USHORT) || + (sqltype == SQL_C_USHORT) || (sqltype == SQL_C_SLONG) || (sqltype == SQL_C_ULONG) || (sqltype == SQL_C_FLOAT) || @@ -378,16 +369,8 @@ bool wxDbGridTableBase::CanGetValueAs(int row, int col, const wxString& typeName return false; } -bool wxDbGridTableBase::CanSetValueAs(int row, int col, const wxString& typeName) +bool wxDbGridTableBase::CanSetValueAs(int WXUNUSED(row), int col, const wxString& typeName) { - //Is this needed? As will be validated on SetValueAsXXXX - ValidateRow(row); - - if (m_data->IsColNull(m_ColInfo[col].DbCol)) - { - return false; - } - if (typeName == wxGRID_VALUE_STRING) { //FIXME ummm What about blob field etc. @@ -401,7 +384,7 @@ bool wxDbGridTableBase::CanSetValueAs(int row, int col, const wxString& typeName if (m_data->GetNumberOfColumns() <= m_ColInfo[col].DbCol) { - //If a virtual column then we can't find it's type. we have to faulse to + //If a virtual column then we can't find it's type. we have to faulse to //get using wxVairent. return false; } @@ -410,7 +393,7 @@ bool wxDbGridTableBase::CanSetValueAs(int row, int col, const wxString& typeName if (typeName == wxGRID_VALUE_DATETIME) { if ((sqltype == SQL_C_DATE) || - (sqltype == SQL_C_TIME) || + (sqltype == SQL_C_TIME) || (sqltype == SQL_C_TIMESTAMP)) { return true; @@ -420,7 +403,7 @@ bool wxDbGridTableBase::CanSetValueAs(int row, int col, const wxString& typeName if (typeName == wxGRID_VALUE_NUMBER) { if ((sqltype == SQL_C_SSHORT) || - (sqltype == SQL_C_USHORT) || + (sqltype == SQL_C_USHORT) || (sqltype == SQL_C_SLONG) || (sqltype == SQL_C_ULONG)) { @@ -431,7 +414,7 @@ bool wxDbGridTableBase::CanSetValueAs(int row, int col, const wxString& typeName if (typeName == wxGRID_VALUE_FLOAT) { if ((sqltype == SQL_C_SSHORT) || - (sqltype == SQL_C_USHORT) || + (sqltype == SQL_C_USHORT) || (sqltype == SQL_C_SLONG) || (sqltype == SQL_C_ULONG) || (sqltype == SQL_C_FLOAT) || @@ -455,11 +438,11 @@ long wxDbGridTableBase::GetValueAsLong(int row, int col) } int sqltype = m_data->GetColDefs()[(m_ColInfo[col].DbCol)].SqlCtype; if ((sqltype == SQL_C_SSHORT) || - (sqltype == SQL_C_USHORT) || + (sqltype == SQL_C_USHORT) || (sqltype == SQL_C_SLONG) || (sqltype == SQL_C_ULONG)) { - wxVariant val = m_data->GetCol(m_ColInfo[col].DbCol); + wxVariant val = m_data->GetColumn(m_ColInfo[col].DbCol); return val.GetLong(); } wxFAIL_MSG (_T("unknown column, ")); @@ -478,13 +461,13 @@ double wxDbGridTableBase::GetValueAsDouble(int row, int col) } int sqltype = m_data->GetColDefs()[(m_ColInfo[col].DbCol)].SqlCtype; if ((sqltype == SQL_C_SSHORT) || - (sqltype == SQL_C_USHORT) || + (sqltype == SQL_C_USHORT) || (sqltype == SQL_C_SLONG) || (sqltype == SQL_C_ULONG) || (sqltype == SQL_C_FLOAT) || (sqltype == SQL_C_DOUBLE)) { - wxVariant val = m_data->GetCol(m_ColInfo[col].DbCol); + wxVariant val = m_data->GetColumn(m_ColInfo[col].DbCol); return val.GetDouble(); } wxFAIL_MSG (_T("unknown column")); @@ -503,11 +486,11 @@ bool wxDbGridTableBase::GetValueAsBool(int row, int col) } int sqltype = m_data->GetColDefs()[(m_ColInfo[col].DbCol)].SqlCtype; if ((sqltype == SQL_C_SSHORT) || - (sqltype == SQL_C_USHORT) || + (sqltype == SQL_C_USHORT) || (sqltype == SQL_C_SLONG) || (sqltype == SQL_C_ULONG)) { - wxVariant val = m_data->GetCol(m_ColInfo[col].DbCol); + wxVariant val = m_data->GetColumn(m_ColInfo[col].DbCol); return val.GetBool(); } wxFAIL_MSG (_T("unknown column, ")); @@ -518,13 +501,13 @@ void* wxDbGridTableBase::GetValueAsCustom(int row, int col, const wxString& type { wxLogDebug(wxT("GetValueAsCustom() on %i,%i"),row,col); ValidateRow(row); - + if (m_data->GetNumberOfColumns() <= m_ColInfo[col].DbCol) { wxFAIL_MSG (_T("You can not use GetValueAsCustom for virtual columns")); return NULL; } - if (m_data->IsColNull(m_ColInfo[col].DbCol)) + if (m_data->IsColNull((UWORD)m_ColInfo[col].DbCol)) return NULL; if (typeName == wxGRID_VALUE_DATETIME) @@ -536,7 +519,7 @@ void* wxDbGridTableBase::GetValueAsCustom(int row, int col, const wxString& type (sqltype == SQL_C_TIME) || (sqltype == SQL_C_TIMESTAMP)) { - wxVariant val = m_data->GetCol(m_ColInfo[col].DbCol); + wxVariant val = m_data->GetColumn(m_ColInfo[col].DbCol); return new wxDateTime(val.GetDateTime()); } } @@ -573,7 +556,7 @@ void wxDbGridTableBase::SetValueAsCustom(int row, int col, const wxString& typeN } wxVariant val(date); m_rowmodified = true; - m_data->SetCol(m_ColInfo[col].DbCol,val); + m_data->SetColumn(m_ColInfo[col].DbCol,val); } } wxFAIL_MSG (_T("unknown column data type")); @@ -596,19 +579,19 @@ bool wxDbGridTableBase::IsEmptyCell(int row, int col) wxLogDebug(wxT("IsEmtpyCell on %i,%i"),row,col); ValidateRow(row); - return m_data->IsColNull(m_ColInfo[col].DbCol); + return m_data->IsColNull((UWORD)m_ColInfo[col].DbCol); } wxString wxDbGridTableBase::GetValue(int row, int col) { wxLogDebug(wxT("GetValue() on %i,%i"),row,col); - + ValidateRow(row); - wxVariant val = m_data->GetCol(m_ColInfo[col].DbCol); + wxVariant val = m_data->GetColumn(m_ColInfo[col].DbCol); wxLogDebug(wxT("\tReturning \"%s\"\n"),val.GetString().c_str()); - - return val.GetString(); + + return val.GetString(); } @@ -620,7 +603,7 @@ void wxDbGridTableBase::SetValue(int row, int col,const wxString& value) wxVariant val(value); m_rowmodified = true; - m_data->SetCol(m_ColInfo[col].DbCol,val); + m_data->SetColumn(m_ColInfo[col].DbCol,val); } @@ -632,7 +615,7 @@ void wxDbGridTableBase::SetValueAsLong(int row, int col, long value) wxVariant val(value); m_rowmodified = true; - m_data->SetCol(m_ColInfo[col].DbCol,val); + m_data->SetColumn(m_ColInfo[col].DbCol,val); } @@ -644,7 +627,7 @@ void wxDbGridTableBase::SetValueAsDouble(int row, int col, double value) wxVariant val(value); m_rowmodified = true; - m_data->SetCol(m_ColInfo[col].DbCol,val); + m_data->SetColumn(m_ColInfo[col].DbCol,val); } @@ -657,13 +640,14 @@ void wxDbGridTableBase::SetValueAsBool(int row, int col, bool value) wxVariant val(value); m_rowmodified = true; - m_data->SetCol(m_ColInfo[col].DbCol,val); + m_data->SetColumn(m_ColInfo[col].DbCol,val); } void wxDbGridTableBase::ValidateRow(int row) { - wxLogDebug(wxT("ValidateRow(%i) currently on row (%i). Array count = %i"),row,m_row,m_keys.GetCount()); + wxLogDebug(wxT("ValidateRow(%i) currently on row (%i). Array count = %lu"), + row, m_row, (unsigned long)m_keys.GetCount()); if (row == m_row) return; @@ -696,7 +680,7 @@ void wxDbGridTableBase::ValidateRow(int row) m_data->SetKey(k); if (!m_data->QueryOnKeyFields()) { - wxDbLogExtendedErrorMsg("ODBC error during Query()\n\n", m_data->GetDb(),__FILE__,__LINE__); + wxDbLogExtendedErrorMsg(_T("ODBC error during Query()\n\n"), m_data->GetDb(),__TFILE__,__LINE__); } m_data->GetNext(); @@ -716,7 +700,7 @@ bool wxDbGridTableBase::Writeback() const bool result=true; wxLogDebug(wxT("\trow key unknown")); -// FIXME: this code requires dbtable support for record status +// FIXME: this code requires dbtable support for record status #if 0 switch (m_data->get_ModifiedStatus()) { @@ -736,10 +720,8 @@ bool wxDbGridTableBase::Writeback() const return result; } -#include - -WX_DEFINE_OBJARRAY(keyarray); +#include "wx/arrimpl.cpp" -#endif // #if wxUSE_NEW_GRID -#endif // #if wxUSE_ODBC +WX_DEFINE_EXPORTED_OBJARRAY(keyarray) +#endif // wxUSE_GRID && wxUSE_ODBC