[+/-]
NdbInterpretedCode
ConstructorNdbInterpretedCode
Methods for Loading Values into
RegistersNdbInterpretedCode
Methods for Copying Values Between
Registers and Table ColumnsNdbInterpretedCode
Register Arithmetic MethodsNdbInterpretedCode
: Labels and BranchingNdbInterpretedCode::def_label()
NdbInterpretedCode::branch_label()
NdbInterpretedCode
Branch OperationsNdbInterpretedCode
Branch OperationsNdbInterpretedCode
Branch OperationsNdbInterpretedCode
Bitwise Comparison OperationsNdbInterpretedCode
Result Handling MethodsNdbInterpretedCode
Convenience MethodsNdbInterpretedCode
NdbInterpretedCode
Utility MethodsDescription.
This is the NdbInterpretedCode
class
constuctor.
Signature.
NdbInterpretedCode ( const NdbDictionary::Table*table
= 0, Uint32*buffer
= 0, Uint32buffer_word_size
= 0 )
Parameters.
The NdbInterpretedCode
constructor takes
three parameters, as described here:
The table
against which which
this program is to be be run. This parameter must be
supplied if the program is table-specific — that
is, if it reads from or writes to columns in a table.
A pointer to a buffer
of
32-bit words used to store the program.
buffer_word_size
is the
length of the buffer passed in. If the program exceeds
this length then adding new instructions will fail with
error 4518 Too many
instructions in interpreted program.
Alternatively, if no buffer is passed, a buffer will be dynamically allocated internally and extended to cope as instructions are added.
Return value.
An instance of NdbInterpretedCode
.
[+/-]
The methods described in this section are used to load constant
values into NdbInterpretedCode
program
registers. The space required by each of these methods is shown
in the following table:
Method | Buffer (words) | Request message (words) |
---|---|---|
load_const_null() |
1 | 1 |
load_const_u16() |
1 | 1 |
load_const_u32() |
2 | 2 |
load_const_u64() |
3 | 3 |
Description.
This method is used to load a NULL
value
into a register.
Signature.
int load_const_null
(
Uint32 RegDest
)
Parameters.
This method takes a single parameter, the register into
which to place the NULL
.
Return value.
Returns 0
on success,
-1
otherwise.
Description. This method loads a 16-bit value into the specified interpreter register.
Signature.
int load_const_u16 ( Uint32RegDest
, Uint32Constant
)
Parameters. This method takes two parameters:
RegDest
: The register into
which the value should be loaded.
A Constant
value to be
loaded
Return value.
Returns 0
on success,
-1
otherwise.
Description. This method loads a 32-bit value into the specified interpreter register.
Signature.
int load_const_u32 ( Uint32RegDest
, Uint32Constant
)
Parameters. This method takes two parameters:
RegDest
: The register into
which the value should be loaded.
A Constant
value to be
loaded
Return value.
Returns 0
on success,
-1
otherwise.
Description. This method loads a 64-bit value into the specified interpreter register.
Signature.
int load_const_u64 ( Uint32RegDest
, Uint64Constant
)
Parameters. This method takes two parameters:
RegDest
: The register into
which the value should be loaded.
A Constant
value to be
loaded
Return value.
Returns 0
on success,
-1
otherwise.
This class provides two methods for copying values between a
column in the current table row and a program register. The
read_attr()
method is used to copy a table
column value into a program register;
write_attr()
is used to copy a value from a
program register into a table column. Both of these methods
require that the table being operated on was specified when
creating the NdbInterpretedCode
object for
which they are called.
The space required by each of these methods is shown in the following table:
Method | Buffer (words) | Request message (words) |
---|---|---|
read_attr() |
1 | 1 |
write_attr() |
1 | 1 |
More detailed information may be found in the next two sections.
Description.
The read_attr()
method is used to read a
table column value into a program register. The column may
be specified either by using its attribute ID or as a
pointer to a Column
object
(Section 2.3.1, “The Column
Class”).
Signature. Referencing the column by its attribute ID:
int read_attr ( Uint32RegDest
, Uint32attrId
)
Referencing the column as a Column
object:
int read_attr ( Uint32RegDest
, const NdbDictionary::Column*column
)
Parameters. This method takes two parameters:
The register to which the column value is to be copied
(RegDest
).
Either of the following references to the table column whose value is to be copied:
The table column's attribute ID
(attrId
)
A pointer to a column
— that is, a pointer to an
NdbDictionary::Column
object
referencing the table column
Return value.
0
on success; -1
on
failure.
Description.
This method is used to copy a register value to a table
column. The column may be specified either by using its
attribute ID or as a pointer to a Column
object (Section 2.3.1, “The Column
Class”).
Signature. Referencing the column by its attribute ID:
int read_attr ( Uint32attrId
, Uint32RegSource
)
Referencing the column as a Column
object:
int read_attr ( const NdbDictionary::Column*column
, Uint32RegSource
)
Parameters. This method takes two parameters:
A reference to the table column to which the register value is to be copied. This can be either of the following:
The table column's attribute ID
(attrId
)
A pointer to a column
— that is, a pointer to an
NdbDictionary::Column
object
referencing the table column
The register whose value is to be copied
(RegSource
).
Return value.
0
on success; -1
on
failure.
This class provides two methods for performing arithmetic
operations on registers. add_reg()
allows you
to load the sum of two registers into another register;
sub_reg()
lets you load the difference of two
registers into another register.
The space required by each of these methods is shown in the following table:
Method | Buffer (words) | Request message (words) |
---|---|---|
add_reg() |
1 | 1 |
sub_reg() |
1 | 1 |
More information about these methods is presented in the next two sections.
Description. This method sums the values stored in any two given registers and stores the result in a third register.
Signature.
int add_reg ( Uint32RegDest
, Uint32RegSource1
, Uint32RegSource2
)
Parameters. This method takes three parameters. The first of these is the register in which the result is to be stored. The second and third parameters are the registers whose values are to be summed.
It is possible to re-use for storing the result one of
the registers whose values are summed; that is,
RegDest
can be the same as
RegSource1
or
RegSource2
.
Return value.
0
on success; -1
on
failure.
Description. This method gets the difference between the values stored in any two given registers and stores the result in a third register.
Signature.
int sub_reg ( Uint32RegDest
, Uint32RegSource1
, Uint32RegSource2
)
Parameters.
This method takes three parameters. The first of these is
the register in which the result is to be stored. The second
and third parameters are the registers whose values are to
be subtracted; that is, the value of register
RegDest
is set equal to
(value in registerRegSource1
) – (value in registerRegSource2
)
It is possible to re-use one of the registers whose
values are subtracted for storing the result; that is,
RegDest
can be the same as
RegSource1
or
RegSource2
.
Return value.
0
on success; -1
on
failure.
The NdbInterpretedCode
class allows you to
define labels within interpreted programs and provides a number
of methods for performing jumps to these labels based on any of
the following types of conditions:
Comparison between two register values
Comparison between a column value and a given constant
Whether or not a column value matches a given pattern
To define a label, use the def_label()
method. See Section 2.3.14.1.6, “NdbInterpretedCode::def_label()
”.
To perform an unconditional jump to a label, use the
branch_label()
method. See
Section 2.3.14.1.7, “NdbInterpretedCode::branch_label()
”.
To perform a jump to a given label based on a comparison of
register values, use one of the
branch_
methods
(*
()branch_ge()
, branch_gt()
,
branch_le()
, branch_lt()
,
branch_eq()
, branch_ne()
,
branch_ne_null()
, or
branch_eq_null()
). See
Section 2.3.14.1.8, “Register-Based NdbInterpretedCode
Branch Operations”.
To perform a jump to a given label based on a comparison of
table column values, use one of the
branch_col_
methods (*
()branch_col_ge()
,
branch_col_gt()
,
branch_col_le()
,
branch_col_lt()
,
branch_col_eq()
,
branch_col_ne()
,
branch_col_ne_null()
, or
branch_col_eq_null()
). See
Section 2.3.14.1.9, “Column-Based NdbInterpretedCode
Branch Operations”.
To perform a jump based on pattern-matching of a table column
value, use one of the methods
branch_col_like()
or
branch_col_notlike()
. See
Section 2.3.14.1.10, “Pattern-Based NdbInterpretedCode
Branch Operations”.
Description. This method defines a label to be used as the target of one or more jumps in an interpreted program.
def_label()
uses a 2-word buffer and requires
no space for request messages.
Signature.
int def_label
(
int LabelNum
)
Parameters.
This method takes a single parameter
LabelNum
, whose value must be
unique among all values used for labels within the interpreted
program.
Return value.
0
on success; -1
on
failure.
Description.
This method performs an unconditional jump to an interpreted
program label (see
Section 2.3.14.1.6, “NdbInterpretedCode::def_label()
”).
Signature.
int branch_label
(
Uint32 Label
)
Parameters.
This method takes a single parameter, an interpreted program
Label
defined using
def_label()
.
Return value.
0
on success, -1
on
failure.
[+/-]
NdbInterpretedCode::branch_ge()
NdbInterpretedCode::branch_gt()
NdbInterpretedCode::branch_le()
NdbInterpretedCode::branch_lt()
NdbInterpretedCode::branch_eq()
NdbInterpretedCode::branch_ne()
NdbInterpretedCode::branch_ne_null()
NdbInterpretedCode::branch_eq_null()
Most of the methods discussed in this section are used to branch
based on the results of register-to-register comparisons. There
are also two methods used to compare a register value with
NULL
. All of these methods require as a
parameter a label defined using the
def_label()
method (see
Section 2.3.14.1.6, “NdbInterpretedCode::def_label()
”).
These methods can be thought of as performing the following logic:
if(register_value1condition
register_value2) gotoLabel
The space required by each of these methods is shown in the following table:
Method | Buffer (words) | Request message (words) |
---|---|---|
branch_ge() |
1 | 1 |
branch_gt() |
1 | 1 |
branch_le() |
1 | 1 |
branch_lt() |
1 | 1 |
branch_eq() |
1 | 1 |
branch_ne() |
1 | 1 |
branch_ne_null() |
1 | 1 |
branch_eq_null() |
1 | 1 |
Description. This method compares two register values; if the first is greater than or equal to the second, the interpreted program jumps to the specified label.
Signature.
int branch_ge ( Uint32RegLvalue
, Uint32RegRvalue
, Uint32Label
)
Parameters.
This method takes three parameters, the registers whose
values are to be compared —
RegLvalue
and
RegRvalue
— and the program
Label
to jump to if
RegLvalue
is greater than or
equal to RegRvalue
.
Label
must have been defined
previously using def_label()
(see
Section 2.3.14.1.6, “NdbInterpretedCode::def_label()
”).
Return value.
0
on success, -1
on
failure.
Description. This method compares two register values; if the first is greater than the second, the interpreted program jumps to the specified label.
Signature.
int branch_gt ( Uint32RegLvalue
, Uint32RegRvalue
, Uint32Label
)
Parameters.
This method takes three parameters, the registers whose
values are to be compared —
RegLvalue
and
RegRvalue
— and the program
Label
to jump to if
RegLvalue
is greater than
RegRvalue
.
Label
must have been defined
previously using def_label()
(see
Section 2.3.14.1.6, “NdbInterpretedCode::def_label()
”).
Return value.
0
on success, -1
on
failure.
Description. This method compares two register values; if the first is less than or equal to the second, the interpreted program jumps to the specified label.
Signature.
int branch_le ( Uint32RegLvalue
, Uint32RegRvalue
, Uint32Label
)
Parameters.
This method takes three parameters, the registers whose
values are to be compared —
RegLvalue
and
RegRvalue
— and the program
Label
to jump to if
RegLvalue
is less than or equal
to RegRvalue
.
Label
must have been defined
previously using def_label()
(see
Section 2.3.14.1.6, “NdbInterpretedCode::def_label()
”).
Return value.
0
on success, -1
on
failure.
Description. This method compares two register values; if the first is less than the second, the interpreted program jumps to the specified label.
Signature.
int branch_lt ( Uint32RegLvalue
, Uint32RegRvalue
, Uint32Label
)
Parameters.
This method takes three parameters, the registers whose
values are to be compared —
RegLvalue
and
RegRvalue
— and the program
Label
to jump to if
RegLvalue
is less than
RegRvalue
.
Label
must have been defined
previously using def_label()
(see
Section 2.3.14.1.6, “NdbInterpretedCode::def_label()
”).
Return value.
0
on success, -1
on
failure.
Description. This method compares two register values; if they equal, then the interpreted program jumps to the specified label.
Signature.
int branch_eq ( Uint32RegLvalue
, Uint32RegRvalue
, Uint32Label
)
Parameters.
This method takes three parameters, the registers whose
values are to be compared —
RegLvalue
and
RegRvalue
— and the program
Label
to jump to if they are
equal. Label
must have been
defined previously using def_label()
(see
Section 2.3.14.1.6, “NdbInterpretedCode::def_label()
”).
Return value.
0
on success, -1
on
failure.
Description. This method compares two register values; if they are not equal, then the interpreted program jumps to the specified label.
Signature.
int branch_ne ( Uint32RegLvalue
, Uint32RegRvalue
, Uint32Label
)
Parameters.
This method takes three parameters, the registers whose
values are to be compared —
RegLvalue
and
RegRvalue
— and the program
Label
to jump they are not equal.
Label
must have been defined
previously using def_label()
(see
Section 2.3.14.1.6, “NdbInterpretedCode::def_label()
”).
Return value.
0
on success, -1
on
failure.
Description.
This method compares a register value with
NULL
; if the value is not null, then the
interpreted program jumps to the specified label.
Signature.
int branch_ne_null ( Uint32RegLvalue
, Uint32Label
)
Parameters.
This method takes two parameters, the register whose value
is to be compared with NULL
(RegLvalue
) and the program
Label
to jump to if
RegLvalue
is not null.
Label
must have been defined
previously using def_label()
(see
Section 2.3.14.1.6, “NdbInterpretedCode::def_label()
”).
Return value.
0
on success, -1
on
failure.
Description.
This method compares a register value with
NULL
; if the register value is null, then
the interpreted program jumps to the specified label.
Signature.
int branch_eq_null ( Uint32RegLvalue
, Uint32Label
)
Parameters.
This method takes two parameters, the register whose value
is to be compared with NULL
(RegLvalue
) and the program
Label
to jump to if
RegLvalue
is null.
Label
must have been defined
previously using def_label()
(see
Section 2.3.14.1.6, “NdbInterpretedCode::def_label()
”).
Return value.
0
on success, -1
on
failure.
[+/-]
NdbInterpretedCode::branch_col_eq()
NdbInterpretedCode::branch_col_ne()
NdbInterpretedCode::branch_col_lt()
NdbInterpretedCode::branch_col_le()
NdbInterpretedCode::branch_col_gt()
NdbInterpretedCode::branch_col_ge()
NdbInterpretedCode::branch_col_eq_null()
NdbInterpretedCode::branch_col_ne_null()
The methods described in this section are used to perform
branching based on a comparison between a table column value and
a given constant value. Each of these methods expects the
attribute ID of the column whose value is to be tested rather
than a reference to a Column
object.
These methods, with the exception of
branch_col_eq_null()
and
branch_col_ne_null()
, can be thought of as
performing the following logic:
if(constant_valuecondition
column_value) gotoLabel
In each case (once again excepting
branch_col_eq_null()
and
branch_col_ne_null()
), the arbitrary constant
is the first parameter passed to the method.
The space requirements for each of these methods is shown in the
following table, where L
represents
the length of the constant value:
Method | Buffer (words) | Request message (words) |
---|---|---|
branch_col_eq_null() |
2 | 2 |
branch_col_ne_null() |
2 | 2 |
branch_col_eq() |
2 | 2 + CEIL(
|
branch_col_ne() |
2 | 2 + CEIL(
|
branch_col_lt() |
2 | 2 + CEIL(
|
branch_col_le() |
2 | 2 + CEIL(
|
branch_col_gt() |
2 | 2 + CEIL(
|
branch_col_ge() |
2 | 2 + CEIL(
|
The expression CEIL(
is the number of whole 8-byte words required to
hold the constant value to be compared.
L
/
8)
Description. This method compares a table column value with an arbitrary constant and jumps to the specified program label if the values are equal.
Signature.
int branch_col_eq ( const void*val
, Uint32len
, Uint32attrId
, Uint32Label
)
Parameters. This method takes 4 parameters:
A constant value (val
)
The length of the value (in bytes)
The attribute ID of the table column whose value is to
be compared with val
A Label
(previously defined
using def_label()
) to jump to if
the compared values are equal
Return value.
0
on success, -1
on
failure.
Description. This method compares a table column value with an arbitrary constant and jumps to the specified program label if the two values are not equal.
Signature.
int branch_col_ne ( const void*val
, Uint32len
, Uint32attrId
, Uint32Label
)
Parameters. This method takes 4 parameters:
A constant value (val
)
The length of the value (in bytes)
The attribute ID of the table column whose value is to
be compared with val
A Label
(previously defined
using def_label()
) to jump to if
the compared values are unequal
Return value.
0
on success, -1
on
failure.
Description. This method compares a table column value with an arbitrary constant and jumps to the specified program label if the constant is less than the column value.
Signature.
int branch_col_lt ( const void*val
, Uint32len
, Uint32attrId
, Uint32Label
)
Parameters. This method takes 4 parameters:
A constant value (val
)
The length of the value (in bytes)
The attribute ID of the table column whose value is to
be compared with val
A Label
(previously defined
using def_label()
) to jump to if
the constant value is less than the column value
Return value.
0
on success, -1
on
failure.
Description. This method compares a table column value with an arbitrary constant and jumps to the specified program label if the constant is less than or equal to the column value.
Signature.
int branch_col_le ( const void*val
, Uint32len
, Uint32attrId
, Uint32Label
)
Parameters. This method takes 4 parameters:
A constant value (val
)
The length of the value (in bytes)
The attribute ID of the table column whose value is to
be compared with val
A Label
(previously defined
using def_label()
) to jump to if
the constant value is less than or equal to the column
value
Return value.
0
on success, -1
on
failure.
Description. This method compares a table column value with an arbitrary constant and jumps to the specified program label if the constant is greater than the column value.
Signature.
int branch_col_gt ( const void*val
, Uint32len
, Uint32attrId
, Uint32Label
)
Parameters. This method takes 4 parameters:
A constant value (val
)
The length of the value (in bytes)
The attribute ID of the table column whose value is to
be compared with val
A Label
(previously defined
using def_label()
) to jump to if
the constant value is greater than the column value
Return value.
0
on success, -1
on
failure.
Description. This method compares a table column value with an arbitrary constant and jumps to the specified program label if the constant is greater than or equal to the column value.
Signature.
int branch_col_ge ( const void*val
, Uint32len
, Uint32attrId
, Uint32Label
)
Parameters. This method takes 4 parameters:
A constant value (val
)
The length of the value (in bytes)
The attribute ID of the table column whose value is to
be compared with val
A Label
(previously defined
using def_label()
) to jump to if
the constant value is greater than or equal to the
column value
Return value.
0
on success, -1
on
failure.
Description.
This method tests the value of a table column and jumps to
the indicated program label if the column value is
NULL
.
Signature.
int branch_col_eq_null ( Uint32attrId
, Uint32Label
)
Parameters.
This method requires two parameters: the attribuite ID for
the table column, and the program label to jump to if the
column value is NULL
.
Return value.
0
on success, -1
on
failure.
Description.
This method tests the value of a table column and jumps to
the indicated program label if the column value is not
NULL
.
Signature.
int branch_col_ne_null ( Uint32attrId
, Uint32Label
)
Parameters.
This method requires two parameters: the attribuite ID of
the table column, and the program label to jump to if the
column value is not NULL
.
Return value.
0
on success, -1
on
failure.
[+/-]
The NdbInterpretedCode
class provides two
methods which can be used to branch based on a comparison
between a column containing character data (that is, a
CHAR
, VARCHAR
,
BINARY
, or VARBINARY
column) and a regular expression pattern.
The pattern syntax allowed in the regular expression is the same
as that supported by the MySQL Server's
LIKE
and NOT LIKE
operators, including the _
and
%
metacharacters. For more information about
these, see String Comparison Functions.
This is also the same regular expression pattern syntax
supported by NdbScanFilter
; see
Section 2.3.17.2.6, “NdbScanFilter::cmp()
”, for more information.
The table being operated upon must be supplied when the
NdbInterpretedCode
object is instantiated.
The regular expression pattern should be in plain
CHAR
format, even if the column is actually a
VARCHAR
(in other words, there should be no
leading length bytes).
These functions behave as shown here:
if (column_value
[NOT] LIKEpattern
) gotoLabel
;
The space requirements for these methods are shown in the
following table, where L
represents
the length of the constant value:
Method | Buffer (words) | Request message (words) |
---|---|---|
branch_col_like() |
2 | 2 + CEIL(
|
branch_col_notlike() |
2 | 2 + CEIL(
|
The expression CEIL(
is the number of whole 8-byte words required to
hold the constant value to be compared.
L
/
8)
Description. This method tests a table column value against a regular expression pattern and jumps to the indicated program label if they match.
Signature.
int branch_col_like ( const void*val
, Uint32len
, Uint32attrId
, Uint32Label
)
Parameters. This method takes 4 parameters, which are listed here:
A regular expression pattern
(val
); see
Section 2.3.14.1.10, “Pattern-Based NdbInterpretedCode
Branch Operations”,
for the syntax supported
Length of the pattern (in bytes)
The attribute ID for the table column being tested
The program label to jump to if the table column value matches the pattern
Return value.
0
on success, -1
on
failure
Description.
This method is similar to
branch_col_like()
in that it tests a
table column value against a regular expression pattern;
however it jumps to the indicated program label only if the
pattern and the column value do not
match.
Signature.
int branch_col_notlike ( const void*val
, Uint32len
, Uint32attrId
, Uint32Label
)
Parameters. This method takes 4 parameters as shown here:
A regular expression pattern
(val
); see
Section 2.3.14.1.10, “Pattern-Based NdbInterpretedCode
Branch Operations”,
for the syntax supported
Length of the pattern (in bytes)
The attribute ID for the table column being tested
The program label to jump to if the table column value does not match the pattern
Return value.
0
on success, -1
on
failure
[+/-]
These instructions are available beginning with MySQL Cluster
NDB 6.3.20. They are used to branch based on the result of a
logical AND
comparison between a
BIT
column value and a bitmask pattern.
Use of these methods requires that the table being operated upon
was supplied when the NdbInterpretedCode
object was constructed. The mask value should be the same size
as the bit column being compared. BIT
values
are passed into and out of the NDB API as 32-bit words with bits
set in order from the least significant bit to the most
significant bit. The endianness of the platform on which the
instructions are executed controls which byte contains the least
significant bits. On x86, this is the first byte (byte 0); on
SPARC and PPC, it is the last byte.
The buffer length and request length for each of these methods each requires an amount of space equal to 2 words plus the column width rounded (up) to the nearest whole word.
Description.
This method is used to compare a BIT
column value with a bitmask; if the column value
AND
ed together with the bitmask is equal
to the bitmask, then execution jumps to a specified label
specified in the method call.
Signature.
int branch_col_and_mask_eq_mask ( const void*mask
, Uint32unused
, Uint32attrId
, Uint32Label
)
Parameters. This method allows for 4 parameters, of which 3 are actually used:
A pointer to a constant
mask
to compare the column
value to
A Uint32
value which is currently
unused
.
The attrId
of the column to
be compared.
A program Label
to jump to
if the condition is true.
Return value.
This method returns 0
on success and
-1
on failure.
Description.
This method is used to compare a BIT
column value with a bitmask; if the column value
AND
ed together with the bitmask is not
equal to the bitmask, then execution jumps to a specified
label specified in the method call.
Signature.
int branch_col_and_mask_ne_mask ( const void*mask
, Uint32unused
, Uint32attrId
, Uint32Label
)
Parameters. This method allows for 4 parameters, of which 3 are actually used:
A pointer to a constant
mask
to compare the column
value to.
A Uint32
value which is currently
unused
.
The attrId
of the column to
be compared.
A program Label
to jump to
if the condition is true.
Return value.
This method returns 0
on success and
-1
on failure.
Description.
This method is used to compare a BIT
column value with a bitmask; if the column value
AND
ed together with the bitmask is equal
to 0
, then execution jumps to a specified
label specified in the method call.
Signature.
int branch_col_and_mask_eq_zero ( const void*mask
, Uint32unused
, Uint32attrId
, Uint32Label
)
Parameters. This method allows for 4 parameters, of which 3 are actually used:
A pointer to a constant
mask
to compare the column
value to.
A Uint32
value which is currently
unused
.
The attrId
of the column to
be compared.
A program Label
to jump to
if the condition is true.
Return value.
This method returns 0
on success and
-1
on failure.
Description.
This method is used to compare a BIT
column value with a bitmask; if the column value
AND
ed together with the bitmask is not
equal to 0
, then execution jumps to a
specified label specified in the method call.
Signature.
int branch_col_and_mask_ne_zero ( const void*mask
, Uint32unused
, Uint32attrId
, Uint32Label
)
Parameters. This method allows for 4 parameters, of which 3 are actually used:
A pointer to a constant
mask
to compare the column
value to.
A Uint32
value which is currently
unused
.
The attrId
of the column to
be compared.
A program Label
to jump to
if the condition is true.
Return value.
This method returns 0
on success and
-1
on failure.
[+/-]
The methods described in this section are used to tell the interpreter that processing of the current row is complete, and — in the case of scans — whether or not to include this row in the results of the scan.
The space requirements for these methods are shown in the
following table, where L
represents
the length of the constant value:
Method | Buffer (words) | Request message (words) |
---|---|---|
interpret_exit_ok() |
1 | 1 |
interpret_exit_nok() |
1 | 1 |
interpret_exit_last_row() |
1 | 1 |
Description. For a scanning operation, this method indicates that the current row should be returned as part of the results of the scan and that the program should move on to the next row. For other operations, calling this method causes the interpreted program to exit.
Signature.
int interpret_exit_ok ( void )
Parameters. None.
Return value.
0
on success, -1
on
failure.
Description. For scanning operations, this method is used to indicate that the current row should not be returned as part of the scan, and to cause the program should move on to the next row. It causes other types of operations to be aborted.
Signature.
int interpret_exit_nok
(
Uint32 ErrorCode
= 899
)
Parameters.
This method takes a single (optional) parameter
ErrorCode
which defaults to NDB
error code 899 (Rowid
already allocated). For a complete listing of
NDB error codes, see Section 5.2.2, “NDB Error Codes and Messages”.
Return value.
0
on success, -1
on
failure.
Description. For a scanning operation, invoking this method indicates that this row should be returned as part of the scan, and that no more rows in this fragment should be scanned. For other types of operations, the method causes the operation to be aborted.
Signature.
int interpret_exit_last_row ( void )
Parameters. None.
Return value.
0
if successful, -1
otherwise.
The methods described in this section can be used to insert multiple instructions (using specific registers) into an interpreted program.
In addition to updating the table column, these methods use
interpreter registers 6 and 7, replacing any existing contents
of register 6 with the original column value and any existing
contents of register 7 with the modified column value. The
table itself must be previously defined when instantiating the
NdbInterpretedCode
object for which the
method is invoked.
The space requirements for these methods are shown in the
following table, where L
represents
the length of the constant value:
Method | Buffer (words) | Request message (words) |
---|---|---|
add_value() |
4 | 1; if the supplied value >= 216: 2; if >= 232: 3 |
sub_value() |
4 | 1; if the supplied value >= 216: 2; if >= 232: 3 |
Description.
This method adds a specified value to the value of a given
table column, and places the original and modified column
values in registers 6 and 7. It is equivalent to the
following series of NdbInterpretedCode
method calls, where attrId
is the
table column' attribute ID and
aValue
is the value to be added:
read_attr(6,attrId
); load_const_u32(7,aValue
); add_reg(7,6,7); write_attr(attrId
, 7);
aValue
can be a 32-bit or 64-bit
integer.
Signature.
int add_val ( Uint32attrId
, Uint32aValue
)
or
int add_val ( Uint32attrId
, Uint64aValue
)
Parameters. A table column attribute ID and a 32-bit or 64-bit integer value to be added to this column value.
Return value.
0
on success, -1
on
failure.
Description.
This method subtracts a specified value from the value of a
given table column, and places the original and modified
column values in registers 6 and 7. It is equivalent to the
following series of NdbInterpretedCode
method calls, where attrId
is the
table column' attribute ID and
aValue
is the value to be
subtracted:
read_attr(6,attrId
); load_const_u32(7,aValue
); sub_reg(7,6,7); write_attr(attrId
, 7);
aValue
can be a 32-bit or 64-bit
integer.
Signature.
int sub_val ( Uint32attrId
, Uint32aValue
)
or
int sub_val ( Uint32attrId
, Uint64aValue
)
Parameters. A table column attribute ID and a 32-bit or 64-bit integer value to be subtracted from this column value.
Return value.
0
on success, -1
on
failure.
[+/-]
NdbInterpretedCode
supports subroutines which
can be invoked from within interpreted programs, with each
subroutine being identified by a unique number. Subroutines can
be defined only following all main program instructions.
Numbers used to identify subroutines must be contiguous; however, they do not have to be in any particular order.
The beginning of a subroutine is indicated by invoking the
def_sub()
method; all instructions after this
belong to this subroutine until the subroutine is terminated
with ret_sub()
. A subroutine is called using
call_sub()
.
Once the subroutine has completed, the program resumes execution with the instruction immediately following the one which invoked the subroutine. Subroutines can also be invoked from other subroutines; currently, the maximum subroutine stack depth is 32.
Description.
This method is used to mark the start of a subroutine. See
Section 2.3.14.1.14, “Using Subroutines with NdbInterpretedCode
”, for
more information.
Signature.
int def_sub
(
Uint32 SubroutineNumber
)
Parameters. A single parameter, a number used to identify the subroutine.
Return value.
0
on success, -1
otherwise.
[+/-]
This section provides information about some utility methods
supplied by NdbInterepretedCode
.
Description.
This method prepares an interpreted program, including any
subroutines it might have, by resolving all branching
instructions and calls to subroutines. It must be called
before using the program, and can be invoked only once for
any given NdbInterpretedCode
object.
If no instructions have been defined, this method attempts to
insert a single interpret_exit_ok()
method
call prior to finalization.
Signature.
int finalise ( void )
Parameters. None.
Return value.
0
on success, -1
otherwise.
Description.
This method can be used to obtain a reference to the table
for which the NdbInterpretedCode
object
was defined.
Signature.
const NdbDictionary::Table* getTable ( void ) const
Parameters. None.
Return value.
A pointer to a Table
object. Returns
NULL
if no table object was supplied when
the NdbInterpretedCode
was instantiated.
Description.
This method returns the most recent error associated with
this NdbInterpretedCode
object.
Signature.
const class NdbError& getNdbError ( void ) const
Parameters. None.
Return value.
A reference to an NdbError
object. See
Section 2.3.31, “The NdbError
Structure”, for more information.