Comments: on this page. Click to read or post your own.

Class Database

Description

Abstract database connectivity class.

Sub-classes of this implement the actual database connection libraries

  • abstract:

Located in /sapphire/core/model/Database.php (line 8)

Object
   |
   --Database
Direct descendents
Class Description
PDODatabase PDO (general database) connector class.
MySQLDatabase MySQL connector class.
Variable Summary
static mixed $globalConn
static mixed $supressOutput
array $fieldList
array $indexList
array $tableList
Method Summary
static void alteration_message ( $message, [ $type = ""])
static void replace_with_null ( &$array, string $array)
void alterTable ( $table, [ $newFields = null], [ $newIndexes = null], [ $alteredFields = null], [ $alteredIndexes = null])
boolean createDatabase ()
void createField (string $table, string $field, string $spec)
void createTable (string $table, [ $fields = null], [ $indexes = null])
void databaseError (string $msg, [int $errorLevel = E_USER_ERROR])
void dontRequireTable (string $table)
void endSchemaUpdate ()
array fieldList (string $table)
string getConnect (array $parameters)
int getGeneratedID ( $table)
boolean isActive ()
void manipulate (array $manipulation)
Query query (string $sql, [int $errorLevel = E_USER_ERROR])
void quiet ()
void renameTable (string $oldTableName, string $newTableName)
void requireField (string $table, string $field, string $spec)
void requireIndex (string $table, string $index, string|boolean $spec)
void requireTable (string $table, [string $fieldSchema = null], [string $indexSchema = null])
array tableList ()
void transAlterField ( $table,  $field,  $schema)
void transAlterIndex ( $table,  $index,  $schema)
void transCreateField ( $table,  $field,  $schema)
void transCreateIndex ( $table,  $index,  $schema)
void transCreateTable ( $table)
void transInitTable ( $table)
Variables
static mixed $globalConn (line 13)

Connection object to the database.

static mixed $supressOutput = false (line 20)

If this is false, then information about database operations will be displayed, eg creation of tables.

  • access: public
array $fieldList (line 118)

The field list, generated by the fieldList() function.

An array of maps of field name => field spec, indexed by table name.

  • access: protected
array $indexList (line 125)

The index list for each table, generated by the indexList() function.

An map from table name to an array of index names.

  • access: protected
mixed $schemaUpdateTransaction (line 131)

Large array structure that represents a schema update transaction

  • access: protected
array $tableList (line 110)

The table list, generated by the tableList() function.

Used by the requireTable() function.

  • access: protected

Inherited Variables

Inherited from Object

Object::$builtInMethods
Object::$class
Object::$classConstructed
Object::$extensions
Object::$extension_instances
Object::$extraMethods
Object::$extraStatics
Object::$statics
Object::$static_cached
Methods
static method alteration_message (line 436)
static void alteration_message ( $message, [ $type = ""])
  • $message
  • $type
static method replace_with_null (line 403)

Replaces "\'\'" with "null", recursively walks through the given array.

static void replace_with_null ( &$array, string $array)
  • string $array: Array where the replacement should happen
  • &$array
alterTable (line 73)

Alter a table's schema.

  • abstract:
void alterTable ( $table, [ $newFields = null], [ $newIndexes = null], [ $alteredFields = null], [ $alteredIndexes = null])
  • $table
  • $newFields
  • $newIndexes
  • $alteredFields
  • $alteredIndexes

Redefined in descendants as:
beginSchemaUpdate (line 138)

Start a schema-updating transaction.

All calls to requireTable/Field/Index will keep track of the changes requested, but not actually do anything. Once

void beginSchemaUpdate ()
createDatabase (line 54)

Create the database and connect to it. This can be called if the initial database connection is not successful because the database does not exist.

It takes no parameters, and should create the database from the information specified in the constructor.

  • return: Returns true if successful
  • abstract:
boolean createDatabase ()

Redefined in descendants as:
createField (line 88)

Create a new field on a table.

  • abstract:
void createField (string $table, string $field, string $spec)
  • string $table: Name of the table.
  • string $field: Name of the field to add.
  • string $spec: The field specification, eg 'INTEGER NOT NULL'

Redefined in descendants as:
createTable (line 68)

Create a new table.

The table will have a single field - the integer key ID.

  • abstract:
void createTable (string $table, [ $fields = null], [ $indexes = null])
  • string $table: Name of table to create.
  • $fields
  • $indexes

Redefined in descendants as:
databaseError (line 425)

Error handler for database errors.

All database errors will call this function to report the error. It isn't a static function; it will be called on the object itself and as such can be overridden in a subclass.

  • todo: hook this into a more well-structured error handling system.
void databaseError (string $msg, [int $errorLevel = E_USER_ERROR])
  • string $msg: The error message.
  • int $errorLevel: The level of the error to throw.

Redefined in descendants as:
dontRequireTable (line 240)

