Overview
- The CADODatabase Class
- The CADORecordset Class
- CADORecordset
- Open
- Execute
- GetQuery
- SetQuery
- RecordBinding
- GetRecordCount
- IsOpen
- Close
- GetFieldCount
- GetFieldValue
- IsFieldNull
- IsFieldEmpty
- IsEof
- IsBof
- Move
- AbsolutePage
- GetPageCount
- PageSize
- AbsolutePosition
- GetFieldInfo
- GetChunk
- AppendChunk
- GetString
- GetLastError
- GetLastErrorString
- AddNew
- Edit
- Delete
- Update
- CancelUpdate
- SetFieldValue
- Find
- FindFirst
- FindNext
- GetBookmark
- SetBookmark
- SetFilter
- SetSort
- GetRecordset
- GetActiveConnection
- Clone
- SaveAsXML
- OpenXML
- OpenSchema
- Requery
- The CADOParameter Class
- The CADOCommand Class
- The CJectEngine Class
- The CADOException Class
- COLEDBDataLink
- COLEDBException
- Common Questions
Overview
I created these classes to make it easy to work with ADO. For this I created the CADODatabse
class and the CADORecordset
class.
The CADODatabase Class
The CADODatabase
class has a set of functions that corresponds to the _ConnectionPtr
.
Creates a CADODatabase
object.
CADODatabase();
The Open
function opens a connection to a database.
BOOL Open(LPCTSTR lpstrConnection = _T("")); throw(CADOException);
Parameters
LPCTSTR lpstrConnection
- The connection string.
Note: the class has the function SetConnectionString
. You can insert the connection string through this function. In this case you can do the following:
//Sample with Connection string for SQL Server CADODatabase* pAdoDb = new CADODatabase(); CString strConnection = _T(""); strConnection = _T("Provider=MSDASQL;PersistSecurityInfo=False;" "Trusted_Connection=Yes;" "Data Source=Access Sql Server;catalog=sampledb"); pAdoDb->SetConnectionString(strConnection); if(pAdoDb->Open()) DoSomething(); . . . //Sample with Connection String for Access database CADODatabase* pAdoDb = new CADODatabase(); CString strConnection = _T(""); strConnection = _T("Provider=Microsoft.Jet.OLEDB.4.0;" "Data Source=C://VCProjects//ADO//Test//dbTest.mdb"); pAdoDb->SetConnectionString(strConnection); if(pAdoDb->Open()) { DoSomething(); . . . pAdoDb->Close(); } delete pAdoDb;
The Execute
function executes a SQL statement in the open database.
BOOL Execute(LPCTSTR lpstrExec);
throw(CADOException);
Parameters
LPCTSTR lpstrExec
- A string pointer containing the SQL statement to execute.
CADODatabase* pAdoDb = new CADODatabase(); CString strConnection = _T(""); strConnection = _T("Provider=MSDASQL;" "PersistSecurityInfo=False;" "Trusted_Connection=Yes" "Data Source=Access Sql Server;catalog=sampledb"); if(pAdoDb->Open(strConnection)) pAdoDb->Execute("Delete From tblClients Where Cheker = 3");
Return Value
The function returns TRUE
if it was executed successfully.
CADODatabase::GetRecordsAffected
The GetRecordsAffcted
function returns the number of records affected by the last SQL statement executed.
int GetRecordsAffected();
CADODatabase::GetActiveConnection
The GetActiveConnection
returns the active connection.
_ConnectionPtr GetActiveConnection();
GetRecordCount
returns the number of records affected in a query.
DWORD GetRecordCount(_RecordsetPtr m_pRs);
Parameters
_RecorsetPtr m_Prs
- The recordset.
CADODatabase::BeginTransaction
Call this function to initiate a transaction. After you call BeginTransaction
, updates you make to your data take effect when you commit the transaction.
long BeginTransaction();
CADODatabase::CommitTransaction
Call CommitTransaction
function to commit a transaction, for example, save a group of edits and updates to one or more databases.
long CommitTransaction();
CADODatabase::RollbackTransaction
Call RollbackTransaction
function to end the current transaction and restore all databases to their condition before the transaction was begun.
long RollbackTransaction();
The IsOpen
function returns the status of the connection with the database.
BOOLIsOpen();
Return Value
The function returns TRUE
if the connection to the database is open.
The Close
function closes the connection to the database.
void Close();
CADODatabase::SetConnectionString
With the SetConnectionString
, you can insert the connection string.
void SetConnectionString(LPCTSTR lpstrConnection);
Parameters
LPCTSTR lpstrConnection
- A connection string used for opening the database.
CADODatabase::GetConnectionString
The GetConnectionString
function returns the connection string used for making a connection with a database.
CString GetConnectionString();
CADODatabase::SetConnectionMode
The SetConnectionMode
function sets the mode of connection.
void SetConnectionMode(cadoConnectModeEnum nMode);
Parameters
cadoConnectModeEnum nMode
- a variable that defines the connection mode to be used. It can be one of the following:
CADODatabase::connectModeUnknown
CADODatabase::connectModeRead
CADODatabase::connectModeWrite
CADODatabase::connectModeReadWrite
CADODatabase::connectModeShareDenyRead
CADODatabase::connectModeShareDenyWrite
CADODatabase::connectModeShareExclusive
CADODatabase::connectModeShareDenyNone
The GetLastError
function returns the last error code.
DWORD GetLastError();
CADODatabase::GetLastErrorString
The GetLastErrorString
function returns the last error string.
CString GetLastErrorString();
The CADORecordset Class
The CADORecordset
class has a set of functions that corresponds to the _RecordsetPtr
.
Creates a CADORecordset
object.
CADODatabase(); CADORecordset(CADODatabase* pAdoDatabase);
Parameters
CADODatabase* pAdoDatabase
- A CADODatabase
object pointer.
The Open
function opens a recordset.
BOOL Open(_ConnectionPtr mpdb, LPCTSTR lpstrExec = _T(""), int nOption = CADORecordset::openUnknown); BOOL Open(LPCTSTR lpstrExec = _T(""), int nOption = CADORecordset::openUnknown);
Parameters
_ConnectionPtr mpdb
- A connection pointer.LPCTSTR lpstrExec
- A string pointer containing an SQLSELECT
statement.int nOption
- An integer that defines the access mode. The values are as follows:CADORecordset::openUnknown
CADORecordset::openQuery
CADORecordset::openTable
CADORecordset::openStoredProc
Return Value
Returns TRUE
if it was executed successfully.
The Execute
function opens a recordset.
BOOL Execute(CADOCommand* pCommand);
throw(CADOException);
Parameters
CADOCommand* pCommand
- A CADOCommand
pointer.
Return Value
Returns TRUE
if it was executed successfully.
GetQuery
returns the string containing the SQL SELECT
statement.
CString GetQuery();
void SetQuery(LPCSTR strQuery);
Parameters
LPCTSTR strQuery
- A string pointer containing an SQL SELECT
statement.
BOOL RecordBinding(CADORecordBinding pAdoRecordBinding);
Parameters
CADORecordBinding pAdoRecordBinding
GetRecordCount
returns the number of records accessed in the recordset.
DWORD GetRecordCount();
IsOpen
determines if the recordset is open.
BOOL IsOpen();
Return Value
This member function returns TRUE
if the recordset has not been closed.
The Close
function closes the recordset.
void Close();
The GetFieldCount
function returns the number of fields in the recordset.
long GetFieldCount();
The GetFieldValue
function returns a value that contains the value of a field.
BOOL GetFieldValue(LPCTSTR lpFieldName, int nValue); BOOL GetFieldValue(int nIndex, int nValue); BOOL GetFieldValue(LPCTSTR lpFieldName, long lValue); BOOL GetFieldValue(int nIndex, long lValue); BOOL GetFieldValue(LPCTSTR lpFieldName, unsigned long ulValue); BOOL GetFieldValue(int nIndex, unsigned long ulValue); BOOL GetFieldValue(LPCTSTR lpFieldName, double dbValue); BOOL GetFieldValue(int nIndex, double dbValue); BOOL GetFieldValue(LPCTSTR lpFieldName, CString strValue, CString strDateFormat = _T("")); BOOL GetFieldValue(int nIndex, CString strValue, CString strDateFormat = _T("")); BOOL GetFieldValue(LPCTSTR lpFieldName, COleDateTime time); BOOL GetFieldValue(int nIndex, COleDateTime time); BOOL GetFieldValue(LPCTSTR lpFieldName, bool bValue); BOOL GetFieldValue(int nIndex, bool bValue); BOOL GetFieldValue(LPCTSTR lpFieldName, COleCurrency cyValue); BOOL GetFieldValue(int nIndex, COleCurrency cyValue); throw(CADOException);
Parameters
LPCTSTR lpFieldName
- A pointer to a string that contains the name of a field.int nIndex
- A zero-based index of the field in the recordset’sFields
collection, for lookup by index.double dbValue
- A reference to an object that will store the value of a field.long lValue
- A reference to an object that will store the value of a field.unsigned long ulValue
- A reference to an object that will store the value of a field.int nValue
- A reference to an object that will store the value of a field.CString strValue
- A reference to an object that will store the value of a field.CString strDateFormat
- A formatting time string similar to thestrftime
formatting string. The more common are:- %a - Abbreviated weekday name
- %A - Full weekday name
- %b - Abbreviated month name
- %B - Full month name
- %c - Date and time representation appropriate for locale
- %d - Day of month as decimal number (01 - 31)
- %H - Hour in 24-hour format (00 - 23)
- %I - Hour in 12-hour format (01 - 12)
- %j - Day of year as decimal number (001 - 366)
- %m - Month as decimal number (01 - 12)
- %M - Minute as decimal number (00 - 59)
- %p - Current locale’s A.M./P.M. indicator for 12-hour clock
- %S - Second as decimal number (00 - 59)
- %U - Week of year as decimal number, with Sunday as first day of week (00 - 53)
- %w - Weekday as decimal number (0 - 6; Sunday is 0)
- %W - Week of year as decimal number, with Monday as first day of week (00 - 53)
- %x - Date representation for current locale
- %X - Time representation for current locale
- %y - Year without century, as decimal number (00 - 99)
- %Y - Year with century, as decimal number
COleDateTime time
- A reference to an object that will store the value of a field.bool bValue
- A reference to an object that will store the value of a field.COleCurrency cyValue
- A reference to an object that will store the value of a field.
The IsFieldNull
function determines if the field data is null.
BOOL IsFieldNull(LPCTSTR lpFieldName); BOOL IsFieldNull(int nIndex); throw(CADOException);
Parameters
LPCTSTR lpFieldName
- A pointer to a string that contains the name of a field.int nIndex
- A zero-based index of the field in the recordset’sFields
collection, for lookup by index.
Return Value
This function returns TRUE
if the field data is null.
The IsFieldEmpty
function determines if the field data is empty.
BOOL IsFieldEmpty(LPCTSTR lpFieldName); BOOL IsFieldEmpty(int nIndex); throw(CADOException);
Parameters
LPCTSTR lpFieldName
- A pointer to a string that contains the name of a field.int nIndex
- A zero-based index of the field in the recordset’sFields
collection, for lookup by index.
Return Value
This function returns TRUE
if the field data is empty.
BOOL IsEof();
Return Value
This function returns TRUE
if the current position contains no records.
BOOL IsBof();
Return Value
This function returns TRUE
if the current position is the bottom of the recordset.
CADORecordset::MoveFirst
CADORecordset::MoveNext
CADORecordset::MovePrevious
CADORecordset::MoveLast
These functions make the first/next/previous/or last record of the recordset as the current record.
void MoveFirst(); void MoveNext(); void MovePrevious(); void MoveLast();
CADORecordset::GetAbsolutePage
CADORecordset::SetAbsolutePage
Indicates on which page the current record resides.
long GetAbsolutePage(); void SetAbsolutePage(int nPage);
Parameters
int nPage
- The number of the page starting from 1.
GetPageCount
returns the number of pages in the recordset.
long GetPageCount();
CADORecordset::GetPageSize
CADORecordset::SetPageSize
Indicates the number of records per page.
long GetPageSize(); void SetPageSize(int nSize);
Parameters
int nSize
- set the number of records per page.
For example
CADORecordset* pRs = new CADORecordset(pDb); if(pRs->Open("MyBigTable", CADORecordset::openTable)) { pRs->SetPageSize(5); for(register int nPageIndex = 1; nPageIndex <= pRs->GetPageCount(); nPageIndex++) { pRs->SetAbsolutePage(nPageIndex); for(register int nRecNumber = 0; nRecNumber < pRs->GetPageSize(); nRecNumber++) { long lVal; pRs->GetFieldValue("ID", lVal); pRs->MoveNext(); if(pRs->IsEof()) break; } } pRs->Close(); } delete pRs;
CADORecordset::GetAbsolutePosition
CADORecordset::SetAbsolutePosition
Indicates the position of the record in the recordset.
long GetAbsolutePosition(); void SetAbsolutePosition(int nPosition);
Parameters
int nPosition
- Move to the position in the recordset.
GetAbsolutePosition()
can return the position of the record or one of the following values:
CADORecordset::positionUnknown
CADORecordset::positionBOF
CADORecordset::positionEOF
GetFieldInfo
returns the attributes of a field.
BOOL GetFieldInfo(LPCTSTR lpFieldName, CAdoFieldInfo* fldInfo);
BOOL GetFieldInfo(int nIndex, CAdoFieldInfo* fldInfo);
Parameters
LPCTSTR lpFieldName
- A pointer to a string that contains the name of a field.int nIndex
- A zero-based index of the field in the recordset'sFields
collection, for lookup by index.CAdoFieldInfo* fldInfo
- A struct that returns the field attributes.
struct CADOFieldInfo { char m_strName[30]; short m_nType; long m_lSize; long m_lDefinedSize; long m_lAttributes; short m_nOrdinalPosition; BOOL m_bRequired; BOOL m_bAllowZeroLength; long m_lCollatingOrder; };
The element m_nType
of the class CADOFieldInfo
can be one of the following values:
CADORecordset::typeEmpty
CADORecordset::typeTinyInt
CADORecordset::typeSmallInt
CADORecordset::typeInteger
CADORecordset::typeBigInt
CADORecordset::typeUnsignedTinyInt
CADORecordset::typeUnsignedSmallInt
CADORecordset::typeUnsignedInt
CADORecordset::typeUnsignedBigInt
CADORecordset::typeSingle
CADORecordset::typeDouble
CADORecordset::typeCurrency
CADORecordset::typeDecimal
CADORecordset::typeNumeric
CADORecordset::typeBoolean
CADORecordset::typeError
CADORecordset::typeUserDefined
CADORecordset::typeVariant
CADORecordset::typeIDispatch
CADORecordset::typeIUnknown
CADORecordset::typeGUID
CADORecordset::typeDate
CADORecordset::typeDBDate
CADORecordset::typeDBTime
CADORecordset::typeDBTimeStamp
CADORecordset::typeBSTR
CADORecordset::typeChar
CADORecordset::typeVarChar
CADORecordset::typeLongVarChar
CADORecordset::typeWChar
CADORecordset::typeVarWChar
CADORecordset::typeLongVarWChar
CADORecordset::typeBinary
CADORecordset::typeVarBinary
CADORecordset::typeLongVarBinary
CADORecordset::typeChapter
CADORecordset::typeFileTime
CADORecordset::typePropVariant
CADORecordset::typeVarNumeric
CADORecordset::typeArray
For example
if(prs->Open("Clients", CADORecordset::openTable)) { CADOFieldInfo pInfo; prs->GetFieldInfo("Description", &pInfo); if(pInfo.m_nType == CADORecordset::typeVarChar) AfxMessageBox("The type Description Field Is VarChar"); } if(prs->Open("TestTable", CADORecordset::openTable)) { CADOFieldInfo* fInfo = new CADOFieldInfo; prs.GetFieldInfo(0, fInfo); CString strFieldName = fInfo->m_strName; prs->Close(); }
Return Value
Returns TRUE
if it was executed successfully.
This function returns all, or a portion, of the contents of a large text or binary data Field
object.
BOOL GetChunk(LPCTSTR lpFieldName, CString& strValue); BOOL GetChunk(int nIndex, CString& strValue); BOOL GetChunk(LPCTSTR lpFieldName, LPVOID pData); BOOL GetChunk(int nIndex, LPVOID pData);
Parameters
LPCTSTR lpFieldName
- A pointer to a string that contains the name of a field.int nIndex
- A zero-based index of the field in the recordset'sFields
collection, for lookup by index.CString& strValue
- A string pointer that contains the data that returns from the object.LPVOID pData
- A pointer that contains the data that returns from the object.
Return Value
Returns TRUE
if it was executd successfully.
This function appends data to a large text or binary data field.
BOOL AppendChunk(LPCTSTR lpFieldName, LPVOID lpData, UINT nBytes); BOOL AppendChunk(int nIndex, LPVOID lpData, UINT nBytes); throw(CADOException);
Parameters
LPCTSTR lpFieldName
- A pointer to a string that contains the name of a field.int nIndex
- A zero-based index of the field in the recordset'sFields
collection, for lookup by index.LPVOID lpData
- A pointer that contains the data to append to the object.UINT nBytes
- AUINT
that indicates the size of the data to be inserted.
Return Value
Returns TRUE
if it was executed successfully.
For example
//Sample of AppendChunck prs.AddNew(); prs.SetFieldValue("ID", 5); prs.SetFieldValue("Description", "Client 05"); prs.SetFieldValue("Checker", 1); prs.AppendChunk("Document", "This Document is the story of Bob and his Friends...", 37); prs.Update(); //Sample of GetChunck char data[1024]; prs.GetChunk("Document", (LPVOID)&data);
This function returns a recordset as a string.
CString GetString(LPCTSTR lpCols, LPCTSTR lpRows, LPCTSTR lpNull, long numRows = 0);
Parameters
LPCTSTR lpCols
- A columns delimiter.LPCTSTR lpRows
- A rows delimiter.LPCTSTR lpNull
- An expression that represents a null value.long numRows
- The number of rows affected.
The GetLastError
function returns the last error code.
DWORD GetLastError();
CADORecordset::GetLastErrorString
The GetLastErrorString
function returns the last error string.
CString GetLastErrorString();
The AddNew
function adds a record in the open recordset.
BOOL AddNew();
throw(CADOException);
Return Value
Returns TRUE
if it was executed successfully.
The Edit
function allows changes to the current record in the open recordset.
void Edit();
The Delete
function deletes the current record in the open recordset.
BOOL Delete();
Return Value
Returns TRUE
if it was executed successfully.
The Update
function updates the pending updates in the current record.
BOOL Update();
throw(CADOException);
Return Value
Returns TRUE
if it was executed successfully.
The CancelUpdate
function cancels any pending update in the open recordset.
void CancelUpdate();
The SetFieldValue
function sets the value of a field.
BOOL SetFieldValue(int nIndex, int nValue); BOOL SetFieldValue(LPCTSTR lpFieldName, int nValue); BOOL SetFieldValue(int nIndex, long lValue); BOOL SetFieldValue(LPCTSTR lpFieldName, long lValue); BOOL SetFieldValue(int nIndex, unsigned long ulValue); BOOL SetFieldValue(LPCTSTR lpFieldName, unsigned long ulValue); BOOL SetFieldValue(int nIndex, double dblValue); BOOL SetFieldValue(LPCTSTR lpFieldName, double dblValue); BOOL SetFieldValue(int nIndex, CString strValue); BOOL SetFieldValue(LPCTSTR lpFieldName, CString strValue); BOOL SetFieldValue(int nIndex, COleDateTime time); BOOL SetFieldValue(LPCTSTR lpFieldName, COleDateTime time); BOOL SetFieldValue(int nIndex, bool bValue); BOOL SetFieldValue(LPCTSTR lpFieldName, bool bValue); BOOL SetFieldValue(int nIndex, COleCurrency cyValue); BOOL SetFieldValue(LPCTSTR lpFieldName, COleCurrency cyValue);
Parameters
LPCTSTR lpFieldName
- A pointer to a string that contains the name of a field.int nIndex
- A zero-based index of the field in the recordset’sFields
collection, for lookup by index.int nValue
- A pointer to an object containing the value of the field.long lValue
- A pointer to an object containing the value of the field.unsigned long lValue
- A pointer to an object containing the value of the field.double dbValue
- A pointer to an object containing the value of the field.CString strValue
- A pointer to an object containing the value of the field.COleDateTime time
- A pointer to an object containing the value of the field.bool bValue
- A pointer to an object containing the value of the field.COleCurrency cyValue
- A pointer to an object containing the value of the field.
Return Value
Returns TRUE
if it was executed successfully.
For example
CADORecordset* prs = new CADORecordset(m_pAdoDb); prs->Open("Test", openTable); prs->AddNew(); prs->SetFieldValue(0, "dataU"); prs->SetFieldValue(1, "data01"); prs->SetFieldValue(2, (long)51000); COleDateTime time = COleDateTime(2001,6,15, 10, 8, 30); prs->SetFieldValue(3, time); prs->Update(); prs->Close(); delete prs;
The Find
function locates a string from the current position in the open recordset using an operator of comparison.
BOOL Find(LPCTSTR lpFind,
int nSearchDirection = CADORecordset::searchForward);
Parameters
LPCTSTR lpFind
- A string expression used to locate the record.int nSearchDirection
- A value that indicates the type of operation. The possible values are:CADORecordset::searchForward
- Find the next location.CADORecordset::searchBackward
- Find the previous location.
Return Value
Returns TRUE
if it was executed successfully.
For example
if(prs.Find("Field0 LIKE 'dataU%'")) { prs.Delete(); while(prs.FindNext()) prs.Delete(); }
The FindFirst
function locates a string from the beginning in the open recordset using an operator of comparison.
BOOL FindFirst(LPCTSTR lpFind);
Parameters
LPCTSTR lpFind
- A string expression used to locate the record.
Return Value
Returns TRUE
if it was executed successfully.
The FindNext
function locates a string from the last position in the open recordset using the operator of comparison used in FindFirst
or Find
functions.
BOOL FindNext();
Return Value
Returns TRUE
if it was executed successfully.
The GetBookmark
function saves the position of the current record.
BOOL GetBookmark();
Return Value
Returns TRUE
if it was executed successfully.
The SetBookmark
function returns to the position saved at any time.
void SetBookmark();
Return Value
Returns TRUE
if it was executed successfully.
The SetFilter
indicates a filter for data in an open Recordset
.
BOOL SetFilter(LPCTSTR strFilter);
throw(CADOException);
Parameters
LPCTSTR strFilter
- a string composed by one or more individual clauses concatenated with AND or OR operators.
Return Value
Returns TRUE
if it was executed successfully.
For example
CADORecordset* pRs = new CADORecordset(pDb); if(pRs->Open("tblTest", CADORecordset::openTable)) { CString strFilter = _T("LastName = 'Smith' And Age > 30"); pRs->SetFilter(strFilter); . . pRs->Close(); } delete pRs
The SetSort
function sets the sort order for records in a CADORecordset
object.
BOOL SetSort(LPCTSTR lpstrCriteria);
throw(CADOException);
Parameters
LPCTSTR lpstrCriteria
- A string that contains the ORDER BY
clause of an SQL statement.
Return Value
Returns TRUE
if it was executed successfully.
The GetRecordset
function returns a pointer to an open recordset.
_RecordsetPtr GetRecordset();
CADORecordset::GetActiveConnection
The GetActiveConnection
returns the active connection.
_ConnectionPtr GetActiveConnection();
The Clone
function creates a duplicate CADORecordset
object from an existing CADORecordset
object.
BOOL Clone(CADORecordset pAdoRecordset);
throw(CADOException);
Parameters
CADORecordset pAdoRecordset
is an existing CADORecordset
object.
Return Value
Returns TRUE
if it was executed successfully.
For example
CADORecordset m_pRs; //Original Recordset CADORecordset RS; //Duplicate Recordset CADORecordset* pRs = CADORecordset(m_pDb); if(pRs->Open("tblTest", CADORecordset::openTable)) //Open the Original Recordset { pRs->Clone(RS); //Create the clone of the original Recordset long lClonRecs = RS.GetRecordCount(); long lOrigRecs = m_pRs->GetRecordCount(); . . RS.Close(); pRs->Close(); } delete pRs;
The SaveAsXML
function saves the open recordset in a file with XML format.
BOOL SaveAsXML(LPCTSTR lpstrXMLFile);
Parameters
LPCTSTR strXMLFile
- a string that indicates the complete path name of the file where the recordset is to be saved.
Return Value
Returns TRUE
if it was executed successfully.
The OpenXML
function opens a XML file format in a recordset.
BOOL OpenXML(LPCTSTR lpstrXMLFile);
Parameters
LPCTSTR strXMLFile
- a string that indicates the complete path name of the XML file to be opened.
Return Value
Returns TRUE
if it was executed successfully.
For example
CADORecordset* pRs = CADORecordset(pDB); if(prs->OpenXML("C://My.XML")) { CString strClient = _T(""); double dblVal = 0; long lrecs = prs->GetRecordCount(); if(!prs->IsEof()) prs->MoveFirst(); prs->GetFieldValue("Budget", dblVal); prs->GetFieldValue("ClientName", strClient); prs->Close(); }
The OpenSchema
function obtains database schema information from the provider.
BOOL OpenSchema(int nSchema, LPCTSTR SchemaID = _T("")); throw(CADOException);
Parameters
int nSchema
- A value that represents the type of schema query.LPCTSTR SchemaID = _T("")
- The GUID for a provider-schema query not defined by the OLE DB specification.
Constant | Value | Description | Constraint Columns |
---|---|---|---|
schemaAsserts |
0 | Returns the assertions defined in the catalog that are owned by a given user. | CONSTRAINT_ CATALOG *CONSTRAINT_ SCHEMA *CONSTRAINT_NAME |
schemaCatalogs |
1 | Returns the physical attributes associated with catalogs accessible from the DBMS. | CATALOG_NAME |
schemaCharacterSets |
2 | Returns the character sets defined in the catalog that are accessible to a given user. | CHARACTER_ SET_CATALOG *CHARACTER_ SET_SCHEMA *CHARACTER_SET _NAME * |
schemaCheckConstraints |
5 | Returns the check constraints defined in the catalog that are owned by a given user. | CONSTRAINT_ CATALOG *CONSTRAINT_ SCHEMA *CONSTRAINT_NAME |
schemaCollations |
3 |
Returns the character collations defined in the catalog that are accessible to a given user. |
COLLATION_ CATALOG *COLLATION_SCHEMA COLLATION_NAME |
schemaColumnPrivileges |
13 |
Returns the privileges on columns of tables defined in the catalog that are available to, or granted by, a given user. |