SourcePro® 2024.1 |
SourcePro® API Reference Guide |
Represents foreign keys in a database, used when creating a database table or fetching a database table schema. More...
#include <rw/db/forkey.h>
Public Types | |
enum | Constraint { Cascade , Restrict , Nullify , Defaultify , cascade , restrict , nullify , defaultify } |
Additional Inherited Members | |
Static Public Member Functions inherited from RWCollectable | |
static RWClassID | classID (const RWStringID &name) |
static RWClassID | classIsA () |
static bool | isAtom (RWClassID id) |
static RWspace | nilStoreSize () |
RWDBForeignKey is used to represent foreign keys in a database, used when building up an RWDBSchema in preparation for an RWDBDatabase::createTable() call. An RWDBForeignKey is also used as elements of lists that are returned from RWDBTable::foreignKeys() and RWDBTable::referredToBy(). RWDBForeignKey has much the same interface and semantics as RWDBSchema.
RWDBForeignKey is designed around the Interface/Implementation paradigm. An RWDBForeignKey instance is an interface to a reference-counted implementation; copy constructors and assignment operators produce additional references to a shared implementation. An RWDBForeignKey implementation is a base class from which a family of database-specific foreign key implementations is derived.
Example 1
In this example, two tables are created, a Professor
table with pid
as the primary key and a Course
table with profid
as a foreign key into the Professor
table.
Example 2
This next example queries the Course
table for its foreign key into the Professor
table. It assumes the tables have been set up according to the example above.
This enum defines the constraint options.
RWDBForeignKey::RWDBForeignKey | ( | ) |
Creates an empty RWDBForeignKey. Provided for convenience only.
RWDBForeignKey::RWDBForeignKey | ( | const RWCString & | refName, |
Constraint | updateConstraint = Restrict, | ||
Constraint | deleteConstraint = Restrict ) |
This constructor creates an empty RWDBForeignKey, that is, one with zero columns. The name of the table to which self refers is refName. The update constraint associated with self is updateConstraint. The delete constraint associated with self is deleteConstraint.
RWDBForeignKey::RWDBForeignKey | ( | const RWCString & | constraintName, |
const RWCString & | refName, | ||
Constraint | updateConstraint = Restrict, | ||
Constraint | deleteConstraint = Restrict ) |
Constructor.
RWDBForeignKey::RWDBForeignKey | ( | const RWDBForeignKey & | fk | ) |
Copy constructor. Self shares an implementation with fk.
RWDBColumn RWDBForeignKey::appendColumn | ( | const RWDBColumn & | col | ) |
Creates a copy of col and appends to self. Returns the copy col.
RWCString RWDBForeignKey::asString | ( | const RWDBPhraseBook & | phraseBook | ) | const |
Returns an RWCString representing self as string based on the format found in phraseBook.
|
virtual |
Returns the number of bytes used by the virtual function saveGuts(RWFile&) to store an object. Typically, this involves adding up the space required to store all primitives, plus the results of calling recursiveStoreSize() for all objects inheriting from RWCollectable. See the Essential Tools Module User's Guide for details.
Reimplemented from RWCollectable.
RWDBForeignKey RWDBForeignKey::clone | ( | ) | const |
Returns a deep copy of self.
RWDBColumn RWDBForeignKey::column | ( | const RWCString & | name | ) | const |
Returns a shallow copy of the column from self whose name matches the given name. If there is no match, returns an RWDBColumn whose status is RWDBStatus::columnNotFound.
RWDBColumn RWDBForeignKey::column | ( | const RWCString & | name, |
RWCString::caseCompare | caseCompare ) const |
Returns a shallow copy of the column from self whose name matches the given name, according to caseCompare. If there is no match, returns an RWDBColumn whose status is RWDBStatus::columnNotFound.
RWDBColumn RWDBForeignKey::column | ( | size_t | index | ) | const |
Returns a shallow copy of the column from self at the specified index. If the index is out of range, returns an RWDBColumn whose status is RWDBStatus::invalidPosition.
|
virtual |
If c points to an RWDBForeignKey, returns the result of asString().compareTo(c->asString()) using the default phrasebook
, otherwise returns a nonzero value.
Reimplemented from RWCollectable.
RWCString RWDBForeignKey::constraintName | ( | ) | const |
Returns the constraint name of this foreign key.
void RWDBForeignKey::constraintName | ( | const RWCString & | newName | ) |
Sets the constraint name of self to be newName. Note that this does not change the name of the foreign key in a table which already exists in the database.
|
virtual |
Returns a new, copy-constructed object of the same type as self. The caller is responsible for deleting the object.
Reimplemented from RWCollectable.
Constraint RWDBForeignKey::deleteConstraint | ( | ) | const |
Returns the delete constraint of self.
void RWDBForeignKey::deleteConstraint | ( | Constraint | newConstraint | ) |
Sets the delete constraint of self to the newConstraint. Note that this does not change the delete constraint of a foreign key of a table which already exists.
size_t RWDBForeignKey::entries | ( | ) | const |
Returns the number of RWDBColumn instances in self.
RWDBStatus::ErrorHandler RWDBForeignKey::errorHandler | ( | ) | const |
Returns the error handler attached to self.
|
virtual |
Returns asString().hash().
Reimplemented from RWCollectable.
size_t RWDBForeignKey::index | ( | const RWCString & | name | ) | const |
Returns the index of the first RWDBColumn in self with the given name. Returns RW_NPOS if no such column is found.
size_t RWDBForeignKey::index | ( | const RWCString & | name, |
RWCString::caseCompare | caseCompare ) const |
Returns the index of the first column from self whose name matches the given name, according to caseCompare. If there is no match, returns RW_NPOS.
size_t RWDBForeignKey::index | ( | const RWDBColumn & | column | ) | const |
Returns the index of the first RWDBColumn in self with the same name as the name of the given column. Returns RW_NPOS if no such column is found.
|
virtual |
Returns __RWDBFOREIGNKEY.
Reimplemented from RWCollectable.
bool RWDBForeignKey::isEmpty | ( | ) | const |
Returns true
if self contains zero entries, otherwise returns false
.
|
virtual |
Behaves as if compareTo(t) was invoked, returning true
if the result equals 0, false
otherwise.
Reimplemented from RWCollectable.
bool RWDBForeignKey::isValid | ( | ) | const |
Returns true
if self's status is RWDBStatus::ok, otherwise returns false
.
|
virtual |
Returns a new, default-constructed object of the same type as self. The caller is responsible for deleting the object.
Reimplemented from RWCollectable.
RWDBForeignKey & RWDBForeignKey::operator= | ( | const RWDBForeignKey & | fk | ) |
Assignment operator. Self shares an implementation with fk.
bool RWDBForeignKey::operator== | ( | const RWDBForeignKey & | fk | ) | const |
Compares self to fk. Returns true
if fk and self share the same implementation.
RWDBColumn RWDBForeignKey::operator[] | ( | const RWCString & | name | ) | const |
Returns the first RWDBColumn in self with the given name. If no such column exists, returns an RWDBColumn with a status of RWDBStatus::columnNotFound. Note that the returned RWDBColumn is not a deep copy; modifications to RWDBColumn change the containing schema.
RWDBColumn RWDBForeignKey::operator[] | ( | size_t | index | ) | const |
Returns the RWDBColumn in self at position index. If the index is out of range, returns an RWDBColumn with a status of RWDBStatus::invalidPosition. Indexing into an empty RWDBForeignKey is treated as out of range. Note that the returned RWDBColumn is not a deep copy; modifications to RWDBColumn change the containing RWDBForeignKey.
RWDBSchema & RWDBForeignKey::referenceKey | ( | ) |
Returns a reference to the currently held reference key of self.
void RWDBForeignKey::referenceKey | ( | const RWDBSchema & | schema | ) |
Sets the referenced key of self to schema. This does not change the referenced key of a foreign key in a table that already exists in the database.
RWCString RWDBForeignKey::referenceName | ( | ) | const |
Returns the reference name of self.
|
virtual |
Reads an object's state from a binary file, using class RWFile, replacing the previous state.
Reimplemented from RWCollectable.
|
virtual |
Reads an object's state from an input stream, replacing the previous state.
Reimplemented from RWCollectable.
|
virtual |
Writes an object's state to a binary file, using class RWFile.
Reimplemented from RWCollectable.
|
virtual |
Writes an object's state to an output stream.
Reimplemented from RWCollectable.
void RWDBForeignKey::setErrorHandler | ( | RWDBStatus::ErrorHandler | handler | ) |
Installs handler as self's error handler. The supplied handler is inherited by all objects produced by self. By default, an RWDBStatus::ErrorHandler is inherited from the object that produced self; this method overrides the default.
RWDBStatus RWDBForeignKey::status | ( | ) | const |
Returns the current status of self.
Constraint RWDBForeignKey::updateConstraint | ( | ) | const |
Returns the update constraint of self.
void RWDBForeignKey::updateConstraint | ( | Constraint | newConstraint | ) |
Sets the update constraint of self to the newConstraint. Note that this does not change the update constraint of a foreign key of a table that already exists.
Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |