X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8853b9a80e58b01a77700cb28c560ba3c1b033ce..97636f1013cfd0ddc1cb7f59353b05aee0ad54ff:/samples/db/dbtest.cpp diff --git a/samples/db/dbtest.cpp b/samples/db/dbtest.cpp index 04fc85e12c..b5d0cbc3d2 100644 --- a/samples/db/dbtest.cpp +++ b/samples/db/dbtest.cpp @@ -41,23 +41,22 @@ #include "db.xpm" #endif -#include // Included strictly for reading the text file with the database parameters +#include /* Included strictly for reading the text file with the database parameters */ -#include // Required in the file which will get the data source connection -#include // Has the wxTable object from which all data objects will inherit their data table functionality +#include /* Required in the file which will get the data source connection */ +#include /* Has the wxTable object from which all data objects will inherit their data table functionality */ -extern DbList* WXDLLEXPORT PtrBegDbList; // from db.cpp, used in getting back error results from db connections +extern DbList* WXDLLEXPORT PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */ -#include "dbtest.h" // Header file for this demonstration program -#include "listdb.h" // Code to support the "Lookup" button on the editor dialog +#include "dbtest.h" /* Header file for this demonstration program */ +#include "listdb.h" /* Code to support the "Lookup" button on the editor dialog */ IMPLEMENT_APP(DatabaseDemoApp) -extern char ListDB_Selection[]; // Used to return the first column value for the selected line from the listDB routines -extern char ListDB_Selection2[]; // Used to return the second column value for the selected line from the listDB routines - -DatabaseDemoFrame *DemoFrame; // Pointer to the main frame +extern char ListDB_Selection[]; /* Used to return the first column value for the selected line from the listDB routines */ +extern char ListDB_Selection2[]; /* Used to return the second column value for the selected line from the listDB routines */ +DatabaseDemoFrame *DemoFrame; /* Pointer to the main frame */ /* Pointer to the main database connection used in the program. This * pointer would normally be used for doing things as database lookups @@ -79,9 +78,9 @@ DatabaseDemoFrame *DemoFrame; // Pointer to the main frame * table object which will do a CommitTrans() or RollbackTrans() that a * new wxDB object be created and used for it. */ + wxDB *READONLY_DB; - /* * This function will return the exact string(s) from the database engine * indicating all error conditions which have just occured during the @@ -94,6 +93,7 @@ wxDB *READONLY_DB; * NOTE: The value returned by this function is for temporary use only and * should be copied for long term use */ + char *GetExtendedDBErrorMsg(char *ErrFile, int ErrLine) { static wxString msg; @@ -102,9 +102,7 @@ char *GetExtendedDBErrorMsg(char *ErrFile, int ErrLine) if (ErrFile || ErrLine) { - msg += "\n"; - msg.Append ('-',80); - msg += "\nFile: "; + msg += "File: "; msg += ErrFile; msg += " Line: "; tStr.Printf("%d",ErrLine); @@ -112,12 +110,11 @@ char *GetExtendedDBErrorMsg(char *ErrFile, int ErrLine) msg += "\n"; } - msg.Append ('-',80); - msg.Append ("\nODBC ERRORS\n"); - msg.Append ('-',80); + msg.Append ("\nODBC errors:\n"); msg += "\n"; - // Scan through each database connection displaying - // any ODBC errors that have occured. + + /* Scan through each database connection displaying + * any ODBC errors that have occured. */ for (DbList *pDbList = PtrBegDbList; pDbList; pDbList = pDbList->PtrNext) { // Skip over any free connections @@ -267,7 +264,7 @@ void DatabaseDemoFrame::OnCloseWindow(wxCloseEvent& event) // to close the program here that is not done elsewhere this->Destroy(); -} // DatabaseDemoFrame::OnClose() +} // DatabaseDemoFrame::OnCloseWindow() void DatabaseDemoFrame::CreateDataTable() @@ -478,6 +475,11 @@ bool Ccontact::FetchByName(char *name) * An instance of Ccontact is created - "Contact" - which is used to hold the Ccontact * object that is currently being worked with. */ + +BEGIN_EVENT_TABLE(CeditorDlg, wxPanel) + EVT_BUTTON(-1, CeditorDlg::OnButton) +END_EVENT_TABLE() + CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455) { // Since the ::OnCommand() function is overridden, this prevents the widget @@ -539,8 +541,8 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455) // Build the dialog - wxStaticBox *FunctionGrp = new wxStaticBox(this, EDITOR_DIALOG_FN_GROUP, "", wxPoint(15, 1), wxSize(497, 69), 0, "FunctionGrp"); - wxStaticBox *SearchGrp = new wxStaticBox(this, EDITOR_DIALOG_SEARCH_GROUP, "", wxPoint(417, 1), wxSize(95, 242), 0, "SearchGrp"); + (void)new wxStaticBox(this, EDITOR_DIALOG_FN_GROUP, "", wxPoint(15, 1), wxSize(497, 69), 0, "FunctionGrp"); + (void)new wxStaticBox(this, EDITOR_DIALOG_SEARCH_GROUP, "", wxPoint(417, 1), wxSize(95, 242), 0, "SearchGrp"); pCreateBtn = new wxButton(this, EDITOR_DIALOG_CREATE, "&Create", wxPoint(25, 21), wxSize(70, 35), 0, wxDefaultValidator, "CreateBtn"); pEditBtn = new wxButton(this, EDITOR_DIALOG_EDIT, "&Edit", wxPoint(102, 21), wxSize(70, 35), 0, wxDefaultValidator, "EditBtn"); @@ -616,8 +618,10 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455) // // The constructed where clause below has a sub-query within it "SELECT MIN(NAME) FROM %s" // to achieve a single row (in this case the first name in alphabetical order). - Contact->whereStr.Printf("NAME = (SELECT MIN(NAME) FROM %s)",Contact->tableName); - + + // commented out because PostgreSQL can't do this + //Contact->whereStr.Printf("NAME = (SELECT MIN(NAME) FROM %s)",Contact->tableName); + // NOTE: (const char*) returns a pointer which may not be valid later, so this is short term use only Contact->where = (char*) (const char*) Contact->whereStr; @@ -648,22 +652,28 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455) } // CeditorDlg constructor -bool CeditorDlg::OnClose() +void CeditorDlg::OnCloseWindow(wxCloseEvent& event) { // Clean up time if ((mode != mCreate) && (mode != mEdit)) { if (Contact) delete Contact; - return TRUE; + this->Destroy(); } else { wxMessageBox("Must finish processing the current record being created/modified before exiting","Notice...",wxOK | wxICON_INFORMATION); - return FALSE; + event.Veto(); } -} // CeditorDlg::OnClose() +} // CeditorDlg::OnCloseWindow() + +void CeditorDlg::OnButton( wxCommandEvent &event ) +{ + wxWindow *win = (wxWindow*) event.GetEventObject(); + OnCommand( *win, event ); +} void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) { @@ -770,11 +780,13 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) } } + // commented out because PostgreSQL can't do this + // Previous record not available, retrieve first record in table - Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM "; - Contact->whereStr += Contact->tableName; - Contact->whereStr += ")"; - + //Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM "; + //Contact->whereStr += Contact->tableName; + //Contact->whereStr += ")"; + Contact->where = (char*) (const char*) Contact->whereStr; if (!Contact->Query()) { @@ -824,9 +836,13 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) // display it, if the query string has changed. if (strcmp(qryWhere, (const char*) Contact->qryWhereStr)) { - Contact->orderBy = "NAME"; - Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM "; - Contact->whereStr += CONTACT_TABLE_NAME; + + // commented out because PostgreSQL can't do this + Contact->whereStr = ""; + //Contact->orderBy = "NAME"; + //Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM "; + //Contact->whereStr += CONTACT_TABLE_NAME; + // Append the query where string (if there is one) Contact->qryWhereStr = qryWhere; if (strlen(qryWhere)) @@ -835,7 +851,7 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) Contact->whereStr += Contact->qryWhereStr; } // Close the expression with a right paren - Contact->whereStr += ")"; + // Contact->whereStr += ")"; // Requery the table Contact->where = (char*) (const char*) Contact->whereStr; if (!Contact->Query()) @@ -866,9 +882,12 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) // Query the first record in the table Contact->orderBy = "NAME"; - Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM "; - Contact->whereStr += CONTACT_TABLE_NAME; - Contact->whereStr += ")"; + + // commented out because PostgreSQL can't do this + //Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM "; + //Contact->whereStr += CONTACT_TABLE_NAME; + //Contact->whereStr += ")"; + Contact->where = (char*) (const char*) Contact->whereStr; if (!Contact->Query()) { @@ -1188,9 +1207,11 @@ bool CeditorDlg::GetNextRec() { wxString w; - w = "NAME = (SELECT MIN(NAME) FROM "; - w += Contact->tableName; - w += " WHERE NAME > '"; + // commented out because PostgreSQL can't do this + //w = "NAME = (SELECT MIN(NAME) FROM "; + //w += Contact->tableName; + // w += " WHERE NAME > '"; + w = "(NAME > '"; w += Contact->Name; w += "'"; @@ -1203,7 +1224,6 @@ bool CeditorDlg::GetNextRec() } w += ")"; - return(GetRec((char*) (const char*) w)); } // CeditorDlg::GetNextRec() @@ -1218,9 +1238,11 @@ bool CeditorDlg::GetPrevRec() { wxString w; - w = "NAME = (SELECT MAX(NAME) FROM "; - w += Contact->tableName; - w += " WHERE NAME < '"; + // commented out because PostgreSQL can't do this + //w = "NAME = (SELECT MAX(NAME) FROM "; + //w += Contact->tableName; + //w += " WHERE NAME < '"; + w = "(NAME < '"; w += Contact->Name; w += "'"; @@ -1272,6 +1294,11 @@ bool CeditorDlg::GetRec(char *whereStr) /* * CparameterDlg constructor */ + +BEGIN_EVENT_TABLE(CparameterDlg, wxDialog) + EVT_CLOSE(CparameterDlg::OnCloseWindow) +END_EVENT_TABLE() + CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialog (parent, PARAMETER_DIALOG, "ODBC parameter settings", wxPoint(-1, -1), wxSize(400, 275)) { // Since the ::OnCommand() function is overridden, this prevents the widget @@ -1304,7 +1331,7 @@ CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialog (parent, PARAMETER_DIA } // CparameterDlg constructor -bool CparameterDlg::OnClose() +void CparameterDlg::OnCloseWindow(wxCloseEvent& event) { // Put any additional checking necessary to make certain it is alright // to close the program here that is not done elsewhere @@ -1313,15 +1340,19 @@ bool CparameterDlg::OnClose() bool Ok = (wxMessageBox("No changes have been saved.\n\nAre you sure you wish exit the parameter screen?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES); if (!Ok) - return FALSE; + { + event.Veto(); + return; + } wxGetApp().params = savedParamSettings; } if (GetParent() != NULL) GetParent()->SetFocus(); - return TRUE; -} // Cparameter::OnClose() + this->Destroy(); + +} // Cparameter::OnCloseWindow() void CparameterDlg::OnCommand(wxWindow& win, wxCommandEvent& event) @@ -1458,6 +1489,11 @@ void CparameterDlg::FillDataSourceList() } // CparameterDlg::CparameterDlg::FillDataSourceList() +BEGIN_EVENT_TABLE(CqueryDlg, wxDialog) + EVT_BUTTON(-1, CqueryDlg::OnButton) + EVT_CLOSE(CqueryDlg::OnCloseWindow) +END_EVENT_TABLE() + // CqueryDlg() constructor CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg) : wxDialog (parent, QUERY_DIALOG, "Query", wxPoint(-1, -1), wxSize(480, 360)) { @@ -1567,6 +1603,12 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereA } // CqueryDlg() constructor +void CqueryDlg::OnButton( wxCommandEvent &event ) +{ + wxWindow *win = (wxWindow*) event.GetEventObject(); + OnCommand( *win, event ); +} + void CqueryDlg::OnCommand(wxWindow& win, wxCommandEvent& event) { // Widget pointers won't be set when the dialog is constructed. @@ -1779,7 +1821,7 @@ void CqueryDlg::OnCommand(wxWindow& win, wxCommandEvent& event) } // CqueryDlg::OnCommand -bool CqueryDlg::OnClose() +void CqueryDlg::OnCloseWindow(wxCloseEvent& event) { // Clean up if (colInf) @@ -1796,9 +1838,10 @@ bool CqueryDlg::OnClose() GetParent()->SetFocus(); wxEndBusyCursor(); - return TRUE; -} // CqueryDlg::OnClose() + this->Destroy(); + +} // CqueryDlg::OnCloseWindow() /* bool CqueryDlg::SetWidgetPtrs()