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
This commit is contained in:
Julian Smart
1998-12-30 17:40:53 +00:00
parent aaa38880c4
commit 1fc5dd6f8e
13 changed files with 804 additions and 585 deletions

Binary file not shown.

View File

@@ -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 <windows.h>
#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

View File

@@ -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

View File

@@ -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

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,9 @@
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma interface "dbtest.h"
#endif
#include <wx/string.h>
#include <wx/dbtable.h>
@@ -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

View File

@@ -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

View File

@@ -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 *********************************

View File

@@ -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
WXDIR = $(WXWIN)
!if "$(MSVCDIR)" == ""
DBLIBS=$(MSDEVDIR)\lib\odbc32.lib
!else
DBLIBS=$(MSVCDIR)\lib\odbc32.lib
!endif
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

View File

@@ -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).
# "%W% %G%"
#
# Makefile for dbtest example (UNIX).
OBJDIR=database
OBJSUFF=.o
SRCSUFF=.cpp
WXDIR = $(WXWIN)
PROGRAM=dbtest
# All common UNIX compiler flags and options are now in
# this central makefile.
include $(WXDIR)/src/make.env
OBJECTS=$(PROGRAM).o listdb.o
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
clean_ol:
$(MAKE) -f makefile.unx GUISUFFIX=_ol cleanany
clean_hp:
$(MAKE) -f makefile.unx GUISUFFIX=_hp cleanany
cleanany:
rm -f $(OBJECTS) $(PROGRAM)$(GUISUFFIX) core
include ../../src/makeprog.env

View File

@@ -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.
///////////////////////////////////////////////////////////////////////////////
/*
// SYNOPSIS START
// SYNOPSIS STOP
*/
#ifdef __GNUG__
#pragma implementation "db.h"
#endif
/*
#ifdef _CONSOLE
// SYNOPSIS START
// SYNOPSIS STOP
*/
/*
#ifdef DBDEBUG_CONSOLE
#include <iostream.h>
#endif
*/
@@ -47,11 +49,10 @@
#if wxUSE_ODBC
#include <wx/db.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#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

View File

@@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#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 <macros.h>
// # endif
# ifdef __WXLINUX__
# ifdef LINUX
# include <sys/minmax.h>
# 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

View File

@@ -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
// ---------------------------------------------------------------------------