X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7e616b1050e4aaa4b8468d82ddf5b85d46412a3c..36cc39686ab0774ac2049ccfdea39e3fcfecafb2:/samples/db/dbtest.cpp diff --git a/samples/db/dbtest.cpp b/samples/db/dbtest.cpp index a05ef94c70..18cc8f144a 100644 --- a/samples/db/dbtest.cpp +++ b/samples/db/dbtest.cpp @@ -41,27 +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 *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 - - -// 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 @@ -83,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 @@ -106,9 +101,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); @@ -116,12 +109,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 @@ -176,12 +168,18 @@ bool DatabaseDemoApp::OnInit() return NULL; } + params.ODBCSource[0] = 0; + params.UserName[0] = 0; + params.Password[0] = 0; + params.DirPath[0] = 0; + FILE *paramFile; if ((paramFile = fopen(paramFilename, "r")) == NULL) { wxString tStr; tStr.Printf("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.",paramFilename); wxMessageBox(tStr,"File I/O Error...",wxOK | wxICON_EXCLAMATION); + DemoFrame->BuildParameterDialog(NULL); if ((paramFile = fopen(paramFilename, "r")) == NULL) return FALSE; @@ -200,12 +198,18 @@ bool DatabaseDemoApp::OnInit() buffer[strlen(buffer)-1] = '\0'; strcpy(params.Password,buffer); + fgets(buffer, sizeof(params.DirPath), paramFile); + buffer[strlen(buffer)-1] = '\0'; + strcpy(params.DirPath,buffer); + fclose(paramFile); // Connect to datasource strcpy(DbConnectInf.Dsn, params.ODBCSource); // ODBC data source name (created with ODBC Administrator under Win95/NT) strcpy(DbConnectInf.Uid, params.UserName); // database username - must already exist in the data source strcpy(DbConnectInf.AuthStr, params.Password); // password database username + strcpy(DbConnectInf.defaultDir,params.DirPath); // path where the table exists (needed for dBase) + READONLY_DB = GetDbConnection(&DbConnectInf); if (READONLY_DB == 0) { @@ -271,7 +275,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() @@ -293,7 +297,7 @@ void DatabaseDemoFrame::CreateDataTable() return; } - if (!Contact->CreateTable()) + if (!Contact->CreateTable(FALSE)) { wxEndBusyCursor(); wxString tStr; @@ -314,7 +318,8 @@ void DatabaseDemoFrame::CreateDataTable() success = FALSE; } } - wxEndBusyCursor(); + while (wxIsBusy()) + wxEndBusyCursor(); delete Contact; @@ -351,7 +356,7 @@ void DatabaseDemoFrame::BuildParameterDialog(wxWindow *parent) * or creating a table objects which use the same pDb, know that all the objects * will be committed or rolled back when any of the objects has this function call made. */ -Ccontact::Ccontact (wxDB *pwxDB) : wxTable(pwxDB ? pwxDB : GetDbConnection(&DbConnectInf),CONTACT_TABLE_NAME,CONTACT_NO_COLS) +Ccontact::Ccontact (wxDB *pwxDB) : wxTable(pwxDB ? pwxDB : GetDbConnection(&DbConnectInf),CONTACT_TABLE_NAME,CONTACT_NO_COLS,NULL,!QUERY_ONLY,DbConnectInf.defaultDir) { // This is used to represent whether the database connection should be released // when this instance of the object is deleted. If using the same connection @@ -409,18 +414,20 @@ Ccontact::~Ccontact() */ void Ccontact::SetupColumns() { - SetColDefs ( 0,"NAME", DB_DATA_TYPE_VARCHAR, Name, SQL_C_CHAR, sizeof(Name), TRUE, TRUE); // Primary index - SetColDefs ( 1,"ADDRESS1", DB_DATA_TYPE_VARCHAR, Addr1, SQL_C_CHAR, sizeof(Addr1), FALSE,TRUE); - SetColDefs ( 2,"ADDRESS2", DB_DATA_TYPE_VARCHAR, Addr2, SQL_C_CHAR, sizeof(Addr2), FALSE,TRUE); - SetColDefs ( 3,"CITY", DB_DATA_TYPE_VARCHAR, City, SQL_C_CHAR, sizeof(City), FALSE,TRUE); - SetColDefs ( 4,"STATE", DB_DATA_TYPE_VARCHAR, State, SQL_C_CHAR, sizeof(State), FALSE,TRUE); - SetColDefs ( 5,"POSTAL_CODE", DB_DATA_TYPE_VARCHAR, PostalCode, SQL_C_CHAR, sizeof(PostalCode), FALSE,TRUE); - SetColDefs ( 6,"COUNTRY", DB_DATA_TYPE_VARCHAR, Country, SQL_C_CHAR, sizeof(Country), FALSE,TRUE); - SetColDefs ( 7,"JOIN_DATE", DB_DATA_TYPE_DATE, &JoinDate, SQL_C_TIMESTAMP, sizeof(JoinDate), FALSE,TRUE); - SetColDefs ( 8,"NATIVE_LANGUAGE", DB_DATA_TYPE_INTEGER, &NativeLanguage, SQL_C_ENUM, sizeof(NativeLanguage), FALSE,TRUE); - SetColDefs ( 9,"IS_DEVELOPER", DB_DATA_TYPE_INTEGER, &IsDeveloper, SQL_C_BOOLEAN, sizeof(bool), FALSE,TRUE); - SetColDefs (10,"CONTRIBUTIONS", DB_DATA_TYPE_INTEGER, &Contributions, SQL_C_USHORT, sizeof(Contributions), FALSE,TRUE); - SetColDefs (11,"LINES_OF_CODE", DB_DATA_TYPE_INTEGER, &LinesOfCode, SQL_C_ULONG, sizeof(LinesOfCode), FALSE,TRUE); + // 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,"NAME", DB_DATA_TYPE_VARCHAR, Name, SQL_C_CHAR, sizeof(Name), TRUE, TRUE); // Primary index + SetColDefs ( 1,"ADDRESS1", DB_DATA_TYPE_VARCHAR, Addr1, SQL_C_CHAR, sizeof(Addr1), FALSE,TRUE); + SetColDefs ( 2,"ADDRESS2", DB_DATA_TYPE_VARCHAR, Addr2, SQL_C_CHAR, sizeof(Addr2), FALSE,TRUE); + SetColDefs ( 3,"CITY", DB_DATA_TYPE_VARCHAR, City, SQL_C_CHAR, sizeof(City), FALSE,TRUE); + SetColDefs ( 4,"STATE", DB_DATA_TYPE_VARCHAR, State, SQL_C_CHAR, sizeof(State), FALSE,TRUE); + SetColDefs ( 5,"POSTCODE", DB_DATA_TYPE_VARCHAR, PostalCode, SQL_C_CHAR, sizeof(PostalCode), FALSE,TRUE); + SetColDefs ( 6,"COUNTRY", DB_DATA_TYPE_VARCHAR, Country, SQL_C_CHAR, sizeof(Country), FALSE,TRUE); + SetColDefs ( 7,"JOINDATE", DB_DATA_TYPE_DATE, &JoinDate, SQL_C_TIMESTAMP, sizeof(JoinDate), FALSE,TRUE); + SetColDefs ( 8,"IS_DEV", DB_DATA_TYPE_INTEGER, &IsDeveloper, SQL_C_BOOLEAN(IsDeveloper),sizeof(IsDeveloper), FALSE,TRUE); + SetColDefs ( 9,"CONTRIBS", DB_DATA_TYPE_INTEGER, &Contributions, SQL_C_USHORT, sizeof(Contributions), FALSE,TRUE); + SetColDefs (10,"LINE_CNT", DB_DATA_TYPE_INTEGER, &LinesOfCode, SQL_C_ULONG, sizeof(LinesOfCode), FALSE,TRUE); + SetColDefs (11,"LANGUAGE", DB_DATA_TYPE_INTEGER, &NativeLanguage, SQL_C_ENUM, sizeof(NativeLanguage), FALSE,TRUE); } // Ccontact::SetupColumns @@ -433,7 +440,7 @@ bool Ccontact::CreateIndexes(void) bool Ok = TRUE; - strcpy(idxDef[0].ColName, "IS_DEVELOPER"); + strcpy(idxDef[0].ColName, "IS_DEV"); idxDef[0].Ascending = TRUE; strcpy(idxDef[1].ColName, "NAME"); @@ -482,6 +489,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 @@ -490,7 +502,7 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455) widgetPtrsSet = FALSE; // Create the data structure and a new database connection. - // (As there is not a pDb being passed in the constructor, a new database + // (As there is not a pDb being passed in the constructor, a new database // connection is created) Contact = new Ccontact(); @@ -502,7 +514,7 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455) // Check if the table exists or not. If it doesn't, ask the user if they want to // create the table. Continue trying to create the table until it exists, or user aborts - while (!Contact->pDb->TableExists((char *)CONTACT_TABLE_NAME)) + while (!Contact->pDb->TableExists((char *)CONTACT_TABLE_NAME,DbConnectInf.Uid,DbConnectInf.defaultDir)) { wxString tStr; tStr.Printf("Unable to open the table '%s'.\n\nTable may need to be created...?\n\n",CONTACT_TABLE_NAME); @@ -543,8 +555,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"); @@ -620,10 +632,16 @@ 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); - - // 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; + + // commented out because PostgreSQL can't do this + if (Contact->pDb->Dbms() != dbmsPOSTGRES) + { + Contact->whereStr.sprintf("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; + } + else + Contact->where = 0; // 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. @@ -652,21 +670,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) @@ -775,11 +800,17 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) } // Previous record not available, retrieve first record in table - Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM "; - Contact->whereStr += Contact->tableName; - Contact->whereStr += ")"; + if (Contact->pDb->Dbms() != dbmsPOSTGRES) + { + // PostgreSQL can't do this + Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM "; + Contact->whereStr += Contact->tableName; + Contact->whereStr += ")"; + Contact->where = (char*) (const char*) Contact->whereStr; + } + else + Contact->where = 0; - Contact->where = (char*) (const char*) Contact->whereStr; if (!Contact->Query()) { wxString tStr; @@ -828,9 +859,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)) @@ -839,7 +874,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()) @@ -870,9 +905,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()) { @@ -897,7 +935,7 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) /* char *windowTitle */ "Select contact name", /* char *tableName */ (char *) CONTACT_TABLE_NAME, /* char *dispCol1 */ "NAME", - /* char *dispCol2 */ "JOIN_DATE", + /* char *dispCol2 */ "JOINDATE", /* char *where */ "", /* char *orderBy */ "NAME", /* bool distinctValues */ TRUE); @@ -1100,7 +1138,7 @@ bool CeditorDlg::GetData() Contact->LinesOfCode = atol(pLinesTxt->GetValue()); Contact->NativeLanguage = (enum Language) pNativeLangChoice->GetSelection(); - Contact->IsDeveloper = (bool) pDeveloperRadio->GetSelection(); + Contact->IsDeveloper = pDeveloperRadio->GetSelection() > 0; return TRUE; } // CeditorDlg::GetData() @@ -1124,8 +1162,6 @@ bool CeditorDlg::Save() failed = TRUE; // Perform any other required validations necessary before saving - - if (!failed) { wxBeginBusyCursor(); @@ -1192,9 +1228,16 @@ bool CeditorDlg::GetNextRec() { wxString w; - w = "NAME = (SELECT MIN(NAME) FROM "; - w += Contact->tableName; - w += " WHERE NAME > '"; + if (Contact->pDb->Dbms() != dbmsPOSTGRES) + { + // PostgreSQL can't do this + w = "NAME = (SELECT MIN(NAME) FROM "; + w += Contact->tableName; + w += " WHERE NAME > '"; + } + else + w = "(NAME > '"; + w += Contact->Name; w += "'"; @@ -1207,7 +1250,6 @@ bool CeditorDlg::GetNextRec() } w += ")"; - return(GetRec((char*) (const char*) w)); } // CeditorDlg::GetNextRec() @@ -1222,9 +1264,16 @@ bool CeditorDlg::GetPrevRec() { wxString w; - w = "NAME = (SELECT MAX(NAME) FROM "; - w += Contact->tableName; - w += " WHERE NAME < '"; + if (Contact->pDb->Dbms() != dbmsPOSTGRES) + { + // PostgreSQL can't do this + w = "NAME = (SELECT MAX(NAME) FROM "; + w += Contact->tableName; + w += " WHERE NAME < '"; + } + else + w = "(NAME < '"; + w += Contact->Name; w += "'"; @@ -1251,7 +1300,7 @@ bool CeditorDlg::GetRec(char *whereStr) { Contact->where = whereStr; Contact->orderBy = "NAME"; - + if (!Contact->Query()) { wxString tStr; @@ -1276,7 +1325,14 @@ bool CeditorDlg::GetRec(char *whereStr) /* * CparameterDlg constructor */ -CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialog (parent, PARAMETER_DIALOG, "ODBC parameter settings", wxPoint(-1, -1), wxSize(400, 275)) + +BEGIN_EVENT_TABLE(CparameterDlg, wxDialog) + EVT_BUTTON(PARAMETER_DIALOG_SAVE, CparameterDlg::OnButton) + EVT_BUTTON(PARAMETER_DIALOG_CANCEL, CparameterDlg::OnButton) + EVT_CLOSE(CparameterDlg::OnCloseWindow) +END_EVENT_TABLE() + +CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialog (parent, PARAMETER_DIALOG, "ODBC parameter settings", wxPoint(-1, -1), wxSize(400, 325)) { // Since the ::OnCommand() function is overridden, this prevents the widget // detection in ::OnCommand() until all widgets have been initialized to prevent @@ -1292,6 +1348,9 @@ CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialog (parent, PARAMETER_DIA pParamPasswordMsg = new wxStaticText(this, PARAMETER_DIALOG_PASSWORD_MSG, "Password:", wxPoint(156, 193), wxSize(-1, -1), 0, "ParamPasswordMsg"); pParamPasswordTxt = new wxTextCtrl(this, PARAMETER_DIALOG_PASSWORD_TEXT, "", wxPoint(156, 209), wxSize(140, 25), 0, wxDefaultValidator, "ParamPasswordTxt"); + pParamDirPathMsg = new wxStaticText(this, PARAMETER_DIALOG_DIRPATH_MSG, "Directory:", wxPoint(10, 243), wxSize(-1, -1), 0, "ParamDirPathMsg"); + pParamDirPathTxt = new wxTextCtrl(this, PARAMETER_DIALOG_DIRPATH_TEXT, "", wxPoint(10, 259), wxSize(140, 25), 0, wxDefaultValidator, "ParamDirPathTxt"); + pParamSaveBtn = new wxButton(this, PARAMETER_DIALOG_SAVE, "&Save", wxPoint(310, 21), wxSize(70, 35), 0, wxDefaultValidator, "ParamSaveBtn"); pParamCancelBtn = new wxButton(this, PARAMETER_DIALOG_CANCEL, "C&ancel", wxPoint(310, 66), wxSize(70, 35), 0, wxDefaultValidator, "ParamCancelBtn"); @@ -1300,7 +1359,7 @@ CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialog (parent, PARAMETER_DIA widgetPtrsSet = TRUE; saved = FALSE; - savedParamSettings = DatabaseDemoApp.params; + savedParamSettings = wxGetApp().params; Centre(wxBOTH); PutData(); @@ -1308,7 +1367,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 @@ -1317,17 +1376,27 @@ 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; + } - DatabaseDemoApp.params = savedParamSettings; + wxGetApp().params = savedParamSettings; } if (GetParent() != NULL) GetParent()->SetFocus(); - return TRUE; -} // Cparameter::OnClose() + this->Destroy(); + +} // Cparameter::OnCloseWindow() +void CparameterDlg::OnButton( wxCommandEvent &event ) +{ + wxWindow *win = (wxWindow*) event.GetEventObject(); + OnCommand( *win, event ); +} + void CparameterDlg::OnCommand(wxWindow& win, wxCommandEvent& event) { wxString widgetName; @@ -1366,9 +1435,11 @@ 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); + if (wxGetApp().params.ODBCSource && wxStrlen(wxGetApp().params.ODBCSource)) + pParamODBCSourceList->SetStringSelection(wxGetApp().params.ODBCSource); + pParamUserNameTxt->SetValue(wxGetApp().params.UserName); + pParamPasswordTxt->SetValue(wxGetApp().params.Password); + pParamDirPathTxt->SetValue(wxGetApp().params.DirPath); return TRUE; } // CparameterDlg::PutData() @@ -1379,47 +1450,58 @@ 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); + + tStr = pParamDirPathTxt->GetValue(); + tStr.Replace("\\","/"); + if (tStr.Length() > (sizeof(wxGetApp().params.DirPath)-1)) + { + wxString errmsg; + errmsg.Printf("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,"Internal program error...",wxOK | wxICON_EXCLAMATION); + return FALSE; + } + strcpy(wxGetApp().params.DirPath,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; } @@ -1432,11 +1514,13 @@ bool CparameterDlg::Save() return FALSE; } - fputs(DatabaseDemoApp.params.ODBCSource, paramFile); + fputs(wxGetApp().params.ODBCSource, paramFile); + fputc('\n', paramFile); + fputs(wxGetApp().params.UserName, paramFile); fputc('\n', paramFile); - fputs(DatabaseDemoApp.params.UserName, paramFile); + fputs(wxGetApp().params.Password, paramFile); fputc('\n', paramFile); - fputs(DatabaseDemoApp.params.Password, paramFile); + fputs(wxGetApp().params.DirPath, paramFile); fputc('\n', paramFile); fclose(paramFile); @@ -1462,6 +1546,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)) { @@ -1534,6 +1623,17 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereA wxString qualName; pQueryCol2Choice->Append("VALUE -->"); colInf = pDB->GetColumns(tblName); + + if (!colInf) + { + wxEndBusyCursor(); + wxString tStr; + tStr = "ODBC error during GetColumns()\n\n"; + tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); + return; + } + for (int i = 0; colInf[i].colName && strlen(colInf[i].colName); i++) { // If there is more than one table being queried, qualify @@ -1571,6 +1671,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. @@ -1783,7 +1889,7 @@ void CqueryDlg::OnCommand(wxWindow& win, wxCommandEvent& event) } // CqueryDlg::OnCommand -bool CqueryDlg::OnClose() +void CqueryDlg::OnCloseWindow(wxCloseEvent& event) { // Clean up if (colInf) @@ -1799,10 +1905,12 @@ bool CqueryDlg::OnClose() } GetParent()->SetFocus(); - wxEndBusyCursor(); - return TRUE; + while (wxIsBusy()) + wxEndBusyCursor(); + + this->Destroy(); -} // CqueryDlg::OnClose() +} // CqueryDlg::OnCloseWindow() /* bool CqueryDlg::SetWidgetPtrs() @@ -1951,7 +2059,7 @@ void CqueryDlg::ProcessCountBtn() if (dbTable == 0) // wxTable object needs to be created and opened { - if (!(dbTable = new wxTable(pDB, masterTableName, 0))) + if (!(dbTable = new wxTable(pDB, masterTableName, 0, NULL, !QUERY_ONLY, DbConnectInf.defaultDir))) { wxMessageBox("Memory allocation failed creating a wxTable object.","Error...",wxOK | wxICON_EXCLAMATION); return;