Click here to Skip to main content
11,492,962 members (60,969 online)
Click here to Skip to main content

A set of ADOX Classes

, 19 Jun 2002 448.4K 4.7K 152
Rate this:
Please Sign up or sign in to vote.
Simple database catalog access using a set of ADOX classes
<!-- Download Links -->

Overview

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

The CADOXCatalog Class

CADOXCatalog::CADOXCatalog

Constructs a CADOXCatalog object

CADOXCatalog();

CADOXCatalog::Open

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);

CADOXCatalog::CreateDatabase

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);

CADOXCatalog::AddTable

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

CADOXCatalog::AddUser

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.

CADOXCatalog::GetProcedureCount

The GetProcedureCount function returns the number of stored procedures defined for the database

long GetProcedureCount();

CADOXCatalog::GetTableCount

The GetTableCount function returns the number of tables defined for the database.

long GetTableCount();

CADOXCatalog::GetViewCount

The GetViewCount function returns the number of fields defined for the database.

long GetViewCount();

CADOXCatalog::GetUserCount

The GetUserCount function returns the number of users that exist in the database.

long GetUserCount();

CADOXCatalog::GetGroupCount

The GetGroupCount function returns the number of groups that exist in the database.

long GetGroupCount();

CADOXCatalog::GetTableName

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.

CADOXCatalog::GetProcedureName

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.

CADOXCatalog::GetViewName

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.

CADOXCatalog::GetUserName

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.

CADOXCatalog::GetGroupName>

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.

CADOXCatalog::DeleteTable

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.

CADOXCatalog::DeleteProcedure

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.

CADOXCatalog::DeleteView

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.

CADOXCatalog::DeleteGroup

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.

CADOXCatalog::DeleteUser

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.

The CADOXTable Class

CADOXTable::CADOXTable

Constructs a CADOXTable object

CADOXTable(CADOXCatalog* pCat);

Parameters

CADOXCatalog* pCat: Pointer to the CADOXCatalog Object.

CADOXTable::Create

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

CADOXTable::Open

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.

CADOXTable::AddField

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

CADOXTable::AddIndex

The AddIndex function creates an Index in the table.

bool AddIndex(CADOXIndex pIndex);

Parameters

CADOXIndex pIndex: Pointer to a CADOXIndex Object.

See sample

CADOXTable::DeleteField

The DeleteField function removes a field and make it inaccessible.

bool DeleteField(LPCTSTR lpstrFieldName);

Parameters

LPCTSTR lpstrFieldName: A string pointer containinig the Field Name.

CADOXTable::GetName

void GetName(CString &strTableName);

Parameters

CString &strTableName: Reference to a buffer in which to return the Table Name.

The CADOXIndex Class

CADOXIndex::CADOXIndex

Constructs a CADOXIndex object

CADOXIndex();

CADOXIndex::Create

bool Create(LPCTSTR lpstrIndexName);

Parameters

LPCTSTR lpstrIndexName: A string pointer containinig a Index Name.

See sample

CADOXIndex::AddField

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

CADOXIndex::SetPrimaryKey

void SetPrimarKey(bool bPrimary = true);

Parameters

bool bPrimary = true

See sample

Sample 01:

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);

The CADOXProcedure Class

CADOXProcedure::CADOXProcedure

Constructs a CADOXProcedure object

CADOXProcedure(CADOXCatalog* pCat);

Parameters

CADOXCatalog* pCat: Pointer to the CADOXCatalog Object.

CADOXProcedure::GetCommand

void GetCommand(CString strCommand);

Parameters

CString strCommand: Pointer to a buffer in which to return the Command String.

CADOXProcedure::GetName

void GetName(CString strName);

Parameters

CString strName: Pointer to a buffer in which to return the Procedure Name.

CADOXProcedure::Open

bool Open(LPCTSTR lpstrProcedureName);

Parameters

LPCTSTR lpstrProcedureName: A string pointer containinig the Procedure Name.

CADOXProcedure::Create

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.

The CADOXView Class

CADOXView::CADOXView

Constructs a CADOXView object

CADOXView(CADOXCatalog* pCat);

Parameters

CADOXCatalog* pCat: Pointer to the CADOXCatalog Object.

CADOXView::GetCommand

void GetCommand(CString strCommand);

Parameters

CString strCommand: Pointer to a buffer in which to return the Command String.

CADOXView::GetName

void GetName(CString strName);

Parameters

CString strName: Pointer to a buffer in which to return the View Name.

