I created these classes to make it easy to work with ADOX. For this I created the
CADOXCatalogclass, the CADOXTable class, the CADOXIndex class,
the CADOXProcedure class and the CADOXUser class
Constructs a CADOXCatalog object
CADOXCatalog();
The Open function establishes connections to a database
bool Open(LPCTSTR lpstrConnection);
Parameters
LPCTSTR lpstrConnection: A string pointer containinig a Connection String.
If the function succeeds, this returns true.
For example:
CADOXCatalog pxcat;
CString strConnection = _T("");
strConnection = "Provider=Microsoft.JET.OLEDB.4.0;Data source = "
"c:\\adox\\Test.mdb;Jet OLEDB:Engine Type=5;";
pxcat.Open(strConnection);
bool CreateDatabase(LPCTSTR lpstrCreate);
Parameters
LPCTSTR lpstrCreate
If the function succeeds, this returns true.
For example:
CADOXCatalog pxcat;
CString strConnection = _T("");
strConnection = "Provider=Microsoft.JET.OLEDB.4.0;Data source = "
"c:\\adox\\Test.mdb;Jet OLEDB:Engine Type=5;";
pxcat.CreateDatabase(strConnection);
The AddTable function adds a new table to the database.
bool AddTable(CADOXTable pTable);
Parameters
CADOXTable pTable: Pointer to the CADOXTable Object.
If the function succeeds, this returns true.
See sample
The AddUser function adds a new user to the database
bool AddUser(CADOXUser pUser, LPCTSTR lpstrPassword);
Parameters
CADOXUser pUser: A pointer to the CADOXUser Object.
LPCTSTR lpstrPassword A string pointer containing the user password.
If the function succeeds, this returns true.
The GetProcedureCount function returns the number of stored procedures defined for the
database
long GetProcedureCount();
The GetTableCount function returns the number of tables defined for the database.
long GetTableCount();
The GetViewCount function returns the number of fields defined for the database.
long GetViewCount();
The GetUserCount function returns the number of users that exist in the database.
long GetUserCount();
The GetGroupCount function returns the number of groups that exist in the database.
long GetGroupCount();
The GetTableName function obtains the table name defined in the database.
void GetTableName(long nTableIndex, CString strTableName);
Parameters
long nTableIndex: The Table Index in the Database that is open by CADOXCatalog
CString strTableName: Pointer to a buffer in which to return the Table Name.
The GetProcedureName function obtains the stored procedure name defined in the database.
void GetProcedureName(long nProcedureIndex, CString strProcedureName);
Parameters
long nProcedureIndex: The Procedure Index in the Database that is open by CADOXCatalog
CString strProcedureName: Pointer to a buffer in which to return the Procedure Name.
The GetViewName function obtains the View name defined in the database.
void GetViewName(long nViewIndex, CString strViewName);
Parameters
long nViewIndex: The View Index in the Database that is open by CADOXCatalog
CString strViewName: Pointer to a buffer in which to return the View Name.
The GetUserName function obtains the User name defined in the database.
void GetUserName(long nUserIndex, CString strUserName);
Parameters
long nUserIndex: The User Index in the Database that is open by CADOXCatalog
CString strUserName: Pointer to a buffer in which to return the User Name.
The GetGroupName function obtains the Group name defined in the database.
void GetGroupName(long nGroupIndex, CString strGroupName);
Parameters
long nGroupIndex: The Group Index in the database that is open by CADOXCatalog
CString strGroupName: Pointer to a buffer in which to return the Group Name.
The DeleteTable function deletes the definition of a table in the database.
bool DeleteTable(long nTableIndex);
bool DeleteTable(LPCTSTR lpstrTableName);
Parameters
long nTableIndex: The Table Index in the database that is open by CADOXCatalog
LPCTSTR lpstrTableName: A string pointer containing the Table Name.
The DeleteProcedure function deletes the definition of a Stored Procedure in the database.
bool DeleteProcedure(long nProcedureIndex);
bool DeleteProcedure(LPCTSTR lpstrProcedureName);
Parameters
long nProcedureIndex: The Procedure Index in the Database that is open by
CADOXCatalog
LPCTSTR lpstrProcedureName: A string pointer containing the Procedure Name.
The DeleteView function deletes the definition of a View in the database.
bool DeleteView(long nViewIndex);
bool DeleteView(LPCTSTR lpstrViewName);
Parameters
long nViewIndex: The View Index in the database that is open by CADOXCatalog
LPCTSTR lpstrViewName: A string pointer containing the View Name.
The DeleteGroup function deletes the definition of a Group in the database.
bool DeleteGroup(long nGroupIndex);
bool DeleteGroup(LPCTSTR lpstrGroupName);
Parameters
long nGroupIndex: The Group Index in the Database that is open by CADOXCatalog
LPCTSTR lpstrGroupName: A string pointer containing the Group Name.
The DeleteUser function deletes the definition of a User in the database.
bool DeleteUser(long nViewIndex);
bool DeleteUser(LPCTSTR lpstrUserName);
Parameters
long nViewIndex: The User Index in the database that is open by CADOXCatalog
LPCTSTR lpstrUserName: A string pointer containing the User Name.
Constructs a CADOXTable object
CADOXTable(CADOXCatalog* pCat);
Parameters
CADOXCatalog* pCat: Pointer to the CADOXCatalog Object.
The Create function creates a table, that can be added to the database using
CADOXCatalog::AddTable.
bool Create(LPCTSTR lpstrTableName);
Parameters
LPCTSTR lpstrTableName: A string pointer containing the Table Name.
See sample
The Open function opens an existing table in the database.
bool Open(long nTableIndex);
bool Open(LPCTSTR lpstrTableName);
Parameters
long nTableIndex: The Table Index in the Database that is open by CADOXCatalog
LPCTSTR lpstrTableName: A string pointer containing the Table Name.
The AddField function creates a field in the table.
bool AddField(LPCTSTR lpstrFieldName, enum DataType Type, int nLength = 0);
Parameters
LPCTSTR lpstrFieldName: A string pointer containing a Field Name.
enum DataType Type: A value indicating the data type of the field. The setting can be one
of these values:
CADOXTable::typeSmallInt
CADOXTable::typeInteger
CADOXTable::typeUnsignedTinyInt
CADOXTable::typeUnsignedSmallInt
CADOXTable::typeUnsignedInt
CADOXTable::typeUnsignedBigInt
CADOXTable::typeSingle
CADOXTable::typeDouble
CADOXTable::typeCurrency
CADOXTable::typeDecimal
CADOXTable::typeNumeric
CADOXTable::typeBoolean
CADOXTable::typeDate
CADOXTable::typeDBDate
CADOXTable::typeDBTime
CADOXTable::typeDBTimeStamp
CADOXTable::typeBSTR
CADOXTable::typeVarChar
CADOXTable::typeLongVarChar
CADOXTable::typeWChar
CADOXTable::typeVarWChar
CADOXTable::typeLongVarWChar
CADOXTable::typeBinary
CADOXTable::typeVarBinary
CADOXTable::typeLongVarBinary
CADOXTable::typeChapter
CADOXTable::typeFileTime
CADOXTable::typePropVariant
CADOXTable::typeVarNumeric
int nLength = 0: A value that indicates the maximum size, in bytes, of a field. In any
kind of fields nLength is ignored
See sample
The AddIndex function creates an Index in the table.
bool AddIndex(CADOXIndex pIndex);
Parameters
CADOXIndex pIndex: Pointer to a CADOXIndex Object.
See sample
The DeleteField function removes a field and make it inaccessible.
bool DeleteField(LPCTSTR lpstrFieldName);
Parameters
LPCTSTR lpstrFieldName: A string pointer containinig the Field Name.
void GetName(CString &strTableName);
Parameters
CString &strTableName: Reference to a buffer in which to return the Table Name.
Constructs a CADOXIndex object
CADOXIndex();
bool Create(LPCTSTR lpstrIndexName);
Parameters
LPCTSTR lpstrIndexName: A string pointer containinig a Index Name.
See sample
The AddField function creates a field in the Index.
bool AddField(LPCTSTR lpstrIndexName, enum DataType Type, int nLength = 0);
Parameters
LPCTSTR lpstrIndexName: A string pointer containinig the Index Name.
enum DataType Type: A value indicating the data type of the field. The setting can be one
of these values:
CADOXIndex::typeSmallInt
CADOXIndex::typeInteger
CADOXIndex::typeUnsignedTinyInt
CADOXIndex::typeUnsignedSmallInt
CADOXIndex::typeUnsignedInt
CADOXIndex::typeUnsignedBigInt
CADOXIndex::typeSingle
CADOXIndex::typeDouble
CADOXIndex::typeCurrency
CADOXIndex::typeDecimal
CADOXIndex::typeNumeric
CADOXIndex::typeBoolean
CADOXIndex::typeDate
CADOXIndex::typeDBDate
CADOXIndex::typeDBTime
CADOXIndex::typeDBTimeStamp
CADOXIndex::typeBSTR
CADOXIndex::typeVarChar
CADOXIndex::typeLongVarChar
CADOXIndex::typeWChar
CADOXIndex::typeVarWChar
CADOXIndex::typeLongVarWChar
CADOXIndex::typeBinary
CADOXIndex::typeVarBinary
CADOXIndex::typeLongVarBinary
CADOXIndex::typeChapter
CADOXIndex::typeFileTime
CADOXIndex::typePropVariant
CADOXIndex::typeVarNumeric
int nLength = 0: A value that indicates the maximum size, in bytes, of a field. In any
kind of fields nLength is ignored
See sample
void SetPrimarKey(bool bPrimary = true);
Parameters
bool bPrimary = true
See sample
CADOXTable pxTable(&pxcat);
pxTable.Create("Table4");
pxTable.AddField("Column1", CADOXTable::typeInteger, 0);
pxTable.AddField("Column2", CADOXTable::typeInteger, 0);
pxTable.AddField("Column3", CADOXTable::typeWChar, 25);
pxcat.AddTable(pxTable);
CADOXIndex pxInd;
pxInd.Create("Index1");
pxInd.AddField("Column1", CADOXIndex::typeInteger, 0);
pxInd.SetPrimarKey();
pxTable.AddIndex(pxInd);
Constructs a CADOXProcedure object
CADOXProcedure(CADOXCatalog* pCat);
Parameters
CADOXCatalog* pCat: Pointer to the CADOXCatalog Object.
void GetCommand(CString strCommand);
Parameters
CString strCommand: Pointer to a buffer in which to return the Command String.
void GetName(CString strName);
Parameters
CString strName: Pointer to a buffer in which to return the Procedure Name.
bool Open(LPCTSTR lpstrProcedureName);
Parameters
LPCTSTR lpstrProcedureName: A string pointer containinig the Procedure Name.
bool Create(CString strName, CString strCommand);
Parameters
CString strName: A string pointer containinig a Procedure Name.
CString strCommand: A string pointer containinig the Command String.
Constructs a CADOXView object
CADOXView(CADOXCatalog* pCat);
Parameters
CADOXCatalog* pCat: Pointer to the CADOXCatalog Object.
void GetCommand(CString strCommand);
Parameters
CString strCommand: Pointer to a buffer in which to return the Command String.
void GetName(CString strName);
Parameters
CString strName: Pointer to a buffer in which to return the View Name.
bool Open(LPCTSTR lpstrViewName);
Parameters
LPCTSTR lpstrViewName: A string pointer containinig the View Name.
bool Create(CString strName, CString strCommand);
Parameters
CString strName: A string pointer containinig a View Name.
CString lpstrCommand: A string pointer containinig the Command String.
CString strCommand = _T("Select * From Table4");
xView.Create("View01", strCommand);
Constructs a CADOXUser object
CADOXUser(CADOXCatalog* pCat);
Parameters
CADOXCatalog* pCat: Pointer to the CADOXCatalog Object.
void GetName(CString strName);
Parameters
CString strName: Pointer to a buffer in which to return the User Name
bool Create(LPCTSTR lpstrUserName);
Parameters
LPCTSTR lpstrUserName: A string pointer containinig a User Name.
bool Open(LPCTSTR lpstrUserName);
Parameters
LPCTSTR lpstrUserName: A string pointer containinig the User Name.
bool ChangePassword(LPCTSTR lpstrOldPassword, LPCTSTR lpstrNewPassword);
Parameters
LPCTSTR lpstrOldPassword: A string pointer containinig the Old Password.
LPCTSTR lpstrNewPassword: A string pointer containinig the New Password.
Remarks
Some functions do not work in all providers, for example CADOXCatalog::AddTable doesn't
work in MS SQL Server.
Special thanks
Thank to all for your ideas, suggestions and colaboration.
- Christian Graus
- Mike Osbahr
- Francis BONTHOUX