Class PostgresDatabase

Description

Database adapter class for PostgreSQL

Located in /class.postgresdatabase.php (line 25)

Database
   |
   --PostgresDatabase
Variable Summary
static mixed $aSchemas
Method Summary
PostgresDatabase __construct (array $aProfile)
void Begin ()
void CacheSchemas (boolean $bEnable)
void Commit ()
int CountFromResult ( &$rResult, resource $rResult)
integer CurrVal (string $sSequenceName)
string FormatData (string $sType, string $sValue)
string GetColumnByNumber (string $sTableName, int $iColumnNumber)
string GetColumnType (string $sTableName, string $sFieldName)
array GetDatabases ()
string GetLastError ()
resource GetResource ()
void GetSchema ( $sTableName)
array GetTableColumns (string $sTableName)
array GetTableForeignKeys (string $sTableName)
An GetTablePrimaryKey (string $sTableName)
array GetTables ()
string GetVersion ()
boolean IsPrimaryKeyReference (string $sTableName, string $sColumnName)
integer NextVal (string $sSequenceName)
object The PullNextResult ( &$rResult, resource $rResult)
string Query (string $sSQL)
bool ResetResult ( &$rResult, resource $rResult)
void Rollback ()
integer SerialCurrVal ( $sTableName, string $sColumnName, string $sTableName,)
integer SerialNextVal (string $sTableName, string $sColumnName)
void SetCacheDirectory (string $sDirectoryName)
boolean TableExists (string $sTableName)
Variables
static mixed $aSchemas = array() (line 35)

Stores information about our database schema discovered through our query processing

  • access: protected

Inherited Variables

Inherited from Database

Database::$aConnections
Database::$aDefaultProfile
Database::$aJoinTypes
Database::$aProfiles
Methods
Constructor __construct (line 55)

The constructor sets up a new connection to the PostgreSQL database. This method is protected, and can only be called from within the class, normally through the GetConnection() method. This helps support the singleton methodology.

  • access: protected
PostgresDatabase __construct (array $aProfile)
  • array $aProfile: The database profile array containing connection information
Begin (line 167)

The Begin() method begins a database transaction which persists until either Commit() or Rollback() is called, or the request ends. If Commit() is not called before the end of the request, the database transaction will automatically roll back.

  • access: public
void Begin ()

Redefinition of:
Database::Begin()
The Begin() method begins a database transaction which persists until either Commit() or Rollback() is called, or the request ends. If Commit() is not called before the end of the request, the database transaction will automatically roll back.
CacheSchemas (line 404)

The CacheSchemas() method toggles whether or not database schemas discovered through the GetSchema(), GetTableColumns(), GetTableForeignKeys() and GetTablePrimaryKey() methods should be cached, and also whether or not those methods will pull their information from a cache, if available.

Attempting to cache schemas without properly setting the cache directory using SetCacheDirectory(). If caching is attempted without setting the directory, an exception will be thrown.

Schema caching is primarily used by the CRUD object, which analyzes database schemas to automate database operations.

  • access: public
void CacheSchemas (boolean $bEnable)
  • boolean $bEnable: Toggles whether or not to cache discovered database schemas

Redefinition of:
Database::CacheSchemas()
The CacheSchemas() method toggles whether or not database schemas discovered through the GetSchema(), GetTableColumns(), GetTableForeignKeys() and GetTablePrimaryKey() methods should be cached, and also whether or not those methods will pull their information from a cache, if available.
Commit (line 182)

The Commit() method commits a database transaction (assuming one was started with Begin()). If Commit() is not called before the end of the request, the database transaction will automatically roll back.

  • access: public
void Commit ()

Redefinition of:
Database::Commit()
The Commit() method commits a database transaction (assuming one was started with Begin()). If Commit() is not called before the end of the request, the database transaction will automatically roll back.
CountFromResult (line 134)

Returns the number of results from the last query performed on the specified database resource object.

  • return: The number of rows in the specified database resource
  • access: public
int CountFromResult ( &$rResult, resource $rResult)
  • resource $rResult: The database connection resource
  • &$rResult

Redefinition of:
Database::CountFromResult()
Returns the number of results from the last query performed on the specified database resource object.
CurrVal (line 250)

Gets the current value of the specified sequence.

This method does not alter the current value of the sequence.

This method will only work if the value of the sequence has already been altered during the current database transaction; meaning that you must call NextVal() or SerialNextVal() prior to using this method.

  • return: An integer representation of the current value of the sequence.
  • access: public
integer CurrVal (string $sSequenceName)
  • string $sSequenceName: The name of the database sequence to get the current value of
FormatData (line 435)

Returns a database-safe formatted representation of the supplied data, based on the supplied data type.

  1. If the supplied data is empty and does not equal zero, this method returns NULL.
  2. If the data type is of text, varchar, timestamp, or bool, this method returns that value surrounded in single quotes.

  • return: A string of the formatted value supplied
  • access: public
string FormatData (string $sType, string $sValue)
  • string $sType: The data type of the supplied value
  • string $sValue: The value to be formatted into a database-safe representation

Redefinition of:
Database::FormatData()
Returns a database-safe formatted representation of the supplied data, based on the supplied data type.
GetColumnByNumber (line 1002)

Returns the name of the column at the specified position from the specified table.

This method is primarily interally as, in the PostgreSQL catalog, table references, indexes, etc, are stored by column number in the catalog tables.

  • return: The name of the column, if one is found, or null
  • access: protected
string GetColumnByNumber (string $sTableName, int $iColumnNumber)
  • string $sTableName: The name of the table that the desired column belongs to
  • int $iColumnNumber: The column number from the table (from the PostgreSQL catalog)
GetColumnType (line 943)

Returns the data type of the specified column in the specified table.

  • return: The data type of the column, if one is found, or null.
  • access: public
string GetColumnType (string $sTableName, string $sFieldName)
  • string $sTableName: The name of the table that the desired column belongs to
  • string $sFieldName: The name of the column that is desired to know the type of

Redefinition of:
Database::GetColumnType()
Returns the data type of the specified column in the specified table.
GetDatabases (line 473)

This method returns all databases on the database server.

  • return: An array of all databases on the database server in the formation of database_name => database_name
  • access: public
array GetDatabases ()

Redefinition of:
Database::GetDatabases()
This method returns all databases on the database server.
GetLastError (line 362)

Returns the last PostgreSQL database error, if any.

  • return: A string representation of the last PostgreSQL error
  • access: public
string GetLastError ()

Redefinition of:
Database::GetLastError()
Returns the last database error, if any.
GetResource (line 416)

Returns the native PHP database resource

  • return: The native PHP database resource
  • access: public
resource GetResource ()

Redefinition of:
Database::GetResource()
Returns the PHP native database connection resource.
GetSchema (line 542)

Collects all fields/columns in the specified database table, as well as data type and key information.

  • access: public
void GetSchema ( $sTableName)
  • $sTableName

Redefinition of:
Database::GetSchema()
Collects information about the schema for the specified table, including information on columns (name, datatype), primary keys and foreign keys (relationships to other tables).
GetTableColumns (line 580)

Returns an array of columns that belong to the specified table.

This method stores its information the static variable $aSchemas so that if the data is required again, the database does not have to be consoluted.

If schema caching is on, this method can pull data from a schema cache.

  • return: An array of columns that belong to the specified table
  • access: public
array GetTableColumns (string $sTableName)
  • string $sTableName: The name of the table for the requested columns

Redefinition of:
Database::GetTableColumns()
Returns an array of columns that belong to the specified table.
GetTableForeignKeys (line 727)

Returns an array of relationships (foreign keys) for the specified table.

This method stores its information the static variable $aSchemas so that if the data is required again, the database does not have to be consoluted.

If schema caching is on, this method can pull data from a schema cache.

  • return: An array of relationships for the table
  • access: public
array GetTableForeignKeys (string $sTableName)
  • string $sTableName: The name of the table for the requested relationships

Redefinition of:
Database::GetTableForeignKeys()
Returns an array of relationships (foreign keys) for the specified table.
GetTablePrimaryKey (line 666)

Returns an array of columns that belong to the primary key for the specified table.

This method stores its information the static variable $aSchemas so that if the data is required again, the database does not have to be consoluted.

If schema caching is on, this method can pull data from a schema cache.

  • return: array of columns that belong to the primary key for the specified table
  • access: public
An GetTablePrimaryKey (string $sTableName)
  • string $sTableName: The name of hte table for the requested primary key

Redefinition of:
Database::GetTablePrimaryKey()
Returns an array of columns that belong to the primary key for the specified table.
GetTables (line 504)

This method returns all tables for the database the class is currently connected to.

  • return: Returns an array of all tables in the form of table_name => table_name.
  • access: public
array GetTables ()

Redefinition of:
Database::GetTables()
This method returns all tables for the database the class is currently connected to.
GetVersion (line 1023)

Returns the version of the database server.

  • return: The database server version reported by the database server
  • access: public
string GetVersion ()

Redefinition of:
Database::GetVersion()
Returns the version of the database server.
IsPrimaryKeyReference (line 919)

This method determines if the specified tables primary key (or a single column from a compound primary key) references another table.

  • return: True if the primary key references another table, false otherwise
  • access: public
boolean IsPrimaryKeyReference (string $sTableName, string $sColumnName)
  • string $sTableName: The name of the table that the key exists on
  • string $sColumnName: The column that is, or is part of, the primary key for the table
NextVal (line 214)