CADOXView::Open

bool Open(LPCTSTR lpstrViewName);

Parameters

LPCTSTR lpstrViewName: A string pointer containinig the View Name.

CADOXView::Create

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);

The CADOXUser Class

CADOXUser::CADOXUser

Constructs a CADOXUser object

CADOXUser(CADOXCatalog* pCat);

Parameters

CADOXCatalog* pCat: Pointer to the CADOXCatalog Object.

CADOXUser::GetName

void GetName(CString strName);

Parameters

CString strName: Pointer to a buffer in which to return the User Name

CADOXUser::Create

bool Create(LPCTSTR lpstrUserName);

Parameters

LPCTSTR lpstrUserName: A string pointer containinig a User Name.

CADOXUser::Open

bool Open(LPCTSTR lpstrUserName);

Parameters

LPCTSTR lpstrUserName: A string pointer containinig the User Name.

CADOXUser::ChangePassword

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Carlos Antollini
Architect Citigroup
Argentina Argentina
Carlos Antollini is a software engineer working on Object Oriented, Visual C++, MFC, COM, ATL, ADO, Internet technologies and Business Intelligence.
Carlos is originally from Argentina, he was living for several years in Fort Lauderdale, Florida, working for Citibank. Then he started his own business.
Carlos is the creator of piFive[^], a family of BI Analytic Platform software, that it deals next to, latinsys[^], his partner in businesses...
Currently he is sharing his passion for project management and BI at Citigroup.

