Documentation Home
MySQL NDB Cluster API Developer Guide
Download this Manual NdbScanFilter::cmp()

Description.  This method is used to define a comparison between a given value and the value of a column. Beginning with NDB 8.0.18, it can also be used to compare two columns. (This method does not actually execute the comparison, which is done later when performing the scan for which this NdbScanFilter is defined.)


In many cases, where the value to be compared is an integer, you can instead use one of several convenience methods provided by NdbScanFilter for this purpose. See NdbScanFilter Integer Comparison Methods.


int cmp
      BinaryCondition condition,
      int columnId,
      const void* value,
      Uint32 length = 0

Addtionally, in NDB 8.0.18 and later:

int cmp
      BinaryCondition condition, 
      int ColumnId1, 
      int ColumnId2

Parameters.  When used to compare a value with a column, this method takes the following parameters:

  • condition: This represents the condition to be tested which compares the value of the column having the column ID columnID with some arbitrary value. The condition is a BinaryCondition value; for permitted values and the relations that they represent, see Section, “NdbScanFilter::BinaryCondition”.

    The condition values COND_LIKE or COND_NOTLIKE are used to compare a column value with a string pattern.

  • columnId: This is the column's identifier, which can be obtained using the Column::getColumnNo() method.

  • value: The value to be compared, repesented as a pointer to void.

    When using a COND_LIKE or COND_NOTLIKE comparison condition, the value is treated as a string pattern. This string must not be padded or use a prefix. The string value can include the pattern metacharacters or wildcard characters % and _, which have the meanings shown here:

    Table 2.60 Pattern metacharacters used with COND_LIKE and COND_NOTLIKE comparisons

    Metacharacter Description
    % Matches zero or more characters
    _ Matches exactly one character

    To match against a literal % or _ character, use the backslash (\) as an escape character. To match a literal \ character, use \\.


    These are the same wildcard characters that are supported by the SQL LIKE and NOT LIKE operators, and are interpreted in the same way. See String Comparison Functions and Operators, for more information.

  • length: The length of the value to be compared. The default value is 0. Using 0 for the length has the same effect as comparing to NULL, that is using the isnull() method.

When used to compare two columns, cmp() takes the following parameters:

  • condition: The condition to be tested when comparing the columns. The condition may be any one of the BinaryCondition values EQ, NE, LT, LE, GT, or GE. Other values are not accepted.

  • columnID1: ID of the first of the two columns to be compared.

  • columnID1: ID of the second column.

Columns being compared using this method must be of exactly the same type. This includes length, precision, scale, and all other particulars.

Return value.  This method returns an integer: 0 on success, and -1 on failure.