HomeProjectsServicesContactus
» Guest
  Sign In     Register    
Projects » AccessDB - MS Access (MDB) Wrapper Class
Developer : Ritey
Date : 2005-03-27 00:00

» Summary :

Wrapper class for the ODBC api specifically for MS Access Databases (MDB).

» Catagories :


  • Development Status: Stable
  • Operating System: 2000 / XP / 2003
  • Development Environment: MSVC.NET

» Latest Project Downloads:

Total Download Count For Project : 2251
 
AccessDB (CMDB)accessdb.zip
 2005-11-27Source Code6 KbNotes / ChangesMD5:1bb995ddf820a4769047e1d632035bcd32130 HitsDownload
 

» Project Information :

Description:
Wrapper class from creating and querying MS Access Databases (*mdb) through ODBC Api (SQL___). This was designed using ODBC version 3.52. So using this class with versions less than this may cause issues.
This file along with the .cpp implementaion file contains two classes.
The first being CMDB which wraps database functions, such as, open/close/create/compact/repair database.
The second CQuery is used to execute sql statements on a databse opened using the CMDB database, and retrieve the results with the ability to update/delete/add rows through ODBC. It also retrieves field information and creates and binds necessary buffers to receive the data.

NOTES:
Cannot determin number of records returned. Need to manually count them or run a SELECT COUNT(*) query beforehand.
Large fields like MEMO/OLE/HYPERLINK are limited to 65535 bytes.

Class CMDB
Functions:

::Open()
Open a database from file. Once opened the class can be used with CQuery to execute SQL statements.

::Close()
Closes the open database.

::GetLastDBError()
Returns pointer to the last ODBC specific 5 character error code.

::GetLastDBErrorMsg()
Returns pointer to the last ODBC specific error description.

::Create/Repair/Compact()
Create, repair or compact a database. The database should be closed at the time.


Class CQuery
Functions:

::Open()
Execute a query on a opened database pointed to by pMDB. sql being the SQL statement. This will also build the fields on the returned rows and allocate and bind data buffers for receiveing the data.

::Close()
Close the open query and clean up resources.

::GetLastQueryError()
Returns pointer to the last ODBC specific 5 character error code.

::GetLastQueryErrorMsg()
Returns pointer to the last ODBC specific error description.

::GetEffectedRowCount()
Returns the number of rows affected by an UPDATE/INSERT/DELETE query. Or -1 on error. This will always return -1 for SELECT queries.

::FetchRowFirst/Last/Next/Prev/Absolute()
Fetches a row from the results of a query and loads the data into the fields (m_fields). The first row is always 1.

::AddRow()
Adds the data currently in the field buffers as a new record in the table. The field data is accessed using the m_fields property.

::UpdateCurrentRow()
Updates the the row with the data currently in the field buffers. The field data is accessed using the m_fields property.

::DeleteCurrentRow()
Deletes the currently fetched row from the table.

Properties:

::m_fieldcount
The number of fields in the returned result set.

::m_fields
Pointer to the zero based array of fields returned. This property will give descriptions on the fields and also a pointer to the field buffer that will contain the data for a fetched row.
<hr>
Sample Usage:
Code:
#include "AccessDB.h"
#include "stdio.h"

void main( void ) {
    CMDB mdb;
    CQuery sql;

    //open the database
    mdb.Open("C:/test.mdb");

    //execute a query
    sql.Open(&mdb,"SELECT * FROM testtable WHERE 1");

    //Fetch the first row
    sql.FetchRowFirst();

    //display something from the result
    printf("%sn",sql.m_fields[0].data.Pointers.pChar);

    //close the query
    sql.Close();

    //close the database
    mdb.Close();

}

0 member(s), 40 guest(s)
| Site Map | Statistics | Terms of Use | Privacy Policy |
Copyright (C) GoCoding.Com 2004-2007
Powered by Seditio
Contacts