Comments and Discussions

 
Generalhelp me, about create database Pin
Love In Snowing15-Apr-09 20:20
memberLove In Snowing15-Apr-09 20:20 
GeneralAbout Add Primary and Foreign Key. (Add tow Fuction) [modified] Pin
tangversion23-Feb-09 8:38
membertangversion23-Feb-09 8:38 
Generalhelp me... create table from mysql Pin
younghoyu6-Aug-08 19:56
memberyounghoyu6-Aug-08 19:56 
GeneralRe: help me... create table from mysql Pin
ldaoust16-Oct-09 7:55
memberldaoust16-Oct-09 7:55 
GeneralRe: help me... create table from mysql [modified] Pin
Theo Buys7-Jan-10 5:36
memberTheo Buys7-Jan-10 5:36 
GeneralHelp me, strange phenomenon Pin
yh_pp9-Aug-07 2:27
memberyh_pp9-Aug-07 2:27 
GeneralRe: Help me, strange phenomenon Pin
Theo Buys5-Sep-07 2:29
memberTheo Buys5-Sep-07 2:29 
GeneralRe: Help me, strange phenomenon Pin
dzyssssss29-Jun-08 18:13
memberdzyssssss29-Jun-08 18:13 
QuestionHow to join two tables in different databases Pin
Theo Buys7-Mar-07 2:20
memberTheo Buys7-Mar-07 2:20 
Question80040154 Error when creating a database Pin
BalouLeFou18-Jan-07 6:43
memberBalouLeFou18-Jan-07 6:43 
QuestionThis class create the sql server database have a bug? Pin
blackgole20-Dec-06 16:47
memberblackgole20-Dec-06 16:47 
AnswerRe: This class create the sql server database have a bug? Pin
dzyssssss29-Jun-08 18:18
memberdzyssssss29-Jun-08 18:18 
GeneralDLL problem [modified] Pin
Mark8419-Dec-06 22:28
memberMark8419-Dec-06 22:28 
QuestionHow can I find the columns in an Index Pin
AlexEvans11-Oct-06 19:10
memberAlexEvans11-Oct-06 19:10 
GeneralWho has a new version with ADOXField Pin
NielsR24-Aug-06 8:24
memberNielsR24-Aug-06 8:24 
GeneralRe: Who has a new version with ADOXField Pin
SupportElitron14-May-07 21:23
memberSupportElitron14-May-07 21:23 
GeneralUnicode support modifications Pin
holst_gustav31-Jul-06 23:40
memberholst_gustav31-Jul-06 23:40 
Questionhow i can implement passimistic lock Pin
syed abbdul qavi22-Feb-06 12:11
membersyed abbdul qavi22-Feb-06 12:11 
GeneralMar Pin
MARARK23-Jan-06 1:03
memberMARARK23-Jan-06 1:03 
QuestionNice stuff but... ado2 and adox in a DLL ? Pin
Mohamed Y. E.28-Nov-05 6:25
memberMohamed Y. E.28-Nov-05 6:25 
AnswerRe: Nice stuff but... ado2 and adox in a DLL ? Pin
Theo Buys22-May-06 23:57
memberTheo Buys22-May-06 23:57 
GeneralNot solved this problem! Pin
y_yy200819-Jun-06 9:31
membery_yy200819-Jun-06 9:31 
AnswerRe: Not solved this problem! Pin
Deng Shi12-Jun-07 0:44
memberDeng Shi12-Jun-07 0:44 
QuestionHow to make the Field may be a NULL!! Pin
bluecrystal16-Aug-05 21:14
memberbluecrystal16-Aug-05 21:14 
QuestionCan someone Join ado2 and adox in a one file ! Pin
bluecrystal9-Aug-05 19:08
memberbluecrystal9-Aug-05 19:08 
GeneralProblem when setting default value for a field Pin
ldaoust27-Jul-05 7:11
memberldaoust27-Jul-05 7:11 
GeneralRe: Problem when setting default value for a field Pin
ldaoust27-Jul-05 8:28
memberldaoust27-Jul-05 8:28 
GeneralWithout Good Documentation and Sample Pin
UMER91113-Jun-05 17:48
memberUMER91113-Jun-05 17:48 
Generalproblem when I try to compile a application that use ADO and ADOX Pin
Silviu Ardelean2-Jun-05 3:36
memberSilviu Ardelean2-Jun-05 3:36 
GeneralRe: problem when I try to compile a application that use ADO and ADOX Pin
Homero De la Garza18-Sep-05 16:05
memberHomero De la Garza18-Sep-05 16:05 
GeneralCADOXView and CADOXProcedure Pin
Theo Buys2-May-05 1:14
memberTheo Buys2-May-05 1:14 
GeneralADODB and ADOX Pin
Theo Buys28-Apr-05 1:41
memberTheo Buys28-Apr-05 1:41 
GeneralProblem using with DAO :( Pin
AndyBa20-Apr-05 20:45
memberAndyBa20-Apr-05 20:45 
GeneralThis can be a bug... Pin
Theo Buys19-Apr-05 5:41
memberTheo Buys19-Apr-05 5:41 
GeneralMore options for access database fields Pin
Theo Buys19-Apr-05 4:48
memberTheo Buys19-Apr-05 4:48 
GeneralClose() functions would be nice Pin
ViolaCase7-Mar-05 0:13
memberViolaCase7-Mar-05 0:13 
GeneralRe: Close() functions would be nice Pin
Theo Buys7-Mar-05 4:05
memberTheo Buys7-Mar-05 4:05 
GeneralRe: Close() functions would be nice Pin
rajas18-Apr-05 9:01
memberrajas18-Apr-05 9:01 
GeneralRe: Close() functions would be nice Pin
Theo Buys19-Apr-05 3:11
memberTheo Buys19-Apr-05 3:11 
GeneralRe: Close() functions would be nice Pin
rajas19-Apr-05 13:42
memberrajas19-Apr-05 13:42 
GeneralOptions for access database fields Pin
Theo Buys6-Mar-05 22:53
memberTheo Buys6-Mar-05 22:53 
GeneralRe: Options for access database fields Pin
ViolaCase7-Mar-05 0:07
memberViolaCase7-Mar-05 0:07 
GeneralRe: Options for access database fields Pin
Bui Tan Duoc7-May-06 19:27
memberBui Tan Duoc7-May-06 19:27 
GeneralRe: Options for access database fields Pin
Theo Buys7-May-06 22:56
memberTheo Buys7-May-06 22:56 
GeneralRe: Options for access database fields Pin
Bui Tan Duoc7-May-06 23:08
memberBui Tan Duoc7-May-06 23:08 
GeneralRe: Options for access database fields Pin
mas_per15-Oct-06 11:43
membermas_per15-Oct-06 11:43 
GeneralHelp me...Big problem of ADO when user disable network Pin
Tâm Hồ5-Mar-05 0:33
memberTâm Hồ5-Mar-05 0:33 
GeneralRe: Help me...Big problem of ADO when user disable network Pin
phucid7-Oct-05 0:43
memberphucid7-Oct-05 0:43 
GeneralHere is a good example... Pin
Theo Buys1-Mar-05 5:59
memberTheo Buys1-Mar-05 5:59 
GeneralRe: Bad examples Pin
ViolaCase6-Mar-05 0:39
memberViolaCase6-Mar-05 0:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 20 Jun 2002
Article Copyright 2002 by Carlos Antollini
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid