SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWDBPrimaryKey Class Reference

Represents a primary key, used when creating a database table or fetching a database table primary key. More...

#include <rw/db/primarykey.h>

Public Member Functions

 RWDBPrimaryKey (const RWCString &constraintName="")
 
 RWDBPrimaryKey (const RWDBPrimaryKey &pk)
 
 RWDBPrimaryKey (const RWDBSchema &sch)
 
RWDBColumn 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)
 
RWDBColumn appendColumn (const RWDBColumn &col)
 
RWCString asString (const RWDBPhraseBook &pb) const
 
RWspace binaryStoreSize () const
 
RWDBPrimaryKey clone () const
 
RWDBColumn column (const RWCString &name) const
 
RWDBColumn column (const RWCString &name, RWCString::caseCompare caseCompare) const
 
RWDBColumn column (size_t index) const
 
RWCString columnName (size_t index) const
 
RWCString constraintName () const
 
RWDBPrimaryKeyconstraintName (const RWCString &newName)
 
size_t entries () const
 
RWDBStatus::ErrorHandler errorHandler () const
 
size_t index (const RWCString &name) const
 
size_t index (const RWCString &name, RWCString::caseCompare caseCompare) const
 
size_t index (const RWDBColumn &column) const
 
bool isEmpty () const
 
bool isValid () const
 
bool operator!= (const RWDBPrimaryKey &pk) const
 
RWDBPrimaryKeyoperator= (const RWDBPrimaryKey &pk)
 
RWDBPrimaryKeyoperator= (const RWDBSchema &sch)
 
bool operator== (const RWDBPrimaryKey &pk) const
 
RWDBColumn operator[] (const RWCString &name) const
 
RWDBColumn operator[] (size_t index) const
 
void setErrorHandler (RWDBStatus::ErrorHandler handler)
 
RWDBStatus status () const
 

Friends

RWFileoperator<< (RWFile &f, const RWDBPrimaryKey &pk)
 
RWvostreamoperator<< (RWvostream &v, const RWDBPrimaryKey &pk)
 
RWFileoperator>> (RWFile &f, RWDBPrimaryKey &pk)
 
RWvistreamoperator>> (RWvistream &v, RWDBPrimaryKey &pk)
 
class RWDBSchema
 

Detailed Description

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.

Synopsis
#include <rw/db/primarykey.h>
pk = myTable.primaryKey();
Represents a primary key, used when creating a database table or fetching a database table primary ke...
Definition primarykey.h:48

Constructor & Destructor Documentation

◆ RWDBPrimaryKey() [1/3]

RWDBPrimaryKey::RWDBPrimaryKey ( const RWCString & constraintName = "")

The default constructor creates an empty RWDBPrimaryKey, that is, one with zero columns.

◆ RWDBPrimaryKey() [2/3]

RWDBPrimaryKey::RWDBPrimaryKey ( const RWDBPrimaryKey & pk)

Copy constructor. Self shares an implementation with pk until the data is modified.

◆ RWDBPrimaryKey() [3/3]

RWDBPrimaryKey::RWDBPrimaryKey ( const RWDBSchema & sch)

Constructor. Self shares an implementation with sch until the data is modified.

Member Function Documentation

◆ appendColumn() [1/2]

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.

Parameters
nameRepresents the name of the column appended to the primary key.
typeShould be one of the data type attributes of the DB Interface Module. See RWDBValue::ValueType for more explanation.
storageLengthShould be set if the data type requires a size, such as String or Blob data types.
nativeTypeShould 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.
precisionprecision is set when specifying a numeric data type, such as Decimal. The precision of the resulting column is set accordingly.
scalescale is set when specifying a numeric data type, such as Decimal. The precision and scale of the resulting column is set accordingly.
nullAllowedShould 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.
paramTypeNot applicable to primary keys.

◆ appendColumn() [2/2]

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.

◆ asString()

RWCString RWDBPrimaryKey::asString ( const RWDBPhraseBook & pb) const

