X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1fc5dd6f8eb590992150b3998266fb50dfaab227..aeafc354935512ddba84502bc60ca3b6246c14ce:/samples/db/dbtest.cpp diff --git a/samples/db/dbtest.cpp b/samples/db/dbtest.cpp index b6dc66390a..466dfaf428 100644 --- a/samples/db/dbtest.cpp +++ b/samples/db/dbtest.cpp @@ -37,27 +37,26 @@ #include #endif //WX_PRECOMP -#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 - -extern DbList *PtrBegDbList; // from db.cpp, used in getting back error results from db connections +#ifdef __WXGTK__ +#include "db.xpm" +#endif -#include "dbtest.h" // Header file for this demonstration program -#include "listdb.h" // Code to support the "Lookup" button on the editor dialog +#include /* Included strictly for reading the text file with the database parameters */ -IMPLEMENT_APP(DatabaseDemoApp) +#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 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 +extern DbList* WXDLLEXPORT PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */ -DatabaseDemoFrame *DemoFrame; // Pointer to the main frame +#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) -// This statement initializes the whole application and calls OnInit -DatabaseDemoApp 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 */ /* 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 @@ DatabaseDemoApp DatabaseDemoApp; * 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 @@ -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,9 @@ 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); - + + 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; @@ -665,6 +668,12 @@ bool CeditorDlg::OnClose() } // CeditorDlg::OnClose() +void CeditorDlg::OnButton( wxCommandEvent &event ) +{ + wxWindow *win = (wxWindow*) event.GetEventObject(); + OnCommand( *win, event ); +} + void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) { wxString widgetName; @@ -774,7 +783,6 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM "; Contact->whereStr += Contact->tableName; Contact->whereStr += ")"; - Contact->where = (char*) (const char*) Contact->whereStr; if (!Contact->Query()) { @@ -827,6 +835,7 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) 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)) @@ -866,9 +875,11 @@ 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 += ")"; + Contact->where = (char*) (const char*) Contact->whereStr; if (!Contact->Query()) { @@ -1188,6 +1199,7 @@ bool CeditorDlg::GetNextRec() { wxString w; + w = "NAME = (SELECT MIN(NAME) FROM "; w += Contact->tableName; w += " WHERE NAME > '"; @@ -1203,7 +1215,6 @@ bool CeditorDlg::GetNextRec() } w += ")"; - return(GetRec((char*) (const char*) w)); } // CeditorDlg::GetNextRec() @@ -1296,7 +1307,7 @@ CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialog (parent, PARAMETER_DIA widgetPtrsSet = TRUE; saved = FALSE; - savedParamSettings = DatabaseDemoApp.params; + savedParamSettings = wxGetApp().params; Centre(wxBOTH); PutData(); @@ -1315,7 +1326,7 @@ bool CparameterDlg::OnClose() if (!Ok) return FALSE; - DatabaseDemoApp.params = savedParamSettings; + wxGetApp().params = savedParamSettings; } if (GetParent() != NULL) @@ -1362,9 +1373,9 @@ bool CparameterDlg::PutData() FillDataSourceList(); // Fill in the fields from the params object - pParamODBCSourceList->SetStringSelection(DatabaseDemoApp.params.ODBCSource); - pParamUserNameTxt->SetValue(DatabaseDemoApp.params.UserName); - pParamPasswordTxt->SetValue(DatabaseDemoApp.params.Password); + pParamODBCSourceList->SetStringSelection(wxGetApp().params.ODBCSource); + pParamUserNameTxt->SetValue(wxGetApp().params.UserName); + pParamPasswordTxt->SetValue(wxGetApp().params.Password); return TRUE; } // CparameterDlg::PutData() @@ -1375,47 +1386,47 @@ bool CparameterDlg::GetData() if (pParamODBCSourceList->GetStringSelection()) { tStr = pParamODBCSourceList->GetStringSelection(); - if (tStr.Length() > (sizeof(DatabaseDemoApp.params.ODBCSource)-1)) + if (tStr.Length() > (sizeof(wxGetApp().params.ODBCSource)-1)) { wxString errmsg; errmsg.Printf("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,"Internal program error...",wxOK | wxICON_EXCLAMATION); return FALSE; } - strcpy(DatabaseDemoApp.params.ODBCSource, tStr); + strcpy(wxGetApp().params.ODBCSource, tStr); } else return FALSE; tStr = pParamUserNameTxt->GetValue(); - if (tStr.Length() > (sizeof(DatabaseDemoApp.params.UserName)-1)) + if (tStr.Length() > (sizeof(wxGetApp().params.UserName)-1)) { wxString errmsg; errmsg.Printf("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,"Internal program error...",wxOK | wxICON_EXCLAMATION); return FALSE; } - strcpy(DatabaseDemoApp.params.UserName, tStr); + strcpy(wxGetApp().params.UserName, tStr); tStr = pParamPasswordTxt->GetValue(); - if (tStr.Length() > (sizeof(DatabaseDemoApp.params.Password)-1)) + if (tStr.Length() > (sizeof(wxGetApp().params.Password)-1)) { wxString errmsg; errmsg.Printf("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,"Internal program error...",wxOK | wxICON_EXCLAMATION); return FALSE; } - strcpy(DatabaseDemoApp.params.Password,tStr); + strcpy(wxGetApp().params.Password,tStr); return TRUE; } // CparameterDlg::GetData() bool CparameterDlg::Save() { - Cparameters saveParams = DatabaseDemoApp.params; + Cparameters saveParams = wxGetApp().params; if (!GetData()) { - DatabaseDemoApp.params = saveParams; + wxGetApp().params = saveParams; return FALSE; } @@ -1428,11 +1439,11 @@ bool CparameterDlg::Save() return FALSE; } - fputs(DatabaseDemoApp.params.ODBCSource, paramFile); + fputs(wxGetApp().params.ODBCSource, paramFile); fputc('\n', paramFile); - fputs(DatabaseDemoApp.params.UserName, paramFile); + fputs(wxGetApp().params.UserName, paramFile); fputc('\n', paramFile); - fputs(DatabaseDemoApp.params.Password, paramFile); + fputs(wxGetApp().params.Password, paramFile); fputc('\n', paramFile); fclose(paramFile); @@ -1458,6 +1469,10 @@ void CparameterDlg::FillDataSourceList() } // CparameterDlg::CparameterDlg::FillDataSourceList() +BEGIN_EVENT_TABLE(CqueryDlg, wxDialog) + EVT_BUTTON(-1, CqueryDlg::OnButton) +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 +1582,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.