From f21b2fd89d02837dfd0d195f8ff0f3f5640af017 Mon Sep 17 00:00:00 2001 From: George Tasker Date: Sun, 10 Jun 2001 17:12:56 +0000 Subject: [PATCH] Added code to show off wxDbGrid (contributed by Paul and Roger Gammans) in wxUSE_NEW_GRID is set to 1. If grid is not enabled, the program does not compile in the wxDbGrid portion of the sample Fixed a bug in the SetColDef() descriptions that had the Contribs column defined as a UCHAR but the SQL data type was set to be SQL_C_SHORT when it needed to be SQL_C_UTINYINT to match the size of the UCHAR data variable General code cleanup TRUE/FALSE changed to true/false Now uses new wxDbLogExtendedErrorMsg() function for reporting human readable ODBC errors git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10505 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/db/dbtest.cpp | 547 +++++++++++++++++++++++++----------------- samples/db/dbtest.h | 27 ++- samples/db/listdb.cpp | 26 +- samples/db/listdb.h | 2 +- 4 files changed, 366 insertions(+), 236 deletions(-) diff --git a/samples/db/dbtest.cpp b/samples/db/dbtest.cpp index 0cdf4bff85..f6dbb909f9 100644 --- a/samples/db/dbtest.cpp +++ b/samples/db/dbtest.cpp @@ -46,6 +46,14 @@ //extern wxDbList WXDLLEXPORT *PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */ +#if wxUSE_NEW_GRID +#include +#include +#include + +#define CHOICEINT +#endif + #include "dbtest.h" /* Header file for this demonstration program */ #include "listdb.h" /* Code to support the "Lookup" button on the editor dialog */ @@ -60,54 +68,14 @@ extern wxChar ListDB_Selection2[]; /* Used to return the second column value fo #endif -const char *GetExtendedDBErrorMsg(wxDb *pDb, char *ErrFile, int ErrLine) -{ - static wxString msg; - msg = wxT(""); - - wxString tStr; - - if (ErrFile || ErrLine) - { - msg += wxT("File: "); - msg += ErrFile; - msg += wxT(" Line: "); - tStr.Printf(wxT("%d"),ErrLine); - msg += tStr.c_str(); - msg += wxT("\n"); - } - - msg.Append (wxT("\nODBC errors:\n")); - msg += wxT("\n"); - - // Display errors for this connection - int i; - for (i = 0; i < DB_MAX_ERROR_HISTORY; i++) - { - if (pDb->errorList[i]) - { - msg.Append(pDb->errorList[i]); - if (wxStrcmp(pDb->errorList[i],wxT("")) != 0) - msg.Append(wxT("\n")); - // Clear the errmsg buffer so the next error will not - // end up showing the previous error that have occurred - wxStrcpy(pDb->errorList[i],wxT("")); - } - } - msg += wxT("\n"); - - return msg.c_str(); -} // GetExtendedDBErrorMsg - - bool DataTypeSupported(wxDb *pDb, SWORD datatype) { wxDbSqlTypeInfo sqlTypeInfo; - bool breakpoint = FALSE; + bool breakpoint = false; if (pDb->GetDataTypeInfo(datatype, sqlTypeInfo)) - breakpoint = TRUE; + breakpoint = true; return breakpoint; @@ -396,6 +364,9 @@ bool DatabaseDemoApp::OnInit() file_menu->Append(FILE_CREATE, wxT("&Create CONTACT table")); file_menu->Append(FILE_RECREATE_TABLE, wxT("&Recreate CONTACT table")); file_menu->Append(FILE_RECREATE_INDEXES, wxT("&Recreate CONTACT indexes")); +#if wxUSE_NEW_GRID + file_menu->Append(FILE_DBGRID_TABLE, wxT("&Open DB Grid example")); +#endif file_menu->Append(FILE_EXIT, wxT("E&xit")); wxMenu *edit_menu = new wxMenu; @@ -416,7 +387,7 @@ bool DatabaseDemoApp::OnInit() params.DirPath[0] = 0; // Show the frame - DemoFrame->Show(TRUE); + DemoFrame->Show(true); // Passing NULL for the SQL environment handle causes // the wxDbConnectInf constructor to obtain a handle @@ -440,7 +411,7 @@ bool DatabaseDemoApp::OnInit() if (!wxStrlen(params.ODBCSource)) { wxDELETE(DbConnectInf); - return(FALSE); + return(false); } DbConnectInf->SetDsn(params.ODBCSource); @@ -455,7 +426,7 @@ bool DatabaseDemoApp::OnInit() DemoFrame->BuildParameterDialog(NULL); wxDELETE(DbConnectInf); wxMessageBox(wxT("Now exiting program.\n\nRestart program to try any new settings."),wxT("Notice..."),wxOK | wxICON_INFORMATION); - return(FALSE); + return(false); } DemoFrame->BuildEditorDialog(); @@ -463,7 +434,7 @@ bool DatabaseDemoApp::OnInit() // Show the frame DemoFrame->Refresh(); - return TRUE; + return true; } // DatabaseDemoApp::OnInit() @@ -476,7 +447,7 @@ bool DatabaseDemoApp::ReadParamFile(Cparameters ¶ms) tStr.Printf(wxT("Unable to open the parameter file '%s' for reading.\n\nYou must specify the data source, user name, and\npassword that will be used and save those settings."),PARAM_FILENAME); wxMessageBox(tStr,wxT("File I/O Error..."),wxOK | wxICON_EXCLAMATION); - return FALSE; + return false; } wxChar buffer[1000+1]; @@ -498,7 +469,7 @@ bool DatabaseDemoApp::ReadParamFile(Cparameters ¶ms) fclose(paramFile); - return TRUE; + return true; } // DatabaseDemoApp::ReadParamFile() @@ -510,7 +481,7 @@ bool DatabaseDemoApp::WriteParamFile(Cparameters ¶ms) wxString tStr; tStr.Printf(wxT("Unable to write/overwrite '%s'."),PARAM_FILENAME); wxMessageBox(tStr,wxT("File I/O Error..."),wxOK | wxICON_EXCLAMATION); - return FALSE; + return false; } fputs(wxGetApp().params.ODBCSource, paramFile); @@ -523,13 +494,13 @@ bool DatabaseDemoApp::WriteParamFile(Cparameters ¶ms) fputc(wxT('\n'), paramFile); fclose(paramFile); - return TRUE; + return true; } // DatabaseDemoApp::WriteParamFile() void DatabaseDemoApp::CreateDataTable(bool recreate) { - bool Ok = TRUE; + bool Ok = true; if (recreate) Ok = (wxMessageBox(wxT("Any data currently residing in the table will be erased.\n\nAre you sure?"),wxT("Confirm"),wxYES_NO|wxICON_QUESTION) == wxYES); @@ -538,7 +509,7 @@ void DatabaseDemoApp::CreateDataTable(bool recreate) wxBeginBusyCursor(); - bool success = TRUE; + bool success = true; Contact->GetDb()->RollbackTrans(); // Make sure the current cursor is in a known/stable state @@ -546,10 +517,11 @@ void DatabaseDemoApp::CreateDataTable(bool recreate) { wxEndBusyCursor(); wxString tStr; - tStr = wxT("Error creating CONTACTS table.\nTable was not created.\n\n"); - tStr += GetExtendedDBErrorMsg(Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); - success = FALSE; + tStr = wxT("Error creating CONTACTS table.\nTable was not created.\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + + success = false; } else { @@ -557,10 +529,11 @@ void DatabaseDemoApp::CreateDataTable(bool recreate) { wxEndBusyCursor(); wxString tStr; - tStr = wxT("Error creating CONTACTS indexes.\nIndexes will be unavailable.\n\n"); - tStr += GetExtendedDBErrorMsg(Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); - success = FALSE; + tStr = wxT("Error creating CONTACTS indexes.\nIndexes will be unavailable.\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + + success = false; } } while (wxIsBusy()) @@ -575,6 +548,9 @@ BEGIN_EVENT_TABLE(DatabaseDemoFrame, wxFrame) EVT_MENU(FILE_CREATE, DatabaseDemoFrame::OnCreate) EVT_MENU(FILE_RECREATE_TABLE, DatabaseDemoFrame::OnRecreateTable) EVT_MENU(FILE_RECREATE_INDEXES, DatabaseDemoFrame::OnRecreateIndexes) +#if wxUSE_NEW_GRID + EVT_MENU(FILE_DBGRID_TABLE, DatabaseDemoFrame::OnDbGridTable) +#endif EVT_MENU(FILE_EXIT, DatabaseDemoFrame::OnExit) EVT_MENU(EDIT_PARAMETERS, DatabaseDemoFrame::OnEditParameters) EVT_MENU(HELP_ABOUT, DatabaseDemoFrame::OnAbout) @@ -603,13 +579,13 @@ DatabaseDemoFrame::~DatabaseDemoFrame() void DatabaseDemoFrame::OnCreate(wxCommandEvent& event) { - wxGetApp().CreateDataTable(FALSE); + wxGetApp().CreateDataTable(false); } // DatabaseDemoFrame::OnCreate() void DatabaseDemoFrame::OnRecreateTable(wxCommandEvent& event) { - wxGetApp().CreateDataTable(TRUE); + wxGetApp().CreateDataTable(true); } // DatabaseDemoFrame::OnRecreate() @@ -622,9 +598,10 @@ void DatabaseDemoFrame::OnRecreateIndexes(wxCommandEvent& event) while (wxIsBusy()) wxEndBusyCursor(); wxString tStr; - tStr = wxT("Error creating CONTACTS indexes.\nNew indexes will be unavailable.\n\n"); - tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + tStr = wxT("Error creating CONTACTS indexes.\nNew indexes will be unavailable.\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + } else wxMessageBox(wxT("Index(es) were successfully recreated."),wxT("Notice..."),wxOK | wxICON_INFORMATION); @@ -632,6 +609,17 @@ void DatabaseDemoFrame::OnRecreateIndexes(wxCommandEvent& event) } // DatabaseDemoFrame::OnRecreateIndexes() +#if wxUSE_NEW_GRID +void DatabaseDemoFrame::OnDbGridTable(wxCommandEvent& ) +{ + DbGridFrame *frame = new DbGridFrame(this); + if (frame->Initialize()) + { + frame->Show(); + } +} +#endif + void DatabaseDemoFrame::OnExit(wxCommandEvent& event) { Close(); @@ -764,7 +752,7 @@ void Ccontact::Initialize() JoinDate.second = 0; JoinDate.fraction = 0; NativeLanguage = langENGLISH; - IsDeveloper = FALSE; + IsDeveloper = false; Contributions = 0; LinesOfCode = 0L; } // Ccontact::Initialize @@ -777,9 +765,10 @@ Ccontact::~Ccontact() if (!wxDbFreeConnection(GetDb())) { wxString tStr; - tStr = wxT("Unable to Free the Ccontact data table handle\n\n"); - tStr += GetExtendedDBErrorMsg(GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + tStr = wxT("Unable to Free the Ccontact data table handle\n\n"); + + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); } } } // Ccontract destructor @@ -790,24 +779,24 @@ Ccontact::~Ccontact() * functions to interface to the data structure used to store records in * memory, and for all the column definitions that define the table structure */ -void Ccontact::SetupColumns() +void Ccontact::SetupColumns() { // NOTE: Columns now are 8 character names, as that is all dBase can support. Longer // names can be used for other database engines - SetColDefs ( 0,wxT("NAME"), DB_DATA_TYPE_VARCHAR, Name, SQL_C_CHAR, sizeof(Name), TRUE, TRUE); // Primary index - SetColDefs ( 1,wxT("ADDRESS1"), DB_DATA_TYPE_VARCHAR, Addr1, SQL_C_CHAR, sizeof(Addr1), FALSE,TRUE); - SetColDefs ( 2,wxT("ADDRESS2"), DB_DATA_TYPE_VARCHAR, Addr2, SQL_C_CHAR, sizeof(Addr2), FALSE,TRUE); - SetColDefs ( 3,wxT("CITY"), DB_DATA_TYPE_VARCHAR, City, SQL_C_CHAR, sizeof(City), FALSE,TRUE); - SetColDefs ( 4,wxT("STATE"), DB_DATA_TYPE_VARCHAR, State, SQL_C_CHAR, sizeof(State), FALSE,TRUE); - SetColDefs ( 5,wxT("POSTCODE"), DB_DATA_TYPE_VARCHAR, PostalCode, SQL_C_CHAR, sizeof(PostalCode), FALSE,TRUE); - SetColDefs ( 6,wxT("COUNTRY"), DB_DATA_TYPE_VARCHAR, Country, SQL_C_CHAR, sizeof(Country), FALSE,TRUE); - SetColDefs ( 7,wxT("JOINDATE"), DB_DATA_TYPE_DATE, &JoinDate, SQL_C_TIMESTAMP, sizeof(JoinDate), FALSE,TRUE); - SetColDefs ( 8,wxT("IS_DEV"), DB_DATA_TYPE_INTEGER, &IsDeveloper, SQL_C_BOOLEAN(IsDeveloper), sizeof(IsDeveloper), FALSE,TRUE); - SetColDefs ( 9,wxT("CONTRIBS"), DB_DATA_TYPE_INTEGER, &Contributions, SQL_C_USHORT, sizeof(Contributions), FALSE,TRUE); - SetColDefs (10,wxT("LINE_CNT"), DB_DATA_TYPE_INTEGER, &LinesOfCode, SQL_C_ULONG, sizeof(LinesOfCode), FALSE,TRUE); - SetColDefs (11,wxT("LANGUAGE"), DB_DATA_TYPE_INTEGER, &NativeLanguage, SQL_C_ENUM, sizeof(NativeLanguage), FALSE,TRUE); + SetColDefs ( 0,wxT("NAME"), DB_DATA_TYPE_VARCHAR, Name, SQL_C_CHAR, sizeof(Name), true, true); // Primary index + SetColDefs ( 1,wxT("ADDRESS1"), DB_DATA_TYPE_VARCHAR, Addr1, SQL_C_CHAR, sizeof(Addr1), false,true); + SetColDefs ( 2,wxT("ADDRESS2"), DB_DATA_TYPE_VARCHAR, Addr2, SQL_C_CHAR, sizeof(Addr2), false,true); + SetColDefs ( 3,wxT("CITY"), DB_DATA_TYPE_VARCHAR, City, SQL_C_CHAR, sizeof(City), false,true); + SetColDefs ( 4,wxT("STATE"), DB_DATA_TYPE_VARCHAR, State, SQL_C_CHAR, sizeof(State), false,true); + SetColDefs ( 5,wxT("POSTCODE"), DB_DATA_TYPE_VARCHAR, PostalCode, SQL_C_CHAR, sizeof(PostalCode), false,true); + SetColDefs ( 6,wxT("COUNTRY"), DB_DATA_TYPE_VARCHAR, Country, SQL_C_CHAR, sizeof(Country), false,true); + SetColDefs ( 7,wxT("JOINDATE"), DB_DATA_TYPE_DATE, &JoinDate, SQL_C_TIMESTAMP, sizeof(JoinDate), false,true); + SetColDefs ( 8,wxT("IS_DEV"), DB_DATA_TYPE_INTEGER, &IsDeveloper, SQL_C_BOOLEAN(IsDeveloper), sizeof(IsDeveloper), false,true); + SetColDefs ( 9,wxT("CONTRIBS"), DB_DATA_TYPE_INTEGER, &Contributions, SQL_C_UTINYINT, sizeof(Contributions), false,true); + SetColDefs (10,wxT("LINE_CNT"), DB_DATA_TYPE_INTEGER, &LinesOfCode, SQL_C_ULONG, sizeof(LinesOfCode), false,true); + SetColDefs (11,wxT("LANGUAGE"), DB_DATA_TYPE_INTEGER, &NativeLanguage, SQL_C_ENUM, sizeof(NativeLanguage), false,true); #if wxODBC_BLOB_EXPERIMENT > 0 - SetColDefs (12,wxT("PICTURE"), DB_DATA_TYPE_BLOB, Picture, SQL_LONGVARBINARY, sizeof(Picture), FALSE,TRUE); + SetColDefs (12,wxT("PICTURE"), DB_DATA_TYPE_BLOB, Picture, SQL_LONGVARBINARY, sizeof(Picture), false,true); #endif } // Ccontact::SetupColumns @@ -819,17 +808,17 @@ bool Ccontact::CreateIndexes(bool recreate) wxString indexName; wxDbIdxDef idxDef[2]; - bool Ok = TRUE; + bool Ok = true; wxStrcpy(idxDef[0].ColName, "IS_DEV"); - idxDef[0].Ascending = TRUE; + idxDef[0].Ascending = true; wxStrcpy(idxDef[1].ColName, "NAME"); - idxDef[1].Ascending = TRUE; + idxDef[1].Ascending = true; indexName = GetTableName(); indexName += "_IDX1"; - Ok = CreateIndex(indexName.c_str(), TRUE, 2, idxDef, recreate); + Ok = CreateIndex(indexName.c_str(), true, 2, idxDef, recreate); return Ok; } // Ccontact::CreateIndexes() @@ -847,7 +836,7 @@ bool Ccontact::FetchByName(const wxString &name) SetOrderByClause(wxT("")); if (!Query()) - return(FALSE); + return(false); // Fetch the record return(GetNext()); @@ -881,13 +870,13 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 0, 0, 537, 480) // Since the ::OnCommand() function is overridden, this prevents the widget // detection in ::OnCommand() until all widgets have been initialized to prevent // uninitialized pointers from crashing the program - widgetPtrsSet = FALSE; + widgetPtrsSet = false; - initialized = FALSE; + initialized = false; SetMode(mView); - Show(FALSE); + Show(false); } // CeditorDlg constructor @@ -1033,9 +1022,10 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) if (!wxGetApp().Contact->Query()) { wxString tStr; - tStr = wxT("ODBC error during Query()\n\n"); - tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + tStr = wxT("ODBC error during Query()\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + SetMode(mView); return; } @@ -1102,9 +1092,10 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) if (!wxGetApp().Contact->Query()) { wxString tStr; - tStr = wxT("ODBC error during Query()\n\n"); - tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + tStr = wxT("ODBC error during Query()\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + return; } // Display the first record from the query set @@ -1138,15 +1129,15 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) if (!wxGetApp().Contact->Query()) { wxString tStr; - tStr = wxT("ODBC error during Query()\n\n"); - tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + tStr = wxT("ODBC error during Query()\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); return; } if (!wxGetApp().Contact->GetNext()) wxGetApp().Contact->Initialize(); PutData(); - pResetBtn->Enable(FALSE); + pResetBtn->Enable(false); return; } // Reset button @@ -1163,7 +1154,7 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) /* wxChar *orderBy */ wxT("NAME"), /* wxDb *pDb */ wxGetApp().READONLY_DB, /* const wxString &defDir */ wxGetApp().DbConnectInf->GetDefaultDir(), - /* bool distinctValues */ TRUE); + /* bool distinctValues */ true); if (ListDB_Selection && wxStrlen(ListDB_Selection)) { @@ -1212,7 +1203,7 @@ bool CeditorDlg::Initialize() if (!wxGetApp().Contact) { wxMessageBox(wxT("Unable to instantiate an instance of Ccontact"),wxT("Error..."),wxOK | wxICON_EXCLAMATION); - return FALSE; + return false; } // Check if the table exists or not. If it doesn't, ask the user if they want to @@ -1222,19 +1213,16 @@ bool CeditorDlg::Initialize() wxGetApp().DbConnectInf->GetDefaultDir())) { wxString tStr; - tStr.Printf(wxT("Unable to open the table '%s'.\n\nTable may need to be created...?\n\n"),CONTACT_TABLE_NAME); - tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); - - bool createTable = (wxMessageBox(wxT("Do you wish to try to create/clear the CONTACTS table?"),wxT("Confirm"),wxYES_NO|wxICON_QUESTION) == wxYES); + tStr.Printf(wxT("Unable to open the table '%s'. The table may\nneed to be created.\n\nDo you wish to try to create/clear the table?\n\n"),CONTACT_TABLE_NAME); + bool createTable = (wxMessageBox(tStr.c_str(),wxT("Confirm"),wxYES_NO|wxICON_QUESTION) == wxYES); if (!createTable) { // Close(); - return FALSE; + return false; } else - wxGetApp().CreateDataTable(FALSE); + wxGetApp().CreateDataTable(false); } // Tables must be "opened" before anything other than creating/deleting table can be done @@ -1255,8 +1243,9 @@ bool CeditorDlg::Initialize() { wxString tStr; tStr.Printf(wxT("Unable to open the table '%s' (likely due to\ninsufficient privileges of the logged in user).\n\n"),CONTACT_TABLE_NAME); - tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); } else #endif @@ -1266,11 +1255,11 @@ bool CeditorDlg::Initialize() { wxString tStr; tStr.Printf(wxT("Unable to open the table '%s' as the table\ndoes not appear to exist in the tablespace available\nto the currently logged in user.\n\n"),CONTACT_TABLE_NAME); - tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); } - return FALSE; + return false; } // Build the dialog @@ -1331,7 +1320,7 @@ bool CeditorDlg::Initialize() // Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to // handle all widget processing - widgetPtrsSet = TRUE; + widgetPtrsSet = true; // Setup the orderBy and where clauses to return back a single record as the result set, // as there will only be one record being shown on the dialog at a time, this optimizes @@ -1359,15 +1348,15 @@ bool CeditorDlg::Initialize() wxGetApp().Contact->SetWhereClause(wxT("")); // Perform the Query to get the result set. - // NOTE: If there are no rows returned, that is a valid result, so Query() would return TRUE. - // Only if there is a database error will Query() come back as FALSE + // NOTE: If there are no rows returned, that is a valid result, so Query() would return true. + // Only if there is a database error will Query() come back as false if (!wxGetApp().Contact->Query()) { wxString tStr; - tStr = wxT("ODBC error during Query()\n\n"); - tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); - return FALSE; + tStr = wxT("ODBC error during Query()\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + return false; } // Since Query succeeded, now get the row that was returned @@ -1382,10 +1371,10 @@ bool CeditorDlg::Initialize() SetMode(mView); PutData(); - Show(TRUE); + Show(true); - initialized = TRUE; - return TRUE; + initialized = true; + return true; } // CeditorDlg::Initialize() @@ -1413,18 +1402,18 @@ void CeditorDlg::FieldsEditable() void CeditorDlg::SetMode(enum DialogModes m) { - bool edit = FALSE; + bool edit = false; mode = m; switch (mode) { case mCreate: case mEdit: - edit = TRUE; + edit = true; break; case mView: case mSearch: - edit = FALSE; + edit = false; break; default: break; @@ -1474,7 +1463,7 @@ bool CeditorDlg::PutData() pDeveloperRadio->SetSelection(wxGetApp().Contact->IsDeveloper); - return TRUE; + return true; } // Ceditor::PutData() @@ -1482,7 +1471,7 @@ bool CeditorDlg::PutData() * Reads the data out of all the widgets on the dialog. Some data evaluation is done * to ensure that there is a name entered and that the date field is valid. * - * A return value of TRUE means that valid data was retrieved from the dialog, otherwise + * A return value of true means that valid data was retrieved from the dialog, otherwise * invalid data was found (and a message was displayed telling the user what to fix), and * the data was not placed into the appropraite fields of Ccontact */ @@ -1495,16 +1484,16 @@ bool CeditorDlg::GetData() if (!wxStrcmp((const wxChar*) tStr,wxT(""))) { wxMessageBox(wxT("A name is required for entry into the contact table"),wxT("Notice..."),wxOK | wxICON_INFORMATION); - return FALSE; + return false; } - bool invalid = FALSE; + bool invalid = false; int mm,dd,yyyy; int first, second; tStr = pJoinDateTxt->GetValue(); if (tStr.Freq(wxT('/')) != 2) - invalid = TRUE; + invalid = true; // Find the month, day, and year tokens if (!invalid) @@ -1521,30 +1510,30 @@ bool CeditorDlg::GetData() // Force Year 2000 compliance if (!invalid && (yyyy < 1000)) - invalid = TRUE; + invalid = true; // Check the token ranges for validity if (!invalid) { if (yyyy > 9999) - invalid = TRUE; + invalid = true; else if ((mm < 1) || (mm > 12)) - invalid = TRUE; + invalid = true; else { if (dd < 1) - invalid = TRUE; + invalid = true; else { int days[12] = {31,28,31,30,31,30, 31,31,30,31,30,31}; if (dd > days[mm-1]) { - invalid = TRUE; + invalid = true; if ((dd == 29) && (mm == 2)) { if (((yyyy % 4) == 0) && (((yyyy % 100) != 0) || ((yyyy % 400) == 0))) - invalid = FALSE; + invalid = false; } } } @@ -1560,7 +1549,7 @@ bool CeditorDlg::GetData() else { wxMessageBox(wxT("Improper date format. Please check the date\nspecified and try again.\n\nNOTE: Dates are in american format (MM/DD/YYYY)"),wxT("Notice..."),wxOK | wxICON_INFORMATION); - return FALSE; + return false; } tStr = pNameTxt->GetValue(); @@ -1578,7 +1567,7 @@ bool CeditorDlg::GetData() wxGetApp().Contact->NativeLanguage = (enum Language) pNativeLangChoice->GetSelection(); wxGetApp().Contact->IsDeveloper = pDeveloperRadio->GetSelection() > 0; - return TRUE; + return true; } // CeditorDlg::GetData() @@ -1587,17 +1576,17 @@ bool CeditorDlg::GetData() * try to insert/update the data to the table based on the current 'mode' the dialog * is set to. * - * A return value of TRUE means the insert/update was completed successfully, a return - * value of FALSE means that Save() failed. If returning FALSE, then this function + * A return value of true means the insert/update was completed successfully, a return + * value of false means that Save() failed. If returning false, then this function * has displayed a detailed error message for the user. */ bool CeditorDlg::Save() { - bool failed = FALSE; + bool failed = false; // Read the data in the widgets of the dialog to get the user's data if (!GetData()) - failed = TRUE; + failed = true; // Perform any other required validations necessary before saving if (!failed) @@ -1616,17 +1605,17 @@ bool CeditorDlg::Save() if (result == DB_ERR_INTEGRITY_CONSTRAINT_VIOL) { wxString tStr; - tStr = wxT("A duplicate key value already exists in the table.\nUnable to save record\n\n"); - tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + tStr = wxT("A duplicate key value already exists in the table.\nUnable to save record\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); } else { // Some other unexpected error occurred wxString tStr; - tStr = wxT("Database insert failed\n\n"); - tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + tStr = wxT("Database insert failed\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); } } } @@ -1637,10 +1626,10 @@ bool CeditorDlg::Save() if (!wxGetApp().Contact->UpdateWhere(wxGetApp().Contact->whereStr)) { wxString tStr; - tStr = wxT("Database update failed\n\n"); - tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); - failed = TRUE; + tStr = wxT("Database update failed\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + failed = true; } } @@ -1744,20 +1733,20 @@ bool CeditorDlg::GetRec(const wxString &whereStr) if (!wxGetApp().Contact->Query()) { wxString tStr; - tStr = wxT("ODBC error during Query()\n\n"); - tStr += GetExtendedDBErrorMsg(wxGetApp().Contact->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + tStr = wxT("ODBC error during Query()\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); - return(FALSE); + return(false); } if (wxGetApp().Contact->GetNext()) { PutData(); - return(TRUE); + return(true); } else - return(FALSE); + return(false); } // CeditorDlg::GetRec() @@ -1777,7 +1766,7 @@ CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialog (parent, PARAMETER_DIA // Since the ::OnCommand() function is overridden, this prevents the widget // detection in ::OnCommand() until all widgets have been initialized to prevent // uninitialized pointers from crashing the program - widgetPtrsSet = FALSE; + widgetPtrsSet = false; pParamODBCSourceMsg = new wxStaticText(this, PARAMETER_DIALOG_SOURCE_MSG, wxT("ODBC data sources:"), wxPoint( 10, 10), wxSize( -1, -1), 0, wxT("ParamODBCSourceMsg")); pParamODBCSourceList = new wxListBox(this, PARAMETER_DIALOG_SOURCE_LISTBOX, wxPoint( 10, 29), wxSize(285, 150), 0, 0, wxLB_SINGLE|wxLB_ALWAYS_SB, wxDefaultValidator, wxT("ParamODBCSourceList")); @@ -1792,9 +1781,9 @@ CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialog (parent, PARAMETER_DIA // Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to // handle all widget processing - widgetPtrsSet = TRUE; + widgetPtrsSet = true; - saved = FALSE; + saved = false; savedParamSettings = wxGetApp().params; Centre(wxBOTH); @@ -1826,7 +1815,7 @@ void CparameterDlg::OnCloseWindow(wxCloseEvent& event) while (wxIsBusy()) wxEndBusyCursor(); - Show(FALSE); + Show(false); SetReturnCode(0); // added so BoundsChecker would not report use of uninitialized variable this->Destroy(); @@ -1858,7 +1847,7 @@ void CparameterDlg::OnCommand(wxWindow& win, wxCommandEvent& event) if (GetParent() != NULL) // The parameter dialog was not called during startup due to a missing cfg file tStr += wxT("\nNew parameters will take effect the next time the program is started."); wxMessageBox(tStr,wxT("Notice..."),wxOK | wxICON_INFORMATION); - saved = TRUE; + saved = true; Close(); } return; @@ -1883,7 +1872,7 @@ bool CparameterDlg::PutData() pParamUserNameTxt->SetValue(wxGetApp().params.UserName); pParamPasswordTxt->SetValue(wxGetApp().params.Password); pParamDirPathTxt->SetValue(wxGetApp().params.DirPath); - return TRUE; + return true; } // CparameterDlg::PutData() @@ -1898,12 +1887,12 @@ bool CparameterDlg::GetData() wxString errmsg; errmsg.Printf(wxT("ODBC Data source name is longer than the data structure to hold it.\n'Cparameter.ODBCSource' must have a larger character array\nto handle a data source with this long of a name\n\nThe data source currently selected is %d characters long."),tStr.Length()); wxMessageBox(errmsg,wxT("Internal program error..."),wxOK | wxICON_EXCLAMATION); - return FALSE; + return false; } wxStrcpy(wxGetApp().params.ODBCSource, tStr); } else - return FALSE; + return false; tStr = pParamUserNameTxt->GetValue(); if (tStr.Length() > (sizeof(wxGetApp().params.UserName)-1)) @@ -1911,7 +1900,7 @@ bool CparameterDlg::GetData() wxString errmsg; errmsg.Printf(wxT("User name is longer than the data structure to hold it.\n'Cparameter.UserName' must have a larger character array\nto handle a data source with this long of a name\n\nThe user name currently specified is %d characters long."),tStr.Length()); wxMessageBox(errmsg,wxT("Internal program error..."),wxOK | wxICON_EXCLAMATION); - return FALSE; + return false; } wxStrcpy(wxGetApp().params.UserName, tStr); @@ -1921,7 +1910,7 @@ bool CparameterDlg::GetData() wxString errmsg; errmsg.Printf(wxT("Password is longer than the data structure to hold it.\n'Cparameter.Password' must have a larger character array\nto handle a data source with this long of a name\n\nThe password currently specified is %d characters long."),tStr.Length()); wxMessageBox(errmsg,wxT("Internal program error..."),wxOK | wxICON_EXCLAMATION); - return FALSE; + return false; } wxStrcpy(wxGetApp().params.Password,tStr); @@ -1932,10 +1921,10 @@ bool CparameterDlg::GetData() wxString errmsg; errmsg.Printf(wxT("DirPath is longer than the data structure to hold it.\n'Cparameter.DirPath' must have a larger character array\nto handle a data source with this long of a name\n\nThe password currently specified is %d characters long."),tStr.Length()); wxMessageBox(errmsg,wxT("Internal program error..."),wxOK | wxICON_EXCLAMATION); - return FALSE; + return false; } wxStrcpy(wxGetApp().params.DirPath,tStr); - return TRUE; + return true; } // CparameterDlg::GetData() @@ -1946,12 +1935,12 @@ bool CparameterDlg::Save() if (!GetData()) { wxGetApp().params = savedParamSettings; - return FALSE; + return false; } wxGetApp().WriteParamFile(wxGetApp().params); - return TRUE; + return true; } // CparameterDlg::Save() @@ -1993,7 +1982,7 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDb *pDb, wxChar *tblName[], colInf = 0; dbTable = 0; masterTableName = tblName[0]; - widgetPtrsSet = FALSE; + widgetPtrsSet = false; pDB = pDb; // Initialize the WHERE clause from the string passed in @@ -2044,7 +2033,7 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDb *pDb, wxChar *tblName[], pQueryHintGrp = new wxStaticBox(this, QUERY_DIALOG_HINT_GROUP, wxT(""), wxPoint( 10, 291), wxSize(377, 40), 0, wxT("QueryHintGrp")); pQueryHintMsg = new wxStaticText(this, QUERY_DIALOG_HINT_MSG, wxT(""), wxPoint( 16, 306), wxSize( -1, -1), 0, wxT("QueryHintMsg")); - widgetPtrsSet = TRUE; + widgetPtrsSet = true; // Initialize the dialog wxString qualName; pQueryCol2Choice->Append(wxT("VALUE -->")); @@ -2054,9 +2043,9 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDb *pDb, wxChar *tblName[], { wxEndBusyCursor(); wxString tStr; - tStr = wxT("ODBC error during GetColumns()\n\n"); - tStr += GetExtendedDBErrorMsg(pDb,__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + tStr = wxT("ODBC error during GetColumns()\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); return; } @@ -2082,8 +2071,8 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDb *pDb, wxChar *tblName[], pQueryCol2Choice->SetSelection(0); pQueryOperatorChoice->SetSelection(0); - pQueryValue2Msg->Show(FALSE); - pQueryValue2Txt->Show(FALSE); + pQueryValue2Msg->Show(false); + pQueryValue2Txt->Show(false); pQueryHintMsg->SetLabel(langQRY_EQ); @@ -2155,8 +2144,8 @@ void CqueryDlg::OnCommand(wxWindow& win, wxCommandEvent& event) } // Hide the value2 widget - pQueryValue2Msg->Show(FALSE); // BETWEEN will show this widget - pQueryValue2Txt->Show(FALSE); // BETWEEN will show this widget + pQueryValue2Msg->Show(false); // BETWEEN will show this widget + pQueryValue2Txt->Show(false); // BETWEEN will show this widget // Disable the NOT operator for <, <=, >, >= switch((qryOp) pQueryOperatorChoice->GetSelection()) @@ -2166,10 +2155,10 @@ void CqueryDlg::OnCommand(wxWindow& win, wxCommandEvent& event) case qryOpLE: case qryOpGE: pQueryNotCheck->SetValue(0); - pQueryNotCheck->Enable(FALSE); + pQueryNotCheck->Enable(false); break; default: - pQueryNotCheck->Enable(TRUE); + pQueryNotCheck->Enable(true); break; } @@ -2181,16 +2170,16 @@ void CqueryDlg::OnCommand(wxWindow& win, wxCommandEvent& event) case qryOpGT: case qryOpLE: case qryOpGE: - pQueryCol2Choice->Enable(TRUE); + pQueryCol2Choice->Enable(true); if (pQueryCol2Choice->GetSelection()) // Column name is highlighted { - pQueryValue1Msg->Show(FALSE); - pQueryValue1Txt->Show(FALSE); + pQueryValue1Msg->Show(false); + pQueryValue1Txt->Show(false); } else // "Value" is highlighted { - pQueryValue1Msg->Show(TRUE); - pQueryValue1Txt->Show(TRUE); + pQueryValue1Msg->Show(true); + pQueryValue1Txt->Show(true); pQueryValue1Txt->SetFocus(); } break; @@ -2198,18 +2187,18 @@ void CqueryDlg::OnCommand(wxWindow& win, wxCommandEvent& event) case qryOpCONTAINS: case qryOpLIKE: pQueryCol2Choice->SetSelection(0); - pQueryCol2Choice->Enable(FALSE); - pQueryValue1Msg->Show(TRUE); - pQueryValue1Txt->Show(TRUE); + pQueryCol2Choice->Enable(false); + pQueryValue1Msg->Show(true); + pQueryValue1Txt->Show(true); pQueryValue1Txt->SetFocus(); break; case qryOpBETWEEN: pQueryCol2Choice->SetSelection(0); - pQueryCol2Choice->Enable(FALSE); - pQueryValue2Msg->Show(TRUE); - pQueryValue2Txt->Show(TRUE); - pQueryValue1Msg->Show(TRUE); - pQueryValue1Txt->Show(TRUE); + pQueryCol2Choice->Enable(false); + pQueryValue2Msg->Show(true); + pQueryValue2Txt->Show(true); + pQueryValue1Msg->Show(true); + pQueryValue1Txt->Show(true); pQueryValue1Txt->SetFocus(); break; } @@ -2223,13 +2212,13 @@ void CqueryDlg::OnCommand(wxWindow& win, wxCommandEvent& event) { if (pQueryCol2Choice->GetSelection()) // Column name is highlighted { - pQueryValue1Msg->Show(FALSE); - pQueryValue1Txt->Show(FALSE); + pQueryValue1Msg->Show(false); + pQueryValue1Txt->Show(false); } else // "Value" is highlighted { - pQueryValue1Msg->Show(TRUE); - pQueryValue1Txt->Show(TRUE); + pQueryValue1Msg->Show(true); + pQueryValue1Txt->Show(true); pQueryValue1Txt->SetFocus(); } return; @@ -2323,7 +2312,7 @@ void CqueryDlg::OnCloseWindow(wxCloseEvent& event) while (wxIsBusy()) wxEndBusyCursor(); - Show(FALSE); + Show(false); SetReturnCode(1); // added so BoundsChecker would not report use of uninitialized variable this->Destroy(); @@ -2402,12 +2391,12 @@ void CqueryDlg::ProcessAddBtn() int col1Idx = pQueryCol1Choice->GetSelection(); - bool quote = FALSE; + bool quote = false; if (colInf[col1Idx].sqlDataType == SQL_VARCHAR || oper == qryOpBEGINS || oper == qryOpCONTAINS || oper == qryOpLIKE) - quote = TRUE; + quote = true; if (pQueryCol2Choice->GetSelection()) // Column name s += pQueryCol2Choice->GetStringSelection(); @@ -2457,9 +2446,9 @@ void CqueryDlg::ProcessCountBtn() if (!dbTable->Open()) { wxString tStr; - tStr = wxT("ODBC error during Open()\n\n"); - tStr += GetExtendedDBErrorMsg(dbTable->GetDb(),__FILE__,__LINE__); - wxMessageBox(tStr,wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + tStr = wxT("ODBC error during Open()\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); return; } } @@ -2504,14 +2493,14 @@ bool CqueryDlg::ValidateWhereClause() if (where.Freq(wxT('(')) != where.Freq(wxT(')'))) { wxMessageBox(wxT("There are mismatched parenthesis in the constructed where clause"),wxT("Error..."),wxOK | wxICON_EXCLAMATION); - return(FALSE); + return(false); } // After a wxMessageBox, the focus does not necessarily return to the // window which was the focus when the message box popped up, so return // focus to the Query dialog for certain SetFocus(); - return(TRUE); + return(true); } // CqueryDlg::ValidateWhereClause() @@ -2520,7 +2509,7 @@ bool CqueryDlg::ValidateWhereClause() void DisplayDbDiagnostics(wxDb *pDb) { wxString s, t; - bool comma = FALSE; + bool comma = false; s = langDBINF_DB_NAME; s += pDb->dbInf.dbmsName; @@ -2662,7 +2651,7 @@ void DisplayDbDiagnostics(wxDb *pDb) } s += "\n"; - comma = FALSE; + comma = false; s += langDBINF_TXN_ISOLATION_OPTS; if (pDb->dbInf.txnIsolationOptions & SQL_TXN_READ_UNCOMMITTED) {s += langDBINF_READ_UNCOMMITTED; comma++;} @@ -2678,7 +2667,7 @@ void DisplayDbDiagnostics(wxDb *pDb) #endif s += "\n"; - comma = FALSE; + comma = false; s += langDBINF_FETCH_DIRS; if (pDb->dbInf.fetchDirections & SQL_FD_FETCH_NEXT) {s += langDBINF_NEXT; comma++;} @@ -2700,7 +2689,7 @@ void DisplayDbDiagnostics(wxDb *pDb) {if (comma++) s += ", "; s += langDBINF_BOOKMARK;} s += "\n"; - comma = FALSE; + comma = false; s += langDBINF_LOCK_TYPES; if (pDb->dbInf.lockTypes & SQL_LCK_NO_CHANGE) {s += langDBINF_NO_CHANGE; comma++;} @@ -2710,7 +2699,7 @@ void DisplayDbDiagnostics(wxDb *pDb) {if (comma++) s += ", "; s += langDBINF_UNLOCK;} s += "\n"; - comma = FALSE; + comma = false; s += langDBINF_POS_OPERS; if (pDb->dbInf.posOperations & SQL_POS_POSITION) {s += langDBINF_POSITION; comma++;} @@ -2724,7 +2713,7 @@ void DisplayDbDiagnostics(wxDb *pDb) {if (comma++) s += ", "; s += langDBINF_ADD;} s += "\n"; - comma = FALSE; + comma = false; s += langDBINF_POS_STMTS; if (pDb->dbInf.posStmts & SQL_PS_POSITIONED_DELETE) {s += langDBINF_POS_DEL; comma++;} @@ -2734,7 +2723,7 @@ void DisplayDbDiagnostics(wxDb *pDb) {if (comma++) s += ", "; s += langDBINF_SELECT_FOR_UPD;} s += "\n"; - comma = FALSE; + comma = false; s += langDBINF_SCROLL_CONCURR; if (pDb->dbInf.scrollConcurrency & SQL_SCCO_READ_ONLY) {s += langDBINF_READ_ONLY; comma++;} @@ -2746,7 +2735,7 @@ void DisplayDbDiagnostics(wxDb *pDb) {if (comma++) s += ", "; s += langDBINF_OPT_VALUES;} s += "\n"; - comma = FALSE; + comma = false; s += langDBINF_SCROLL_OPTS; if (pDb->dbInf.scrollOptions & SQL_SO_FORWARD_ONLY) {s += langDBINF_FWD_ONLY; comma++;} @@ -2760,7 +2749,7 @@ void DisplayDbDiagnostics(wxDb *pDb) {if (comma++) s += ", "; s += langDBINF_MIXED;} s += "\n"; - comma = FALSE; + comma = false; s += langDBINF_STATIC_SENS; if (pDb->dbInf.staticSensitivity & SQL_SS_ADDITIONS) {s += langDBINF_ADDITIONS; comma++;} @@ -2849,14 +2838,130 @@ void DisplayDbDiagnostics(wxDb *pDb) } // DisplayDbDiagnostics() +#if wxUSE_NEW_GRID + +BEGIN_EVENT_TABLE(DbGridFrame, wxFrame) + // EVT_CLOSE(DbGridFrame::OnCloseWindow) +END_EVENT_TABLE() + + +DbGridFrame::DbGridFrame(wxWindow *parent) + : wxFrame (parent, -1, wxT("Database Table"), + wxDefaultPosition, wxSize(400, 325)) +{ + initialized = false; +} + + +void DbGridFrame::OnCloseWindow(wxCloseEvent& event) +{ + this->Destroy(); +} + + +bool DbGridFrame::Initialize() +{ + wxGrid *grid = new wxGrid(this, -1, wxDefaultPosition); + + grid->RegisterDataType(wxGRID_VALUE_DATETIME, + new wxGridCellDateTimeRenderer(_T("%d %b %Y")), + new wxGridCellTextEditor); +#ifdef CHOICEINT + grid->RegisterDataType(wxGRID_VALUE_CHOICEINT, + new wxGridCellEnumRenderer, + new wxGridCellEnumEditor); + + wxString NativeLangChoice( wxString::Format("%s:%s,%s,%s,%s,%s",wxGRID_VALUE_CHOICEINT, + wxT("English"), + wxT("French"), + wxT("German"), + wxT("Spanish"), + wxT("Other") )); +#endif + + // Columns must match the sequence specified in SetColDef() calls + wxDbGridColInfo* cols = + new wxDbGridColInfo( 0,wxGRID_VALUE_STRING,wxT("Name"), + new wxDbGridColInfo( 1,wxGRID_VALUE_STRING,wxT("Address 1"), + new wxDbGridColInfo( 2,wxGRID_VALUE_STRING,wxT("Address 2"), + new wxDbGridColInfo( 3,wxGRID_VALUE_STRING,wxT("City"), + new wxDbGridColInfo( 4,wxGRID_VALUE_STRING,wxT("State"), + new wxDbGridColInfo( 5,wxGRID_VALUE_STRING,wxT("PostCode"), + new wxDbGridColInfo( 6,wxGRID_VALUE_STRING,wxT("Country"), + new wxDbGridColInfo( 7,wxGRID_VALUE_DBAUTO,wxT("Join Date"), + new wxDbGridColInfo( 8,wxGRID_VALUE_BOOL, wxT("Developer"), + new wxDbGridColInfo( 9,wxGRID_VALUE_NUMBER,wxT("Contributions"), + new wxDbGridColInfo(10,wxGRID_VALUE_NUMBER,wxT("Lines Of Code"), +#ifdef CHOICEINT + new wxDbGridColInfo(11,NativeLangChoice, wxT("Native Language"),NULL)))))))))))); +#else + new wxDbGridColInfo(11,wxGRID_VALUE_NUMBER,wxT("Native Language"),NULL)))))))))))); +#endif + + Ccontact *Contact = new Ccontact(); + //wxGetApp().Contact + + if (!Contact) + { + wxMessageBox(wxT("Unable to instantiate an instance of Ccontact"), wxT("Error..."), wxOK | wxICON_EXCLAMATION); + return false; + } + + if (!Contact->Open()) + { + if (Contact->GetDb()->TableExists(CONTACT_TABLE_NAME, Contact->GetDb()->GetUsername(), + wxGetApp().DbConnectInf->GetDefaultDir())) + { + wxString tStr; + tStr.Printf(wxT("Unable to open the table '%s'.\n\n"),CONTACT_TABLE_NAME); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + } + + return false; + } + + // Execute the following query using the cursor designated + // for full table query + Contact->SetRowMode(wxDbTable::WX_ROW_MODE_QUERY); + + if (!Contact->Query()) + { + wxString tStr; + tStr = wxT("ODBC error during Query()\n\n"); + wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__FILE__,__LINE__), + wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION); + return false; + } + + // No data has been read in from the database yet, so + // we need to initialize the data members to valid values + // so Fit() can correctly size the grid + Contact->Initialize(); + + wxDbGridTableBase* db = new wxDbGridTableBase(Contact, cols, wxUSE_QUERY, true); + + delete cols; + + grid->SetTable(db,true); + grid->SetMargins(0, 0); + grid->Fit(); + wxSize size = grid->GetSize(); + size.x += 10; + size.y += 10; + SetClientSize(size); + initialized = true; + return true; +} // DbGridFrame::Initialize() +#endif // #if wxUSE_NEW_GRID /* TEST CODE FOR TESTING THE wxDbCreateDataSource() FUNCTION int result = 0; - result = wxDbCreateDataSource(wxT("Microsoft Access Driver (*.mdb)"),wxT("GLT-TEST2"),wxT("GLT-Descrip"),FALSE,wxT(""),this); + result = wxDbCreateDataSource(wxT("Microsoft Access Driver (*.mdb)"),wxT("GLT-TEST2"),wxT("GLT-Descrip"),false,wxT(""),this); if (!result) { // check for errors caused by ConfigDSN based functions diff --git a/samples/db/dbtest.h b/samples/db/dbtest.h index d6bde8d91d..4e19c5a3db 100644 --- a/samples/db/dbtest.h +++ b/samples/db/dbtest.h @@ -22,6 +22,9 @@ enum DialogModes {mView,mCreate,mEdit,mSearch}; #define FILE_CREATE 100 #define FILE_RECREATE_TABLE 110 #define FILE_RECREATE_INDEXES 120 +#if wxUSE_NEW_GRID +#define FILE_DBGRID_TABLE 130 +#endif #define FILE_EXIT 199 #define EDIT_PARAMETERS 200 #define HELP_ABOUT 300 @@ -166,7 +169,10 @@ class DatabaseDemoFrame: public wxFrame void OnExit(wxCommandEvent& event); void OnEditParameters(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); - +#if wxUSE_NEW_GRID + void OnDbGridTable( wxCommandEvent& ); +#endif + void CreateDataTable(bool recreate); void BuildEditorDialog(); void BuildParameterDialog(wxWindow *parent); @@ -174,6 +180,25 @@ DECLARE_EVENT_TABLE() }; // DatabaseDemoFrame +#if wxUSE_NEW_GRID + +// *************************** DBGridFrame *************************** + +class DbGridFrame : public wxFrame +{ +public: + bool initialized; + + DbGridFrame(wxWindow *parent); + + void OnCloseWindow(wxCloseEvent& event); + bool Initialize(); + + DECLARE_EVENT_TABLE() +}; + +#endif + // Define a new application type class DatabaseDemoApp: public wxApp { diff --git a/samples/db/listdb.cpp b/samples/db/listdb.cpp index 163a0ae414..fb68ff5be0 100644 --- a/samples/db/listdb.cpp +++ b/samples/db/listdb.cpp @@ -135,7 +135,7 @@ Clookup::Clookup(wxChar *tblName, wxChar *colName, wxDb *pDb, const wxString &de defDir) { - SetColDefs (0, colName, DB_DATA_TYPE_VARCHAR, lookupCol, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE); + SetColDefs (0, colName, DB_DATA_TYPE_VARCHAR, lookupCol, SQL_C_CHAR, LOOKUP_COL_LEN+1, false, false); } // Clookup() @@ -153,10 +153,10 @@ Clookup2::Clookup2(wxChar *tblName, wxChar *colName1, wxChar *colName2, int i = 0; - SetColDefs (i, colName1, DB_DATA_TYPE_VARCHAR, lookupCol1, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE); + SetColDefs (i, colName1, DB_DATA_TYPE_VARCHAR, lookupCol1, SQL_C_CHAR, LOOKUP_COL_LEN+1, false, false); if (wxStrlen(colName2) > 0) - SetColDefs (++i, colName2, DB_DATA_TYPE_VARCHAR, lookupCol2, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE); + SetColDefs (++i, colName2, DB_DATA_TYPE_VARCHAR, lookupCol2, SQL_C_CHAR, LOOKUP_COL_LEN+1, false, false); } // Clookup2() @@ -177,7 +177,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, wxChar *windowTitle, wxChar *tableName, wxBeginBusyCursor(); wxStrcpy(ListDB_Selection,wxT("")); - widgetPtrsSet = FALSE; + widgetPtrsSet = false; lookup = 0; lookup2 = 0; noDisplayCols = 1; @@ -187,7 +187,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, wxChar *windowTitle, wxChar *tableName, pLookUpOkBtn = new wxButton(this, LOOKUP_DIALOG_OK, wxT("&Ok"), wxPoint(113, 222), wxSize( 70, 35), 0, wxDefaultValidator, wxT("LookUpOkBtn")); pLookUpCancelBtn = new wxButton(this, LOOKUP_DIALOG_CANCEL, wxT("C&ancel"), wxPoint(212, 222), wxSize( 70, 35), 0, wxDefaultValidator, wxT("LookUpCancelBtn")); - widgetPtrsSet = TRUE; + widgetPtrsSet = true; // Query the lookup table and display the result set lookup = new Clookup(tableName, colName, pDb, defDir); @@ -229,7 +229,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, wxChar *windowTitle, wxChar *tableName, else { pLookUpCancelBtn->SetDefault(); - pLookUpOkBtn->Enable(FALSE); + pLookUpOkBtn->Enable(false); } // Display the dialog window @@ -275,7 +275,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, wxChar *windowTitle, wxChar *tableName, wxStrcpy(ListDB_Selection,wxT("")); wxStrcpy(ListDB_Selection2,wxT("")); - widgetPtrsSet = FALSE; + widgetPtrsSet = false; lookup = 0; lookup2 = 0; noDisplayCols = (wxStrlen(dispCol2) ? 2 : 1); @@ -292,7 +292,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, wxChar *windowTitle, wxChar *tableName, pLookUpOkBtn = new wxButton(this, LOOKUP_DIALOG_OK, wxT("&Ok"), wxPoint(113, 222), wxSize(70, 35), 0, wxDefaultValidator, wxT("LookUpOkBtn")); pLookUpCancelBtn = new wxButton(this, LOOKUP_DIALOG_CANCEL, wxT("C&ancel"), wxPoint(212, 222), wxSize(70, 35), 0, wxDefaultValidator, wxT("LookUpCancelBtn")); - widgetPtrsSet = TRUE; + widgetPtrsSet = true; // Query the lookup table and display the result set lookup2 = new Clookup2(tableName, dispCol1, dispCol2, pDb, defDir); @@ -359,7 +359,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, wxChar *windowTitle, wxChar *tableName, { lookup2->SetOrderByClause(orderBy); lookup2->SetWhereClause(where); - if (!lookup2->Query(FALSE, distinctValues)) + if (!lookup2->Query(false, distinctValues)) { wxMessageBox(wxT("ODBC error during Query()"),wxT("ODBC Error...")); Close(); @@ -389,7 +389,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, wxChar *windowTitle, wxChar *tableName, else { pLookUpCancelBtn->SetDefault(); - pLookUpOkBtn->Enable(FALSE); + pLookUpOkBtn->Enable(false); } pLookUpOkBtn->Enable(allowOk); @@ -405,8 +405,8 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, wxChar *windowTitle, wxChar *tableName, void ClookUpDlg::OnClose(wxCloseEvent& event) { - widgetPtrsSet = FALSE; - GetParent()->Enable(TRUE); + widgetPtrsSet = false; + GetParent()->Enable(true); if (lookup) delete lookup; @@ -418,7 +418,7 @@ void ClookUpDlg::OnClose(wxCloseEvent& event) while (wxIsBusy()) wxEndBusyCursor(); event.Skip(); -// return TRUE; +// return true; } // ClookUpDlg::OnClose diff --git a/samples/db/listdb.h b/samples/db/listdb.h index 82897c2bb2..422889e095 100644 --- a/samples/db/listdb.h +++ b/samples/db/listdb.h @@ -113,7 +113,7 @@ class ClookUpDlg : public wxDialog bool distinctValues, // e.g. SELECT DISTINCT ... wxChar *selectStmt = 0, // If you wish to query by SQLstmt (complicated lookups) int maxLenCol1 = 0, // Mandatory if querying by SQLstmt - bool allowOk = TRUE); // is the OK button enabled + bool allowOk = true); // is the OK button enabled void OnButton( wxCommandEvent &event ); void OnCommand(wxWindow& win, wxCommandEvent& event); -- 2.45.2