class CTTime
Description
The CTTime class represents Time objects.
See also
CTTimeTime, CTTime
Preconditions
This is one of the basic objects from the c-tree database layer.
CTTime Operators
- operator = : Assignment operator
- operator <, <=, >, >=, ==, != : Comparison operators
CTTime::operator =
Syntax
CTTime& operator = (const CTTime& Time)
CTTime& operator = (CTTIME Time)
Parameters
- Time [in] The CTTime object or Time to be assigned to the new CTTime object
Description
These overloaded operators assign a Time or CTTime object to a CTTime object
Return
The new CTTime object
CTTime::operator <, <=, >, >=, ==, !=
Syntax
CTBOOL operator < (const CTTime& Time)
CTBOOL operator <= (const CTTime& Time)
CTBOOL operator > (const CTTime& Time)
CTBOOL operator >= (const CTTime& Time)
CTBOOL operator == (const CTTime& Time)
CTBOOL operator != (const CTTime& Time)
Parameters
- Time [in] The Time to be compared to this CTTime object
Description
These overloaded operators make comparisons between the CTTime object and Time.
Return
The operators return YES or NO, depending on the result of the comparison.
CTTime Methods
Constructor / Destructor
- CTTime(): Creates a CTTime object
- ~CTTime(): Destroys a CTTime Object and resets all the dependent objects
Time Handling
- GetTime(): Retrieves the Time.
- SetTime(): Sets the Time to the CTTime object.
- Pack(): Packs an hour, minute and second value into a CTTIME object.
- Unpack(): Unpacks a CTTIME object into hour, minute and second values
- Hour(): Retrieves the hour component from a CTTIME object
- Minute(): Retrieves the minute component from a CTTIME object
- Second(): Retrieves the second component from a CTTIME object
- TimeToString(): Converts a packed CTTIME object to a CTString object
- StringToTime(): Converts a CTString object to a Time object
- CurrentTime(): Retrieves the current system Time.
CTTable::Attach
Attaches a c-tree Plus ISAM datno object to a FairCom DB API table object.
Declaration
void CTTable::Attach(NINT datno);
Description
- datno is data file number opened with one of the c-tree ISAM open functions.
CTTable::Attach() attaches a c-tree Plus ISAM datno object to a FairCom DB API table object. This function is useful if you have opened a data and index file using one of c-tree’s ISAM open functions and need to attach it to a table handle to use some of the advanced FairCom DB API features such as alter table or the record handler.
Return
void
Example
CTSession hSession(CTSESSION_CTREE);
CTTable hTable(hSession);
CTRecord hRecord(hTable);
NINT datno, count = 0;
// logon to c-tree
hSession.Logon(SERVER, USER, PASSWD);
// open the file using c-tree ISAM
datno = (NINT)OPNRFILX((COUNT) -1, "test309.dat", (COUNT)0, NULL);)
// attach to table
hTable.Attach(datno);
// read the records
if (hRecord.First())
do
{
count++;
}
while (hRecord.Next());
// cleanup
hTable.Detach();
hSession.Logout();
See Also
CTTable::AttachXtd(), CTTable::Detach()
CTTable::AttachXtd
Attaches a c-tree Plus ISAM datno object to a FairCom DB API table handle allowing a DODA and IFIL to be specified.
Declaration
void CTTable::AttachXtd(NINT datno, NINT nbrfields, pDATOBJ dodaptr,
pIFIL ifilptr);
Description
- datno is the data file number.
- nbrfields is the number of fields described by dodaptr. If nbrfields is zero, it is assumed that the DODA is not supplied and a DODA resource will be read from the table itself.
- dodaptr pointer to DODA entries for each field in table. If dodaptr is NULL, it is assumed that the DODA is not supplied and a DODA resource will be read from the table itself.
- ifilptr is a pointer to IFIL structure describing indexes of table. If ifilptr is NULL it is assumed that an IFIL is not supplied and an IFIL resource will be read from the table itself.
CTTable::AttachXtd() attaches a c-tree Plus ISAM datno object to a FairCom DB API table object. This function is useful if you have opened a data and index file using one of c-tree’s ISAM open functions and need to attach it to a table handle to use some of the advanced FairCom DB API features such as alter table or the record handler. This extended version allows the user to specify the DODA and IFIL for the table, enabling tables without DODA and/or IFIL to be attached to FairCom DB API.
Return
void
Example
/* DODA */
static DATOBJ doda[] =
{
{"f1", (pTEXT)0, CT_INT4, 4},
{"f2", (pTEXT)4, CT_FSTRING, 10}
};
/* IFIL */
static ISEG iseg = {0, 4, 12};
static IIDX iidx = {4, 0, 0, 0, 0, 1, &iseg, "i311x1", NULL, NULL, NULL};
static IFIL ifil = {"test310", -1, 14, 0, 0, 1, 0, 0, &iidx, "f1", "f2", 0};
CTSession hSession(CTSESSION_CTREE);
CTTable hTable(hSession);
CTRecord hRecord(hTable);
NINT datno, count = 0;
// logon to c-tree
hSession.Logon(SERVER, USER, PASSWD);
// open the file using c-tree ISAM
datno = (NINT)OPNRFILX((COUNT) -1, "test309.dat", (COUNT)0, NULL);)
// attach to table
hTable.AttachXtd(datno, 2, doda, &ifil);
// read the records
if (hRecord.First())
do
{
count++;
}
while (hRecord.Next());
// cleanup
hTable.Detach();
hSession.Logout();
CTTable::ClearAllFieldDefaultValue
Clears the default value associated with all fields in a table.
Declaration
void CTTable::ClearAllFieldDefaultValue();
Description
Clears the default value associated with all fields in a table. The default date and time types for each field are also reset to the default values of CTDATE_MDCY and CTIME_HMS respectively.
Return
void
Example
// clear all field default value
try
{
hTable.ClearAllFieldDefaultValue();
}
catch (CTException &err)
{
printf("ClearAllFieldDefaultValue failed\n");
}
See Also
SetFieldDefaultValue(), GetFieldDefaultValue(), IsFieldDefaultValueSet(), ClearFieldDefaultValue(), SetFieldDefaultDateTimeType(), GetFieldDefaultDateType(), GetFieldDefaultTimeType()
CTTime::CTTime
Syntax
CTTime ( )
CTTime(NINT hour, NINT minute, NINT second)
CTTime(CTTIME Time)
CTTime(const CTTime& Time)
Parameters
- hour [in] The hour to set to the CTTime object.
- minute [in] The minute to set to the CTTime object.
- second [in] The second to set to the CTTime object.
- Time [in] The Time to set to the CTTime object
Description
This is the constructor for the CTTime object.
See also
~CTTime()
CTTime::~CTTime
Syntax
~CTTime
Parameters
This destructor has no parameters.
Description
This is the destructor for the CTTime object.
See also
CTTime()
CTTime::CurrentTime
Syntax
CTTime CurrentTime( )
Parameters
This method has no parameters.
Description
Retrieves the current system time
Return
CurrentTime() returns a CTTime object with the system current Time.
See also
GetTime()
CTTable::Detach
Detaches a FairCom DB API table object from a c-tree data and index files.
Declaration
void CTTable::Detach();
Description
CTTable::Detach() detaches a FairCom DB API table object from a c-tree data and index files. The table is not closed but the FairCom DB API table handle resources are released and the handle re-initialized.
Return
void
Example
CTSession hSession(CTSESSION_CTREE);
CTTable hTable(hSession);
CTRecord hRecord(hTable);
NINT datno, count = 0;
// logon to c-tree
hSession.Logon(SERVER, USER, PASSWD);
// open the file using c-tree ISAM
datno = (NINT)OPNRFILX((COUNT) -1, "test309.dat", (COUNT)0, NULL);)
// attach to table
hTable.Attach(datno);
// read the records
if (hRecord.First())
do
{
count++;
}
while (hRecord.Next());
// cleanup
hTable.Detach();
hSession.Logout();
See Also
CTTable::Attach(), CTTable::AttachXtd()
CTTable::GetDatno
Retrieve the table data file number.
Declaration
NINT CTTable::GetDatno()
Description
Retrieves the table data file number from a table object. If an error is detected, GetDatno() throw a CTException.
Return
GetDatno() returns the table data file number.
Example
void DeleteTable(CTSEssion& hSession, pTEXT tablename)
{
CTDBRET eRet;
CTTable hTable(hSession);
// open the table exclusive
hTable.Open(tablename, CTOPEN_EXCLUSIVE);
// delete a file
eRet = (CTDBRET)DeleteRFile((COUNT)hTable.GetDatno());
if (eRet != CTDBRET_OK)
throw CTException(eRet, "DeleteTable", __FILE__, __LINE__);
}
See Also
CTBase::SwitchInstance(), CTRecord::SwitchContext(), CTTable::GetIdxno(), CTIndex::GetIdxno()
CTTable::GetIdxno
Retrieve a table index file number given the index name or the FairCom DB API index number.
Declaration
NINT CTTable::GetIdxno(const CTString& IndexName)
NINT CTTable::GetIdxno(NINT index)
Description
Retrieves the index file number given the index name or the FairCom DB API index number.
- IndexName contains the symbolic name for the index. Please note the difference between the index symbolic name and the index file name.
- index is a FairCom DB API index number. The first FairCom DB API index number is zero.
Return
GetIdxno() returns a table index file number.
Example
// retrieve the first key of first index
TEXT keyval[256];
if (FirstKey(hTable.GetIdxno("IndexName"), keyval)
printf("FirstKey failed\n");
if (FirstKey(hTable.GetIdxno(0), keyval)
printf("FirstKey failed\n");
See Also
CTBase::SwitchInstance(), CTRecord::SwitchContext(), CTTable::GetDatno(), CTIndex::GetIdxno()
CTTable::GetTableKSeg
Retrieves the current table wide extended key segment definition.
Declaration
void CTTable::GetTableKSeg(pctKSEGDEF pKSeg);
Description
CTTable::GetTableKSeg() retrieves the current table wide extended key segment definition. pKSeg is a pointer to an extended key segment definition structure which will receive the definition.
Return
void
Example
ctKSEGDEF kseg;
hTable.GetTableKSeg(&ksge);
See Also
CTIndex::GetIndexKSeg(), CTIndex::SetIndexKSeg(), CTSegment::GetSegmentKSeg(),
CTSegment::SetKSegDefaults(), CTSegment::SetSegmentKSeg(), CTTable::SetTableKSeg()
CTTime::GetTime
Syntax
CTTIME GetTime( ) const
Parameters
This method has no parameters.
Description
Retrieves the Time.
Return
GetTime() returns a CTTIME object with the Time.
See also
SetTime(), CurrentTime()
CTTime::Hour
Syntax
NINT Hour( ) const
Parameters
This method has no parameters.
Description
Retrieves the hour component from a CTTIME object.
Return
Hour returns the unpacked hour.
See also
Minute(), Second(), Unpack(), Pack()
CTTime::Minute
Syntax
NINT Minute( ) const
Parameters
This method has no parameters.
Description
Retrieves the minute component from a CTTIME object
Return
Minute returns the unpacked minute.
See also
Unpack(), Hour(), Second(), Pack()
CTTable::MoveSegment
Moves a key segment to a location.
Declaration
void CTTable::MoveSegment(CTIndex hIndex, NINT segNumber, NINT newIndex);
void CTTable::MoveSegment(NINT indexNumber, NINT segNumber, NINT newIndex);
void CTTAble::MoveSegment(const CTString& indexName, NINT segNumber,
NINT newIndex);
Description
CTTable::MoveSegment() moves a key segment to a location indicated by newIndex.
- hIndex is an index object.
- indexNumber is a relative number for a index object in a table definition.
- indexName is the unique name for the index.
- newIndex indicates the relative position were the key segment should be moved to.
Return
void
Example
// move the last segment to first
CTIndex hIndex = hTable.GetIndex(0);
NINT count = hIndex.GetSegmentCount();
if (count > 0)
hTable.MoveSegment(hIndex, (count - 1), 0);
See Also
CTIndex::MoveSegment(), CTSegment::MoveSegment()
CTTime::Pack
Syntax
void Pack(NINT hour, NINT minute, NINT second)
Parameters
- hour [in] The hour to pack.
- minute [in] The minute to pack.
- second [in] The second to pack.
Description
Packs an hour, minute and second value into a CTTIME object.
Return
None.
See also
Unpack()
CTTable::Remove
Removes any FairCom DB API table.
Declaration
void CTTable::Remove();
Description
The CTTable::Remove() function allows any table to be deleted, including tables that are not members of a database.
The CTTable::Remove() function deletes a c-tree data file and the associated index files from disk. If the table was opened under a database handle, the table is closed and CTDatabase::DeleteTable() is called. If the handle is not active, the table is opened exclusive and then deleted. If the table handle is not active, you must set the path, file extension and password for the handle before calling the RemoveTable() method.
A CTException is thrown when an error occurs. Use CTException::GetErrorCode() and CTException::GetErrorMsg() to retrieve the error code and descriptive message.
Return
void
Example
/* delete a FairCom DB API Table */
try {
MyTable.Remove();
}
catch(CTException &E) {
printf("MyTable.Remove error: (%d) - %s\n", E.GetErrorCode(),
E.GetErrorMsg());
}
See Also
CTDatabase::DeleteTable()
CTTime::Second
Syntax
NINT Second( ) const
Parameters
This method has no parameters.
Description
Retrieves the second component from a CTTIME object.
Return
Second returns the unpacked second.
See also
Minute(), Hour(), SecondOfWeek(), Unpack(), Pack()
CTTable::SetTableKSeg
Establishes a table wide extended key segment definition.
Declaration
void CTTable::SetTableKSeg(pctKSEGDEF pKSeg);
Description
CTTable::SetTableKSeg() establishes a table wide extended key segment definition. pKSeg is a pointer to an extended key segment definition structure with the extended key definition.
Return
void
Example
ctKSEGDEF kseg;
kseg.kseg_ssiz = ctKSEG_SSIZ_COMPUTED;
kseg.kseg_type = ctKSEG_TYPE_UNICODE;
kseg.kseg_styp = ctKSEG_STYP_UTF16;
kseg.kseg_comp = ctKSEG_COMPU_S_DEFAULT | ctKSEG_COMPU_N_NONE;
kseg.kseg_desc = "en_US"
hTable.SetTableKSeg(&kseg);
See Also
CTIndex::GetIndexKSeg(), CTIndex::SetIndexKSeg(), CTSegment::GetSegmentKSeg(),
CTSegment::SetKSegDefaults(), CTSegment::SetSegmentKSeg(), CTTable::GetTableKSeg()
CTTime::SetTime
Syntax
void SetTime(CTTIME Time)
void SetTime(const CTTime& Time)
Parameters
- Time [in] The new Time to set to the CTTime object.
Description
Sets the Time to the CTTime object.
Return
None.
See also
GetTime()
CTTime::StringToTime
Syntax
void StringToTime(const CTString& str, CTTIME_TYPE TimeType)
Parameters
- str [in] The string object to be converted.
- TimeType [in] The Time type format to be used in the conversion. Valid Time formats are shown in "Data Types".
Description
Converts a CTString object to a Time object.
Return
None.
See also
TimeToString()
CTTable::SystemFilterOff
Deletes a permanent system wide record filter.
Declaration
void CTTable::SystemFilterOff(CTSYSFILTER mode);
Description
Deletes a permanent system wide record filter. The table must be opened exclusive and the user must have file definition permission for the table.
mode specifies one of the following:
- CTSYSFILTER_READ - Indicates you are deleting only a system wide read record filter.
- CTSYSFILTER_WRITE - Indicates you are deleting only a system wide write record filter
- CTSYSFILTER_READ | CTSYSFILTER_WRITE - Indicates you are deleting both a system wide read record filter and a system wide write record filter.
Return
On error CTTable::SystemFilterOff() throws a CTException exception object.
See Also
CTTable::SystemFilterOn()
CTTable::SystemFilterOn
Establishes a permanent system wide data record filter.
Declaration
void CTTable::SystemFilterOn(CTSYSFILTER mode);
Description
Establishes a permanent system wide, i.e. the filter applies to all users, read and/or write record filter. Depending on server file security setting, the table must be opened exclusive and the user must have file definition permission for the table. Once a read or a write filter is established, it can only be deleted by calling method CTTable::SystemFilterOff().
A table may have at most one read and one write system wide filter. A write filter will be called when data records are added, updated or deleted.
mode specifies one of the following:
- CTSYSFILTER_READ - Indicates you are deleting only a system wide read record filter.
- CTSYSFILTER_WRITE - Indicates you are deleting only a system wide write record filter
- CTSYSFILTER_READ | CTSYSFILTER_WRITE - Indicates you are deleting both a system wide read record filter and a system wide write record filter.
System wide filters must be callback filters. The actual callback evaluation takes place in a new callback function ctfiltercb_rowl() located in module ctclbk.c.
There different levels of security settings when users modify data file definition resources such as IFIL and DODA. The c-tree Server can be configured for three different levels of data file resource security:
FILEDEF_SECURITY_LEVEL LOW:
Lowest security setting. There is no protection as any user may add or delete data file definition resources. This setting may be used to keep the c-tree Server data compatible with legacy applications.
FILEDEF_SECURITY_LEVEL MEDIUM:
Default security setting. Any user may add or delete data file definition resources, but the file must be opened exclusive. This default setting may be enough to keep the c-tree Server data compatible with most legacy applications.
FILEDEF_SECURITY_LEVEL HIGH:
Highest security setting. A user must have file definition permission before a definition resource is added or deleted. The file must be opened exclusive. This setting is appropriate for applications that require the highest level of security and may cause compatibility problems with existing legacy applications.
Return
On error CTTable::SystemFilterOn() throws a CTException exception object.
Example
try
{
// open an existing table
hTable.Open("table_name", CTOPEN_EXCLUSIVE);
// establish a new system wide read-write filter
hTable.SystemFilterOn(CTSYSFILTER_READ | CTSYSFILTER_WRITE);
// close the table
hTable.Close();
}
catch (CTException &err)
{
printf("Setting system filter failed with error %d\n", err.GetErrorCode());
}
See Also
CTTable::SystemFilterOff()
CTTime::TimeToString
Syntax
CTString TimeToString(CTTIME_TYPE TimeType) const
Parameters
- TimeType [in] The Time type format used to convert to string. The valid Time type formats are shown in "Data Types".
Description
Converts a packed CTTIME object to a CTString object.
Return
TimeToString() returns a CTString object with the Time.
See also
StringToTime()
CTTime::Unpack
Syntax
void Unpack(NINT& hour, NINT& minute, NINT& second) const
Parameters
- hour [out] The unpacked hour.
- minute [out] The unpacked minute.
- second [out] The unpacked second.
Description
Unpacks a CTTIME object into hour, minute and second values
Return
None.
See also
Pack(), Hour(), Minute(), Second(), DayOfWeek()