This section provides information about the
ForeignKey
class, which models a foreign key on
an NDB
table.
- Parent class
- Child classes
None.
- Methods
-
The following table lists the public methods of the
ForeignKey
class and the purpose or use of each method:Table 2.20 ForeignKey class methods and descriptions
Name Description ForeignKey()
Class constructor ~ForeignKey()
Class destructor getName()
Get the foreign key's name getParentTable()
Get the foreign key's parent table getChildTable()
Get the foreign key's child table getParentColumnCount()
Get the number of columns in the parent table getChildColumnCount()
Get the number of columns in the child table getParentColumnNo()
Get the column number in the parent table getChildColumnNo()
Get the column number in the child table getParentIndex()
Returns 0 if key points to parent table's primary key getChildIndex()
Returns 0 if child references resolved using child table's primary key getOnUpdateAction()
Get the foreign's key update action ( FkAction
)getOnDeleteAction()
Get the foreign key's delete action ( FkAction
)setName()
Set the foreign key's name setParent()
Set the foreign key's parent table setChild()
Set a foreign key's child table setOnUpdateAction()
Set the foreign's key update action ( FkAction
)setOnDeleteAction()
Set the foreign key's delete action ( FkAction
)getObjectStatus()
Get the object status getObjectId()
Get the object ID getObjectVersion()
Get the object version
- Types
The
ForeignKey
class has one public type, theFkAction
type.
- Description
Create either an entirely new foreign key reference, or a copy of an existing one.
- Signature
-
New instance:
ForeignKey ( void )
Copy constructor:
ForeignKey ( const ForeignKey& )
- Parameters
-
For a new instance: None.
For the copy constructor: A reference to an existing instance of
ForeignKey
. - Return value
A new instance of
ForeignKey
.
This section provides information about
FkAction
, which is an enumeration modelling a
reference action for a foreign key when an update or delete
operation is performed on the parent table.
- Enumeration values
-
Possible values are shown, along with the corresponding reference action, in the following table:
Table 2.21 ForeignKey::FkAction data type values and descriptions
Name Description NoAction
NO ACTION
: Deferred check.Restrict
RESTRICT
: Reject operation on parent table.Cascade
CASCADE
: Perform operation on row from parent table; perform same operation on matching rows in child table.SetNull
SET NULL
: Perform operation on row from parent table; set any matching foreign key columns in child table toNULL
.SetDefault
SET DEFAULT
: Currently not supported in NDB Cluster.
See also FOREIGN KEY Constraints, in the MySQL Manual.
- Description
Retrieve the name of the
ForeignKey
instance for which the method is invoked.- Signature
const char* getName ( void ) const
- Parameters
None.
- Return value
The name of the
ForeignKey
.
- Description
Retrieve the parent table of the
ForeignKey
instance for which the method is invoked.- Signature
const char* getParentTable ( void ) const
- Parameters
None.
- Return value
A pointer to the parent table of the
ForeignKey
.
- Description
Retrieve the child table of the
ForeignKey
instance for which the method is invoked.- Signature
const char* getChildTable ( void ) const
- Parameters
None.
- Return value
A pointer to the child table of this
ForeignKey
.
- Description
Retrieve the number of columns in the parent table of this
ForeignKey
.- Signature
unsigned getParentColumnCount ( void ) const
- Parameters
None.
- Return value
The number of columns in the parent table.
- Description
Retrieve the number of columns in the child table of this
ForeignKey
.- Signature
unsigned getChildColumnCount ( void ) const
- Parameters
None.
- Return value
The number of columns in the child table.
- Description
Returns 0 if the child table refers to the parent table's primary key.
- Signature
const char* getParentIndex ( void ) const
- Parameters
None.
- Return value
See description.
- Description
Return 0 if child references are resolved using the child table's primary key.
- Signature
const char* getChildIndex ( void ) const
- Parameters
None.
- Return value
See description.
- Description
This method gets the sequence number of a foreign key column in the parent table for a given index. See the documentation for
Column::getColumnNo()
, for information about handling columns in the NDB API.- Signature
int getParentColumnNo ( unsigned no ) const
- Parameters
None.
- Return value
The sequence number of the column.
- Description
This method gets the sequence number of a foreign key column in the child table for a given index. See the documentation for
Column::getColumnNo()
for information about handling columns in the NDB API.- Signature
int getChildColumnNo ( unsigned no ) const
- Parameters
None.
- Return value
The sequence number of the column.
- Description
Get the foreign key's
ON UPDATE
action. This is aForeignKey::FkAction
and has one of the valuesNoAction
,Restrict
,Cascade
, orSetNull
.- Signature
FkAction getOnUpdateAction ( void ) const
- Parameters
None.
- Return value
The sequence number of the column.
- Description
Get the foreign key's
ON DELETE
action. This is aForeignKey::FkAction
and has one of the valuesNoAction
,Restrict
,Cascade
, orSetNull
.- Signature
FkAction getOnDeleteAction ( void ) const
- Parameters
None.
- Return value
The sequence number of the column.
- Description
Set the name of the
ForeignKey
instance for which the method is invoked.- Signature
void setName ( const char* )
- Parameters
The name of the
ForeignKey
.- Return value
None.
- Description
Set the parent table of a
ForeignKey
, given a reference to the table, and optionally, an index to use as the foreign key.- Signature
void setParent ( const Table&, const Index* index = 0, const Column* cols[] = 0 )
- Parameters
A reference to a
Table
(required). Optionally, an index using the indicated column or columns.- Return value
None.
- Description
Set the child table of a
ForeignKey
, given a reference to the table, and optionally, an index to use as the foreign key.- Signature
void setChild ( const Table&, const Index* index = 0, const Column* cols[] = 0 )
- Parameters
A reference to a
Table
(required). Optionally, an index using the indicated column or columns.- Return value
None.
- Description
Set the foreign key's
ON UPDATE
action.- Signature
void setOnUpdateAction ( FkAction )
- Parameters
The
ON UPDATE
action to be performed. This must be aForeignKey::FkAction
having one of the valuesNoAction
,Restrict
,Cascade
, orSetNull
.- Return value
None
- Description
Set the foreign key's
ON DELETE
action.- Signature
void setOnUpdateAction ( FkAction )
- Parameters
The
ON UPDATE
action to be performed, of typeForeignKey::FkAction
. Must be one of the valuesNoAction
,Restrict
,Cascade
, orSetNull
.- Return value
None
- Description
Get the object status (see Object::Status) for this
ForeignKey
object.- Signature
virtual Object::Status getObjectStatus ( void ) const
- Parameters
None.
- Return value
The
ForeignKey
object's status, as a value of typeObject::Status
. See this type's documentation for possible values and their interpretation.
- Description
Get the object ID (see Object::getObjectId()) for this
ForeignKey
object.- Signature
virtual int getObjectId ( void ) const
- Parameters
None.
- Return value
The
ForeignKey
object's ID, as returned byObject::getObjectId()
.
- Description
Get the object version (see Object::getObjectVersion()) for this
ForeignKey
object.- Signature
virtual int getObjectVersion ( void ) const
- Parameters
None.
- Return value
The
ForeignKey
object's version number (an integer), as returned byObject::getObjectVersion()
.