ccDataDictionary

10/13/99

Author: Daniel.Lindh@Home.se
ICQ: 7983755
HOMEPAGE: home.bip.net/CyberCow

Copyright © Cyber Cow 1995 - 1999.
All Rights Reserved.

OverView
Class Members
Base Class None

 

Overview

#include <**class header**>

Hierarchy Chart

moo.bmp (10726 bytes)


This class handles all the communications with the database tables. You can say that this is the middle tier in a three tier structure. All bussniess logic is placed in this class.

 

Class Members

Macros

Private:

None

Data Items:

Private:

None

Construction

Public:

ccDataDictionary

Default Constructor

addField

Add table fields to use from the database table. 

sortBy

Tell in which order the rows should be sorted.
setPrimKey
getPrimKey
Used by relations.

Protected:

open

Opening the table.

 retriveFieldInfo Retrive information about the table.

Navigation

Public:

moveFirst

Move current record pointer to the first record in the table

movePrev

Move current record pointer to the previous record in the table

moveNext

Move current record pointer to the next record in the table

moveLast

Move current record pointer to the last record in the table

setBookMark

Positions the current record on the record specified by the bookmark.

Update the database

Public:

requery

Get the latest information from the database fields to the datadictionarys ccFields.

saveRecord

Save information in the datadictionary fields to the database and clear all the fields.

saveRecordNoClear

Save information in the datadictionary fields to the database 

deleteRecord

Delete the record the current record pointer is pointing to.

clearRecord

Clear all the fields in the datadictionary.

findRecord

Protected:

Nones

Private:

None

 

asdf

Public:

None

Protected:

Nones

Private:

None

 

 

ccDataDictionary::ccDataDictionary

ccDataDictionary( ccDataBase* apDataBase, 

                  CString asTableName, 

                  UINT nOpenType = snapshot 

                 );

Return Value:

None

Arguments:

apDataBase

This should point to the ccDataBase derivied class this datadicionary is a member of.

asTableName

This is the name of the table in the Database. This name should be sourounded by [ and ]. 

nOpenType

Accept the default value, AFX_DB_USE_DEFAULT_TYPE, or use one of the following values from the enum OpenType:

  • CRecordset::dynaset   A recordset with bi-directional scrolling. The membership and ordering of the records are determined when the recordset is opened, but changes made by other users to the data values are visible following a fetch operation. Dynasets are also known as keyset-driven recordsets.

  • CRecordset::snapshot   A static recordset with bi-directional scrolling. The membership and ordering of the records are determined when the recordset is opened; the data values are determined when the records are fetched. Changes made by other users are not visible until the recordset is closed and then reopened.

  • CRecordset::dynamic   A recordset with bi-directional scrolling. Changes made by other users to the membership, ordering, and data values are visible following a fetch operation. Note that many ODBC drivers do not support this type of recordset.

  • CRecordset::forwardOnly   A read-only recordset with only forward scrolling.

    For CRecordset, the default value is CRecordset::snapshot. The default-value mechanism allows the Visual C++ wizards to interact with both ODBC CRecordset and DAO CDaoRecordset, which have different defaults.

    For more information about these recordset types, see CRecordset::open in the MSDN help. 

Remarks:

This is the default constructor who initzialize the ccDataDictionary class. 

 

This member should be overloaded in the derivied class and contain initializiaion of member ccFields. It also opens the table, sort it in right order and sets the primkey.

 

Usually this class will be created in the constructor of a ccDataBase derivied class.

Example:

cddTEmployee::cddTEmployee( ccDataBase* pDatabase ) 
: ccDataDictionary( pDatabase, _T("[TEmployee]") )
{

   // Open the table.
   m_Contact.init ( this, TEmployee_Contact, _T("Contact") );

   open();
   sortBy( &m_Contact, NULL ); 
   setPrimKey( &m_Contact );

   // TEmployee.Contact
   m_Contact.setLongCaption ( _T("Contact") ); 
}

 

ccDataDictionary::addField

E_ccErrRet addField(ccField * aoField);

Return Value:

E_ccErrRet

CCSUCCEDED if field added without problems. 

Arguments:

aoField

The ccField member who should be used by the dicionary.

Remarks:

The ccField added by this function should be a member object of this dataDicionary. But this member tell the dictionary that it has this ccField member, so it can be used by intern functions. 

 

This member doesn't need to be called, because it's called automatically from the ccField::init member. And this ccField member  will be called from this datadicionarys constructor.

Example:

not needed.

 

ccDataDictionary::sortBy

E_ccErrRet sortBy( ccField * aoSortField ... );

Return Value:

E_ccErrRet

CCSUCCEDED the sorting succeded.
CCFAILED the sorting was unsuccesful or the table wasn't opened.

Arguments:

aoSortField ...

ccField objects in that the table should be sorted. Should be ended with NULL.

Caution: The ccField must be a pointer. It's not absolutely sure the compiler will give you a warning if you don't give it a pointer.  

Remarks:

This member will sort the table in a user specified order. 

 

It will also enable moveFirst, movePrev( F7), moveNext(F8) and moveLast functins for the ccdbSuperCtrls connected to ccFields included in the sortBy argument.

Example:

// From a ccDataDicionary constructor.

m_Contact.init ( this, TEmployee_Contact, _T("Contact") );
m_Address.init ( this, TEmployee_Address, _T("Address") );

open();
sortBy( &m_Contact, &m_Address, NULL ); 

 

ccDataDictionary::setPrimKey
ccDataDictionary::getPrimKey

void setPrimKey( ccField * aoPrimKey );
ccField * getPrimKey();

throw( ccdbException )

Return Value:

ccField

Return the current primKey.

Arguments:

ccField

The ccField who is the prim key.

Remarks:

