SourcePro® 2022.1 |
SourcePro® API Reference Guide |
Represents a primary key, used when creating a database table or fetching a database table primary key. More...
#include <rw/db/primarykey.h>
Friends | |
RWvostream & | operator<< (RWvostream &v, const RWDBPrimaryKey &pk) |
RWFile & | operator<< (RWFile &f, const RWDBPrimaryKey &pk) |
RWvistream & | operator>> (RWvistream &v, RWDBPrimaryKey &pk) |
RWFile & | operator>> (RWFile &f, RWDBPrimaryKey &pk) |
Class RWDBPrimaryKey is an ordered collection of RWDBColumn instances. An RWDBPrimaryKey serves as an encapsulation of the database notion of primary key, a set of attributes defining a primary key.
An RWDBTable can have an RWDBPrimaryKey. An application can interrogate an RWDBTable for primary key information, or obtain a copy of an RWDBPrimaryKey for its own use. An RWDBPrimaryKey instance can be used with RWDBSchema to create a database table with a primary key. To do this, an application can use an RWDBPrimaryKey obtained from an existing RWDBTable, modify an existing RWDBPrimaryKey, or build one from scratch using the methods appendColumn() and constraintName().
This class is implemented using a technique called copy-on-write. With this technique, the copy constructor and assignment operator reference the existing object, making a copy only when the object changes. The result is excellent performance, with easy-to-understand copy semantics.
RWDBPrimaryKey::RWDBPrimaryKey | ( | const RWCString & | constraintName = "" | ) |
The default constructor creates an empty RWDBPrimaryKey, that is, one with zero columns.
RWDBPrimaryKey::RWDBPrimaryKey | ( | const RWDBPrimaryKey & | pk | ) |
Copy constructor. Self shares an implementation with pk until the data is modified.
RWDBPrimaryKey::RWDBPrimaryKey | ( | const RWDBSchema & | sch | ) |
Constructor. Self shares an implementation with sch until the data is modified.
RWDBColumn RWDBPrimaryKey::appendColumn | ( | const RWCString & | name, |
RWDBValue::ValueType | type = RWDBValue::NoType , |
||
long | storageLength = RWDB_NO_TRAIT , |
||
int | nativeType = RWDB_NO_TRAIT , |
||
int | precision = RWDB_NO_TRAIT , |
||
int | scale = RWDB_NO_TRAIT , |
||
bool | nullAllowed = true , |
||
RWDBColumn::ParamType | paramType = RWDBColumn::notAParameter |
||
) |
Constructs a new RWDBColumn according to the supplied parameters, appends it to self, and returns it. Applications using this method must usually supply only a name.
name | Represents the name of the column appended to the primary key. |
type | Should be one of the data type attributes of the DB Interface Module. See RWDBValue::ValueType for more explanation. |
storageLength | Should be set if the data type requires a size, such as String or Blob data types. |
nativeType | Should be set if one of the data type attributes of the DB Interface Module cannot represent the native data type of the database. If this field is set, type should be left as the default to show that a native data type was requested. You can determine native data types of a specific database through documentation or header files. |
precision | precision is set when specifying a numeric data type, such as Decimal. The precision of the resulting column is set accordingly. |
scale | scale is set when specifying a numeric data type, such as Decimal. The precision and scale of the resulting column is set accordingly. |
nullAllowed | Should be set to false if a column requires a value. The default value of true allows a column's value to be set to NULL . |
paramType | Not applicable to primary keys. |
RWDBColumn RWDBPrimaryKey::appendColumn | ( | const RWDBColumn & | col | ) |
Creates a deep copy of the RWDBColumn col, using the RWDBColumn::clone() method. Appends the copied column to self, and returns it.
RWCString RWDBPrimaryKey::asString | ( | const RWDBPhraseBook & | pb | ) | const |
Returns an RWCString representing self as a string based on the format found in pb.
RWspace RWDBPrimaryKey::binaryStoreSize | ( | ) | const |
Returns the number of bytes necessary to store the object using the global functions:
RWDBPrimaryKey RWDBPrimaryKey::clone | ( | ) | const |
Produces a deep copy of self.
RWDBColumn RWDBPrimaryKey::column | ( | size_t | index | ) | const |
Returns a shallow copy of the column from self at the specified index. If index is out of range, returns an RWDBColumn with a status of RWDBStatus::invalidPosition.
RWDBColumn RWDBPrimaryKey::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 with a status of RWDBStatus::columnNotFound.
RWDBColumn RWDBPrimaryKey::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 with a status of RWDBStatus::columnNotFound.
RWCString RWDBPrimaryKey::columnName | ( | size_t | index | ) | const |
Returns the name of the column at the specified index. Returns an empty string if the index is out of range.
RWCString RWDBPrimaryKey::constraintName | ( | ) | const |
Returns the constraint name of this primary key.
RWDBPrimaryKey& RWDBPrimaryKey::constraintName | ( | const RWCString & | newName | ) |
Sets the constraint name of self to newName. Returns a reference to self.
size_t RWDBPrimaryKey::entries | ( | ) | const |
Returns the number of RWDBColumn instances in self.
RWDBStatus::ErrorHandler RWDBPrimaryKey::errorHandler | ( | ) | const |
Returns the error handler attached to self.
size_t RWDBPrimaryKey::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 RWDBPrimaryKey::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 RWDBPrimaryKey::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.
bool RWDBPrimaryKey::isEmpty | ( | ) | const |
Returns true
if self contains zero entries, otherwise returns false
.
bool RWDBPrimaryKey::isValid | ( | ) | const |
Returns true
if self's status is RWDBStatus::ok, otherwise returns false
.
bool RWDBPrimaryKey::operator!= | ( | const RWDBPrimaryKey & | pk | ) | const |
Compares self to pk. Returns true
if pk and self do not share the same implementation.
This is equivalent to:
RWDBPrimaryKey& RWDBPrimaryKey::operator= | ( | const RWDBPrimaryKey & | pk | ) |
Assignment operator. Self shares an implementation with pk until the data is modified.
RWDBPrimaryKey& RWDBPrimaryKey::operator= | ( | const RWDBSchema & | sch | ) |
Assignment operator. Self shares an implementation with sch until the data is modified.
bool RWDBPrimaryKey::operator== | ( | const RWDBPrimaryKey & | pk | ) | const |
Compares self to pk. Returns true
if pk and self share the same implementation.
RWDBColumn RWDBPrimaryKey::operator[] | ( | size_t | index | ) | const |
Returns the RWDBColumn in self at position index. If index is out of range, returns an RWDBColumn with a status of RWDBStatus::invalidPosition. Indexing into an empty primary key is treated as out of range.
RWDBColumn RWDBPrimaryKey::operator[] | ( | const RWCString & | name | ) | const |
Returns the first RWDBColumn in self with the given name. If no such column exists, an RWDBColumn is returned with a status RWDBStatus::columnNotFound.
void RWDBPrimaryKey::setErrorHandler | ( | RWDBStatus::ErrorHandler | handler | ) |
Installs handler as self's error handler. The supplied handler is inherited by all objects produced by self. By default, the RWDBStatus::ErrorHandler of an RWDBPrimaryKey is inherited from the object that produced it; this method overrides the default.
RWDBStatus RWDBPrimaryKey::status | ( | ) | const |
Returns the current status of self.
|
friend |
Saves pk to an RWvostream.
Throws an RWExternalErr if the stream is corrupted.
|
friend |
Saves pk to an RWFile.
Throws an RWExternalErr if the file is corrupted.
|
friend |
Restores an RWDBPrimaryKey into pk from an RWvistream, replacing the previous contents of pk.
Throws an RWExternalErr if the stream is corrupted.
|
friend |
Restores an RWDBPrimaryKey into pk from an RWFile, replacing the previous contents of pk.
Throws an RWExternalErr if the file is corrupted.
Copyright © 2022 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |