Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

DAO library extension

0.00/5 (No votes)
4 Mar 2002 1  
My added DAO functionality makes database reading and writing easier

Introduction

DAO database library DLL

I have noticed that working with DAO databases and recordsets can often be tedious and time consuming, which is why I created this DAO database library. My goal was to create a library to speed up coding time when working with DAO. My classes inherit from the base DAO classes so no functionality is lost.

My library allows you to 

  1. quickly open database and recordset objects,
  2. close them quickly without worrying about memory leaks, 
  3. easily read and write from the database for specific data types.

These functions are not intended to replace CDaoDatabase/CDaoRecordset functionality, but rather extend them for reduced coding.

I. DLL Setup

1. Open the project and compile the DLL using "rebuild all", it will create a .dll and .lib file for you in your release folder.

II. Client EXE Setup

  1. In project -> settings -> link -> object libraries include daolibrary.lib 
  2. In Release folder add daolibrary.dll 
  3. In project workspace add daolibrary.lib 
  4. Add dllHeader.h to project and following lines in client .cpp file.
#include "dllHeader.h" 

CDaoDB db; // database 

CDaoRS rs; // recordset

Functions available:

CDaoDB Documentation Class CDaoDB extends the CDaoDatabase class

bool CDaoDB::dbOpen(CString strFilePathName);

Opens connection to CDaoDatabase given a database filename with path.

bool CDaoDB::dbClose();

Closes the CDaoDatabase, deletes variables to prevent memory leaking.

CString CDaoDB::GetTableName(int tableNum);

Returns the name of a table based on the table number.

CDaoRS Documentation Class CDaoRS extends the CDaoRecordset class bool CDaoRS::rsOpen(CString sql,CDaoDatabase* db);

Opens connection to CDaoRecordset given sql and database. i.e. 

rs.rsOpen("SELECT * FROM TABLE",database.db);

*note that this opens the recordset as dbOpenDynaset

bool CDaoRS::rsClose();

Closes the CDaoRecordset, deletes variables to prevent memory leaking.

double CDaoRS::GetAsDouble(int col);

Returns a double value from the specified column in the recordset.

int CDaoRS::GetAsInt(int col);

Returns an int value from the specified column in the recordset.

long CDaoRS::GetAsLong(int col);

Returns a long value from the specified column in the recordset.

CString CDaoRS::GetAsString(int col);

Returns a long value from the specified column in the recordset.

CString CDaoRS::GetDateAsString(int col);

Returns a date value in CString format from the specified column in the recordset. The CString will be returned with mm/dd/yyy format.

CString CDaoRS::GetTimeAsString(int col);

Returns a date value in CString format from the specified column in the recordset. The CString will be returned with hh:mm:ss format.

void CDaoRS::SetAsString(CString field,CString string);

Set specified fieldname field in recordset to the CString value string.

void CDaoRS::SetAsInt(CString field,int integer);

Set specified fieldname field in recordset to the integer value int.

void CDaoRS::SetAsLong(CString field,long lngValue);

Set specified fieldname field in recordset to the long value lngValue.

void CDaoRS::SetAsDouble(CString field,double dblValue);

Set specified fieldname field in recordset to the double value dblValue.

CString CDaoRS::GetFieldName(int col);

Returns the field name of the specified column number in the recordset.

int CDaoRS::GetRecordCount();

Returns the number of records in the recordset.

Please give suggestions for other functions you would like to see in here. Sample client app will be available soon...

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