If some dataDictionary has a relation to this dd, the child field will be related to the primKey field. 

 

This member will throw a ccdbException if the primkey isn't sorted.

Example:

m_Contact.init ( this, TEmployee_Contact, _T("Contact") );

open();
sortBy( &m_Contact, NULL ); 
setPrimKey( &m_Contact );

 

ccDataDictionary::open

BOOL open(); 

Return Value:

BOOL

Nonzero if the table was successfully opened; otherwise 0

Arguments:

None

Remarks:

Opening up the connection to the table in the database.

Example:

Open();

 

ccDataDictionary::retriveFieldInfo

E_ccErrRet retriveFieldInfo();

Return Value:

E_ccErrRet

CCSUCCEDED if succeful field retreving, otherwise failed.

Arguments:

None

Remarks:

Get information from the database table for the connected ccField:s. This is called from the open member and doesn't need to be called from some other place.

Example:

Not needed

 

ccDataDictionary::moveFirst
ccDataDictionary::movePrev
ccDataDictionary::moveNext
ccDataDictionary::moveLast

E_ccErrRet moveFirst();
E_ccErrRet movePrev();
E_ccErrRet moveNext();
E_ccErrRet moveLast();

Return Value:

E_ccErrRet

CCSUCCEDED if succseded else failed.

Arguments:

None

Remarks:

Move the current record pointer to the first, previous, next or last record in the database table. 

 

It also finds all parent related datadicionary records, and makes this dicionary and all parent dictionarys editable. If the table doesn't have any records the datadictionary will be cleared.

 

ccDataDictionary::setBookmark

E_ccErrRet setBookmark( const CDBVariant& varBookmark );

Return Value:

E_ccErrRet 

CCSUCCEDED if succseded else failed.

Arguments:

varBookMark

Remarks:

Call this member function to position the recordset on the record containing the specified bookmark.

This member does the same stuff that the CRecordset::SetBookmark in MFC with some small exceptions.

It won't throw any exceptions, because they will be catched from the setBookmark member. It also finds all parent related datadicionary records, and makes this dicionary and all parent dictionarys editable. If the table doesn't have any records the datadictionary will be cleared.

Example:

...

cDBVariant l_CyberCow;

m_ddCompany.GetBookMark( l_CyberCow );

...

m_ddCompany.SetBookMark( l_CyberCow );

 

ccDataDictionary::requery

E_ccErrRet requery();

Return Value:

E_ccErrRet

CCSUCCEDED if succeded else failed.

Arguments:

None

Remarks:

This member refreshes the value in the dataDictionarys ccFields with the new values in the database table. This needs to be done to show changes other users has done to the database, like changeing, deleteing or creating a new record.

 

Exceptions from that is if the datadicionary is a dynaset. Then changes to exsiting records will be reflected automatically (but not additions).

 

For more info see CRecordset::requery in MSDN help.

Example:

none

 

ccDataDictionary::saveRecord
ccDataDictionary::saveRecordNoClear

E_ccErrRet saveRecord();

E_ccErrRet saveRecordNoClear();

Return Value:

E_ccErrRet

CCSUCCEDED if succeded else failed

Arguments:

None

Remarks:

Save information in the datadictionary fields to the database and clear all the fields.

 

But first it will run the backout procedure for all parents dd and this dd. Starting with the top parent. Then it will run the creating procedure for all parents dd and thisdd, starting with the top parent. And after that it will run the updating procedure for all parents dd and this dd starting with this dd. Then it will save the data to the database. And for the saveRecord member the dataDictionary will be cleared so a new record can be typed.

 

Exceptions are: the backout procedure will only be executed in those dd:s who has an existing record and the creating procedure will be executed on those who has a new record.

Example:

none

 

ccDataDictionary::deleteRecord

E_ccErrRet deleteRecord();

Return Value:

E_ccErrRet

CCSUCCEDED if succeded else failed.

Arguments:

None

Remarks:

This member will delete the current record. The user will first be asked if she wants the record to be deleted.

Caution: In this version no deleting of childs will be done.

Example:

none

 

ccDataDictionary::clearRecord

E_ccErrRet clearRecord();

Return Value:

E_ccErrRet

CCSUCCEDED if succeded else failed.

Arguments:

None

Remarks:

Clear the current record and prepares so a new record can be typed. If the record is modified the user will first be asked if she wants the record to be cleared.

Example:

none

 

ccDataDictionary::

**constructor();**

Return Value:

None

Arguments:

None

Remarks:

**Description**

Example:

**class object;**

 

ccDataDictionary::

**constructor();**

Return Value:

None

Arguments:

None

Remarks:

**Description**

Example:

**class object;**

 

ccDataDictionary::

**constructor();**

Return Value:

None

Arguments:

None

Remarks:

**Description**

Example:

**class object;**

 

ccDataDictionary::

**constructor();**

Return Value:

None

Arguments:

None

Remarks:

**Description**

Example:

**class object;**

 

ccDataDictionary::

**constructor();**

Return Value:

None

Arguments:

None

Remarks:

**Description**

Example:

**class object;**

 

ccDataDictionary::

**constructor();**

Return Value:

None

Arguments:

None

Remarks:

**Description**

Example:

**class object;**

 

ccDataDictionary::

**constructor();**

Return Value:

None

Arguments:

None

Remarks:

**Description**

Example:

**class object;**

 

ccDataDictionary::

**constructor();**

Return Value:

None

Arguments:

None

Remarks:

**Description**

Example:

**class object;**

 

ccDataDictionary::

**constructor();**

Return Value:

None

Arguments:

None

Remarks:

**Description**

Example:

**class object;**

 

ccDataDictionary::

**constructor();**

Return Value:

None

Arguments:

None

Remarks:

**Description**

Example:

**class object;**