QbConnectClass is derived from the QbBaseClass and is used to obtain a connection to a database or a file system. The Connect method establishes a connection to a database, or mounts a filesystem (processing that is expensive and typically only done once). The Disconnect method disconnects from the database, or dismounts the file system.
The function QbGetConnection in the file QbCreate.cpp implements the simple one-connection-per-address-space connection needed by the current QBIC implementation, which uses the Berkeley dbm system. QbGetConnection takes two arguments:
It returns a const pointer to an instance of the connection class. Because it is a const, you cannot Disconnect or Connect to a database, nor can you delete the pointer yourself. However, you can create instances of a database appropriate for this connection using the functions CreateDatabaseClass and CreateKeyDatabaseClass. Use the method QbDestroyConnection, also in QbCreate.cpp, when you are finished with the connection. The default implementation for Berkeley dbm files creates a directory using the database name.
This chapter describes the following methods:
You can see coding examples in Appendix C, "Sample Code" on page 185. Other programs are located in the qbic/QbicApi
directory.
This is the constructor for the class.
QbConnectClass( void )
This is the destructor for the class.
virtual ~QbConnectClass( void )
This method connects to the named database in either read or write mode.
virtual int Connect( const char *dsNameArg, const char *modeArg )
An integer value: 0 indicates success; -1 indicates failure
This method provides an abstract architected method to create a catalog class.
virtual QbCatalogClass * CreateCatalogClass( void )
A pointer to a QbCatalogClass object
This method provides an abstract architected method to create a database class to support database operations such as Open, Close, Insert, Delete, Update, and so on.
virtual QbDatabaseClass * CreateDatabaseClass( void )
A pointer to a QbDatabaseClass object
This method provides an abstract architected method to create a key database class for storing query results and for specifying the restriction list in a query.
virtual QbKeyDatabaseClass * CreateKeyDatabaseClass( void )
A pointer to a QbKeyDatabaseClass object
This method disconnects from the database.
virtual int Disconnect( void )
An integer value: 0 indicates success; -1 indicates failure
This method returns the database connection mode: either "r" or "w" for read or write.
virtual const char * GetConnectMode( void )
A pointer to a char that contains either "r" or "w" for read or write
This method returns the name of the database to which the current object is connected.
virtual const char * GetDSName( void )
A pointer to a string that contains the database name
This method returns True if the database is connected already, and False if it is not.
virtual Boolean IsConnected( void )
A Boolean value; True if connected, False it not