If the given table exists, move it out of the way by renaming it to _obsolete_(tablename).

void dontRequireTable (string $table)
  • string $table: The table name.
endSchemaUpdate (line 145)
void endSchemaUpdate ()
fieldList (line 96)

Get a list of all the fields for the given table.

Returns a map of field name => field spec.

  • abstract:
  • access: protected
array fieldList (string $table)
  • string $table: The table name.

Redefined in descendants as:
getConnect (line 61)

Build the connection string from input

  • return: The connection string
  • abstract:
string getConnect (array $parameters)
  • array $parameters: The connection details

Redefined in descendants as:
getGeneratedID (line 36)

Get the autogenerated ID from the previous INSERT query.

  • abstract:
int getGeneratedID ( $table)
  • $table

Redefined in descendants as:
isActive (line 42)

Check if the connection to the database is active.

  • abstract:
boolean isActive ()

Redefined in descendants as:
manipulate (line 355)

Execute a complex manipulation on the database.

A manipulation is an array of insert / or update sequences. The keys of the array are table names, and the values are map containing 'command' and 'fields'. Command should be 'insert' or 'update', and fields should be a map of field names to field values, including quotes. The field value can also be a SQL function or similar.

void manipulate (array $manipulation)
  • array $manipulation
query (line 30)

Execute the given SQL query.

This abstract function must be defined by subclasses as part of the actual implementation. It should return a subclass of Query as the result.

  • abstract:
Query query (string $sql, [int $errorLevel = E_USER_ERROR])
  • string $sql: The SQL query to execute
  • int $errorLevel: The level of error reporting to enable for the query

Redefined in descendants as:
quiet (line 432)

Enable supression of database messages.

void quiet ()
renameTable (line 80)

Rename a table.

  • abstract:
void renameTable (string $oldTableName, string $newTableName)
  • string $oldTableName: The old table name.
  • string $newTableName: The new table name.

Redefined in descendants as:
requireField (line 286)

Generate the given field on the table, modifying whatever already exists as necessary.

void requireField (string $table, string $field, string $spec)
  • string $table: The table name.
  • string $field: The field name.
  • string $spec: The field specification.
requireIndex (line 258)

Generate the given index in the database, modifying whatever already exists as necessary.

void requireIndex (string $table, string $index, string|boolean $spec)
  • string $table: The table name.
  • string $index: The index name.
  • string|boolean $spec: The specification of the index. See requireTable() for more information.
requireTable (line 211)

Generate the following table in the database, modifying whatever already exists as necessary.

void requireTable (string $table, [string $fieldSchema = null], [string $indexSchema = null])
  • string $table: The name of the table
  • string $fieldSchema: A list of the fields to create, in the same form as DataObject::$db
  • string $indexSchema: A list of indexes to create. The keys of the array are the names of the index. The values of the array can be one of:
    • true: Create a single column index on the field named the same as the index.
    • array('fields' => array('A','B','C'), 'type' => 'index/unique/fulltext'): This gives you full control over the index.
tableList (line 103)

Returns a list of all tables in the database.

The table names will be in lower case.

  • abstract:
  • access: protected
array tableList ()

Redefined in descendants as:
transAlterField (line 174)
void transAlterField ( $table,  $field,  $schema)
  • $table
  • $field
  • $schema
transAlterIndex (line 178)
void transAlterIndex ( $table,  $index,  $schema)
  • $table
  • $index
  • $schema
transCreateField (line 166)
void transCreateField ( $table,  $field,  $schema)
  • $table
  • $field
  • $schema
transCreateIndex (line 170)
void transCreateIndex ( $table,  $index,  $schema)
  • $table
  • $index
  • $schema
transCreateTable (line 163)
void transCreateTable ( $table)
  • $table
transInitTable (line 187)

Handler for the other transXXX methods - mark the given table as being altered

if it doesn't already exist

  • access: protected
void transInitTable ( $table)
  • $table

Inherited Methods

Inherited From Object

Object::__construct()
Object::addMethodsFrom()
Object::addStaticVars()
Object::addWrapperMethod()
Object::add_extension()
Object::allMethodNames()
Object::buildMethodList()
Object::cacheToFile()
Object::cacheToFileWithArgs()
Object::create()
Object::createMethod()
Object::defineMethods()
Object::exists()
Object::extend()
Object::extInstance()
Object::getCustomClass()
Object::hasExtension()
Object::hasMethod()
Object::invokeWithExtensions()
Object::is_a()
Object::loadCache()
Object::parentClass()
Object::sanitiseCachename()
Object::saveCache()
Object::set_stat()
Object::set_uninherited()
Object::stat()
Object::strong_create()
Object::uninherited()
Object::useCustomClass()
Object::__call()
Object::__toString()
blog comments powered by Disqus

Documentation generated on Sun, 19 Oct 2008 06:39:44 +1300 by phpDocumentor 1.3.2