From: Julian Smart Date: Wed, 30 Dec 1998 17:40:53 +0000 (+0000) Subject: Updated the Remstar ODBC files, got the db sample compiling; added Freq and SubString X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1fc5dd6f8eb590992150b3998266fb50dfaab227?ds=sidebyside Updated the Remstar ODBC files, got the db sample compiling; added Freq and SubString to wxString git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1283 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/word/odbc.doc b/docs/word/odbc.doc index 7f60405dd2..8f6929136d 100644 Binary files a/docs/word/odbc.doc and b/docs/word/odbc.doc differ diff --git a/include/wx/db.h b/include/wx/db.h index 9f47abf00b..25edff65da 100644 --- a/include/wx/db.h +++ b/include/wx/db.h @@ -5,6 +5,8 @@ // source such as opening and closing the data source. // Author: Doug Card // Modified by: +// Mods: Dec, 1998: Added support for SQL statement logging and database +// cataloging // Created: 9.96 // RCS-ID: $Id$ // Copyright: (c) 1996 Remstar International, Inc. @@ -18,6 +20,7 @@ // 3) These classes may not be distributed as part of any other class library, // DLL, text (written or electronic), other than a complete distribution of // the wxWindows GUI development toolkit. +// /////////////////////////////////////////////////////////////////////////////// /* @@ -27,12 +30,12 @@ #ifndef DB_DOT_H #define DB_DOT_H - + #ifdef __GNUG__ #pragma interface "db.h" #endif -#if defined(wx_msw) || defined(WIN32) +#if defined(__WXMSW__) || defined(WIN32) #include #endif @@ -45,20 +48,6 @@ enum enumDummy {enumDum1}; #define SQL_C_BOOLEAN (sizeof(int) == 2 ? SQL_C_USHORT : SQL_C_ULONG) #define SQL_C_ENUM (sizeof(enumDummy) == 2 ? SQL_C_USHORT : SQL_C_ULONG) //glt 2-21-97 -/* -#ifndef Bool -#define Bool int -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif -*/ - // Database Globals const DB_TYPE_NAME_LEN = 40; const DB_MAX_STATEMENT_LEN = 2048; @@ -224,15 +213,23 @@ public: int sqlDataType; }; +enum sqlLog +{ + sqlLogOFF, + sqlLogON +}; + class wxDB { private: // Private data - bool dbIsOpen; - char *dsn; // Data source name - char *uid; // User ID - char *authStr; // Authorization string (password) + bool dbIsOpen; + char *dsn; // Data source name + char *uid; // User ID + char *authStr; // Authorization string (password) + FILE *fpSqlLog; // Sql Log file pointer + enum sqlLog sqlLogState; // On or Off // Private member functions bool getDbInfo(void); @@ -303,28 +300,31 @@ public: // Public member functions wxDB(HENV &aHenv); - bool Open(char *Dsn, char *Uid, char *AuthStr); // Data Source Name, User ID, Password - void Close(void); - bool CommitTrans(void); - bool RollbackTrans(void); - bool DispAllErrors(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT); - bool GetNextError(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT); - void DispNextError(void); - bool CreateView(char *viewName, char *colList, char *pSqlStmt); - bool ExecSql(char *pSqlStmt); - bool Grant(int privileges, char *tableName, char *userList = "PUBLIC"); - int TranslateSqlState(char *SQLState); - CcolInf *GetColumns(char *tableName[]); - char *GetDatabaseName(void) {return dbInf.dbmsName;} - char *GetDataSource(void) {return dsn;} - char *GetUsername(void) {return uid;} - char *GetPassword(void) {return authStr;} - bool IsOpen(void) {return dbIsOpen;} - HENV GetHENV(void) {return henv;} - HDBC GetHDBC(void) {return hdbc;} - HSTMT GetHSTMT(void) {return hstmt;} - bool TableExists(char *tableName); // Table name can refer to a table, view, alias or synonym - void LogError(char *errMsg, char *SQLState = 0) {logError(errMsg, SQLState);} + bool Open(char *Dsn, char *Uid, char *AuthStr); // Data Source Name, User ID, Password + void Close(void); + bool CommitTrans(void); + bool RollbackTrans(void); + bool DispAllErrors(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT); + bool GetNextError(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT); + void DispNextError(void); + bool CreateView(char *viewName, char *colList, char *pSqlStmt); + bool ExecSql(char *pSqlStmt); + bool Grant(int privileges, char *tableName, char *userList = "PUBLIC"); + int TranslateSqlState(char *SQLState); + bool Catalog(char *userID, char *fileName = "Catalog.txt"); + CcolInf *GetColumns(char *tableName[]); + char *GetDatabaseName(void) {return dbInf.dbmsName;} + char *GetDataSource(void) {return dsn;} + char *GetUsername(void) {return uid;} + char *GetPassword(void) {return authStr;} + bool IsOpen(void) {return dbIsOpen;} + HENV GetHENV(void) {return henv;} + HDBC GetHDBC(void) {return hdbc;} + HSTMT GetHSTMT(void) {return hstmt;} + bool TableExists(char *tableName); // Table name can refer to a table, view, alias or synonym + void LogError(char *errMsg, char *SQLState = 0) {logError(errMsg, SQLState);} + bool SqlLog(enum sqlLog state, char *filename = "sqllog.txt", bool append = FALSE); + bool WriteSqlLog(char *logMsg); }; // wxDB @@ -359,4 +359,3 @@ bool GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDes UWORD direction = SQL_FETCH_NEXT); #endif - diff --git a/include/wx/dbtable.h b/include/wx/dbtable.h index 23e6d10f8a..0fa4fef0b9 100644 --- a/include/wx/dbtable.h +++ b/include/wx/dbtable.h @@ -46,24 +46,24 @@ const ROWID_LEN = 24; // 18 is the max, 24 is in case it gets larger class CcolDef { public: - char ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name glt 4/19/97 added one for the null terminator - int DbDataType; // Logical Data Type; e.g. DB_DATA_TYPE_INTEGER - int SqlCtype; // C data type; e.g. SQL_C_LONG - void *PtrDataObj; // Address of the data object - int SzDataObj; // Size, in bytes, of the data object - bool KeyField; // TRUE if this column is part of the PRIMARY KEY to the table; Date fields should NOT be KeyFields. - bool Updateable; // Specifies whether this column is updateable - bool InsertAllowed; // Specifies whether this column should be included in an INSERT statement - bool DerivedCol; // Specifies whether this column is a derived value - SDWORD CbValue; // Internal use only!!! + char ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name glt 4/19/97 added one for the null terminator + int DbDataType; // Logical Data Type; e.g. DB_DATA_TYPE_INTEGER + int SqlCtype; // C data type; e.g. SQL_C_LONG + void *PtrDataObj; // Address of the data object + int SzDataObj; // Size, in bytes, of the data object + bool KeyField; // TRUE if this column is part of the PRIMARY KEY to the table; Date fields should NOT be KeyFields. + bool Updateable; // Specifies whether this column is updateable + bool InsertAllowed; // Specifies whether this column should be included in an INSERT statement + bool DerivedCol; // Specifies whether this column is a derived value + SDWORD CbValue; // Internal use only!!! }; // CcolDef // This structure is used when creating secondary indexes. class CidxDef { public: - char ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name glt 4/19/97 added one for the null terminator - bool Ascending; + char ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name glt 4/19/97 added one for the null terminator + bool Ascending; }; // CidxDef class wxTable @@ -106,9 +106,10 @@ public: // Column Definitions CcolDef *colDefs; // Array of CcolDef structures - // Where and Order By clauses + // Where, Order By and From clauses char *where; // Standard SQL where clause, minus the word WHERE char *orderBy; // Standard SQL order by clause, minus the ORDER BY + char *from; // Allows for joins in a Ctable::Query(). Format: ",tbl,tbl..." // Flags bool selectForUpdate; @@ -116,50 +117,49 @@ public: // Public member functions wxTable(wxDB *pwxDB, const char *tblName, const int nCols, const char *qryTblName = 0); ~wxTable(); - bool Open(void); - bool CreateTable(void); - bool CreateIndex(char * idxName, bool unique, int noIdxCols, CidxDef *pIdxDefs); - bool CloseCursor(HSTMT cursor); - int Insert(void); - bool Update(void); - bool Update(char *pSqlStmt); - bool UpdateWhere(char *pWhereClause); - bool Delete(void); - bool DeleteWhere(char *pWhereClause); - bool DeleteMatching(void); - bool Query(bool forUpdate = FALSE, bool distinct = FALSE); - bool QueryBySqlStmt(char *pSqlStmt); - bool QueryMatching(bool forUpdate = FALSE, bool distinct = FALSE); - bool QueryOnKeyFields(bool forUpdate = FALSE, bool distinct = FALSE); - bool GetNext(void) { return(getRec(SQL_FETCH_NEXT)); } - bool operator++(int) { return(getRec(SQL_FETCH_NEXT)); } + bool Open(void); + bool CreateTable(void); + bool CreateIndex(char * idxName, bool unique, int noIdxCols, CidxDef *pIdxDefs); + bool CloseCursor(HSTMT cursor); + int Insert(void); + bool Update(void); + bool Update(char *pSqlStmt); + bool UpdateWhere(char *pWhereClause); + bool Delete(void); + bool DeleteWhere(char *pWhereClause); + bool DeleteMatching(void); + virtual bool Query(bool forUpdate = FALSE, bool distinct = FALSE); + bool QueryBySqlStmt(char *pSqlStmt); + bool QueryMatching(bool forUpdate = FALSE, bool distinct = FALSE); + bool QueryOnKeyFields(bool forUpdate = FALSE, bool distinct = FALSE); + bool GetNext(void) { return(getRec(SQL_FETCH_NEXT)); } + bool operator++(int) { return(getRec(SQL_FETCH_NEXT)); } #ifndef FWD_ONLY_CURSORS - bool GetPrev(void) { return(getRec(SQL_FETCH_PRIOR)); } - bool operator--(int) { return(getRec(SQL_FETCH_PRIOR)); } - bool GetFirst(void) { return(getRec(SQL_FETCH_FIRST)); } - bool GetLast(void) { return(getRec(SQL_FETCH_LAST)); } + bool GetPrev(void) { return(getRec(SQL_FETCH_PRIOR)); } + bool operator--(int) { return(getRec(SQL_FETCH_PRIOR)); } + bool GetFirst(void) { return(getRec(SQL_FETCH_FIRST)); } + bool GetLast(void) { return(getRec(SQL_FETCH_LAST)); } #endif - bool IsCursorClosedOnCommit(void); - bool IsColNull(int colNo); - UWORD GetRowNum(void); - void GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct); - void GetDeleteStmt(char *pSqlStmt, int typeOfDel, char *pWhereClause = 0); - void GetUpdateStmt(char *pSqlStmt, int typeOfUpd, char *pWhereClause = 0); - void GetWhereClause(char *pWhereClause, int typeOfWhere); - bool CanSelectForUpdate(void); - bool CanUpdByROWID(void); - void ClearMemberVars(void); - bool SetQueryTimeout(UDWORD nSeconds); - void SetColDefs (int index, char *fieldName, int dataType, void *pData, int cType, - int size, bool keyField = FALSE, bool upd = TRUE, - bool insAllow = TRUE, bool derivedCol = FALSE); - bool SetCursor(int cursorNo = DB_CURSOR0); - int GetCursor(void) { return(currCursorNo); } - ULONG Count(void); - int DB_STATUS(void) { return(pDb->DB_STATUS); } - bool Refresh(void); + bool IsCursorClosedOnCommit(void); + bool IsColNull(int colNo); + UWORD GetRowNum(void); + void GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct); + void GetDeleteStmt(char *pSqlStmt, int typeOfDel, char *pWhereClause = 0); + void GetUpdateStmt(char *pSqlStmt, int typeOfUpd, char *pWhereClause = 0); + void GetWhereClause(char *pWhereClause, int typeOfWhere, char *qualTableName = 0); + bool CanSelectForUpdate(void); + bool CanUpdByROWID(void); + void ClearMemberVars(void); + bool SetQueryTimeout(UDWORD nSeconds); + void SetColDefs (int index, char *fieldName, int dataType, void *pData, int cType, + int size, bool keyField = FALSE, bool upd = TRUE, + bool insAllow = TRUE, bool derivedCol = FALSE); + bool SetCursor(int cursorNo = DB_CURSOR0); + int GetCursor(void) { return(currCursorNo); } + ULONG Count(void); + int DB_STATUS(void) { return(pDb->DB_STATUS); } + bool Refresh(void); }; // wxTable #endif - diff --git a/include/wx/string.h b/include/wx/string.h index f9f731380f..9e7a4fe95b 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -433,6 +433,11 @@ public: nCount (or till the end if nCount = default value) */ wxString Mid(size_t nFirst, size_t nCount = STRING_MAXLEN) const; + /// Compatibility with wxWindows 1.xx + wxString SubString(size_t from, size_t to) const + { + return Mid(from, (to - from + 1)); + } /// get first nCount characters wxString Left(size_t nCount) const; /// get all characters before the first occurence of ch @@ -547,6 +552,8 @@ public: { *this = str + *this; return *this; } /// same as Len size_t Length() const { return Len(); } + /// Count the number of characters + int Freq(char ch) const; /// same as MakeLower void LowerCase() { MakeLower(); } /// same as MakeUpper diff --git a/samples/db/dbtest.cpp b/samples/db/dbtest.cpp index 165444a0ad..b6dc66390a 100644 --- a/samples/db/dbtest.cpp +++ b/samples/db/dbtest.cpp @@ -37,17 +37,18 @@ #include #endif //WX_PRECOMP -IMPLEMENT_APP(DatabaseDemoApp) - #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 wx_db.cpp, used in getting back error results from db connections +extern DbList *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 + +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 @@ -87,7 +88,7 @@ wxDB *READONLY_DB; * last call to the database engine. * * This demo uses the returned string by displaying it in a wxMessageBox. The - * formatting therefore is not the greatest, but this is just a demo, not a + * formatting therefore is not the greatest, but this is just a demo, not a * finished product. :-) gt * * NOTE: The value returned by this function is for temporary use only and @@ -106,7 +107,7 @@ char *GetExtendedDBErrorMsg(char *ErrFile, int ErrLine) msg += "\nFile: "; msg += ErrFile; msg += " Line: "; - tStr.sprintf("%d",ErrLine); + tStr.Printf("%d",ErrLine); msg += tStr.GetData(); msg += "\n"; } @@ -135,24 +136,17 @@ char *GetExtendedDBErrorMsg(char *ErrFile, int ErrLine) } msg += "\n"; - return msg.GetData(); + return (char*) (const char*) msg; } // GetExtendedDBErrorMsg - -// `Main program' equivalent, creating windows and returning main app frame -wxFrame *DatabaseDemoApp::OnInit(void) +bool DatabaseDemoApp::OnInit() { // Create the main frame window - DemoFrame = new DatabaseDemoFrame(NULL, "wxWindows Database Demo", 50, 50, 537, 480); + DemoFrame = new DatabaseDemoFrame(NULL, "wxWindows Database Demo", wxPoint(50, 50), wxSize(537, 480)); // Give it an icon -#ifdef __WXMSW__ - DemoFrame->SetIcon(wxIcon("db_icon")); -#endif -#ifdef __X__ - DemoFrame->SetIcon(wxIcon("db.xbm")); -#endif + DemoFrame->SetIcon(wxICON(db)); // Make a menubar wxMenu *file_menu = new wxMenu; @@ -182,8 +176,8 @@ wxFrame *DatabaseDemoApp::OnInit(void) if ((paramFile = fopen(paramFilename, "r")) == NULL) { wxString tStr; - tStr.sprintf("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.GetData(),"File I/O Error...",wxOK | wxICON_EXCLAMATION); + 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; @@ -225,63 +219,67 @@ wxFrame *DatabaseDemoApp::OnInit(void) // Show the frame DemoFrame->Show(TRUE); - // Return the main frame window - return DemoFrame; + return TRUE; } // DatabaseDemoApp::OnInit() - +BEGIN_EVENT_TABLE(DatabaseDemoFrame, wxFrame) + EVT_MENU(FILE_CREATE, DatabaseDemoFrame::OnCreate) + EVT_MENU(FILE_EXIT, DatabaseDemoFrame::OnExit) + EVT_MENU(EDIT_PARAMETERS, DatabaseDemoFrame::OnEditParameters) + EVT_MENU(ABOUT_DEMO, DatabaseDemoFrame::OnAbout) + EVT_CLOSE(DatabaseDemoFrame::OnCloseWindow) +END_EVENT_TABLE() // DatabaseDemoFrame constructor -DatabaseDemoFrame::DatabaseDemoFrame(wxFrame *frame, char *title, int x, int y, int w, int h): - wxFrame(frame, title, x, y, w, h) +DatabaseDemoFrame::DatabaseDemoFrame(wxFrame *frame, const wxString& title, + const wxPoint& pos, const wxSize& size): + wxFrame(frame, -1, title, pos, size) { // Put any code in necessary for initializing the main frame here } +void DatabaseDemoFrame::OnCreate(wxCommandEvent& event) +{ + CreateDataTable(); +} -// Intercept menu commands -void DatabaseDemoFrame::OnMenuCommand(int id) +void DatabaseDemoFrame::OnExit(wxCommandEvent& event) { - switch (id) - { - case FILE_CREATE: - CreateDataTable(); - break; - case FILE_EXIT: - Close(); - break; - case EDIT_PARAMETERS: - if ((pEditorDlg->mode != mCreate) && (pEditorDlg->mode != mEdit)) - BuildParameterDialog(this); - else - wxMessageBox("Cannot change database parameters while creating or editing a record","Notice...",wxOK | wxICON_INFORMATION); - break; - case ABOUT_DEMO: - wxMessageBox("wxWindows sample program for database classes\n\nContributed on 27 July 1998","About...",wxOK | wxICON_INFORMATION); - break; - } -} // DatabaseDemoFrame::OnMenuCommand() + this->Destroy(); +} +void DatabaseDemoFrame::OnEditParameters(wxCommandEvent& event) +{ + if ((pEditorDlg->mode != mCreate) && (pEditorDlg->mode != mEdit)) + BuildParameterDialog(this); + else + wxMessageBox("Cannot change database parameters while creating or editing a record","Notice...",wxOK | wxICON_INFORMATION); +} + +void DatabaseDemoFrame::OnAbout(wxCommandEvent& event) +{ + wxMessageBox("wxWindows sample program for database classes\n\nContributed on 27 July 1998","About...",wxOK | wxICON_INFORMATION); +} -Bool DatabaseDemoFrame::OnClose(void) +void DatabaseDemoFrame::OnCloseWindow(wxCloseEvent& event) { // Put any additional checking necessary to make certain it is alright // to close the program here that is not done elsewhere - return TRUE; + this->Destroy(); } // DatabaseDemoFrame::OnClose() void DatabaseDemoFrame::CreateDataTable() { - Bool Ok = (wxMessageBox("Any data currently residing in the table will be erased.\n\nAre you sure?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES); + bool Ok = (wxMessageBox("Any data currently residing in the table will be erased.\n\nAre you sure?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES); if (!Ok) return; wxBeginBusyCursor(); - Bool success = TRUE; + bool success = TRUE; Ccontact *Contact = new Ccontact(); if (!Contact) @@ -297,7 +295,7 @@ void DatabaseDemoFrame::CreateDataTable() wxString tStr; tStr = "Error creating CONTACTS table.\nTable was not created.\n\n"; tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); success = FALSE; } else @@ -308,7 +306,7 @@ void DatabaseDemoFrame::CreateDataTable() wxString tStr; tStr = "Error creating CONTACTS indexes.\nIndexes will be unavailable.\n\n"; tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); success = FALSE; } } @@ -394,7 +392,7 @@ Ccontact::~Ccontact() wxString tStr; tStr = "Unable to Free the Ccontact data table handle\n\n"; tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); } } } // Ccontract destructor @@ -416,20 +414,20 @@ void Ccontact::SetupColumns() 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 ( 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); } // Ccontact::SetupColumns -Bool Ccontact::CreateIndexes(void) +bool Ccontact::CreateIndexes(void) { // This index could easily be accomplished with an "orderBy" clause, // but is done to show how to construct a non-primary index. wxString indexName; CidxDef idxDef[2]; - Bool Ok = TRUE; + bool Ok = TRUE; strcpy(idxDef[0].ColName, "IS_DEVELOPER"); idxDef[0].Ascending = TRUE; @@ -439,7 +437,7 @@ Bool Ccontact::CreateIndexes(void) indexName = CONTACT_TABLE_NAME; indexName += "_IDX1"; - Ok = CreateIndex(indexName.GetData(), TRUE, 2, idxDef); + Ok = CreateIndex((char*) (const char*) indexName, TRUE, 2, idxDef); return Ok; } // Ccontact::CreateIndexes() @@ -450,10 +448,10 @@ Bool Ccontact::CreateIndexes(void) * very efficient and tighter coding so that it is available where ever the object * is. Great for use with multiple tables when not using views or outer joins */ -Bool Ccontact::FetchByName(char *name) +bool Ccontact::FetchByName(char *name) { - whereStr.sprintf("NAME = '%s'",name); - where = this->whereStr.GetData(); + whereStr.Printf("NAME = '%s'",name); + where = (char*) (const char*) this->whereStr; orderBy = 0; if (!Query()) @@ -503,11 +501,11 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455) while (!Contact->pDb->TableExists((char *)CONTACT_TABLE_NAME)) { wxString tStr; - tStr.sprintf("Unable to open the table '%s'.\n\nTable may need to be created...?\n\n",CONTACT_TABLE_NAME); + tStr.Printf("Unable to open the table '%s'.\n\nTable may need to be created...?\n\n",CONTACT_TABLE_NAME); tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); - Bool createTable = (wxMessageBox("Do you wish to try to create/clear the CONTACTS table?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES); + bool createTable = (wxMessageBox("Do you wish to try to create/clear the CONTACTS table?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES); if (!createTable) { @@ -529,9 +527,9 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455) if (Contact->pDb->TableExists((char *)CONTACT_TABLE_NAME)) { wxString tStr; - tStr.sprintf("Unable to open the table '%s'.\n\n",CONTACT_TABLE_NAME); + tStr.Printf("Unable to open the table '%s'.\n\n",CONTACT_TABLE_NAME); tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); delete Contact; Close(); DemoFrame->Close(); @@ -540,74 +538,66 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455) } // Build the dialog - SetLabelPosition(wxHORIZONTAL); - - wxFont *ButtonFont = new wxFont(12,wxSWISS,wxNORMAL,wxBOLD); - wxFont *TextFont = new wxFont(12,wxSWISS,wxNORMAL,wxNORMAL); - SetButtonFont(ButtonFont); - SetLabelFont(TextFont); - SetLabelPosition(wxVERTICAL); + 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"); - wxGroupBox *FunctionGrp = new wxGroupBox(this, "", 15, 1, 497, 69, 0, "FunctionGrp"); - wxGroupBox *SearchGrp = new wxGroupBox(this, "", 417, 1, 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"); + pDeleteBtn = new wxButton(this, EDITOR_DIALOG_DELETE, "&Delete", wxPoint(179, 21), wxSize(70, 35), 0, wxDefaultValidator, "DeleteBtn"); + pCopyBtn = new wxButton(this, EDITOR_DIALOG_COPY, "Cop&y", wxPoint(256, 21), wxSize(70, 35), 0, wxDefaultValidator, "CopyBtn"); + pSaveBtn = new wxButton(this, EDITOR_DIALOG_SAVE, "&Save", wxPoint(333, 21), wxSize(70, 35), 0, wxDefaultValidator, "SaveBtn"); + pCancelBtn = new wxButton(this, EDITOR_DIALOG_CANCEL, "C&ancel", wxPoint(430, 21), wxSize(70, 35), 0, wxDefaultValidator, "CancelBtn"); - pCreateBtn = new wxButton(this, NULL, "&Create", 25, 21, 70, 35, 0, "CreateBtn"); - pEditBtn = new wxButton(this, NULL, "&Edit", 102, 21, 70, 35, 0, "EditBtn"); - pDeleteBtn = new wxButton(this, NULL, "&Delete", 179, 21, 70, 35, 0, "DeleteBtn"); - pCopyBtn = new wxButton(this, NULL, "Cop&y", 256, 21, 70, 35, 0, "CopyBtn"); - pSaveBtn = new wxButton(this, NULL, "&Save", 333, 21, 70, 35, 0, "SaveBtn"); - pCancelBtn = new wxButton(this, NULL, "C&ancel", 430, 21, 70, 35, 0, "CancelBtn"); + pPrevBtn = new wxButton(this, EDITOR_DIALOG_PREV, "<< &Prev", wxPoint(430, 81), wxSize(70, 35), 0, wxDefaultValidator, "PrevBtn"); + pNextBtn = new wxButton(this, EDITOR_DIALOG_NEXT, "&Next >>", wxPoint(430, 121), wxSize(70, 35), 0, wxDefaultValidator, "NextBtn"); + pQueryBtn = new wxButton(this, EDITOR_DIALOG_QUERY, "&Query", wxPoint(430, 161), wxSize(70, 35), 0, wxDefaultValidator, "QueryBtn"); + pResetBtn = new wxButton(this, EDITOR_DIALOG_RESET, "&Reset", wxPoint(430, 200), wxSize(70, 35), 0, wxDefaultValidator, "ResetBtn"); - pPrevBtn = new wxButton(this, NULL, "<< &Prev",430, 81, 70, 35, 0, "PrevBtn"); - pNextBtn = new wxButton(this, NULL, "&Next >>",430, 121, 70, 35, 0, "NextBtn"); - pQueryBtn = new wxButton(this, NULL, "&Query", 430, 161, 70, 35, 0, "QueryBtn"); - pResetBtn = new wxButton(this, NULL, "&Reset", 430, 200, 70, 35, 0, "ResetBtn"); + pNameMsg = new wxStaticText(this, EDITOR_DIALOG_NAME_MSG, "Name:", wxPoint(17, 80), wxSize(-1, -1), 0, "NameMsg"); + pNameTxt = new wxTextCtrl(this, EDITOR_DIALOG_NAME_TEXT, "", wxPoint(17, 97), wxSize(308, 25), 0, wxDefaultValidator, "NameTxt"); + pNameListBtn = new wxButton(this, EDITOR_DIALOG_LOOKUP, "&Lookup", wxPoint(333, 99), wxSize(70, 24), 0, wxDefaultValidator, "LookupBtn"); - pNameMsg = new wxMessage(this, "Name:", 17, 80, -1, -1, 0, "NameMsg"); - pNameTxt = new wxText(this, NULL, "", "", 17, 97, 308, 25, 0, "NameTxt"); - pNameListBtn = new wxButton(this, NULL, "&Lookup", 333, 99, 70, 24, 0, "LookupBtn"); + pAddress1Msg = new wxStaticText(this, EDITOR_DIALOG_ADDRESS1_MSG, "Address:", wxPoint(17, 130), wxSize(-1, -1), 0, "Address1Msg"); + pAddress1Txt = new wxTextCtrl(this, EDITOR_DIALOG_ADDRESS2_TEXT, "", wxPoint(17, 147), wxSize(308, 25), 0, wxDefaultValidator, "Address1Txt"); - pAddress1Msg = new wxMessage(this, "Address:", 17, 130, -1, -1, 0, "Address1Msg"); - pAddress1Txt = new wxText(this, NULL, "", "", 17, 147, 308, 25, 0, "Address1Txt"); + pAddress2Msg = new wxStaticText(this, EDITOR_DIALOG_ADDRESS2_MSG, "Address:", wxPoint(17, 180), wxSize(-1, -1), 0, "Address2Msg"); + pAddress2Txt = new wxTextCtrl(this, EDITOR_DIALOG_ADDRESS2_TEXT, "", wxPoint(17, 197), wxSize(308, 25), 0, wxDefaultValidator, "Address2Txt"); - pAddress2Msg = new wxMessage(this, "Address:", 17, 180, -1, -1, 0, "Address2Msg"); - pAddress2Txt = new wxText(this, NULL, "", "", 17, 197, 308, 25, 0, "Address2Txt"); + pCityMsg = new wxStaticText(this, EDITOR_DIALOG_CITY_MSG, "City:", wxPoint(17, 230), wxSize(-1, -1), 0, "CityMsg"); + pCityTxt = new wxTextCtrl(this, EDITOR_DIALOG_CITY_TEXT, "", wxPoint(17, 247), wxSize(225, 25), 0, wxDefaultValidator, "CityTxt"); - pCityMsg = new wxMessage(this, "City:", 17, 230, -1, -1, 0, "CityMsg"); - pCityTxt = new wxText(this, NULL, "", "", 17, 247, 225, 25, 0, "CityTxt"); + pStateMsg = new wxStaticText(this, EDITOR_DIALOG_STATE_MSG, "State:", wxPoint(250, 230), wxSize(-1, -1), 0, "StateMsg"); + pStateTxt = new wxTextCtrl(this, EDITOR_DIALOG_STATE_TEXT, "", wxPoint(250, 247), wxSize(153, 25), 0, wxDefaultValidator, "StateTxt"); - pStateMsg = new wxMessage(this, "State:", 250, 230, -1, -1, 0, "StateMsg"); - pStateTxt = new wxText(this, NULL, "", "", 250, 247, 153, 25, 0, "StateTxt"); + pCountryMsg = new wxStaticText(this, EDITOR_DIALOG_COUNTRY_MSG, "Country:", wxPoint(17, 280), wxSize(-1, -1), 0, "CountryMsg"); + pCountryTxt = new wxTextCtrl(this, EDITOR_DIALOG_COUNTRY_TEXT, "", wxPoint(17, 297), wxSize(225, 25), 0, wxDefaultValidator, "CountryTxt"); - pCountryMsg = new wxMessage(this, "Country:", 17, 280, -1, -1, 0, "CountryMsg"); - pCountryTxt = new wxText(this, NULL, "", "", 17, 297, 225, 25, 0, "CountryTxt"); + pPostalCodeMsg = new wxStaticText(this, EDITOR_DIALOG_POSTAL_MSG, "Postal Code:", wxPoint(250, 280), wxSize(-1, -1), 0, "PostalCodeMsg"); + pPostalCodeTxt = new wxTextCtrl(this, EDITOR_DIALOG_POSTAL_TEXT, "", wxPoint(250, 297), wxSize(153, 25), 0, wxDefaultValidator, "PostalCodeTxt"); - pPostalCodeMsg = new wxMessage(this, "Postal Code:", 250, 280, -1, -1, 0, "PostalCodeMsg"); - pPostalCodeTxt = new wxText(this, NULL, "", "", 250, 297, 153, 25, 0, "PostalCodeTxt"); - - char *choice_strings[5]; + wxString choice_strings[5]; choice_strings[0] = "English"; choice_strings[1] = "French"; choice_strings[2] = "German"; choice_strings[3] = "Spanish"; choice_strings[4] = "Other"; - pNativeLangChoice = new wxChoice(this, NULL, "",17, 346, 277, -1, 5, choice_strings); - pNativeLangMsg = new wxMessage(this, "Native language:", 17, 330, -1, -1, 0, "NativeLangMsg"); + pNativeLangChoice = new wxChoice(this, EDITOR_DIALOG_LANG_CHOICE, wxPoint(17, 346), wxSize(277, -1), 5, choice_strings); + pNativeLangMsg = new wxStaticText(this, EDITOR_DIALOG_LANG_MSG, "Native language:", wxPoint(17, 330), wxSize(-1, -1), 0, "NativeLangMsg"); - char *radio_strings[2]; + wxString radio_strings[2]; radio_strings[0] = "No"; radio_strings[1] = "Yes"; - pDeveloperRadio = new wxRadioBox(this,NULL,"Developer:",303,330,-1,-1,2,radio_strings,2,wxHORIZONTAL|wxFLAT); + pDeveloperRadio = new wxRadioBox(this,EDITOR_DIALOG_DEVELOPER,"Developer:",wxPoint(303,330),wxSize(-1,-1),2,radio_strings,2,wxHORIZONTAL); - pJoinDateMsg = new wxMessage(this, "Date joined:", 17, 380, -1, -1, 0, "JoinDateMsg"); - pJoinDateTxt = new wxText(this, NULL, "", "", 17, 397, 150, 25, 0, "JoinDateTxt"); + pJoinDateMsg = new wxStaticText(this, EDITOR_DIALOG_JOIN_MSG, "Date joined:", wxPoint(17, 380), wxSize(-1, -1), 0, "JoinDateMsg"); + pJoinDateTxt = new wxTextCtrl(this, EDITOR_DIALOG_JOIN_TEXT, "", wxPoint(17, 397), wxSize(150, 25), 0, wxDefaultValidator, "JoinDateTxt"); - pContribMsg = new wxMessage(this, "Contributions:", 175, 380, -1, -1, 0, "ContribMsg"); - pContribTxt = new wxText(this, NULL, "", "", 175, 397, 120, 25, 0, "ContribTxt"); + pContribMsg = new wxStaticText(this, EDITOR_DIALOG_CONTRIB_MSG, "Contributions:", wxPoint(175, 380), wxSize(-1, -1), 0, "ContribMsg"); + pContribTxt = new wxTextCtrl(this, EDITOR_DIALOG_CONTRIB_TEXT, "", wxPoint(175, 397), wxSize(120, 25), 0, wxDefaultValidator, "ContribTxt"); - pLinesMsg = new wxMessage(this, "Lines of code:", 303, 380, -1, -1, 0, "LinesMsg"); - pLinesTxt = new wxText(this, NULL, "", "", 303, 397, 100, 25, 0, "LinesTxt"); + pLinesMsg = new wxStaticText(this, EDITOR_DIALOG_LINES_MSG, "Lines of code:", wxPoint(303, 380), wxSize(-1, -1), 0, "LinesMsg"); + pLinesTxt = new wxTextCtrl(this, EDITOR_DIALOG_LINES_TEXT, "", wxPoint(303, 397), wxSize(100, 25), 0, wxDefaultValidator, "LinesTxt"); // Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to // handle all widget processing @@ -626,10 +616,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.sprintf("NAME = (SELECT MIN(NAME) FROM %s)",Contact->tableName); - - // NOTE: GetData() returns a pointer which may not be valid later, so this is short term use only - Contact->where = Contact->whereStr.GetData(); + 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; // 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. @@ -639,7 +629,7 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455) wxString tStr; tStr = "ODBC error during Query()\n\n"; tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); GetParent()->Close(); return; } @@ -658,7 +648,7 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455) } // CeditorDlg constructor -Bool CeditorDlg::OnClose() +bool CeditorDlg::OnClose() { // Clean up time if ((mode != mCreate) && (mode != mEdit)) @@ -712,7 +702,7 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) if (widgetName == pDeleteBtn->GetName()) { - Bool Ok = (wxMessageBox("Are you sure?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES); + bool Ok = (wxMessageBox("Are you sure?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES); if (!Ok) return; @@ -757,12 +747,12 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) if (widgetName == pCancelBtn->GetName()) { - Bool Ok = (wxMessageBox("Are you sure?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES); + bool Ok = (wxMessageBox("Are you sure?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES); if (!Ok) return; - if (!strcmp(saveName.GetData(),"")) + if (!strcmp((const char*) saveName,"")) { Contact->Initialize(); PutData(); @@ -772,7 +762,7 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) else { // Requery previous record - if (Contact->FetchByName(saveName.GetData())) + if (Contact->FetchByName((char*) (const char*) saveName)) { PutData(); SetMode(mView); @@ -785,13 +775,13 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) Contact->whereStr += Contact->tableName; Contact->whereStr += ")"; - Contact->where = Contact->whereStr.GetData(); + Contact->where = (char*) (const char*) Contact->whereStr; if (!Contact->Query()) { wxString tStr; tStr = "ODBC error during Query()\n\n"; tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); SetMode(mView); return; } @@ -826,13 +816,13 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) { // Display the query dialog box char qryWhere[DB_MAX_WHERE_CLAUSE_LEN+1]; - strcpy(qryWhere, Contact->qryWhereStr.GetData()); + strcpy(qryWhere, (const char*) Contact->qryWhereStr); char *tblName[] = {(char *)CONTACT_TABLE_NAME, 0}; new CqueryDlg(GetParent(), Contact->pDb, tblName, qryWhere); // Query the first record in the new record set and // display it, if the query string has changed. - if (strcmp(qryWhere, Contact->qryWhereStr.GetData())) + if (strcmp(qryWhere, (const char*) Contact->qryWhereStr)) { Contact->orderBy = "NAME"; Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM "; @@ -847,13 +837,13 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) // Close the expression with a right paren Contact->whereStr += ")"; // Requery the table - Contact->where = Contact->whereStr.GetData(); + Contact->where = (char*) (const char*) Contact->whereStr; if (!Contact->Query()) { wxString tStr; tStr = "ODBC error during Query()\n\n"; tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); return; } // Display the first record from the query set @@ -863,7 +853,7 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) } // Enable/Disable the reset button - pResetBtn->Enable(!Contact->qryWhereStr.Empty()); + pResetBtn->Enable(!Contact->qryWhereStr.IsEmpty()); return; } // Query button @@ -879,13 +869,13 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM "; Contact->whereStr += CONTACT_TABLE_NAME; Contact->whereStr += ")"; - Contact->where = Contact->whereStr.GetData(); + Contact->where = (char*) (const char*) Contact->whereStr; if (!Contact->Query()) { wxString tStr; tStr = "ODBC error during Query()\n\n"; tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); return; } if (!Contact->GetNext()) @@ -906,14 +896,14 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) /* char *dispCol2 */ "JOIN_DATE", /* char *where */ "", /* char *orderBy */ "NAME", - /* Bool distinctValues */ TRUE); + /* bool distinctValues */ TRUE); if (ListDB_Selection && strlen(ListDB_Selection)) { wxString w = "NAME = '"; w += ListDB_Selection; w += "'"; - GetRec(w.GetData()); + GetRec((char*) (const char*) w); } return; @@ -943,7 +933,7 @@ void CeditorDlg::FieldsEditable() void CeditorDlg::SetMode(enum DialogModes m) { - Bool edit = FALSE; + bool edit = FALSE; mode = m; switch (mode) @@ -971,7 +961,7 @@ void CeditorDlg::SetMode(enum DialogModes m) pPrevBtn->Enable( !edit ); pNextBtn->Enable( !edit ); pQueryBtn->Enable( !edit ); - pResetBtn->Enable( !edit && !Contact->qryWhereStr.Empty() ); + pResetBtn->Enable( !edit && !Contact->qryWhereStr.IsEmpty() ); pNameListBtn->Enable( !edit ); } @@ -979,7 +969,7 @@ void CeditorDlg::SetMode(enum DialogModes m) } // CeditorDlg::SetMode() -Bool CeditorDlg::PutData() +bool CeditorDlg::PutData() { wxString tStr; @@ -991,14 +981,14 @@ Bool CeditorDlg::PutData() pCountryTxt->SetValue(Contact->Country); pPostalCodeTxt->SetValue(Contact->PostalCode); - tStr.sprintf("%d/%d/%d",Contact->JoinDate.month,Contact->JoinDate.day,Contact->JoinDate.year); - pJoinDateTxt->SetValue(tStr.GetData()); + tStr.Printf("%d/%d/%d",Contact->JoinDate.month,Contact->JoinDate.day,Contact->JoinDate.year); + pJoinDateTxt->SetValue(tStr); - tStr.sprintf("%d",Contact->Contributions); - pContribTxt->SetValue(tStr.GetData()); + tStr.Printf("%d",Contact->Contributions); + pContribTxt->SetValue(tStr); - tStr.sprintf("%lu",Contact->LinesOfCode); - pLinesTxt->SetValue(tStr.GetData()); + tStr.Printf("%lu",Contact->LinesOfCode); + pLinesTxt->SetValue(tStr); pNativeLangChoice->SetSelection(Contact->NativeLanguage); @@ -1016,19 +1006,19 @@ Bool CeditorDlg::PutData() * 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 */ -Bool CeditorDlg::GetData() +bool CeditorDlg::GetData() { // Validate that the data currently entered into the widgets is valid data wxString tStr; tStr = pNameTxt->GetValue(); - if (!strcmp(tStr.GetData(),"")) + if (!strcmp((const char*) tStr,"")) { wxMessageBox("A name is required for entry into the contact table","Notice...",wxOK | wxICON_INFORMATION); return FALSE; } - Bool invalid = FALSE; + bool invalid = FALSE; int mm,dd,yyyy; int first, second; @@ -1094,7 +1084,7 @@ Bool CeditorDlg::GetData() } tStr = pNameTxt->GetValue(); - strcpy(Contact->Name,tStr.GetData()); + strcpy(Contact->Name,(const char*) tStr); strcpy(Contact->Addr1,pAddress1Txt->GetValue()); strcpy(Contact->Addr2,pAddress2Txt->GetValue()); strcpy(Contact->City,pCityTxt->GetValue()); @@ -1106,7 +1096,7 @@ Bool CeditorDlg::GetData() Contact->LinesOfCode = atol(pLinesTxt->GetValue()); Contact->NativeLanguage = (enum Language) pNativeLangChoice->GetSelection(); - Contact->IsDeveloper = pDeveloperRadio->GetSelection(); + Contact->IsDeveloper = (bool) pDeveloperRadio->GetSelection(); return TRUE; } // CeditorDlg::GetData() @@ -1121,9 +1111,9 @@ Bool CeditorDlg::GetData() * 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 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()) @@ -1150,7 +1140,7 @@ Bool CeditorDlg::Save() wxString tStr; tStr = "A duplicate key value already exists in the table.\nUnable to save record\n\n"; tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); } else { @@ -1158,7 +1148,7 @@ Bool CeditorDlg::Save() wxString tStr; tStr = "Database insert failed\n\n"; tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); } } } @@ -1169,7 +1159,7 @@ Bool CeditorDlg::Save() wxString tStr; tStr = "Database update failed\n\n"; tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); failed = TRUE; } } @@ -1194,7 +1184,7 @@ Bool CeditorDlg::Save() * a special where clause must be built to find just the single row which, * in sequence, would follow the currently displayed row. */ -Bool CeditorDlg::GetNextRec() +bool CeditorDlg::GetNextRec() { wxString w; @@ -1205,7 +1195,7 @@ Bool CeditorDlg::GetNextRec() w += "'"; // If a query where string is currently set, append that criteria - if (!Contact->qryWhereStr.Empty()) + if (!Contact->qryWhereStr.IsEmpty()) { w += " AND ("; w += Contact->qryWhereStr; @@ -1214,7 +1204,7 @@ Bool CeditorDlg::GetNextRec() w += ")"; - return(GetRec(w.GetData())); + return(GetRec((char*) (const char*) w)); } // CeditorDlg::GetNextRec() @@ -1224,7 +1214,7 @@ Bool CeditorDlg::GetNextRec() * a special where clause must be built to find just the single row which, * in sequence, would precede the currently displayed row. */ -Bool CeditorDlg::GetPrevRec() +bool CeditorDlg::GetPrevRec() { wxString w; @@ -1235,7 +1225,7 @@ Bool CeditorDlg::GetPrevRec() w += "'"; // If a query where string is currently set, append that criteria - if (!Contact->qryWhereStr.Empty()) + if (!Contact->qryWhereStr.IsEmpty()) { w += " AND ("; w += Contact->qryWhereStr; @@ -1244,7 +1234,7 @@ Bool CeditorDlg::GetPrevRec() w += ")"; - return(GetRec(w.GetData())); + return(GetRec((char*) (const char*)w)); } // CeditorDlg::GetPrevRec() @@ -1253,7 +1243,7 @@ Bool CeditorDlg::GetPrevRec() * This function is here to avoid duplicating this same code in both the * GetPrevRec() and GetNextRec() functions */ -Bool CeditorDlg::GetRec(char *whereStr) +bool CeditorDlg::GetRec(char *whereStr) { Contact->where = whereStr; Contact->orderBy = "NAME"; @@ -1263,7 +1253,7 @@ Bool CeditorDlg::GetRec(char *whereStr) wxString tStr; tStr = "ODBC error during Query()\n\n"; tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); return(FALSE); } @@ -1282,34 +1272,24 @@ Bool CeditorDlg::GetRec(char *whereStr) /* * CparameterDlg constructor */ -CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialogBox (parent, "ODBC parameter settings", 1, -1, -1, 400, 275) +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 // detection in ::OnCommand() until all widgets have been initialized to prevent // uninitialized pointers from crashing the program widgetPtrsSet = FALSE; - // Build the dialog - SetLabelPosition(wxVERTICAL); - - wxFont *ButtonFont = new wxFont(12,wxSWISS,wxNORMAL,wxBOLD); - wxFont *TextFont = new wxFont(12,wxSWISS,wxNORMAL,wxNORMAL); + pParamODBCSourceMsg = new wxStaticText(this, PARAMETER_DIALOG_SOURCE_MSG, "ODBC data sources:", wxPoint(10, 10), wxSize(-1, -1), 0, "ParamODBCSourceMsg"); + pParamODBCSourceList = new wxListBox(this, PARAMETER_DIALOG_SOURCE_LISTBOX, wxPoint(10, 29), wxSize(285, 150), 0, 0, wxLB_SINGLE|wxLB_ALWAYS_SB, wxDefaultValidator, "ParamODBCSourceList"); - SetButtonFont(ButtonFont); - SetLabelFont(TextFont); - SetLabelPosition(wxVERTICAL); + pParamUserNameMsg = new wxStaticText(this, PARAMETER_DIALOG_NAME_MSG, "Database user name:", wxPoint(10, 193), wxSize(-1, -1), 0, "ParamUserNameMsg"); + pParamUserNameTxt = new wxTextCtrl(this, PARAMETER_DIALOG_NAME_TEXT, "", wxPoint(10, 209), wxSize(140, 25), 0, wxDefaultValidator, "ParamUserNameTxt"); - pParamODBCSourceMsg = new wxMessage(this, "ODBC data sources:", 10, 10, -1, -1, 0, "ParamODBCSourceMsg"); - pParamODBCSourceList = new wxListBox(this, NULL, "", wxSINGLE|wxALWAYS_SB, 10, 29, 285, 150, 0, 0, 0, "ParamODBCSourceList"); + 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"); - pParamUserNameMsg = new wxMessage(this, "Database user name:", 10, 193, -1, -1, 0, "ParamUserNameMsg"); - pParamUserNameTxt = new wxText(this, NULL, "", "", 10, 209, 140, 25, 0, "ParamUserNameTxt"); - - pParamPasswordMsg = new wxMessage(this, "Password:", 156, 193, -1, -1, 0, "ParamPasswordMsg"); - pParamPasswordTxt = new wxText(this, NULL, "", "", 156, 209, 140, 25, 0, "ParamPasswordTxt"); - - pParamSaveBtn = new wxButton(this, NULL, "&Save", 310, 21, 70, 35, 0, "ParamSaveBtn"); - pParamCancelBtn = new wxButton(this, NULL, "C&ancel", 310, 66, 70, 35, 0, "ParamCancelBtn"); + 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"); // Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to // handle all widget processing @@ -1320,17 +1300,17 @@ CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialogBox (parent, "ODBC para Centre(wxBOTH); PutData(); - Show(TRUE); + ShowModal(); } // CparameterDlg constructor -Bool CparameterDlg::OnClose() +bool CparameterDlg::OnClose() { // Put any additional checking necessary to make certain it is alright // to close the program here that is not done elsewhere if (!saved) { - Bool Ok = (wxMessageBox("No changes have been saved.\n\nAre you sure you wish exit the parameter screen?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES); + 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; @@ -1361,7 +1341,7 @@ void CparameterDlg::OnCommand(wxWindow& win, wxCommandEvent& event) tStr = "Database parameters have been saved."; if (GetParent() != NULL) // The parameter dialog was not called during startup due to a missing cfg file tStr += "\nNew parameters will take effect the next time the program is started."; - wxMessageBox(tStr.GetData(),"Notice...",wxOK | wxICON_INFORMATION); + wxMessageBox(tStr,"Notice...",wxOK | wxICON_INFORMATION); saved = TRUE; Close(); } @@ -1376,7 +1356,7 @@ void CparameterDlg::OnCommand(wxWindow& win, wxCommandEvent& event) } // CparameterDlg::OnCommand() -Bool CparameterDlg::PutData() +bool CparameterDlg::PutData() { // Fill the data source list box FillDataSourceList(); @@ -1389,7 +1369,7 @@ Bool CparameterDlg::PutData() } // CparameterDlg::PutData() -Bool CparameterDlg::GetData() +bool CparameterDlg::GetData() { wxString tStr; if (pParamODBCSourceList->GetStringSelection()) @@ -1398,11 +1378,11 @@ Bool CparameterDlg::GetData() if (tStr.Length() > (sizeof(DatabaseDemoApp.params.ODBCSource)-1)) { wxString errmsg; - errmsg.sprintf("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.GetData(),"Internal program error...",wxOK | wxICON_EXCLAMATION); + 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.GetData()); + strcpy(DatabaseDemoApp.params.ODBCSource, tStr); } else return FALSE; @@ -1411,26 +1391,26 @@ Bool CparameterDlg::GetData() if (tStr.Length() > (sizeof(DatabaseDemoApp.params.UserName)-1)) { wxString errmsg; - errmsg.sprintf("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.GetData(),"Internal program error...",wxOK | wxICON_EXCLAMATION); + 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.GetData()); + strcpy(DatabaseDemoApp.params.UserName, tStr); tStr = pParamPasswordTxt->GetValue(); if (tStr.Length() > (sizeof(DatabaseDemoApp.params.Password)-1)) { wxString errmsg; - errmsg.sprintf("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.GetData(),"Internal program error...",wxOK | wxICON_EXCLAMATION); + 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.GetData()); + strcpy(DatabaseDemoApp.params.Password,tStr); return TRUE; } // CparameterDlg::GetData() -Bool CparameterDlg::Save() +bool CparameterDlg::Save() { Cparameters saveParams = DatabaseDemoApp.params; if (!GetData()) @@ -1443,8 +1423,8 @@ Bool CparameterDlg::Save() if ((paramFile = fopen(paramFilename, "wt")) == NULL) { wxString tStr; - tStr.sprintf("Unable to write/overwrite '%s'.",paramFilename); - wxMessageBox(tStr.GetData(),"File I/O Error...",wxOK | wxICON_EXCLAMATION); + tStr.Printf("Unable to write/overwrite '%s'.",paramFilename); + wxMessageBox(tStr,"File I/O Error...",wxOK | wxICON_EXCLAMATION); return FALSE; } @@ -1479,7 +1459,7 @@ void CparameterDlg::FillDataSourceList() // CqueryDlg() constructor -CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg) : wxDialogBox (parent, "Query", 1, -1, -1, 480, 360) +CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg) : wxDialog (parent, QUERY_DIALOG, "Query", wxPoint(-1, -1), wxSize(480, 360)) { wxBeginBusyCursor(); @@ -1494,29 +1474,19 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereA if (strlen(pWhere) > DB_MAX_WHERE_CLAUSE_LEN) // Check the length of the buffer passed in { wxString s; - s.sprintf("Maximum where clause length exceeded.\nLength must be less than %d", DB_MAX_WHERE_CLAUSE_LEN+1); - wxMessageBox(s.GetData(),"Error...",wxOK | wxICON_EXCLAMATION); + s.Printf("Maximum where clause length exceeded.\nLength must be less than %d", DB_MAX_WHERE_CLAUSE_LEN+1); + wxMessageBox(s,"Error...",wxOK | wxICON_EXCLAMATION); Close(); return; } - // Build the dialog - SetLabelPosition(wxVERTICAL); - - wxFont *ButtonFont = new wxFont(12,wxSWISS,wxNORMAL,wxBOLD); - wxFont *TextFont = new wxFont(12,wxSWISS,wxNORMAL,wxNORMAL); + pQueryCol1Msg = new wxStaticText(this, QUERY_DIALOG_COL_MSG, "Column 1:", wxPoint(10, 10), wxSize(69, 16), 0, "QueryCol1Msg"); + pQueryCol1Choice = new wxChoice(this, QUERY_DIALOG_COL_CHOICE, wxPoint(10, 27), wxSize(250, 27), 0, 0, 0, wxDefaultValidator, "QueryCol1Choice"); - SetButtonFont(ButtonFont); - SetLabelFont(TextFont); - SetLabelPosition(wxVERTICAL); + pQueryNotMsg = new wxStaticText(this, QUERY_DIALOG_NOT_MSG, "NOT", wxPoint(268, 10), wxSize(-1, -1), 0, "QueryNotMsg"); + pQueryNotCheck = new wxCheckBox(this, QUERY_DIALOG_NOT_CHECKBOX, "", wxPoint(275, 37), wxSize(20, 20), 0, wxDefaultValidator, "QueryNotCheck"); - pQueryCol1Msg = new wxMessage(this, "Column 1:", 10, 10, 69, 16, 0, "QueryCol1Msg"); - pQueryCol1Choice = new wxChoice(this, NULL, "", 10, 27, 250, 27, 0, 0, 0, "QueryCol1Choice"); - - pQueryNotMsg = new wxMessage(this, "NOT", 268, 10, -1, -1, 0, "QueryNotMsg"); - pQueryNotCheck = new wxCheckBox(this, NULL, "", 275, 37, 20, 20, 0, "QueryNotCheck"); - - char *choice_strings[9]; + wxString choice_strings[9]; choice_strings[0] = "="; choice_strings[1] = "<"; choice_strings[2] = ">"; @@ -1526,34 +1496,34 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereA choice_strings[6] = "Contains"; choice_strings[7] = "Like"; choice_strings[8] = "Between"; - pQueryOperatorMsg = new wxMessage(this, "Operator:", 305, 10, -1, -1, 0, "QueryOperatorMsg"); - pQueryOperatorChoice = new wxChoice(this, NULL, "", 305, 27, 80, 27, 9, choice_strings, 0, "QueryOperatorChoice"); - - pQueryCol2Msg = new wxMessage(this, "Column 2:", 10, 65, 69, 16, 0, "QueryCol2Msg"); - pQueryCol2Choice = new wxChoice(this, NULL, "", 10, 82, 250, 27, 0, 0, 0, "QueryCol2Choice"); + pQueryOperatorMsg = new wxStaticText(this, QUERY_DIALOG_OP_MSG, "Operator:", wxPoint(305, 10), wxSize(-1, -1), 0, "QueryOperatorMsg"); + pQueryOperatorChoice = new wxChoice(this, QUERY_DIALOG_OP_CHOICE, wxPoint(305, 27), wxSize(80, 27), 9, choice_strings, 0, wxDefaultValidator, "QueryOperatorChoice"); - pQuerySqlWhereMsg = new wxMessage(this, "SQL where clause:", 10, 141, -1, -1, 0, "QuerySqlWhereMsg"); - pQuerySqlWhereMtxt = new wxMultiText(this, NULL, "", "", 10, 159, 377, 134, 0, "QuerySqlWhereMtxt"); + pQueryCol2Msg = new wxStaticText(this, QUERY_DIALOG_COL2_MSG, "Column 2:", wxPoint(10, 65), wxSize(69, 16), 0, "QueryCol2Msg"); + pQueryCol2Choice = new wxChoice(this, QUERY_DIALOG_COL2_CHOICE, wxPoint(10, 82), wxSize(250, 27), 0, 0, 0, wxDefaultValidator, "QueryCol2Choice"); - pQueryAddBtn = new wxButton(this, NULL, "&Add", 406, 24, 56, 26, 0, "QueryAddBtn"); - pQueryAndBtn = new wxButton(this, NULL, "A&nd", 406, 58, 56, 26, 0, "QueryAndBtn"); - pQueryOrBtn = new wxButton(this, NULL, "&Or", 406, 92, 56, 26, 0, "QueryOrBtn"); + pQuerySqlWhereMsg = new wxStaticText(this, QUERY_DIALOG_WHERE_MSG, "SQL where clause:", wxPoint(10, 141), wxSize(-1, -1), 0, "QuerySqlWhereMsg"); + pQuerySqlWhereMtxt = new wxTextCtrl(this, QUERY_DIALOG_WHERE_TEXT, "", wxPoint(10, 159), wxSize(377, 134), wxTE_MULTILINE, wxDefaultValidator, "QuerySqlWhereMtxt"); - pQueryLParenBtn = new wxButton(this, NULL, "(", 406, 126, 26, 26, 0, "QueryLParenBtn"); - pQueryRParenBtn = new wxButton(this, NULL, ")", 436, 126, 26, 26, 0, "QueryRParenBtn"); + pQueryAddBtn = new wxButton(this, QUERY_DIALOG_ADD, "&Add", wxPoint(406, 24), wxSize(56, 26), 0, wxDefaultValidator, "QueryAddBtn"); + pQueryAndBtn = new wxButton(this, QUERY_DIALOG_AND, "A&nd", wxPoint(406, 58), wxSize(56, 26), 0, wxDefaultValidator, "QueryAndBtn"); + pQueryOrBtn = new wxButton(this, QUERY_DIALOG_OR, "&Or", wxPoint(406, 92), wxSize(56, 26), 0, wxDefaultValidator, "QueryOrBtn"); - pQueryDoneBtn = new wxButton(this, NULL, "&Done", 406, 185, 56, 26, 0, "QueryDoneBtn"); - pQueryClearBtn = new wxButton(this, NULL, "C&lear", 406, 218, 56, 26, 0, "QueryClearBtn"); - pQueryCountBtn = new wxButton(this, NULL, "&Count", 406, 252, 56, 26, 0, "QueryCountBtn"); + pQueryLParenBtn = new wxButton(this, QUERY_DIALOG_LPAREN, "(", wxPoint(406, 126), wxSize(26, 26), 0, wxDefaultValidator, "QueryLParenBtn"); + pQueryRParenBtn = new wxButton(this, QUERY_DIALOG_RPAREN, ")", wxPoint(436, 126), wxSize(26, 26), 0, wxDefaultValidator, "QueryRParenBtn"); - pQueryValue1Msg = new wxMessage(this, "Value:", 277, 66, -1, -1, 0, "QueryValue1Msg"); - pQueryValue1Txt = new wxText(this, NULL, "", "", 277, 83, 108, 25, 0, "QueryValue1Txt"); + pQueryDoneBtn = new wxButton(this, QUERY_DIALOG_DONE, "&Done", wxPoint(406, 185), wxSize(56, 26), 0, wxDefaultValidator, "QueryDoneBtn"); + pQueryClearBtn = new wxButton(this, QUERY_DIALOG_CLEAR, "C&lear", wxPoint(406, 218), wxSize(56, 26), 0, wxDefaultValidator, "QueryClearBtn"); + pQueryCountBtn = new wxButton(this, QUERY_DIALOG_COUNT, "&Count", wxPoint(406, 252), wxSize(56, 26), 0, wxDefaultValidator, "QueryCountBtn"); - pQueryValue2Msg = new wxMessage(this, "AND", 238, 126, -1, -1, 0, "QueryValue2Msg"); - pQueryValue2Txt = new wxText(this, NULL, "", "", 277, 120, 108, 25, 0, "QueryValue2Txt"); + pQueryValue1Msg = new wxStaticText(this, QUERY_DIALOG_VALUE1_MSG, "Value:", wxPoint(277, 66), wxSize(-1, -1), 0, "QueryValue1Msg"); + pQueryValue1Txt = new wxTextCtrl(this, QUERY_DIALOG_VALUE1_TEXT, "", wxPoint(277, 83), wxSize(108, 25), 0, wxDefaultValidator, "QueryValue1Txt"); - pQueryHintGrp = new wxGroupBox(this, "", 10, 291, 377, 40, 0, "QueryHintGrp"); - pQueryHintMsg = new wxMessage(this, "", 16, 306, -1, -1, 0, "QueryHintMsg"); + pQueryValue2Msg = new wxStaticText(this, QUERY_DIALOG_VALUE2_MSG, "AND", wxPoint(238, 126), wxSize(-1, -1), 0, "QueryValue2Msg"); + pQueryValue2Txt = new wxTextCtrl(this, QUERY_DIALOG_VALUE2_TEXT, "", wxPoint(277, 120), wxSize(108, 25), 0, wxDefaultValidator, "QueryValue2Txt"); + + pQueryHintGrp = new wxStaticBox(this, QUERY_DIALOG_HINT_GROUP, "", wxPoint(10, 291), wxSize(377, 40), 0, "QueryHintGrp"); + pQueryHintMsg = new wxStaticText(this, QUERY_DIALOG_HINT_MSG, "", wxPoint(16, 306), wxSize(-1, -1), 0, "QueryHintMsg"); widgetPtrsSet = TRUE; // Initialize the dialog @@ -1566,9 +1536,9 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereA // the column names with the table name prefix. if (tblName[1] && strlen(tblName[1])) { - qualName.sprintf("%s.%s", colInf[i].tableName, colInf[i].colName); - pQueryCol1Choice->Append(qualName.GetData()); - pQueryCol2Choice->Append(qualName.GetData()); + qualName.Printf("%s.%s", colInf[i].tableName, colInf[i].colName); + pQueryCol1Choice->Append(qualName); + pQueryCol2Choice->Append(qualName); } else // Single table query, append just the column names { @@ -1591,9 +1561,8 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereA wxEndBusyCursor(); // Display the dialog window - SetModal(TRUE); Centre(wxBOTH); - Show(TRUE); + ShowModal(); } // CqueryDlg() constructor @@ -1772,8 +1741,8 @@ void CqueryDlg::OnCommand(wxWindow& win, wxCommandEvent& event) if (strlen(pQuerySqlWhereMtxt->GetValue()) > DB_MAX_WHERE_CLAUSE_LEN) { wxString s; - s.sprintf("Maximum where clause length exceeded.\nLength must be less than %d", DB_MAX_WHERE_CLAUSE_LEN+1); - wxMessageBox(s.GetData(),"Error...",wxOK | wxICON_EXCLAMATION); + s.Printf("Maximum where clause length exceeded.\nLength must be less than %d", DB_MAX_WHERE_CLAUSE_LEN+1); + wxMessageBox(s,"Error...",wxOK | wxICON_EXCLAMATION); return; } // Validate the where clause for things such as matching parens @@ -1789,7 +1758,7 @@ void CqueryDlg::OnCommand(wxWindow& win, wxCommandEvent& event) // Clear button if (widgetName == pQueryClearBtn->GetName()) { - Bool Ok = (wxMessageBox("Are you sure you wish to clear the Query?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES); + bool Ok = (wxMessageBox("Are you sure you wish to clear the Query?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES); if (Ok) pQuerySqlWhereMtxt->SetValue(""); @@ -1810,7 +1779,7 @@ void CqueryDlg::OnCommand(wxWindow& win, wxCommandEvent& event) } // CqueryDlg::OnCommand -Bool CqueryDlg::OnClose() +bool CqueryDlg::OnClose() { // Clean up if (colInf) @@ -1832,16 +1801,16 @@ Bool CqueryDlg::OnClose() } // CqueryDlg::OnClose() /* -Bool CqueryDlg::SetWidgetPtrs() +bool CqueryDlg::SetWidgetPtrs() { - Bool abort = FALSE; + bool abort = FALSE; abort = abort || !(pQueryCol1Choice = (wxChoice *)GetWidgetPtr("QueryCol1Choice",this)); abort = abort || !(pQueryNotCheck = (wxCheckBox *)GetWidgetPtr("QueryNotCheck",this)); abort = abort || !(pQueryOperatorChoice = (wxChoice *)GetWidgetPtr("QueryOperatorChoice",this)); abort = abort || !(pQueryCol2Choice = (wxChoice *)GetWidgetPtr("QueryCol2Choice",this)); - abort = abort || !(pQueryValue1Txt = (wxText *)GetWidgetPtr("QueryValue1Txt",this)); - abort = abort || !(pQueryValue2Txt = (wxText *)GetWidgetPtr("QueryValue2Txt",this)); + abort = abort || !(pQueryValue1Txt = (wxTextCtrl *)GetWidgetPtr("QueryValue1Txt",this)); + abort = abort || !(pQueryValue2Txt = (wxTextCtrl *)GetWidgetPtr("QueryValue2Txt",this)); abort = abort || !(pQuerySqlWhereMtxt = (wxMultiText *)GetWidgetPtr("QuerySqlWhereMtxt",this)); abort = abort || !(pQueryAddBtn = (wxButton *)GetWidgetPtr("QueryAddBtn",this)); abort = abort || !(pQueryAndBtn = (wxButton *)GetWidgetPtr("QueryAndBtn",this)); @@ -1852,7 +1821,7 @@ Bool CqueryDlg::SetWidgetPtrs() abort = abort || !(pQueryClearBtn = (wxButton *)GetWidgetPtr("QueryClearBtn",this)); abort = abort || !(pQueryCountBtn = (wxButton *)GetWidgetPtr("QueryCountBtn",this)); abort = abort || !(pQueryHelpBtn = (wxButton *)GetWidgetPtr("QueryHelpBtn",this)); - abort = abort || !(pQueryHintMsg = (wxMessage *)GetWidgetPtr("QueryHintMsg",this)); + abort = abort || !(pQueryHintMsg = (wxStaticText *)GetWidgetPtr("QueryHintMsg",this)); pFocusTxt = NULL; @@ -1865,7 +1834,7 @@ void CqueryDlg::AppendToWhere(char *s) { wxString whereStr = pQuerySqlWhereMtxt->GetValue(); whereStr += s; - pQuerySqlWhereMtxt->SetValue(whereStr.GetData()); + pQuerySqlWhereMtxt->SetValue(whereStr); } // CqueryDlg::AppendToWhere() @@ -1934,8 +1903,8 @@ void CqueryDlg::ProcessAddBtn() int col1Idx = pQueryCol1Choice->GetSelection(); - Bool quote = FALSE; - if (colInf[col1Idx].sqlDataType == SQL_VARCHAR || + bool quote = FALSE; + if (colInf[col1Idx].sqlDataType == SQL_VARCHAR || oper == qryOpBEGINS || oper == qryOpCONTAINS || oper == qryOpLIKE) @@ -1966,7 +1935,7 @@ void CqueryDlg::ProcessAddBtn() s += "'"; } - AppendToWhere(s.GetData()); + AppendToWhere((char*) (const char*) s); } // CqueryDlg::ProcessAddBtn() @@ -1988,13 +1957,13 @@ void CqueryDlg::ProcessCountBtn() wxString tStr; tStr = "ODBC error during Open()\n\n"; tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__); - wxMessageBox(tStr.GetData(),"ODBC Error...",wxOK | wxICON_EXCLAMATION); + wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION); return; } } // Count() with WHERE clause - dbTable->where = pQuerySqlWhereMtxt->GetValue(); + dbTable->where = (char*) (const char*) pQuerySqlWhereMtxt->GetValue(); ULONG whereCnt = dbTable->Count(); // Count() of all records in the table @@ -2004,14 +1973,14 @@ void CqueryDlg::ProcessCountBtn() if (whereCnt > 0 || totalCnt == 0) { wxString tStr; - tStr.sprintf("%lu of %lu records match the query criteria.",whereCnt,totalCnt); - wxMessageBox(tStr.GetData(),"Notice...",wxOK | wxICON_INFORMATION); + tStr.Printf("%lu of %lu records match the query criteria.",whereCnt,totalCnt); + wxMessageBox(tStr,"Notice...",wxOK | wxICON_INFORMATION); } else { wxString tStr; - tStr.sprintf("%lu of %lu records match the query criteria.\n\nEither the criteria entered produced a result set\nwith no records, or there was a syntactical error\nin the clause you entered.\n\nPress the details button to see if any database errors were reported.",whereCnt,totalCnt); - wxMessageBox(tStr.GetData(),"Notice...",wxOK | wxICON_INFORMATION); + tStr.Printf("%lu of %lu records match the query criteria.\n\nEither the criteria entered produced a result set\nwith no records, or there was a syntactical error\nin the clause you entered.\n\nPress the details button to see if any database errors were reported.",whereCnt,totalCnt); + wxMessageBox(tStr,"Notice...",wxOK | wxICON_INFORMATION); } // After a wxMessageBox, the focus does not necessarily return to the @@ -2022,7 +1991,7 @@ void CqueryDlg::ProcessCountBtn() } // CqueryDlg::ProcessCountBtn() -Bool CqueryDlg::ValidateWhereClause() +bool CqueryDlg::ValidateWhereClause() { wxString where = pQuerySqlWhereMtxt->GetValue(); diff --git a/samples/db/dbtest.h b/samples/db/dbtest.h index 76ee48eaba..6689d522ea 100644 --- a/samples/db/dbtest.h +++ b/samples/db/dbtest.h @@ -9,7 +9,9 @@ // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// +#ifdef __GNUG__ #pragma interface "dbtest.h" +#endif #include #include @@ -104,7 +106,7 @@ class DatabaseDemoApp: public wxApp { public: Cparameters params; - wxFrame *OnInit(void); + bool OnInit(); }; // DatabaseDemoApp DECLARE_APP(DatabaseDemoApp) @@ -117,14 +119,19 @@ class DatabaseDemoFrame: public wxFrame CparameterDlg *pParamDlg; public: - DatabaseDemoFrame(wxFrame *frame, char *title, int x, int y, int w, int h); + DatabaseDemoFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& sz); - void OnMenuCommand(int id); - bool OnClose(void); + void OnCloseWindow(wxCloseEvent& event); + void OnCreate(wxCommandEvent& event); + void OnExit(wxCommandEvent& event); + void OnEditParameters(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); void CreateDataTable(); void BuildEditorDialog(); void BuildParameterDialog(wxWindow *parent); + +DECLARE_EVENT_TABLE() }; // DatabaseDemoFrame @@ -141,13 +148,13 @@ class CeditorDlg : public wxPanel wxButton *pCreateBtn, *pEditBtn, *pDeleteBtn, *pCopyBtn, *pSaveBtn, *pCancelBtn; wxButton *pPrevBtn, *pNextBtn, *pQueryBtn, *pResetBtn, *pDoneBtn, *pHelpBtn; wxButton *pNameListBtn; - wxText *pNameTxt, *pAddress1Txt, *pAddress2Txt,*pCityTxt, *pStateTxt, *pCountryTxt,*pPostalCodeTxt; - wxMessage *pNameMsg, *pAddress1Msg, *pAddress2Msg,*pCityMsg, *pStateMsg, *pCountryMsg,*pPostalCodeMsg; - wxText *pJoinDateTxt,*pContribTxt, *pLinesTxt; - wxMessage *pJoinDateMsg,*pContribMsg, *pLinesMsg; + wxTextCtrl *pNameTxt, *pAddress1Txt, *pAddress2Txt,*pCityTxt, *pStateTxt, *pCountryTxt,*pPostalCodeTxt; + wxStaticText *pNameMsg, *pAddress1Msg, *pAddress2Msg,*pCityMsg, *pStateMsg, *pCountryMsg,*pPostalCodeMsg; + wxTextCtrl *pJoinDateTxt,*pContribTxt, *pLinesTxt; + wxStaticText *pJoinDateMsg,*pContribMsg, *pLinesMsg; wxRadioBox *pDeveloperRadio; wxChoice *pNativeLangChoice; - wxMessage *pNativeLangMsg; + wxStaticText *pNativeLangMsg; public: enum DialogModes mode; @@ -168,10 +175,51 @@ class CeditorDlg : public wxPanel bool GetRec(char *whereStr); }; // CeditorDlg +#define EDITOR_DIALOG 199 + +// Editor dialog control ids +#define EDITOR_DIALOG_FN_GROUP 200 +#define EDITOR_DIALOG_SEARCH_GROUP 201 +#define EDITOR_DIALOG_CREATE 202 +#define EDITOR_DIALOG_EDIT 203 +#define EDITOR_DIALOG_DELETE 204 +#define EDITOR_DIALOG_COPY 205 +#define EDITOR_DIALOG_SAVE 206 +#define EDITOR_DIALOG_CANCEL 207 +#define EDITOR_DIALOG_PREV 208 +#define EDITOR_DIALOG_NEXT 209 +#define EDITOR_DIALOG_QUERY 211 +#define EDITOR_DIALOG_RESET 212 +#define EDITOR_DIALOG_NAME_MSG 213 +#define EDITOR_DIALOG_NAME_TEXT 214 +#define EDITOR_DIALOG_LOOKUP 215 +#define EDITOR_DIALOG_ADDRESS1_MSG 216 +#define EDITOR_DIALOG_ADDRESS1_TEXT 217 +#define EDITOR_DIALOG_ADDRESS2_MSG 218 +#define EDITOR_DIALOG_ADDRESS2_TEXT 219 +#define EDITOR_DIALOG_CITY_MSG 220 +#define EDITOR_DIALOG_CITY_TEXT 221 +#define EDITOR_DIALOG_COUNTRY_MSG 222 +#define EDITOR_DIALOG_COUNTRY_TEXT 223 +#define EDITOR_DIALOG_POSTAL_MSG 224 +#define EDITOR_DIALOG_POSTAL_TEXT 225 +#define EDITOR_DIALOG_LANG_MSG 226 +#define EDITOR_DIALOG_LANG_CHOICE 227 +#define EDITOR_DIALOG_DATE_MSG 228 +#define EDITOR_DIALOG_DATE_TEXT 229 +#define EDITOR_DIALOG_CONTRIB_MSG 230 +#define EDITOR_DIALOG_CONTRIB_TEXT 231 +#define EDITOR_DIALOG_LINES_MSG 232 +#define EDITOR_DIALOG_LINES_TEXT 233 +#define EDITOR_DIALOG_STATE_MSG 234 +#define EDITOR_DIALOG_STATE_TEXT 235 +#define EDITOR_DIALOG_DEVELOPER 236 +#define EDITOR_DIALOG_JOIN_MSG 237 +#define EDITOR_DIALOG_JOIN_TEXT 238 // *************************** CparameterDlg *************************** -class CparameterDlg : public wxDialogBox +class CparameterDlg : public wxDialog { private: bool widgetPtrsSet; @@ -180,10 +228,10 @@ class CparameterDlg : public wxDialogBox Cparameters savedParamSettings; // Pointers to all widgets on the dialog - wxMessage *pParamODBCSourceMsg; + wxStaticText *pParamODBCSourceMsg; wxListBox *pParamODBCSourceList; - wxMessage *pParamUserNameMsg, *pParamPasswordMsg; - wxText *pParamUserNameTxt, *pParamPasswordTxt; + wxStaticText *pParamUserNameMsg, *pParamPasswordMsg; + wxTextCtrl *pParamUserNameTxt, *pParamPasswordTxt; wxButton *pParamSaveBtn, *pParamCancelBtn; public: @@ -199,6 +247,17 @@ class CparameterDlg : public wxDialogBox }; // CparameterDlg +#define PARAMETER_DIALOG 400 + +// Parameter dialog control ids +#define PARAMETER_DIALOG_SOURCE_MSG 401 +#define PARAMETER_DIALOG_SOURCE_LISTBOX 402 +#define PARAMETER_DIALOG_NAME_MSG 403 +#define PARAMETER_DIALOG_NAME_TEXT 404 +#define PARAMETER_DIALOG_PASSWORD_MSG 405 +#define PARAMETER_DIALOG_PASSWORD_TEXT 406 +#define PARAMETER_DIALOG_SAVE 407 +#define PARAMETER_DIALOG_CANCEL 408 // *************************** CqueryDlg *************************** @@ -230,7 +289,7 @@ char * const langQRY_LIKE = "% matches 0 or more of any char; _ matches char * const langQRY_BETWEEN = "column BETWEEN value AND value"; -class CqueryDlg : public wxDialogBox +class CqueryDlg : public wxDialog { private: CcolInf *colInf; // Column inf. returned by db->GetColumns() @@ -243,20 +302,20 @@ class CqueryDlg : public wxDialogBox bool widgetPtrsSet; // Widget pointers - wxMessage *pQueryCol1Msg; + wxStaticText *pQueryCol1Msg; wxChoice *pQueryCol1Choice; - wxMessage *pQueryNotMsg; + wxStaticText *pQueryNotMsg; wxCheckBox *pQueryNotCheck; - wxMessage *pQueryOperatorMsg; + wxStaticText *pQueryOperatorMsg; wxChoice *pQueryOperatorChoice; - wxMessage *pQueryCol2Msg; + wxStaticText *pQueryCol2Msg; wxChoice *pQueryCol2Choice; - wxMessage *pQueryValue1Msg; - wxText *pQueryValue1Txt; - wxMessage *pQueryValue2Msg; - wxText *pQueryValue2Txt; - wxMessage *pQuerySqlWhereMsg; - wxMultiText *pQuerySqlWhereMtxt; + wxStaticText *pQueryValue1Msg; + wxTextCtrl *pQueryValue1Txt; + wxStaticText *pQueryValue2Msg; + wxTextCtrl *pQueryValue2Txt; + wxStaticText *pQuerySqlWhereMsg; + wxTextCtrl *pQuerySqlWhereMtxt; wxButton *pQueryAddBtn; wxButton *pQueryAndBtn; wxButton *pQueryOrBtn; @@ -266,10 +325,10 @@ class CqueryDlg : public wxDialogBox wxButton *pQueryClearBtn; wxButton *pQueryCountBtn; wxButton *pQueryHelpBtn; - wxGroupBox *pQueryHintGrp; - wxMessage *pQueryHintMsg; + wxStaticBox *pQueryHintGrp; + wxStaticText *pQueryHintMsg; - wxText *pFocusTxt; + wxTextCtrl *pFocusTxt; CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg); @@ -284,3 +343,32 @@ class CqueryDlg : public wxDialogBox bool ValidateWhereClause(); }; // CqueryDlg + +#define QUERY_DIALOG 300 + +// Parameter dialog control ids +#define QUERY_DIALOG_COL_MSG 301 +#define QUERY_DIALOG_COL_CHOICE 302 +#define QUERY_DIALOG_NOT_MSG 303 +#define QUERY_DIALOG_NOT_CHECKBOX 304 +#define QUERY_DIALOG_OP_MSG 305 +#define QUERY_DIALOG_OP_CHOICE 306 +#define QUERY_DIALOG_COL2_MSG 307 +#define QUERY_DIALOG_COL2_CHOICE 308 +#define QUERY_DIALOG_WHERE_MSG 309 +#define QUERY_DIALOG_WHERE_TEXT 310 +#define QUERY_DIALOG_ADD 311 +#define QUERY_DIALOG_AND 312 +#define QUERY_DIALOG_OR 313 +#define QUERY_DIALOG_LPAREN 314 +#define QUERY_DIALOG_RPAREN 315 +#define QUERY_DIALOG_DONE 316 +#define QUERY_DIALOG_CLEAR 317 +#define QUERY_DIALOG_COUNT 318 +#define QUERY_DIALOG_VALUE1_MSG 319 +#define QUERY_DIALOG_VALUE1_TEXT 320 +#define QUERY_DIALOG_VALUE2_MSG 321 +#define QUERY_DIALOG_VALUE2_TEXT 322 +#define QUERY_DIALOG_HINT_GROUP 323 +#define QUERY_DIALOG_HINT_MSG 324 + diff --git a/samples/db/listdb.cpp b/samples/db/listdb.cpp index 330c79db2a..bea0ddc717 100644 --- a/samples/db/listdb.cpp +++ b/samples/db/listdb.cpp @@ -103,7 +103,7 @@ Clookup2::Clookup2(char *tblName, char *colName1, char *colName2, wxDB *pDb) // This is a generic lookup constructor that will work with any table and any column ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, char *colName, - char *where, char *orderBy) : wxDialogBox (parent, "Select...", 1, -1, -1, 400, 290) + char *where, char *orderBy) : wxDialog (parent, LOOKUP_DIALOG, "Select...", wxPoint(-1, -1), wxSize(400, 290)) { wxBeginBusyCursor(); @@ -114,19 +114,9 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, cha noDisplayCols = 1; col1Len = 0; - // Build the dialog - SetLabelPosition(wxVERTICAL); - - wxFont *ButtonFont = new wxFont(12,wxSWISS,wxNORMAL,wxBOLD); - wxFont *TextFont = new wxFont(12,wxSWISS,wxNORMAL,wxNORMAL); - - SetButtonFont(ButtonFont); - SetLabelFont(TextFont); - SetLabelPosition(wxVERTICAL); - - pLookUpSelectList = new wxListBox(this, NULL, "", wxSINGLE|wxALWAYS_SB, 5, 15, 384, 195, 0, 0, 0, "LookUpSelectList"); - pLookUpOkBtn = new wxButton(this, NULL, "&Ok", 113, 222, 70, 35, 0, "LookUpOkBtn"); - pLookUpCancelBtn = new wxButton(this, NULL, "C&ancel", 212, 222, 70, 35, 0, "LookUpCancelBtn"); + pLookUpSelectList = new wxListBox(this, LOOKUP_DIALOG_SELECT, wxPoint(5, 15), wxSize(384, 195), 0, 0, wxLB_SINGLE|wxLB_ALWAYS_SB, wxDefaultValidator, "LookUpSelectList"); + pLookUpOkBtn = new wxButton(this, LOOKUP_DIALOG_OK, "&Ok", wxPoint(113, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpOkBtn"); + pLookUpCancelBtn = new wxButton(this, LOOKUP_DIALOG_CANCEL, "C&ancel", wxPoint(212, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpCancelBtn"); widgetPtrsSet = TRUE; @@ -141,8 +131,8 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, cha if (!lookup->Open()) { wxString tStr; - tStr.sprintf("Unable to open the table '%s'.",tableName); - wxMessageBox(tStr.GetData(),"ODBC Error..."); + tStr.Printf("Unable to open the table '%s'.",tableName); + wxMessageBox(tStr,"ODBC Error..."); Close(); return; } @@ -176,7 +166,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, cha SetTitle(windowTitle); Centre(wxBOTH); wxEndBusyCursor(); - Show(TRUE); + ShowModal(); } // Generic lookup constructor @@ -207,7 +197,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, cha // ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, char *dispCol1, char *dispCol2, char *where, char *orderBy, bool distinctValues, - char *selectStmt, int maxLenCol1, wxDB *pDb, bool allowOk) : wxDialogBox (parent, "Select...", 1, -1, -1, 400, 290) + char *selectStmt, int maxLenCol1, wxDB *pDb, bool allowOk) : wxDialog (parent, LOOKUP_DIALOG, "Select...", wxPoint(-1, -1), wxSize(400, 290)) { wxBeginBusyCursor(); @@ -219,24 +209,16 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, noDisplayCols = (strlen(dispCol2) ? 2 : 1); col1Len = 0; - // Build the dialog - SetLabelPosition(wxVERTICAL); - - wxFont *ButtonFont = new wxFont(12,wxSWISS,wxNORMAL,wxBOLD); - wxFont *TextFont = new wxFont(12,wxSWISS,wxNORMAL,wxNORMAL); - wxFont *FixedFont = new wxFont(12,wxMODERN,wxNORMAL,wxNORMAL); - - SetButtonFont(ButtonFont); - SetLabelFont(TextFont); - SetLabelPosition(wxVERTICAL); + wxFont fixedFont(12,wxMODERN,wxNORMAL,wxNORMAL); // this is done with fixed font so that the second column (if any) will be left // justified in the second column - SetButtonFont(FixedFont); - pLookUpSelectList = new wxListBox(this, NULL, "", wxSINGLE|wxALWAYS_SB, 5, 15, 384, 195, 0, 0, 0, "LookUpSelectList"); - SetButtonFont(ButtonFont); - pLookUpOkBtn = new wxButton(this, NULL, "&Ok", 113, 222, 70, 35, 0, "LookUpOkBtn"); - pLookUpCancelBtn = new wxButton(this, NULL, "C&ancel", 212, 222, 70, 35, 0, "LookUpCancelBtn"); + pLookUpSelectList = new wxListBox(this, LOOKUP_DIALOG_SELECT, wxPoint(5, 15), wxSize(384, 195), 0, 0, wxLB_SINGLE|wxLB_ALWAYS_SB, wxDefaultValidator, "LookUpSelectList"); + + pLookUpSelectList->SetFont(fixedFont); + + pLookUpOkBtn = new wxButton(this, LOOKUP_DIALOG_OK, "&Ok", wxPoint(113, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpOkBtn"); + pLookUpCancelBtn = new wxButton(this, LOOKUP_DIALOG_CANCEL, "C&ancel", wxPoint(212, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpCancelBtn"); widgetPtrsSet = TRUE; @@ -251,8 +233,8 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, if (!lookup2->Open()) { wxString tStr; - tStr.sprintf("Unable to open the table '%s'.",tableName); - wxMessageBox(tStr.GetData(),"ODBC Error..."); + tStr.Printf("Unable to open the table '%s'.",tableName); + wxMessageBox(tStr,"ODBC Error..."); Close(); return; } @@ -276,7 +258,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, q += " WHERE "; q += where; } - if (!lookup2->QueryBySqlStmt(q.GetData())) + if (!lookup2->QueryBySqlStmt((char*) (const char*) q)) { wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error..."); Close(); @@ -321,7 +303,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, s.Append(' ', (maxColLen + LISTDB_NO_SPACES_BETWEEN_COLS - strlen(lookup2->lookupCol1))); s.Append(lookup2->lookupCol2); } - pLookUpSelectList->Append(s.GetData()); + pLookUpSelectList->Append(s); } // Highlight the first list item @@ -342,7 +324,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, SetTitle(windowTitle); Centre(wxBOTH); wxEndBusyCursor(); - Show(TRUE); + ShowModal(); } // Generic lookup constructor 2 @@ -382,12 +364,12 @@ void ClookUpDlg::OnCommand(wxWindow& win, wxCommandEvent& event) // Column 1 s = s.SubString(0, col1Len-1); s = s.Strip(); - strcpy(ListDB_Selection, s.GetData()); + strcpy(ListDB_Selection, s); // Column 2 s = pLookUpSelectList->GetStringSelection(); - s = s.From(col1Len + LISTDB_NO_SPACES_BETWEEN_COLS); + s = s.Mid(col1Len + LISTDB_NO_SPACES_BETWEEN_COLS); s = s.Strip(); - strcpy(ListDB_Selection2, s.GetData()); + strcpy(ListDB_Selection2, s); } } else diff --git a/samples/db/listdb.h b/samples/db/listdb.h index 0d966c961e..f510fbf130 100644 --- a/samples/db/listdb.h +++ b/samples/db/listdb.h @@ -9,7 +9,9 @@ // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// +#ifdef __GNUG__ #pragma interface "listdb.h" +#endif /* /* @@ -54,7 +56,7 @@ class Clookup2 : public wxTable }; // Clookup2 -class ClookUpDlg : public wxDialogBox +class ClookUpDlg : public wxDialog { private: bool widgetPtrsSet; @@ -120,6 +122,12 @@ class ClookUpDlg : public wxDialogBox void OnActivate(bool) {}; // necessary for hot keys }; +#define LOOKUP_DIALOG 500 + +#define LOOKUP_DIALOG_SELECT 501 +#define LOOKUP_DIALOG_OK 502 +#define LOOKUP_DIALOG_CANCEL 503 + #endif // LISTDB_DOT_H // ************************************ listdb.h ********************************* diff --git a/samples/db/makefile.nt b/samples/db/makefile.nt index 2db0a71c6e..1888b9caf0 100644 --- a/samples/db/makefile.nt +++ b/samples/db/makefile.nt @@ -1,53 +1,31 @@ # # File: makefile.nt -# Author: George Tasker -# Created: 1998 +# Author: Julian Smart +# Created: 1993 # Updated: +# Copyright: (c) 1993, AIAI, University of Edinburgh # # "%W% %G%" # -# Makefile : Builds database example (MS VC++). - -!if "$(FINAL)" == "" -FINAL=0 -!endif - - -!if "$(MSVCDIR)" == "" -MSVCDIR=c:\devstudio\vc -!endif +# Makefile : Builds db example (MS VC++). +# Use FINAL=1 argument to nmake to build final version with no debugging +# info # Set WXDIR for your system -WXDIR = $(WXWIN) -THISDIR = $(WXDIR)\samples\database -WXODBCDIR = $(WXDIR)\utils\wxodbc - -!if "$(MSVCDIR)" == "" -DBLIBS=$(MSDEVDIR)\lib\odbc32.lib -!else -DBLIBS=$(MSVCDIR)\lib\odbc32.lib -!endif +WXDIR = $(WXWIN) -EXTRAINC = -I$(WXODBCDIR)\src -EXTRALIBS = $(DBLIBS) $(WXODBCDIR)\lib\wxodbc.lib +WXUSINGDLL=0 !include $(WXDIR)\src\ntwxwin.mak -PROGRAM=database +THISDIR = $(WXDIR)\samples\db +PROGRAM=dbtest -OBJECTS = $(PROGRAM).$(OBJSUFF) listdb.$(OBJSUFF) - -all: wxodbc $(PROGRAM).exe +OBJECTS = $(PROGRAM).obj listdb.obj $(PROGRAM): $(PROGRAM).exe -gt: - cd $(CPPFLAGS) - -wxodbc: - cd $(WXODBCDIR)\src - nmake -f makefile.nt FINAL=$(FINAL) - cd $(THISDIR) +all: wx $(PROGRAM).exe wx: cd $(WXDIR)\src\msw @@ -58,12 +36,8 @@ wxclean: cd $(WXDIR)\src\msw nmake -f makefile.nt clean cd $(THISDIR) - cd $(WXODBCDIR)\src - nmake -f makefile.nt clean - cd $(THISDIR) - -$(PROGRAM).exe: $(DUMMYOBJ) $(OBJECTS) $(PROGRAM).res +$(PROGRAM).exe: $(DUMMYOBJ) $(WXLIB) $(OBJECTS) $(PROGRAM).res $(link) @<< -out:$(PROGRAM).exe $(LINKFLAGS) @@ -72,19 +46,17 @@ $(LIBS) << -listdb.$(OBJSUFF): $(*B).$(SRCSUFF) $(*B).h - $(cc) @<< -$(CPPFLAGS) /c /Fo$(*B).$(OBJSUFF) /Tp $(*B).$(SRCSUFF) +$(PROGRAM).obj: $(PROGRAM).$(SRCSUFF) $(DUMMYOBJ) + $(cc) @<< +$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) << - -$(PROGRAM).$(OBJSUFF): $(PROGRAM).$(SRCSUFF) $(PROGRAM).h listdb.h - $(cc) @<< -$(CPPFLAGS) /c /Fo$(*B).$(OBJSUFF) /Tp $(*B).$(SRCSUFF) +listdb.obj: listdb.cpp $(DUMMYOBJ) + $(cc) @<< +$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) << - -$(PROGRAM).res: $(PROGRAM).rc $(WXDIR)\include\wx\msw\wx.rc +$(PROGRAM).res : $(PROGRAM).rc $(WXDIR)\include\wx\msw\wx.rc $(rc) -r /i$(WXDIR)\include -fo$@ $(PROGRAM).rc diff --git a/samples/db/makefile.unx b/samples/db/makefile.unx index 3c4142d09b..2c8bf754e9 100644 --- a/samples/db/makefile.unx +++ b/samples/db/makefile.unx @@ -1,71 +1,17 @@ # # File: makefile.unx -# Author: Terry Tompkins +# Author: Julian Smart # Created: 1998 # Updated: -# Copyright: (c) 1998, Remstar International +# Copyright: (c) 1998 Julian Smart # -# Makefile for wxDB (UNIX). - -OBJDIR=database -OBJSUFF=.o -SRCSUFF=.cpp -WXDIR = $(WXWIN) - -# All common UNIX compiler flags and options are now in -# this central makefile. -include $(WXDIR)/src/make.env - -PROGRAM=database - -OBJECTS = $(OBJDIR)/$(PROGRAM).$(OBJSUFF) $(OBJDIR)/table.$(OBJSUFF) $(OBJDIR)/db.$(OBJSUFF) $(OBJDIR)/listdb.$(OBJSUFF) - -.SUFFIXES: - -all: $(OBJDIR) $(PROGRAM)$(GUISUFFIX) - -wx: - - -motif: - $(MAKE) -f makefile.unx GUISUFFIX=_motif GUI=-Dwx_motif GUISUFFIX=_motif OPT='$(OPT)' LDLIBS='$(MOTIFLDLIBS)' WXLIB=$(WXDIR)/lib/libwx_motif.a OPTIONS='$(OPTIONS)' DEBUG='$(DEBUG)' WARN='$(WARN)' XLIB='$(XLIB)' XINCLUDE='$(XINCLUDE)' XVIEW_LINK= - -xview: - cd $(WXDIR)/src/x; $(MAKE) -f makefile.unx xview - $(MAKE) -f makefile.unx GUI=-Dwx_xview GUISUFFIX=_ol CC=$(CC) OPTIONS='$(OPTIONS)' DEBUG='$(DEBUG)' WARN='$(WARN)' XLIB='$(XLIB)' XINCLUDE='$(XINCLUDE)' - -hp: - cd $(WXDIR)/src/x; $(MAKE) -f makefile.unx hp - $(MAKE) -f makefile.unx GUI=-Dwx_motif GUISUFFIX=_hp CC=CC DEBUG='$(DEBUG)' WARN='-w' \ - XINCLUDE='$(HPXINCLUDE)' XLIB='$(HPXLIB)' XVIEW_LINK='' LDLIBS='$(HPLDLIBS)' - -$(OBJDIR): - mkdir $(OBJDIR) - -$(PROGRAM)$(GUISUFFIX): $(DUMMYOBJ) $(DBLIBS) $(OBJECTS) $(WXLIB) - $(CC) $(LDFLAGS) -o $(PROGRAM)$(GUISUFFIX) $(OBJECTS) $(XVIEW_LINK) $(LDLIBS) - -$(OBJDIR)/$(PROGRAM).$(OBJSUFF): $(PROGRAM).$(SRCSUFF) - $(CC) -c $(CPPFLAGS) -o $@ $(PROGRAM).$(SRCSUFF) - -$(OBJDIR)/table.$(OBJSUFF): table.$(SRCSUFF) - $(CC) -c $(CPPFLAGS) -o $@ table.$(SRCSUFF) - -$(OBJDIR)/db.$(OBJSUFF): db.$(SRCSUFF) - $(CC) -c $(CPPFLAGS) -o $@ db.$(SRCSUFF) - -$(OBJDIR)/listdb.$(OBJSUFF): listdb.$(SRCSUFF) - $(CC) -c $(CPPFLAGS) -o $@ listdb.$(SRCSUFF) - -clean_motif: - $(MAKE) -f makefile.unx GUISUFFIX=_motif cleanany +# "%W% %G%" +# +# Makefile for dbtest example (UNIX). -clean_ol: - $(MAKE) -f makefile.unx GUISUFFIX=_ol cleanany +PROGRAM=dbtest -clean_hp: - $(MAKE) -f makefile.unx GUISUFFIX=_hp cleanany +OBJECTS=$(PROGRAM).o listdb.o -cleanany: - rm -f $(OBJECTS) $(PROGRAM)$(GUISUFFIX) core +include ../../src/makeprog.env diff --git a/src/common/db.cpp b/src/common/db.cpp index 1c2c703f42..9125384a3f 100644 --- a/src/common/db.cpp +++ b/src/common/db.cpp @@ -5,6 +5,8 @@ // source such as opening and closing the data source. // Author: Doug Card // Modified by: +// Mods: Dec, 1998: Added support for SQL statement logging and database +// cataloging // Created: 9.96 // RCS-ID: $Id$ // Copyright: (c) 1996 Remstar International, Inc. @@ -20,17 +22,17 @@ // the wxWindows GUI development toolkit. /////////////////////////////////////////////////////////////////////////////// +#ifdef __GNUG__ +#pragma implementation "db.h" +#endif + /* // SYNOPSIS START // SYNOPSIS STOP */ -#ifdef __GNUG__ -#pragma implementation "db.h" -#endif - /* -#ifdef _CONSOLE +#ifdef DBDEBUG_CONSOLE #include #endif */ @@ -47,11 +49,10 @@ #if wxUSE_ODBC -#include - #include #include #include +#include "wx/db.h" DbList *PtrBegDbList = 0; @@ -59,6 +60,9 @@ DbList *PtrBegDbList = 0; wxDB::wxDB(HENV &aHenv) { int i; + + fpSqlLog = 0; // Sql Log file pointer + sqlLogState = sqlLogOFF; // By default, logging is turned off strcpy(sqlState,""); strcpy(errorMsg,""); @@ -112,7 +116,7 @@ wxDB::wxDB(HENV &aHenv) /********** wxDB::Open() **********/ bool wxDB::Open(char *Dsn, char *Uid, char *AuthStr) { - assert(Dsn); + assert(Dsn && strlen(Dsn)); dsn = Dsn; uid = Uid; authStr = AuthStr; @@ -125,7 +129,7 @@ bool wxDB::Open(char *Dsn, char *Uid, char *AuthStr) // specified before the connection is made. retcode = SQLSetConnectOption(hdbc, SQL_ODBC_CURSORS, SQL_CUR_USE_IF_NEEDED); - #ifdef _CONSOLE + #ifdef DBDEBUG_CONSOLE if (retcode == SQL_SUCCESS) cout << "SQLSetConnectOption(CURSOR_LIB) successful" << endl; else @@ -240,7 +244,7 @@ bool wxDB::Open(char *Dsn, char *Uid, char *AuthStr) else typeInfDate.FsqlType = SQL_TIMESTAMP; -#ifdef _CONSOLE +#ifdef DBDEBUG_CONSOLE cout << "VARCHAR DATA TYPE: " << typeInfVarchar.TypeName << endl; cout << "INTEGER DATA TYPE: " << typeInfInteger.TypeName << endl; cout << "FLOAT DATA TYPE: " << typeInfFloat.TypeName << endl; @@ -262,7 +266,7 @@ bool wxDB::setConnectionOptions(void) SQLSetConnectOption(hdbc, SQL_OPT_TRACE, SQL_OPT_TRACE_OFF); // Display the connection options to verify them -#ifdef _CONSOLE +#ifdef DBDEBUG_CONSOLE long l; cout << ">>>>> CONNECTION OPTIONS <<<<<<" << endl; @@ -394,7 +398,7 @@ bool wxDB::getDbInfo(void) if (SQLGetInfo(hdbc, SQL_LOGIN_TIMEOUT, &dbInf.loginTimeout, sizeof(dbInf.loginTimeout), &cb) != SQL_SUCCESS) return(DispAllErrors(henv, hdbc)); -#ifdef _CONSOLE +#ifdef DBDEBUG_CONSOLE cout << ">>>>> DATA SOURCE INFORMATION <<<<<" << endl; cout << "SERVER Name: " << dbInf.serverName << endl; cout << "DBMS Name: " << dbInf.dbmsName << "; DBMS Version: " << dbInf.dbmsVer << endl; @@ -612,7 +616,7 @@ bool wxDB::getDataTypeInfo(SWORD fSqlType, SqlTypeInfo &structSQLTypeInfo) // Fetch the record if ((retcode = SQLFetch(hstmt)) != SQL_SUCCESS) { -#ifdef _CONSOLE +#ifdef DBDEBUG_CONSOLE if (retcode == SQL_NO_DATA_FOUND) cout << "SQL_NO_DATA_FOUND fetching inf. about data type." << endl; #endif @@ -647,6 +651,13 @@ bool wxDB::getDataTypeInfo(SWORD fSqlType, SqlTypeInfo &structSQLTypeInfo) /********** wxDB::Close() **********/ void wxDB::Close(void) { + // Close the Sql Log file + if (fpSqlLog) + { + fclose(fpSqlLog); + fpSqlLog = 0; //glt + } + // Free statement handle if (dbIsOpen) { @@ -699,7 +710,7 @@ bool wxDB::DispAllErrors(HENV aHenv, HDBC aHdbc, HSTMT aHstmt) logError(odbcErrMsg, sqlState); if (!silent) { -#ifdef _CONSOLE +#ifdef DBDEBUG_CONSOLE // When run in console mode, use standard out to display errors. cout << odbcErrMsg << endl; cout << "Press any key to continue..." << endl; @@ -733,7 +744,7 @@ void wxDB::DispNextError(void) if (silent) return; -#ifdef _CONSOLE +#ifdef DBDEBUG_CONSOLE // When run in console mode, use standard out to display errors. cout << odbcErrMsg << endl; cout << "Press any key to continue..." << endl; @@ -994,10 +1005,12 @@ bool wxDB::Grant(int privileges, char *tableName, char *userList) strcat(sqlStmt, " TO "); strcat(sqlStmt, userList); -#ifdef _CONSOLE +#ifdef DBDEBUG_CONSOLE cout << endl << sqlStmt << endl; #endif + WriteSqlLog(sqlStmt); + return(ExecSql(sqlStmt)); } // wxDB::Grant() @@ -1025,7 +1038,9 @@ bool wxDB::CreateView(char *viewName, char *colList, char *pSqlStmt) } } -#ifdef _CONSOLE + WriteSqlLog(sqlStmt); + +#ifdef DBDEBUG_CONSOLE cout << endl << sqlStmt << endl; #endif @@ -1043,7 +1058,9 @@ bool wxDB::CreateView(char *viewName, char *colList, char *pSqlStmt) strcat(sqlStmt, " AS "); strcat(sqlStmt, pSqlStmt); -#ifdef _CONSOLE + WriteSqlLog(sqlStmt); + +#ifdef DBDEBUG_CONSOLE cout << sqlStmt << endl; #endif @@ -1161,6 +1178,101 @@ CcolInf *wxDB::GetColumns(char *tableName[]) } // wxDB::GetColumns() +/********** wxDB::Catalog() **********/ +bool wxDB::Catalog(char *userID, char *fileName) +{ + assert(userID && strlen(userID)); + assert(fileName && strlen(fileName)); + + RETCODE retcode; + SDWORD cb; + char tblName[DB_MAX_TABLE_NAME_LEN+1]; + char tblNameSave[DB_MAX_TABLE_NAME_LEN+1]; + char colName[DB_MAX_COLUMN_NAME_LEN+1]; + SWORD sqlDataType; + char typeName[16]; + SWORD precision, length; + + FILE *fp = fopen(fileName,"wt"); + if (fp == NULL) + return(FALSE); + + SQLFreeStmt(hstmt, SQL_CLOSE); + + int i = 0; + char userIdUC[81]; + for (char *p = userID; *p; p++) + userIdUC[i++] = toupper(*p); + userIdUC[i] = 0; + + retcode = SQLColumns(hstmt, + NULL, 0, // All qualifiers + (UCHAR *) userIdUC, SQL_NTS, // User specified + NULL, 0, // All tables + NULL, 0); // All columns + if (retcode != SQL_SUCCESS) + { + DispAllErrors(henv, hdbc, hstmt); + fclose(fp); + return(FALSE); + } + + SQLBindCol(hstmt, 3, SQL_C_CHAR, tblName, DB_MAX_TABLE_NAME_LEN+1, &cb); + SQLBindCol(hstmt, 4, SQL_C_CHAR, colName, DB_MAX_COLUMN_NAME_LEN+1, &cb); + SQLBindCol(hstmt, 5, SQL_C_SSHORT, &sqlDataType, 0, &cb); + SQLBindCol(hstmt, 6, SQL_C_CHAR, typeName, 16, &cb); + SQLBindCol(hstmt, 7, SQL_C_SSHORT, &precision, 0, &cb); + SQLBindCol(hstmt, 8, SQL_C_SSHORT, &length, 0, &cb); + + char outStr[256]; + strcpy(tblNameSave,""); + int cnt = 0; + + while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS) + { + if (strcmp(tblName,tblNameSave)) + { + if (cnt) + fputs("\n", fp); + fputs("================================ ", fp); + fputs("================================ ", fp); + fputs("===================== ", fp); + fputs("========= ", fp); + fputs("=========\n", fp); + sprintf(outStr, "%-32s %-32s %-21s %9s %9s\n", + "TABLE NAME", "COLUMN NAME", "DATA TYPE", "PRECISION", "LENGTH"); + fputs(outStr, fp); + fputs("================================ ", fp); + fputs("================================ ", fp); + fputs("===================== ", fp); + fputs("========= ", fp); + fputs("=========\n", fp); + strcpy(tblNameSave,tblName); + } + sprintf(outStr, "%-32s %-32s (%04d)%-15s %9d %9d\n", + tblName, colName, sqlDataType, typeName, precision, length); + if (fputs(outStr, fp) == EOF) + { + fclose(fp); + return(FALSE); + } + cnt++; + } + + if (retcode != SQL_NO_DATA_FOUND) + { + DispAllErrors(henv, hdbc, hstmt); + fclose(fp); + return(FALSE); + } + + SQLFreeStmt(hstmt, SQL_CLOSE); + fclose(fp); + return(TRUE); + +} // wxDB::Catalog() + + // Table name can refer to a table, view, alias or synonym. Returns true // if the object exists in the database. This function does not indicate // whether or not the user has privleges to query or perform other functions @@ -1190,6 +1302,54 @@ bool wxDB::TableExists(char *tableName) } // wxDB::TableExists() +/********** wxDB::SqlLog() **********/ +bool wxDB::SqlLog(enum sqlLog state, char *filename, bool append) +{ + assert(state == sqlLogON || state == sqlLogOFF); + assert(state == sqlLogOFF || filename); + + if (state == sqlLogON) + { + if (fpSqlLog == 0) + { + fpSqlLog = fopen(filename, (append ? "at" : "wt")); + if (fpSqlLog == NULL) + return(FALSE); + } + } + else // sqlLogOFF + { + if (fpSqlLog) + { + if (fclose(fpSqlLog)) + return(FALSE); + fpSqlLog = 0; + } + } + + sqlLogState = state; + return(TRUE); + +} // wxDB::SqlLog() + + +/********** wxDB::WriteSqlLog() **********/ +bool wxDB::WriteSqlLog(char *logMsg) +{ + assert(logMsg); + + if (fpSqlLog == 0 || sqlLogState == sqlLogOFF) + return(FALSE); + + if (fputs("\n", fpSqlLog) == EOF) return(FALSE); + if (fputs(logMsg, fpSqlLog) == EOF) return(FALSE); + if (fputs("\n", fpSqlLog) == EOF) return(FALSE); + + return(TRUE); + +} // wxDB::WriteSqlLog() + + /********** GetDbConnection() **********/ wxDB *GetDbConnection(DbStuff *pDbStuff) { @@ -1319,4 +1479,5 @@ bool GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDes } // GetDataSource() #endif - // wxUSE_ODBC + // wxUSE_ODBC + diff --git a/src/common/dbtable.cpp b/src/common/dbtable.cpp index 5a888dec03..decce99426 100644 --- a/src/common/dbtable.cpp +++ b/src/common/dbtable.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: table.cpp +// Name: dbtable.cpp // Purpose: Implementation of the wxTable class. // Author: Doug Card // Modified by: @@ -18,6 +18,10 @@ // the wxWindows GUI development toolkit. /////////////////////////////////////////////////////////////////////////////// +#ifdef __GNUG__ +#pragma implementation "dbtable.h" +#endif + /* // SYNOPSIS START // SYNOPSIS STOP @@ -46,14 +50,15 @@ #include #include #include +#include -#ifdef __WXUNIX__ +#ifdef __UNIX__ // The HPUX preprocessor lines below were commented out on 8/20/97 // because macros.h currently redefines DEBUG and is unneeded. // # ifdef HPUX // # include // # endif -# ifdef __WXLINUX__ +# ifdef LINUX # include # endif #endif @@ -63,16 +68,22 @@ wxTable::wxTable(wxDB *pwxDB, const char *tblName, const int nCols, const char * { // Assign member variables pDb = pwxDB; // Pointer to the wxDB object + strcpy(tableName, tblName); // Table Name if (qryTblName) // Name of the table/view to query strcpy(queryTableName, qryTblName); else strcpy(queryTableName, tblName); - noCols = nCols; // No. of cols in the table - where = 0; // Where clause - orderBy = 0; // Order By clause - selectForUpdate = FALSE; // SELECT ... FOR UPDATE; Indicates whether to include the FOR UPDATE phrase + assert(pDb); // Assert is placed after table name is assigned for error reporting reasons + if (!pDb) + return; + + noCols = nCols; // No. of cols in the table + where = 0; // Where clause + orderBy = 0; // Order By clause + from = 0; // From clause + selectForUpdate = FALSE; // SELECT ... FOR UPDATE; Indicates whether to include the FOR UPDATE phrase // Grab the HENV and HDBC from the wxDB object henv = pDb->henv; @@ -214,15 +225,18 @@ wxTable::~wxTable() /********** wxTable::Open() **********/ bool wxTable::Open(void) { + if (!pDb) + return FALSE; + int i; char sqlStmt[DB_MAX_STATEMENT_LEN]; // Verify that the table exists in the database if (!pDb->TableExists(tableName)) { - wxString s; - s.Printf("Error opening '%s', table/view does not exist in the database.", tableName); - pDb->LogError(WXSTRINGCAST(s)); + char s[128]; + sprintf(s, "Error opening '%s', table/view does not exist in the database.", tableName); + pDb->LogError(s); return(FALSE); } @@ -272,6 +286,8 @@ bool wxTable::Open(void) } strcat(sqlStmt, ")"); + pDb->WriteSqlLog(sqlStmt); + // Prepare the insert statement for execution if (SQLPrepare(hstmtInsert, (UCHAR FAR *) sqlStmt, SQL_NTS) != SQL_SUCCESS) return(pDb->DispAllErrors(henv, hdbc, hstmtInsert)); @@ -293,6 +309,7 @@ bool wxTable::Query(bool forUpdate, bool distinct) /********** wxTable::QueryBySqlStmt() **********/ bool wxTable::QueryBySqlStmt(char *pSqlStmt) { + pDb->WriteSqlLog(pSqlStmt); return(query(DB_SELECT_STATEMENT, FALSE, FALSE, pSqlStmt)); @@ -328,7 +345,10 @@ bool wxTable::query(int queryType, bool forUpdate, bool distinct, char *pSqlStmt // Set the SQL SELECT string if (queryType != DB_SELECT_STATEMENT) // A select statement was not passed in, - GetSelectStmt(sqlStmt, queryType, distinct); // so generate a select statement. + { // so generate a select statement. + GetSelectStmt(sqlStmt, queryType, distinct); + pDb->WriteSqlLog(sqlStmt); + } // Make sure the cursor is closed first if (! CloseCursor(hstmt)) @@ -358,9 +378,21 @@ void wxTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct) if (distinct) strcat(pSqlStmt, "DISTINCT "); + // Was a FROM clause specified to join tables to the base table? + // Available for ::Query() only!!! + bool appendFromClause = FALSE; + if (typeOfSelect == DB_SELECT_WHERE && from && strlen(from)) + appendFromClause = TRUE; + // Add the column list for (int i = 0; i < noCols; i++) { + // If joining tables, the base table column names must be qualified to avoid ambiguity + if (appendFromClause) + { + strcat(pSqlStmt, queryTableName); + strcat(pSqlStmt, "."); + } strcat(pSqlStmt, colDefs[i].ColName); if (i + 1 < noCols) strcat(pSqlStmt, ","); @@ -369,11 +401,23 @@ void wxTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct) // If the datasource supports ROWID, get this column as well. Exception: Don't retrieve // the ROWID if querying distinct records. The rowid will always be unique. if (!distinct && CanUpdByROWID()) - strcat(pSqlStmt, ",ROWID"); + { + // If joining tables, the base table column names must be qualified to avoid ambiguity + if (appendFromClause) + { + strcat(pSqlStmt, ","); + strcat(pSqlStmt, queryTableName); + strcat(pSqlStmt, ".ROWID"); + } + else + strcat(pSqlStmt, ",ROWID"); + } // Append the FROM tablename portion strcat(pSqlStmt, " FROM "); strcat(pSqlStmt, queryTableName); + if (appendFromClause) + strcat(pSqlStmt, from); // Append the WHERE clause. Either append the where clause for the class // or build a where clause. The typeOfSelect determines this. @@ -468,12 +512,9 @@ bool wxTable::bindInsertParams(void) UDWORD precision; SWORD scale; -//glt CcolDef *tColDef; - // Bind each column (that can be inserted) of the table to a parameter marker for (int i = 0; i < noCols; i++) { -//glt tColDef = &colDefs[i]; if (! colDefs[i].InsertAllowed) continue; switch(colDefs[i].DbDataType) @@ -606,6 +647,9 @@ bool wxTable::CloseCursor(HSTMT cursor) /********** wxTable::CreateTable() **********/ bool wxTable::CreateTable(void) { + if (!pDb) + return FALSE; + int i, j; char sqlStmt[DB_MAX_STATEMENT_LEN]; @@ -632,6 +676,8 @@ bool wxTable::CreateTable(void) } } + pDb->WriteSqlLog(sqlStmt); + // Commit the transaction and close the cursor if (! pDb->CommitTrans()) return(FALSE); @@ -694,11 +740,11 @@ bool wxTable::CreateTable(void) // For varchars, append the size of the string if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR) { + char s[10]; // strcat(sqlStmt, "("); // strcat(sqlStmt, itoa(colDefs[i].SzDataObj, s, 10)); // strcat(sqlStmt, ")"); - wxString s; - s.Printf("(%d)", colDefs[i].SzDataObj); + sprintf(s, "(%d)", colDefs[i].SzDataObj); strcat(sqlStmt, s); } needComma = TRUE; @@ -732,6 +778,8 @@ bool wxTable::CreateTable(void) // Append the closing parentheses for the create table statement strcat(sqlStmt, ")"); + pDb->WriteSqlLog(sqlStmt); + #ifdef _CONSOLE cout << endl << sqlStmt << endl; #endif @@ -787,6 +835,8 @@ bool wxTable::CreateIndex(char * idxName, bool unique, int noIdxCols, CidxDef *p // Append closing parentheses strcat(sqlStmt, ")"); + pDb->WriteSqlLog(sqlStmt); + #ifdef _CONSOLE cout << endl << sqlStmt << endl << endl; #endif @@ -837,6 +887,7 @@ int wxTable::Insert(void) /********** wxTable::Update(pSqlStmt) **********/ bool wxTable::Update(char *pSqlStmt) { + pDb->WriteSqlLog(pSqlStmt); return(execUpdate(pSqlStmt)); @@ -850,6 +901,8 @@ bool wxTable::Update(void) // Build the SQL UPDATE statement GetUpdateStmt(sqlStmt, DB_UPD_KEYFIELDS); + pDb->WriteSqlLog(sqlStmt); + #ifdef _CONSOLE cout << endl << sqlStmt << endl << endl; #endif @@ -867,6 +920,8 @@ bool wxTable::UpdateWhere(char *pWhereClause) // Build the SQL UPDATE statement GetUpdateStmt(sqlStmt, DB_UPD_WHERE, pWhereClause); + pDb->WriteSqlLog(sqlStmt); + #ifdef _CONSOLE cout << endl << sqlStmt << endl << endl; #endif @@ -884,6 +939,8 @@ bool wxTable::Delete(void) // Build the SQL DELETE statement GetDeleteStmt(sqlStmt, DB_DEL_KEYFIELDS); + pDb->WriteSqlLog(sqlStmt); + // Execute the SQL DELETE statement return(execDelete(sqlStmt)); @@ -897,6 +954,8 @@ bool wxTable::DeleteWhere(char *pWhereClause) // Build the SQL DELETE statement GetDeleteStmt(sqlStmt, DB_DEL_WHERE, pWhereClause); + pDb->WriteSqlLog(sqlStmt); + // Execute the SQL DELETE statement return(execDelete(sqlStmt)); @@ -910,6 +969,8 @@ bool wxTable::DeleteMatching(void) // Build the SQL DELETE statement GetDeleteStmt(sqlStmt, DB_DEL_MATCHING); + pDb->WriteSqlLog(sqlStmt); + // Execute the SQL DELETE statement return(execDelete(sqlStmt)); @@ -1061,10 +1122,10 @@ void wxTable::GetDeleteStmt(char *pSqlStmt, int typeOfDel, char *pWhereClause) * They are not included as part of the where clause. */ -void wxTable::GetWhereClause(char *pWhereClause, int typeOfWhere) +void wxTable::GetWhereClause(char *pWhereClause, int typeOfWhere, char *qualTableName) { bool moreThanOneColumn = FALSE; - wxString colValue; + char colValue[255]; // Loop through the columns building a where clause as you go for (int i = 0; i < noCols; i++) @@ -1082,30 +1143,35 @@ void wxTable::GetWhereClause(char *pWhereClause, int typeOfWhere) else moreThanOneColumn = TRUE; // Concatenate where phrase for the column + if (qualTableName && strlen(qualTableName)) + { + strcat(pWhereClause, qualTableName); + strcat(pWhereClause, "."); + } strcat(pWhereClause, colDefs[i].ColName); strcat(pWhereClause, " = "); switch(colDefs[i].SqlCtype) { case SQL_C_CHAR: - colValue.Printf("'%s'", (UCHAR FAR *) colDefs[i].PtrDataObj); + sprintf(colValue, "'%s'", (UCHAR FAR *) colDefs[i].PtrDataObj); break; case SQL_C_SSHORT: - colValue.Printf("%hi", *((SWORD *) colDefs[i].PtrDataObj)); + sprintf(colValue, "%hi", *((SWORD *) colDefs[i].PtrDataObj)); break; case SQL_C_USHORT: - colValue.Printf("%hu", *((UWORD *) colDefs[i].PtrDataObj)); + sprintf(colValue, "%hu", *((UWORD *) colDefs[i].PtrDataObj)); break; case SQL_C_SLONG: - colValue.Printf("%li", *((SDWORD *) colDefs[i].PtrDataObj)); + sprintf(colValue, "%li", *((SDWORD *) colDefs[i].PtrDataObj)); break; case SQL_C_ULONG: - colValue.Printf("%lu", *((UDWORD *) colDefs[i].PtrDataObj)); + sprintf(colValue, "%lu", *((UDWORD *) colDefs[i].PtrDataObj)); break; case SQL_C_FLOAT: - colValue.Printf("%.6f", *((SFLOAT *) colDefs[i].PtrDataObj)); + sprintf(colValue, "%.6f", *((SFLOAT *) colDefs[i].PtrDataObj)); break; case SQL_C_DOUBLE: - colValue.Printf("%.6f", *((SDOUBLE *) colDefs[i].PtrDataObj)); + sprintf(colValue, "%.6f", *((SDOUBLE *) colDefs[i].PtrDataObj)); break; } strcat(pWhereClause, colValue); @@ -1161,7 +1227,8 @@ bool wxTable::CanSelectForUpdate(void) bool wxTable::CanUpdByROWID(void) { -//@@@@@@glt - returning FALSE for testing purposes, as the ROWID is not getting updated correctly +//NOTE: Returning FALSE for now until this can be debugged, +// as the ROWID is not getting updated correctly return FALSE; if ((! strcmp(pDb->dbInf.dbmsName, "Oracle")) || (! strcmp(pDb->dbInf.dbmsName, "ORACLE"))) @@ -1345,6 +1412,9 @@ ULONG wxTable::Count(void) strcpy(sqlStmt, "SELECT COUNT(*) FROM "); strcat(sqlStmt, queryTableName); + if (from && strlen(from)) + strcat(sqlStmt, from); + // Add the where clause if one is provided if (where && strlen(where)) { @@ -1352,6 +1422,8 @@ ULONG wxTable::Count(void) strcat(sqlStmt, where); } + pDb->WriteSqlLog(sqlStmt); + // Execute the SQL statement if (SQLExecDirect(hstmtCount, (UCHAR FAR *) sqlStmt, SQL_NTS) != SQL_SUCCESS) { @@ -1410,7 +1482,8 @@ bool wxTable::Refresh(void) // based on the key fields. if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, rowid, ROWID_LEN, &cb) == SQL_SUCCESS) { - strcat(whereClause, "ROWID = '"); + strcat(whereClause, queryTableName); + strcat(whereClause, ".ROWID = '"); strcat(whereClause, rowid); strcat(whereClause, "'"); } @@ -1418,7 +1491,7 @@ bool wxTable::Refresh(void) // If unable to use the ROWID, build a where clause from the keyfields if (strlen(whereClause) == 0) - GetWhereClause(whereClause, DB_WHERE_KEYFIELDS); + GetWhereClause(whereClause, DB_WHERE_KEYFIELDS, queryTableName); // Requery the record where = whereClause; @@ -1442,4 +1515,5 @@ bool wxTable::Refresh(void) } // wxTable::Refresh() #endif - // wxUSE_ODBC + // wxUSE_ODBC + diff --git a/src/common/string.cpp b/src/common/string.cpp index dcd371e0d2..9d05639046 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -1075,6 +1075,19 @@ bool wxString::Matches(const char *pszMask) const return *pszTxt == '\0'; } +// Count the number of chars +int wxString::Freq(char ch) const +{ + int count = 0; + int len = Len(); + for (int i = 0; i < len; i++) + { + if (GetChar(i) == ch) + count ++; + } + return count; +} + // --------------------------------------------------------------------------- // standard C++ library string functions // ---------------------------------------------------------------------------