Index

DKQTerm

Purpose:

DKQTerm is used to represent a predicate logic expression of a query. A basic query term can be as simple as a text-string (as part of a text query) or a pair of attribute name and value separated by a relational operator (=, >, <, >=, <=, !=, BETWEEN, LIKE, IN). Query terms can be combined together with logical operators (AND, OR, NOT).

Class summary:

class DKQTerm
{
  public:
    DKQTerm();
    DKQTerm(const char* stringTerm);
    DKQTerm(const char* stringTerm, const DKNVPair* options,
            long arraySize);
    DKQTerm(const char* atrrName, short cmpOpCode,
            const char* attrValue);
    DKQTerm(const char* atrrName, short cmpOpCode,
            const DKString* attrValues, long arraySize);
    DKQTerm(DKQTerm* left, short logOpCode, DKQTerm* right);
    virtual ~DKQTerm();
 
    virtual short getOpCode();
    virtual void setOpCode(short opCode);
 
    virtual DKQTerm* getLeft();
    virtual void setLeft(DKQTerm* left);
    virtual DKQTerm* getRight();
    virtual void setRight(DKQTerm* right);
    virtual DKQTerm* and(DKQTerm* rhs);
    virtual DKQTerm* or(DKQTerm* rhs);
    virtual DKQTerm* not();
 
    virtual DKBoolean isNotTerm();
    virtual DKBoolean isLeaf();
 
    virtual DKString getStringTerm();
    virtual void setStringTerm(const char* stringTerm);
    virtual DKString getName();
    virtual void setName(const char* attrName);
    virtual DKString getValue();
    virtual void setValue(const char* attrValue);
    virtual DKString* getValues(long& arraySize);
    virtual void setValues(const DKString* attrValues, long arraySize);
    virtual DKBoolean hasMultiValues();
 
    virtual DKNVPair* getOptions(long& arraySize);
    virtual void setOptions(const DKNVPair* options, long arraySize);
    virtual DKString toString();
    virtual DKQTerm* clone();
 
    static DKString duplicateSingleQuote(const char* str);
    static DKString unDuplicateSingleQuote(const char* str);
 
    static DKString formatWithSingleQuotes(const char* str);
    static DKString formatWithDoubleQuotes(const char* str);
    static DKString formatWithoutSingleQuotes(const char* str);
    static DKString convertSingleQuotesFormatToDouble(const char* str);
};

Members:

Constructors and destructor
The first constructor is the basic constructor. The next two are constructors for text query terms. The option is a bit pattern which encodes text query options for this term. For example, if it is a free-text-search, indispensable condition (the text must exist) or a not condition (the text must not exist), the text should be given a negative weight, proximity search, and so forth. Not all text search engines support all of the options.

The last three constructors are constructors for parametric query terms. The constructor for a basic query term takes an attribute name, a relational operator code, and the attribute value in string. The second of these constructors takes two terms and combine them with a logical operator. After the construction, leftTerm and rightTerm are absorbed and owned by the new term and will be deleted when this new term is deleted.

    DKQTerm();
    DKQTerm(const char* stringTerm);
    DKQTerm(const char* stringTerm, const DKNVPair* options, long arraySize);
    DKQTerm(const char* atrrName, short cmpOpCode, const char* attrValue);
    DKQTerm(const char* atrrName, short cmpOpCode, const DKString* attrValues, long arraySize);
    DKQTerm(DKQTerm* left, short logOpCode, DKQTerm* right);
    virtual ~DKQTerm();

Member functions

getOpCode
Gets the operator code in this term.
virtual short getOpCode();

setOpCode
Sets the operator code in this term.
virtual void setOpCode(short opCode);

getLeft
Gets the left hand side part of this term.
virtual DKQTerm* getLeft();

setLeft
Sets the left hand side part of this term.
virtual void setLeft(DKQTerm* left);

getRight
Gets the right hand side part of this term.
virtual DKQTerm* getRight();

setRight
Sets the right hand side part of this term.
virtual void setRight(DKQTerm* right);

and
Applies a logical AND operator between this term and another given term.
virtual DKQTerm* and(DKQTerm* rhs);

or
Applies a logical OR operator between this term and another given term.
virtual DKQTerm* or(DKQTerm* rhs);

not
Applies a logical NOT operator to this term, that is, it negates this term.
virtual DKQTerm* not();

isNotTerm
Checks if this term is negated.
virtual DKBoolean isNotTerm();

isLeaf
Checks if this term is a leaf.
virtual DKBoolean isLeaf();

getStringTerm
Gets the string part of this term.
virtual DKString getStringTerm();

setStringTerm
Sets the string part of this term.
virtual void setStringTerm(const char* stringTerm);

getName
Gets the attribute name in this term.
virtual DKString getName();

setName
Sets the attribute name part of this term.
virtual void setName(const char* attrName);

getValue
Gets the value part of this term (or a null if the value is not initialized). It is assumed that there is only one value. String attribute values are assumed to have the correct pair of quotes, for example, 'Anonymous',\"John Smith\",\"Mary's Lamb\".
virtual DKString getValue();

setValue
Sets the value part of this term. It is assumed that the new value is one value.
virtual void setValue(const char* attrValue);

getValues
Gets a string array of values (or a null if the attribute value is not initialized). There are more values than one.
virtual DKString* getValues(long& arraySize);

setValues
Gets a string array of values. There are more values than one.
virtual void setValues(const DKString* attrValues, long arraySize);

hasMultiValues
Checks if this term has multi-values.
virtual DKBoolean hasMultiValues();

getOptions
Gets options defined in this term. Options are only applicable to the text query term.
virtual DKNVPair* getOptions(long& arraySize);

setOptions
Sets options for this term.
virtual void setOptions(const DKNVPair* options, long arraySize);

toString
Reconstructs the string form of this query expression and returns it with the correct levels of required parentheses. String attribute values are assumed to have the correct pair of quotes, for example, 'Anonymous',\"John Smith\",\"Mary's Lamb\".
virtual DKString toString();

clone
A new term is constructed and returned.
virtual DKQTerm* clone();

duplicateSingleQuote
duplicateSingleQuote has been deprecated and replaced by formatWithSingleQuotes.
static DKString duplicateSingleQuote(const char* str);

unDuplicateSingleQuote
unDuplicateSingleQuote has been deprecated and replaced by formatWithoutSingleQuotes.
static DKString unDuplicateSingleQuote(const char* str);

formatWithSingleQuotes
Encloses a string between single quotes and duplicates any single quote that is present inside the string. For example, "Mary's Lamb" will be converted to "'Mary''s Lamb'".
static DKString formatWithSingleQuotes(const char* str);

formatWithDoubleQuotes
Encloses a string between double quotes and duplicates any double quote that is present inside the string. For example, "Mary's Lamb" will be converted to ""Mary's Lamb"".
static DKString formatWithDoubleQuotes(const char* str);

formatWithoutSingleQuotes
Removes the single quotes enclosing a string and converts any adjacent two single quotes present inside the string into one single quote. For example, "Mary''s Lamb" will be converted to "Mary's Lamb".
static DKString formatWithoutSingleQuotes(const char* str);

convertSingleQuotesFormatToDouble
Converts a string enclosed between single quotes to a string enclosed between double quotes. Converts any adjacent two single quotes present inside the string into one single quote. Converts any occurrences of a double quote into two double quotes. For example, "'Mary''s \" Lamb'" will be converted to "\"Mary's \"\" Lamb\"".
static DKString convertSingleQuotesFormatToDouble(const                                                       char* str);

(c) Copyright International Business Machines Corporation 1996, 2003. IBM Corp. All rights reserved.