CTSegment Class

class CTSegment

Description

Objects of the CTSegment class manage index segments. The segment is part of the index; one single index may be composed of several segments. It uses CTBase as the base class, and implements the constructor/destructor allocating/freeing memory to the segment operations.

See also

CTBase, CTTable, CTRecord, CTField, CTIndex

Preconditions

Before any task is developed with a CTSegment object, a CTIndex must have been initialized.

 

CTSegment Operators

  • = : Assign a CTSegment object to another

 

CTSegment::operator=

Syntax

CTSegment& operator=(const CTSegment& pSeg)

Parameters

  • pSeg [in] The segment object.

Description

Assigns one CTSegment object to another

Return

Returns a CTSegment object

 

CTSegment Methods

Constructor / Destructor

  • CTSegment(): Creates a CTSegment object
  • ~CTSegment(): Destroys a CTSegment Object and resets all the dependent objects

Segment Handling

  • GetField(): Retrieves the segment field object.
  • GetFieldName(): Retrieves the segment field name
  • GetMode(): Retrieves the segment mode
  • SetMode(): Sets the segment mode
  • GetNumber(): Retrieves the segment index position in the index segments list

 

CTSegment::CTSegment

Syntax

CTSegment ( )
CTSegment (const CTSegment& pSeg)

Parameters

  • pSeg [in] The CTSegment object.

Description

This is the constructor for the CTSegment Class.

See also

~CTSegment()

 

CTSegment::~CTSegment

Syntax

~CTSegment

Parameters

This destructor has no parameters.

Description

This is the destructor for the CTSegment class.

See also

CTSegment

 

CTSegment::GetField

Syntax

CTField GetField( ) const

Parameters

This method has no parameters.

Description

Retrieves the segment field object.

Return

GetField() returns the field object.

See also

GetFieldName()

 

CTSegment::GetFieldName

Syntax

CTString GetFieldName( ) const

Parameters

This method has no parameters.

Description

Retrieves the segment field name.

Return

GetFieldName() returns the segment field name.

See also

GetField()

 

CTSegment::GetMode

Syntax

CTSEG_MODE GetMode( ) const

Parameters

This method has no parameters.

Description

Retrieves the segment mode. See SetMode() for valid values for the segment mode.

Return

GetMode() returns the segment mode.

See also

SetMode()

 

CTSegment::GetNumber

Syntax

NINT GetNumber( )

Parameters

This method has no parameters.

Description

Retrieves the segment index position in the index segments list

Return

GetNumber() returns the segment position.

 

CTSegment::GetPartialField

Retrieves the field object on which a key segment is based, even when the segment does not match the entire field length.

Declaration

CTField CTSegment::GetPartialField() const;

Description

FairCom DB API was able to find the matching between a key segment and a field only if the key segment started at the beginning of a field and exactly matched the field length, as is required by SQL standards. It was desirable to retrieve a field on which the key segment start at the beginning of a field and does not exactly match the entire field.

The CTSegment::GetPartialField() method retrieves a field object that match a key, even when the segment does not match the entire field length.

Return

GetPartialField() returns a field object if a match can be found. If a match can’t be found, GetPartialField() throws a CTException object.

Example


// find a field that match, or partial match, for the key segment
CTField GetFieldMatch(CTIndex &hIndex, NINT segnbr)
{
    return hIndex.GetSegment(segnbr).GetPartialField();
}
 

See Also

CTSegment::GetField(), CTSegment::GetFieldName(), CTSegment::GetPartialFieldName()

 

CTSegment::GetPartialFieldName

Retrieves the name of a field that match a key segment, even when the segment does not match the entire field length.

Declaration

CTString CTSegment::GetPartialFieldName();

Description

FairCom DB API was able to find the matching between a key segment and a field only if the key segment started at the beginning of a field and exactly matched the field length, as it is required by SQL. It was desirable to retrieve a field on which the key segment start at the beginning of a field and does not exactly match the entire field.

CTSegment::GetPartialFieldName() was added to retrieve the name of a field that match a key segment, even when the segment does not match the entire field length.

Return

GetPartialFieldName() returns a CTString object with the name of the field if a match can be found. If a match can’t be found, GetPartialFieldName() throws a CTException object.

Example


