home *** CD-ROM | disk | FTP | other *** search
- // =================================================================
- // Database.cpp
- // =================================================================
- // Harold Kasperink / John Dekker
- // Dr. Dobb's Journal 1997
- // =================================================================
- // Database interface functions
- // In this file you'll find some examples of Database command
- // classes:
- // CDbCommit : implements a database commit command
- // CDbRollback : implements a database rollback command
- // CDbFindPerson : implements a search person command
- //
- // You can construct your own database classes in a similar way
- // =================================================================
- #include <stdio.h>
- #include <iostream.h>
-
- #include "database.h"
- ////////////////////////////////////////////////////////////////////
- // CDbCommit::CDbCommit
- ////////////////////////////////////////////////////////////////////
- // Constructor
- ////////////////////////////////////////////////////////////////////
- CDbCommit::CDbCommit(CDbase &dbase, boolean bUnlock)
- : CDbCommand(dbase)
- {
- m_bUnlock = bUnlock;
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbCommit::~CDbCommit
- ////////////////////////////////////////////////////////////////////
- // Destructor
- ////////////////////////////////////////////////////////////////////
- CDbCommit::~CDbCommit()
- {
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbCommit::Do
- ////////////////////////////////////////////////////////////////////
- // Perform Command
- ////////////////////////////////////////////////////////////////////
- void CDbCommit::Do()
- {
- if (Dbase()->Do(*this))
- ThrowDbError(m_bUnlock);
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbCommit::Execute
- ////////////////////////////////////////////////////////////////////
- // Here the call to the Oracel database function is made
- // DB_Commit is defined in Oracle.cpp which is the compiled
- // Oracle ProC/C++ file where the real database command is
- // exucuted
- ////////////////////////////////////////////////////////////////////
- long CDbCommit::Execute()
- {
- return DB_Commit(this);
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbRollback::CDbRollback
- ////////////////////////////////////////////////////////////////////
- CDbRollback::CDbRollback(CDbase &dbase, boolean bUnlock)
- : CDbCommand(dbase)
- {
- m_bUnlock = bUnlock;
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbRollback::~CDbRollback
- ////////////////////////////////////////////////////////////////////
- CDbRollback::~CDbRollback()
- {
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbRollback::Do
- ////////////////////////////////////////////////////////////////////
- void CDbRollback::Do()
- {
- if (Dbase()->Do(*this))
- ThrowDbError(m_bUnlock);
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbRollback::Execute
- ////////////////////////////////////////////////////////////////////
- long CDbRollback::Execute()
- {
- return DB_Rollback(this);
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbConnect::CDbConnect
- ////////////////////////////////////////////////////////////////////
- CDbConnect::CDbConnect(CDbase &dbase, char* pszConnect)
- : CDbCommand(dbase),
- m_pszConnect(pszConnect)
- {
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbConnect::~CDbConnect
- ////////////////////////////////////////////////////////////////////
- // Destructor
- ////////////////////////////////////////////////////////////////////
- CDbConnect::~CDbConnect()
- {
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbConnect::Do
- ////////////////////////////////////////////////////////////////////
- // Perform Command
- ////////////////////////////////////////////////////////////////////
- void CDbConnect::Do()
- {
- if (Dbase()->Do(*this))
- ThrowDbError(FALSE);
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbConnect::Execute
- ////////////////////////////////////////////////////////////////////
- // Here the call to the Oracel database function is made
- // DB_Commit is defined in Oracle.cpp which is the compiled
- // Oracle ProC/C++ file where the real database command is
- // exucuted
- ////////////////////////////////////////////////////////////////////
- long CDbConnect::Execute()
- {
- return DB_Connect(m_pszConnect);
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbDisConnect::CDbDisConnect
- ////////////////////////////////////////////////////////////////////
- CDbDisConnect::CDbDisConnect(CDbase &dbase)
- : CDbCommand(dbase)
- {
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbDisConnect::~CDbDisConnect
- ////////////////////////////////////////////////////////////////////
- CDbDisConnect::~CDbDisConnect()
- {
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbDisConnect::Do
- ////////////////////////////////////////////////////////////////////
- // Perform Command
- ////////////////////////////////////////////////////////////////////
- void CDbDisConnect::Do()
- {
- if (Dbase()->Do(*this))
- ThrowDbError(FALSE);
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbDisConnect::Execute
- ////////////////////////////////////////////////////////////////////
- // Here the call to the Oracel database function is made
- // DB_Commit is defined in Oracle.cpp which is the compiled
- // Oracle ProC/C++ file where the real database command is
- // exucuted
- ////////////////////////////////////////////////////////////////////
- long CDbDisConnect::Execute()
- {
- return DB_Disconnect();
- }
-
-
- ////////////////////////////////////////////////////////////////////
- // CDbFindPerson::CDbFindPerson
- ////////////////////////////////////////////////////////////////////
- CDbFindPerson::CDbFindPerson(char *pszFirstName, char *pszLastName)
- : CDbCommand()
- , m_pszFirstName(pszFirstName)
- , m_pszLastName(pszLastName)
- {
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbFindPerson::~CDbFindPerson
- ////////////////////////////////////////////////////////////////////
- CDbFindPerson::~CDbFindPerson()
- {
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbFindPerson::Do
- ////////////////////////////////////////////////////////////////////
- void CDbFindPerson::Do()
- {
- if (Dbase()->Do(*this))
- ThrowDbError(m_bUnlock);
- }
-
- ////////////////////////////////////////////////////////////////////
- // CDbFindPerson::Execute
- ////////////////////////////////////////////////////////////////////
- long CDbFindPerson::Execute()
- {
- return DB_FindPerson(this, m_pszFirstName, m_pszLastName );
- }
-
-