Documentation Home
MySQL NDB Cluster API Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 3.6Mb
PDF (A4) - 3.6Mb


2.3.6 The ForeignKey Class

This section provides information about the ForeignKey class, which models a foreign key on an NDB table.

ForeignKey Class Overview

Parent class

Object

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, the FkAction type.

ForeignKey()

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.

ForeignKey::FkAction

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 to NULL.
SetDefault SET DEFAULT: Currently not supported in NDB Cluster.

See also FOREIGN KEY Constraints, in the MySQL Manual.

ForeignKey::getName()

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.

ForeignKey::getParentTable()

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.

ForeignKey::getChildTable()

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.

ForeignKey::getParentColumnCount()

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.

ForeignKey::getChildColumnCount()

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.

ForeignKey::getParentIndex()

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.

ForeignKey::getChildIndex()

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.

ForeignKey::getParentColumnNo()

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.

ForeignKey::getChildColumnNo()

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.

ForeignKey::getOnUpdateAction()

Description

Get the foreign key's ON UPDATE action. This is a ForeignKey::FkAction and has one of the values NoAction, Restrict, Cascade, or SetNull.

Signature
FkAction getOnUpdateAction
    (
      void
    ) const
Parameters

None.

Return value

The sequence number of the column.

ForeignKey::getOnDeleteAction()

Description

Get the foreign key's ON DELETE action. This is a ForeignKey::FkAction and has one of the values NoAction, Restrict, Cascade, or SetNull.

Signature
FkAction getOnDeleteAction
    (
      void
    ) const
Parameters

None.

Return value

The sequence number of the column.

ForeignKey::setName()

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.

ForeignKey::setParent()

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.

ForeignKey::setChild()

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.

ForeignKey::setOnUpdateAction()

Description

Set the foreign key's ON UPDATE action.

Signature
void setOnUpdateAction
  (
    FkAction
  )
Parameters

The ON UPDATE action to be performed. This must be a ForeignKey::FkAction having one of the values NoAction, Restrict, Cascade, or SetNull.

Return value

None

ForeignKey::setOnDeleteAction()

Description

Set the foreign key's ON DELETE action.

Signature
void setOnUpdateAction
  (
    FkAction
  )
Parameters

The ON UPDATE action to be performed, of type ForeignKey::FkAction. Must be one of the values NoAction, Restrict, Cascade, or SetNull.

Return value

None

ForeignKey::getObjectStatus()

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 type Object::Status. See this type's documentation for possible values and their interpretation.

ForeignKey::getObjectId()

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 by Object::getObjectId().

ForeignKey::getObjectVersion()

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 by Object::getObjectVersion().