#include <rw/db/schema.h> RWDBSchema s; RWDBSchema s = myTable.schema();
Class RWDBSchema is an ordered collection of RWDBColumns. An RWDBSchema serves as an encapsulation of the database notion of schema, a set of attributes defining a table. DBTools.h++ extends this notion slightly by using an RWDBSchema to define a stored procedure's formal parameter list, and to specify a list of columns wherever one is required. Each RWDBSchema can have foreign key and primary key information associated with it.
Every RWDBTable has an RWDBSchema. An application can interrogate the RWDBSchema of an RWDBTable for schema information, or obtain a copy of an RWDBSchema for its own use. An RWDBSchema instance may be used to create a database table. To do this, an application can use an RWDBSchema obtained from an existing RWDBTable, modify an existing RWDBSchema, or build one from scratch using the methods appendColumn, foreignKey, and primaryKey.
This class is implemented using a technique called copy on write. With this technique, the copy constructor and assignment operators reference the old object and, as a result, are very fast. An actual copy is made only when the object is about to be changed. The net result is excellent performance, with easy-to-understand copy semantics.
RWDBSchema();
The default constructor creates an empty RWDBSchema, that is, one with zero columns.
RWDBSchema(const RWDBSchema& schema);
Copy constructor. Self shares an implementation with schema.
RWDBSchema& operator=(RWDBSchema& schema);
Assignment operator. Self shares an implementation with schema.
RWBoolean operator==(const RWDBSchema& schema) const;
Compares self to schema. Returns TRUE if schema and self are identical.
RWDBColumn 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 schema is treated as out of range. Note that the returned RWDBColumn is not a deep copy; modifications to it change the containing schema.
RWDBColumn 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 of RWDBStatus::columnNotFound. Note that the returned RWDBColumn is not a deep copy; modifications to it change the containing schema.
void acquire() const;
Attempts to acquire the internal mutex lock. If the mutex is already locked by another thread, the function blocks until the mutex is released. This function can be called from a const object. Note: in nonmultithreaded builds, this function evaluates to a no-op.
RWDBColumn appendColumn(const RWDBColumn& col);
Appends col to self and returns col.
RWDBColumn appendColumn(const RWCString& name, RWDBValue::ValueType type = RWDBValue::NoType, long storageLength = 0, int nativeType = -1, int precision = -1, int scale = -1, RWBoolean 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 name and type, as well as storagelength if type is RWDBValue::string.
name represents the name of the new column appended to the schema.
type should be one of the DBTools.h++ datatype attributes. See RWDBValue for more explanation.
storageLength should be set if the datatype requires a size, such as String or Blob datatypes.
nativeType should be set if one of the DBTools.h++ datatype attributes cannot represent the native datatype of the database. If this field is set, type should be left as the default to show that a native datatype was requested. The native datatypes of a specific database can be determined through documentation or header files.
precision and scale are used when specifying a numeric datatype, 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 should be set when specifying the parameters of a stored procedure. See RWDBStoredProc for more information on how to use this parameter. For normal tables, use the default value.
RWCString asString() const;
Produces a comma-delimited list of names of RWDBColumns in self.
RWCString asString(const RWDBPhraseBook& phraseBook) const;
Produces a list of the names of the RWDBColumns in self, delimited by the listDelimiter character defined in phraseBook.
RWDBSchema clone() const;
Produces a deep copy of self.
RWDBColumn 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 whose status is RWDBStatus::invalidPosition.
RWDBColumn 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::invalidPosition.
RWDBColumn 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::invalidPosition.
RWCString columnName(size_t index) const;
Returns the name of the column at the specified index.
size_t entries() const;
Returns the number of RWDBColumns in self.
RWDBStatus::ErrorHandler errorHandler() const;
Returns the error handler attached to self.
RWDBSchema& foreignKey(const RWDBForeignKey& fk);
Appends fk to self's list of foreign keys. Returns a reference to self.
size_t 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 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 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.
RWBoolean isEmpty() const;
Returns TRUE if self contains zero entries, otherwise returns FALSE.
RWBoolean isValid() const;
Returns TRUE if self's status is RWDBStatus::ok, otherwise returns FALSE.
RWCString keysAsString();
Returns a comma-delimited string of the foreign keys attached to self.
RWCString keysAsString(const RWDBPhraseBook&);
Returns a comma-delimited string of the foreign keys attached to self.
RWDBSchema primaryKey();
Returns the primary key associated with self as an RWDBSchema. An empty schema indicates there is no primary key associated with self.
RWDBSchema& primaryKey(const RWDBSchema& pk);
Sets self's primary key to pk. Returns a reference to self.
void release() const;
Releases a previously acquired mutex. This function can be called from a const object. Note: in nonmultithreaded builds, this function evaluates to a no-op.
void 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 error handler of an RWDBSchema is inherited from the object that produced it; this method overrides the default. ErrorHandler is declared as a typedef within the scope of RWDBStatus:
typedef void (*ErrorHandler)(const RWDBStatus&);
RWDBStatus status() const;
Returns the current status of self.
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.