Adjusted sample to reflect class name changes
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7051 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
donated by the development team at Remstar International.
|
donated by the development team at Remstar International.
|
||||||
|
|
||||||
The table this sample is based on is developer contact table, and shows
|
The table this sample is based on is developer contact table, and shows
|
||||||
some of the simple uses of the database classes wxDB and wxTable.
|
some of the simple uses of the database classes wxDb and wxDbTable.
|
||||||
|
|
||||||
* SYNOPSIS END
|
* SYNOPSIS END
|
||||||
*/
|
*/
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
#include <stdio.h> /* Included strictly for reading the text file with the database parameters */
|
#include <stdio.h> /* Included strictly for reading the text file with the database parameters */
|
||||||
|
|
||||||
#include <wx/db.h> /* Required in the file which will get the data source connection */
|
#include <wx/db.h> /* Required in the file which will get the data source connection */
|
||||||
#include <wx/dbtable.h> /* Has the wxTable object from which all data objects will inherit their data table functionality */
|
#include <wx/dbtable.h> /* Has the wxDbTable object from which all data objects will inherit their data table functionality */
|
||||||
|
|
||||||
extern wxDbList WXDLLEXPORT *PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */
|
extern wxDbList WXDLLEXPORT *PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */
|
||||||
|
|
||||||
@@ -61,23 +61,23 @@ DatabaseDemoFrame *DemoFrame; /* Pointer to the main frame */
|
|||||||
* for user login names and passwords, getting workstation settings, etc.
|
* for user login names and passwords, getting workstation settings, etc.
|
||||||
* ---> IMPORTANT <---
|
* ---> IMPORTANT <---
|
||||||
*
|
*
|
||||||
* For each database object created which uses this wxDB pointer
|
* For each database object created which uses this wxDb pointer
|
||||||
* connection to the database, when a CommitTrans() or RollBackTrans()
|
* connection to the database, when a CommitTrans() or RollBackTrans()
|
||||||
* will commit or rollback EVERY object which uses this wxDB pointer.
|
* will commit or rollback EVERY object which uses this wxDb pointer.
|
||||||
*
|
*
|
||||||
* To allow each table object (those derived from wxTable) to be
|
* To allow each table object (those derived from wxDbTable) to be
|
||||||
* individually committed or rolled back, you MUST use a different
|
* individually committed or rolled back, you MUST use a different
|
||||||
* instance of wxDB in the constructor of the table. Doing so creates
|
* instance of wxDb in the constructor of the table. Doing so creates
|
||||||
* more overhead, and will use more database connections (some DBs have
|
* more overhead, and will use more database connections (some DBs have
|
||||||
* connection limits...), so use connections sparringly.
|
* connection limits...), so use connections sparringly.
|
||||||
*
|
*
|
||||||
* It is recommended that one "main" database connection be created for
|
* It is recommended that one "main" database connection be created for
|
||||||
* the entire program to use for READ-ONLY database accesses, but for each
|
* the entire program to use for READ-ONLY database accesses, but for each
|
||||||
* table object which will do a CommitTrans() or RollbackTrans() that a
|
* table object which will do a CommitTrans() or RollbackTrans() that a
|
||||||
* new wxDB object be created and used for it.
|
* new wxDb object be created and used for it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
wxDB *READONLY_DB;
|
wxDb *READONLY_DB;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function will return the exact string(s) from the database engine
|
* This function will return the exact string(s) from the database engine
|
||||||
@@ -353,24 +353,24 @@ void DatabaseDemoFrame::BuildParameterDialog(wxWindow *parent)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor note: If no wxDB object is passed in, a new connection to the database
|
* Constructor note: If no wxDb object is passed in, a new connection to the database
|
||||||
* is created for this instance of Ccontact. This can be a slow process depending
|
* is created for this instance of Ccontact. This can be a slow process depending
|
||||||
* on the database engine being used, and some database engines have a limit on the
|
* on the database engine being used, and some database engines have a limit on the
|
||||||
* number of connections (either hard limits, or license restricted) so care should
|
* number of connections (either hard limits, or license restricted) so care should
|
||||||
* be used to use as few connections as is necessary.
|
* be used to use as few connections as is necessary.
|
||||||
*
|
*
|
||||||
* IMPORTANT: Objects which share a wxDB pointer are ALL acted upon whenever a member
|
* IMPORTANT: Objects which share a wxDb pointer are ALL acted upon whenever a member
|
||||||
* function of pDb is called (i.e. CommitTrans() or RollbackTrans(), so if modifying
|
* function of pDb is called (i.e. CommitTrans() or RollbackTrans(), so if modifying
|
||||||
* or creating a table objects which use the same pDb, know that all the objects
|
* or creating a table objects which use the same pDb, know that all the objects
|
||||||
* will be committed or rolled back when any of the objects has this function call made.
|
* will be committed or rolled back when any of the objects has this function call made.
|
||||||
*/
|
*/
|
||||||
Ccontact::Ccontact (wxDB *pwxDB) : wxTable(pwxDB ? pwxDB : wxDbGetConnection(&DbConnectInf),CONTACT_TABLE_NAME,CONTACT_NO_COLS,NULL,!QUERY_ONLY,DbConnectInf.defaultDir)
|
Ccontact::Ccontact (wxDb *pwxDb) : wxDbTable(pwxDb ? pwxDb : wxDbGetConnection(&DbConnectInf),CONTACT_TABLE_NAME,CONTACT_NO_COLS,NULL,!QUERY_ONLY,DbConnectInf.defaultDir)
|
||||||
{
|
{
|
||||||
// This is used to represent whether the database connection should be released
|
// This is used to represent whether the database connection should be released
|
||||||
// when this instance of the object is deleted. If using the same connection
|
// when this instance of the object is deleted. If using the same connection
|
||||||
// for multiple instance of database objects, then the connection should only be
|
// for multiple instance of database objects, then the connection should only be
|
||||||
// released when the last database instance using the connection is deleted
|
// released when the last database instance using the connection is deleted
|
||||||
freeDbConn = !pwxDB;
|
freeDbConn = !pwxDb;
|
||||||
|
|
||||||
SetupColumns();
|
SetupColumns();
|
||||||
|
|
||||||
@@ -416,7 +416,7 @@ Ccontact::~Ccontact()
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handles setting up all the connections for the interface from the wxTable
|
* Handles setting up all the connections for the interface from the wxDbTable
|
||||||
* functions to interface to the data structure used to store records in
|
* functions to interface to the data structure used to store records in
|
||||||
* memory, and for all the column definitions that define the table structure
|
* memory, and for all the column definitions that define the table structure
|
||||||
*/
|
*/
|
||||||
@@ -444,7 +444,7 @@ bool Ccontact::CreateIndexes(void)
|
|||||||
// This index could easily be accomplished with an "orderBy" clause,
|
// This index could easily be accomplished with an "orderBy" clause,
|
||||||
// but is done to show how to construct a non-primary index.
|
// but is done to show how to construct a non-primary index.
|
||||||
wxString indexName;
|
wxString indexName;
|
||||||
CidxDef idxDef[2];
|
wxDbIdxDef idxDef[2];
|
||||||
|
|
||||||
bool Ok = TRUE;
|
bool Ok = TRUE;
|
||||||
|
|
||||||
@@ -624,9 +624,9 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455)
|
|||||||
|
|
||||||
Contact->orderBy = "NAME"; // field name to sort by
|
Contact->orderBy = "NAME"; // field name to sort by
|
||||||
|
|
||||||
// The wxString "whereStr" is not a member of the wxTable object, it is a member variable
|
// The wxString "whereStr" is not a member of the wxDbTable object, it is a member variable
|
||||||
// specifically in the Ccontact class. It is used here for simpler construction of a varying
|
// specifically in the Ccontact class. It is used here for simpler construction of a varying
|
||||||
// length string, and then after the string is built, the wxTable member variable "where" is
|
// length string, and then after the string is built, the wxDbTable member variable "where" is
|
||||||
// assigned the pointer to the constructed string.
|
// assigned the pointer to the constructed string.
|
||||||
//
|
//
|
||||||
// The constructed where clause below has a sub-query within it "SELECT MIN(NAME) FROM %s"
|
// The constructed where clause below has a sub-query within it "SELECT MIN(NAME) FROM %s"
|
||||||
@@ -1548,7 +1548,7 @@ BEGIN_EVENT_TABLE(CqueryDlg, wxDialog)
|
|||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
// CqueryDlg() constructor
|
// CqueryDlg() constructor
|
||||||
CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg) : wxDialog (parent, QUERY_DIALOG, "Query", wxPoint(-1, -1), wxSize(480, 360))
|
CqueryDlg::CqueryDlg(wxWindow *parent, wxDb *pDb, char *tblName[], char *pWhereArg) : wxDialog (parent, QUERY_DIALOG, "Query", wxPoint(-1, -1), wxSize(480, 360))
|
||||||
{
|
{
|
||||||
wxBeginBusyCursor();
|
wxBeginBusyCursor();
|
||||||
|
|
||||||
@@ -2023,11 +2023,11 @@ void CqueryDlg::ProcessCountBtn()
|
|||||||
if (!ValidateWhereClause())
|
if (!ValidateWhereClause())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (dbTable == 0) // wxTable object needs to be created and opened
|
if (dbTable == 0) // wxDbTable object needs to be created and opened
|
||||||
{
|
{
|
||||||
if (!(dbTable = new wxTable(pDB, masterTableName, 0, NULL, !QUERY_ONLY, DbConnectInf.defaultDir)))
|
if (!(dbTable = new wxDbTable(pDB, masterTableName, 0, NULL, !QUERY_ONLY, DbConnectInf.defaultDir)))
|
||||||
{
|
{
|
||||||
wxMessageBox("Memory allocation failed creating a wxTable object.","Error...",wxOK | wxICON_EXCLAMATION);
|
wxMessageBox("Memory allocation failed creating a wxDbTable object.","Error...",wxOK | wxICON_EXCLAMATION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!dbTable->Open())
|
if (!dbTable->Open())
|
||||||
|
@@ -74,9 +74,9 @@ class CstructContact : public wxObject
|
|||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// NOTE: Ccontact inherits wxTable, which gives access to all the database functionality
|
// NOTE: Ccontact inherits wxDbTable, which gives access to all the database functionality
|
||||||
//
|
//
|
||||||
class Ccontact : public wxTable, public CstructContact
|
class Ccontact : public wxDbTable, public CstructContact
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool freeDbConn;
|
bool freeDbConn;
|
||||||
@@ -86,7 +86,7 @@ class Ccontact : public wxTable, public CstructContact
|
|||||||
wxString whereStr;
|
wxString whereStr;
|
||||||
wxString qryWhereStr; // Where string returned from the query dialog
|
wxString qryWhereStr; // Where string returned from the query dialog
|
||||||
|
|
||||||
Ccontact(wxDB *pwxDB=NULL);
|
Ccontact(wxDb *pwxDb=NULL);
|
||||||
~Ccontact();
|
~Ccontact();
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
@@ -307,11 +307,11 @@ char * const langQRY_BETWEEN = "column BETWEEN value AND value";
|
|||||||
class CqueryDlg : public wxDialog
|
class CqueryDlg : public wxDialog
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
wxColInf *colInf; // Column inf. returned by db->GetColumns()
|
wxDbColInf *colInf; // Column inf. returned by db->GetColumns()
|
||||||
wxTable *dbTable;
|
wxDbTable *dbTable;
|
||||||
char *masterTableName;
|
char *masterTableName;
|
||||||
char *pWhere; // A pointer to the storage for the resulting where clause
|
char *pWhere; // A pointer to the storage for the resulting where clause
|
||||||
wxDB *pDB;
|
wxDb *pDB;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool widgetPtrsSet;
|
bool widgetPtrsSet;
|
||||||
@@ -345,7 +345,7 @@ class CqueryDlg : public wxDialog
|
|||||||
|
|
||||||
wxTextCtrl *pFocusTxt;
|
wxTextCtrl *pFocusTxt;
|
||||||
|
|
||||||
CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg);
|
CqueryDlg(wxWindow *parent, wxDb *pDb, char *tblName[], char *pWhereArg);
|
||||||
~CqueryDlg();
|
~CqueryDlg();
|
||||||
|
|
||||||
void OnButton( wxCommandEvent &event );
|
void OnButton( wxCommandEvent &event );
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
data table/object for building the list.
|
data table/object for building the list.
|
||||||
|
|
||||||
The data table record access is all handled through the routines
|
The data table record access is all handled through the routines
|
||||||
in this module, interfacing with the methods defined in wxTable.
|
in this module, interfacing with the methods defined in wxDbTable.
|
||||||
|
|
||||||
All objects which use data table access must be initialized and
|
All objects which use data table access must be initialized and
|
||||||
have opened the table prior to passing them in the dialog
|
have opened the table prior to passing them in the dialog
|
||||||
@@ -64,7 +64,7 @@ extern wxDbList WXDLLEXPORT *PtrBegDbList; /* from db.cpp, used in getting ba
|
|||||||
extern wxDbConnectInf DbConnectInf;
|
extern wxDbConnectInf DbConnectInf;
|
||||||
|
|
||||||
// Global database connection
|
// Global database connection
|
||||||
extern wxDB *READONLY_DB;
|
extern wxDb *READONLY_DB;
|
||||||
|
|
||||||
|
|
||||||
// Used for passing the selected listbox selection back to the calling
|
// Used for passing the selected listbox selection back to the calling
|
||||||
@@ -139,7 +139,7 @@ char *GetExtendedDBErrorMsg2(char *ErrFile, int ErrLine)
|
|||||||
|
|
||||||
|
|
||||||
// Clookup constructor
|
// Clookup constructor
|
||||||
Clookup::Clookup(char *tblName, char *colName) : wxTable(READONLY_DB, tblName, 1, NULL, !QUERY_ONLY, DbConnectInf.defaultDir)
|
Clookup::Clookup(char *tblName, char *colName) : wxDbTable(READONLY_DB, tblName, 1, NULL, !QUERY_ONLY, DbConnectInf.defaultDir)
|
||||||
{
|
{
|
||||||
|
|
||||||
SetColDefs (0, colName, DB_DATA_TYPE_VARCHAR, lookupCol, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE);
|
SetColDefs (0, colName, DB_DATA_TYPE_VARCHAR, lookupCol, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE);
|
||||||
@@ -148,8 +148,8 @@ Clookup::Clookup(char *tblName, char *colName) : wxTable(READONLY_DB, tblName, 1
|
|||||||
|
|
||||||
|
|
||||||
// Clookup2 constructor
|
// Clookup2 constructor
|
||||||
Clookup2::Clookup2(char *tblName, char *colName1, char *colName2, wxDB *pDb)
|
Clookup2::Clookup2(char *tblName, char *colName1, char *colName2, wxDb *pDb)
|
||||||
: wxTable(pDb, tblName, (1 + (strlen(colName2) > 0)), NULL, !QUERY_ONLY, DbConnectInf.defaultDir)
|
: wxDbTable(pDb, tblName, (1 + (strlen(colName2) > 0)), NULL, !QUERY_ONLY, DbConnectInf.defaultDir)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
@@ -264,7 +264,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, cha
|
|||||||
//
|
//
|
||||||
ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName,
|
ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName,
|
||||||
char *dispCol1, char *dispCol2, char *where, char *orderBy, bool distinctValues,
|
char *dispCol1, char *dispCol2, char *where, char *orderBy, bool distinctValues,
|
||||||
char *selectStmt, int maxLenCol1, wxDB *pDb, bool allowOk) : wxDialog (parent, LOOKUP_DIALOG, "Select...", wxPoint(-1, -1), wxSize(400, 290))
|
char *selectStmt, int maxLenCol1, wxDb *pDb, bool allowOk) : wxDialog (parent, LOOKUP_DIALOG, "Select...", wxPoint(-1, -1), wxSize(400, 290))
|
||||||
{
|
{
|
||||||
wxBeginBusyCursor();
|
wxBeginBusyCursor();
|
||||||
|
|
||||||
|
@@ -26,10 +26,10 @@
|
|||||||
const int LOOKUP_COL_LEN = 250;
|
const int LOOKUP_COL_LEN = 250;
|
||||||
|
|
||||||
// Global database connection
|
// Global database connection
|
||||||
extern wxDB *READONLY_DB;
|
extern wxDb *READONLY_DB;
|
||||||
|
|
||||||
// Clookup class
|
// Clookup class
|
||||||
class Clookup : public wxTable
|
class Clookup : public wxDbTable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -40,14 +40,14 @@ class Clookup : public wxTable
|
|||||||
}; // Clookup
|
}; // Clookup
|
||||||
|
|
||||||
// Clookup2 class
|
// Clookup2 class
|
||||||
class Clookup2 : public wxTable
|
class Clookup2 : public wxDbTable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
char lookupCol1[LOOKUP_COL_LEN+1];
|
char lookupCol1[LOOKUP_COL_LEN+1];
|
||||||
char lookupCol2[LOOKUP_COL_LEN+1];
|
char lookupCol2[LOOKUP_COL_LEN+1];
|
||||||
|
|
||||||
Clookup2(char *tblName, char *colName1, char *colName2, wxDB *pDb);
|
Clookup2(char *tblName, char *colName1, char *colName2, wxDb *pDb);
|
||||||
|
|
||||||
}; // Clookup2
|
}; // Clookup2
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ class ClookUpDlg : public wxDialog
|
|||||||
bool distinctValues, // e.g. SELECT DISTINCT ...
|
bool distinctValues, // e.g. SELECT DISTINCT ...
|
||||||
char *selectStmt = 0, // If you wish to query by SQLstmt (complicated lookups)
|
char *selectStmt = 0, // If you wish to query by SQLstmt (complicated lookups)
|
||||||
int maxLenCol1 = 0, // Mandatory if querying by SQLstmt
|
int maxLenCol1 = 0, // Mandatory if querying by SQLstmt
|
||||||
wxDB *pDb = READONLY_DB, // Database connection pointer
|
wxDb *pDb = READONLY_DB, // Database connection pointer
|
||||||
bool allowOk = TRUE); // is the OK button enabled
|
bool allowOk = TRUE); // is the OK button enabled
|
||||||
|
|
||||||
void OnButton( wxCommandEvent &event );
|
void OnButton( wxCommandEvent &event );
|
||||||
|
Reference in New Issue
Block a user