Returns an RWCString representing self as a string based on the format found in pb.

◆ binaryStoreSize()

RWspace RWDBPrimaryKey::binaryStoreSize ( ) const

Returns the number of bytes necessary to store the object using the global functions:

friend RWvostream & operator<<(RWvostream &v, const RWDBPrimaryKey &pk)
Represents an abstraction of a filesystem regular file.
Definition rwfile.h:68
Abstract base class that provides an interface for format-dependent storage of fundamental types and ...
Definition vstream.h:749

◆ clone()

RWDBPrimaryKey RWDBPrimaryKey::clone ( ) const

Produces a deep copy of self.

◆ column() [1/3]

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.

◆ column() [2/3]

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.

◆ column() [3/3]

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.

◆ columnName()

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.

◆ constraintName() [1/2]

RWCString RWDBPrimaryKey::constraintName ( ) const

Returns the constraint name of this primary key.

◆ constraintName() [2/2]

RWDBPrimaryKey & RWDBPrimaryKey::constraintName ( const RWCString & newName)

Sets the constraint name of self to newName. Returns a reference to self.

Note
This does not change the name of the primary key on a table that already exists in the database.

◆ entries()

size_t RWDBPrimaryKey::entries ( ) const

Returns the number of RWDBColumn instances in self.

◆ errorHandler()

RWDBStatus::ErrorHandler RWDBPrimaryKey::errorHandler ( ) const

Returns the error handler attached to self.

◆ index() [1/3]

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.

◆ index() [2/3]

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.

◆ index() [3/3]

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.

◆ isEmpty()

bool RWDBPrimaryKey::isEmpty ( ) const

Returns true if self contains zero entries, otherwise returns false.

◆ isValid()

bool RWDBPrimaryKey::isValid ( ) const

Returns true if self's status is RWDBStatus::ok, otherwise returns false.

◆ operator!=()

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:

!(self == pk)

◆ operator=() [1/2]

RWDBPrimaryKey & RWDBPrimaryKey::operator= ( const RWDBPrimaryKey & pk)

Assignment operator. Self shares an implementation with pk until the data is modified.

◆ operator=() [2/2]

RWDBPrimaryKey & RWDBPrimaryKey::operator= ( const RWDBSchema & sch)

Assignment operator. Self shares an implementation with sch until the data is modified.

◆ operator==()

bool RWDBPrimaryKey::operator== ( const RWDBPrimaryKey & pk) const

Compares self to pk. Returns true if pk and self share the same implementation.

◆ operator[]() [1/2]

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.

Note
The returned RWDBColumn is not a deep copy; modifications to it change the containing primary key.

◆ operator[]() [2/2]

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.

Note
The returned RWDBColumn is not a deep copy; modifications to it change the containing primary key.

◆ setErrorHandler()

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.

◆ status()

RWDBStatus RWDBPrimaryKey::status ( ) const

Returns the current status of self.

Friends And Related Symbol Documentation

◆ operator<< [1/2]

RWFile & operator<< ( RWFile & f,
const RWDBPrimaryKey & pk )
friend

Saves pk to an RWFile.

Throws an RWExternalErr if the file is corrupted.

◆ operator<< [2/2]

RWvostream & operator<< ( RWvostream & v,
const RWDBPrimaryKey & pk )
friend

Saves pk to an RWvostream.

Throws an RWExternalErr if the stream is corrupted.

◆ operator>> [1/2]

RWFile & operator>> ( RWFile & f,
RWDBPrimaryKey & pk )
friend

Restores an RWDBPrimaryKey into pk from an RWFile, replacing the previous contents of pk.

Throws an RWExternalErr if the file is corrupted.

◆ operator>> [2/2]

RWvistream & operator>> ( RWvistream & v,
RWDBPrimaryKey & pk )
friend

Restores an RWDBPrimaryKey into pk from an RWvistream, replacing the previous contents of pk.

Throws an RWExternalErr if the stream is corrupted.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.