// Display the field name of a partial match
void PrintFieldMatch(CTIndex &hIndex, NINT segnbr)
{
    printf("Field name: %s\n",
        hIndex.GetSegment(segnbr).GetPartialFieldName().c_str());
}
 

See Also

CTSegment::GetField(), CTSegment::GetFieldName(), CTSegment::GetPartialField()

 

CTSegment::GetSegmentKSeg

Retrieves the current index wide extended key segment definition.

Declaration

void CTSegment::GetSegmentKSeg(pctKSEGDEF pKSeg);

Description

CTSegment::GetSegmentKSeg() retrieves the current index 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;

hSegment->GetSegmentKSeg(&ksge);
 

See Also

CTIndex::GetIndexKSeg(), CTIndex::SetIndexKSeg(), CTSegment::SetKSegDefaults(),
CTSegment::SetSegmentKSeg(), CTTable::GetTableKSeg(), CTTable::SetTableKSeg()

 

CTSegment::GetStatus

Retrieves the status of the segment object.

Declaration

ULONG CTSegment::GetStatus() const;

Description

Retrieves the status of a segment object. The status of the segment handle is a bit map describing one or more changes that have occurred to the segment object.

Return

CTSegment::GetStatus() returns a bitmap of the following:

Value Symbolic Constant Explanation
0x00 CTDBISEG_OLD Original segment as read from file
0x01 CTDBISEG_NEW Segment added or inserted
0x02 CTDBISEG_DEL Original segment deleted
0x04 CTDBISEG_MOVED Original segment moved
0x10 CTDBISEG_MODE Segment mode changed
0x20 CTDBISEG_FIELD Segment field changed

Example


// if any segment of an index has changed, call alter table
for (i = 0; i < hIndex->GetSegmentCount(); i++)
{
    CTSegment hSeg = hIndex->GetSegment(i);
 
    if (hSeg->GetStatus() != CTDBISEG_OLD)
        hTable.Alter(CTDB_ALTER_NORMAL);
}
 

See Also

CTField::GetStatus(), CTIndex::GetStatus()

 

CTSegment::MoveSegment

Moves a key segment.

Declaration

void CTSegment::MoveSegment(NINT newIndex);

Description

CTSegment::MoveSegment() moves a key segment to a location indicated by newIndex. 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)
{
    CTSegment hSeg = hIndex->GetSegment(count - 1);
    hSeg->MoveSegment(0);
}
 

See Also

CTTable::MoveSegment(), CTIndex::MoveSegment()

 

CTSegment::SetKSegDefaults

Sets the system wide default values for the extended key segment definition.

Declaration

void CTSegment::SetKSegDefaults(pctKSEGDEF pKSeg);

Description

Set the system wide default values for the extended key segment definition. The default values are:

kseg_ssiz = ctKSEG_SSIZ_COMPUTED;
kseg_type = ctKSEG_TYPE_UNICODE;
kseg_styp = ctKSEG_STYP_UTF16;
kseg_comp = ctKSEG_COMPU_S_DEFAULT | ctKSEG_COMPU_N_NONE;
kseg_desc = "en_US"

Return

void

Example


ctKSEGDEF kseg;
hSegment->SetKSegDefaults(&ksge);
 

See Also

CTIndex::GetIndexKSeg(), CTIndex::SetIndexKSeg(), CTSegment::GetSegmentKSeg(),
CTSegment::SetSegmentKSeg(), CTTable::GetTableKSeg(), CTTable::SetTableKSeg()

 

CTSegment::SetMode

Syntax

void SetMode(CTSEG_MODE SegMode)

Parameters

  • SegMode [in] The segment mode. Valid values for segment modes are shown in "Segment Modes".

Description

Sets the segment mode.

Return

None.

See also

GetMode()

 

CTSegment::SetSegmentKSeg

Establishes a segment’s extended key segment definition.

Declaration

void CTSegment::SetSegmentKSeg(pctKSEGDEF pKSeg);

Description

CTSegment::SetSegmentKSeg() establishes a segment’s 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"
hSegment.SetSegmentKSeg(&kseg);

See Also

CTIndex::GetIndexKSeg(), CTIndex::SetIndexKSeg(), CTSegment::GetSegmentKSeg(),
CTSegment::SetKSegDefaults(), CTTable::GetTableKSeg(), CTTable::SetTableKSeg()