Advances the value of the supplied sequence and returns the new value.

  • return: An integer representation of the next value of the sequence
  • access: public
integer NextVal (string $sSequenceName)
  • string $sSequenceName: The name of the database sequence to advance and get the current value of
PullNextResult (line 113)

Pulls the next record from specified database resource and returns it as an object.

  • return: next record from the database, or null if there are no more records
  • access: public
object The PullNextResult ( &$rResult, resource $rResult)
  • resource $rResult: The database connection resource to pull the next record from
  • &$rResult

Redefinition of:
Database::PullNextResult()
Pulls the next record from specified database resource and returns it as an object.
Query (line 93)

Queries the PostgreSQL database using the supplied SQL query.

  • return: A ResultSet object containing the results of the database query
  • access: public
string Query (string $sSQL)
  • string $sSQL: The PostgreSQL query to execute

Redefinition of:
Database::Query()
Queries the database using the supplied SQL query.
ResetResult (line 155)

Attempts to return the internal pointer of the specified database resource to the first row.

  • return: True if the operation was successful, false otherwise
  • access: public
bool ResetResult ( &$rResult, resource $rResult)
  • resource $rResult: The database connection resource to pull the next record from
  • &$rResult

Redefinition of:
Database::ResetResult()
Attempts to return the internal pointer of the specified database resource to the first row.
Rollback (line 197)

The Rollback() method rolls back a database transaction (assuming one was started with Begin()). The database transaction is automatically rolled back if Commit() is not called.

  • access: public
void Rollback ()

Redefinition of:
Database::Rollback()
The Rollback() method rolls back a database transaction (assuming one was started with Begin()). The database transaction is automatically rolled back if Commit() is not called.
SerialCurrVal (line 290)

Gets the current value of the specified sequence by the name of the table and the name of the database column. This will only work if a sequence is defined as the default value of a table column.

This method does not alter the current value of the sequence.

This method will only work if the value of the sequence has already been altered during the current database transaction; meaning that you must call NextVal() or SerialNextVal() prior to using this method.

  • return: An integer representation of the current value of the sequence
  • access: public
integer SerialCurrVal ( $sTableName, string $sColumnName, string $sTableName,)
  • string $sTableName,: The name of the database table that holds the column with the sequence as a default value
  • string $sColumnName: The name of the database table column with the sequence as a default value
  • $sTableName
SerialNextVal (line 329)

Advances the value of the supplied sequence and returns the new value by the name of the table and the name of the column. This will only work if a sequence is defined as the default value of a table column.

  • return: An integer representation of the next value of the sequence
  • access: public
integer SerialNextVal (string $sTableName, string $sColumnName)
  • string $sTableName: The name of the database table that holds the column with the sequence as a default value
  • string $sColumnName: The name of the database table column with the sequence as a default value
SetCacheDirectory (line 382)

The SetCacheDirectory() method stores which directory should be used to load and store database schema cache files. If the directory does not exist, an exception will be thrown.

Setting the cache directory is useless unless schema caching is turned on using CacheSchemas().

Schema caching is primarily used by the CRUD object, which analyzes database schemas to automate database operations.

  • access: public
void SetCacheDirectory (string $sDirectoryName)
  • string $sDirectoryName: The absolute path to the directory in the system to store and read cached database schema files

Redefinition of:
Database::SetCacheDirectory()
The SetCacheDirectory() method stores which directory should be used to load and store database schema cache files. If the directory does not exist, an exception will be thrown. Setting the cache directory is useless unless schema caching is turned on using CacheSchemas().
TableExists (line 969)

Determines whether the specified table exists in the current database.

This method first determines whether or not the table exists in the schemas array. If not, it attempts to find the table in the PostgreSQL catalog.

  • return: True or false, depending on whether the table exists
  • access: public
boolean TableExists (string $sTableName)
  • string $sTableName: The name of the table to determine existence

Redefinition of:
Database::TableExists()
Determines whether the specified table exists in the current database.

Inherited Methods

Inherited From Database

Database::AddProfile()
Database::Begin()
Database::CacheSchemas()
Database::Commit()
Database::CountFromResult()
Database::FormatData()
Database::GetColumnType()
Database::GetConnection()
Database::GetDatabases()
Database::GetLastError()
Database::GetResource()
Database::GetSchema()
Database::GetTableColumns()
Database::GetTableForeignKeys()
Database::GetTablePrimaryKey()
Database::GetTables()
Database::GetVersion()
Database::PullNextResult()
Database::Query()
Database::ResetResult()
Database::Rollback()
Database::SetCacheDirectory()
Database::SetDefaultProfile()
Database::TableExists()
Class Constants

Inherited Constants

Inherited from Database

Database::JoinTypeInner
Database::JoinTypeLeft

Documentation generated on Thu, 25 Feb 2010 15:59:41 -0500 by phpDocumentor 1.4.3