PACK PHP-Binding  $VERSION$
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
DbEngine Class Reference
Inheritance diagram for DbEngine:
MysqlEngine PGsqlEngine

Public Member Functions

 tryConnect ()
 
 isConnected ()
 check whether the DB object is connected to an actual database More...
 
 setAdminPassCode ($u, $p)
 
 checkAdmin ()
 
 canAdministrate ()
 
 needVersion ()
 
 hasTable ($tablename)
 
 beginTransaction ()
 
 commitTransaction ()
 
 rollbackTransaction ()
 
 select ($table, $cols, $where="", $orderby="")
 
 insert ($table, array $values)
 
 update ($table, array $values, $where)
 
 deleteRows ($table, $where)
 
 dbName ()
 returns the name of the database the instance is connected to More...
 
 tableName ($tname)
 
 sqlSelect ($table, $cols, $where, $orderby)
 
 sqlBeginTransaction ()
 
 sqlCommitTransaction ()
 
 sqlRollbackTransaction ()
 
 escapeInt ($i)
 
 escapeIntList (array $il)
 
 escapeStringList (array $il)
 
 escapeListColumn (array $il, $table, $col)
 
 escapeString ($s)
 
 escapeBlob ($s)
 
 escapeBool ($s)
 
 escapeColumn ($table, $col, $val)
 
 getConfig ($key)
 
 setConfig ($key, $val)
 
 canUseDb ($checkVersion=true)
 
 createDb ()
 
 showCreateDb ()
 
 upgradeDb ($doexec=true)
 Upgrades the database, used by admin.php. More...
 
 lastError ()
 
 isNull ($val)
 
 transactionIsUpdating ()
 
 setTransactionUpdating ($tm)
 
 dumpBackup ()
 
 exploreBackup ()
 
 syncSequences ()
 
 syncSequence ($table)
 
 restoreData ($file, $overwrite)
 

Public Attributes

const COLUMN_CREATE_TYPE = 1
 
const COLUMN_CREATE_NULL = 2
 
const COLUMN_CREATE_PKEY = 4
 
const COLUMN_CREATE_FKEY = 8
 
const COLUMN_CREATE_KEY = 12
 
const COLUMN_CREATE_DEFAULT = 16
 
const COLUMN_CREATE_INDEX = 32
 
const COLUMN_CREATE_CONSTRAINT = 64
 
const COLUMN_CREATE_ALL = 0xffff
 

Protected Member Functions

 lockDB ($writelock)
 
 unlockDB ()
 
 createTable ($tablename, $table)
 
 dataType ($type)
 
 columnFlag ($flag, $col, $table, $cflags)
 
 sqlCreateTable ($tablename, $table)
 
 sqlCreateColumn ($tablename, $columnname, $columndef, $flags=self::COLUMN_CREATE_ALL)
 creates SQL92 part of a statement for creating a single column More...
 
 createTableExtras ($tablename, $table)
 
 sqlCreateTablePrimaryKey (array $cols)
 
 sqlCreateTableUniqueConstraint (array $constraints)
 creates the complex unique constraints; overwrite this to implement DB specific syntax More...
 
 sqlInsert ($table, array $values)
 
 sqlDelete ($table, $where)
 
 sqlUpdate ($table, array $values, $where)
 
 upgradeTable ($tablename, $doexec)
 helper for upgradeDb -> upgrades a single table More...
 

Protected Attributes

 $transmode =false
 

Detailed Description

Abstract base class for database engines

Member Function Documentation

DbEngine::beginTransaction ( )
abstract

begins a transaction; must be implemented by driver; use sqlBeginTransaction to create the SQL statement!

DbEngine::canAdministrate ( )

returns whether a passcode is known and admin.php may be used

DbEngine::canUseDb (   $checkVersion = true)

tries to find out whether the connected DB version is usable

DbEngine::checkAdmin ( )

check admin credentials

DbEngine::columnFlag (   $flag,
  $col,
  $table,
  $cflags 
)
protected

returns the correct name/coding of a flag: primarykey, notnull, unique (implies notnull), foreignkey:$table:$col, defaultint:$val, defaultstr:$val, index

DbEngine::commitTransaction ( )
abstract

ends a transaction successfully; must be implemented by driver; returns true on success; use sqlCommitTransaction to create the SQL statement!

DbEngine::createDb ( )

creates the database, used by admin.php only!!

DbEngine::createTable (   $tablename,
  $table 
)
abstractprotected

creates a table; the argument is an array of the form "col-name" => array("col-type", "flags"...); use sqlCreateTable() etc. to create the actual statement

DbEngine::createTableExtras (   $tablename,
  $table 
)
protected

This function can be used to amend the column definitions of a table; if overwritten it must return a string; overwrite this to implement DB specific syntax

DbEngine::dataType (   $type)
protected

returns the correct type name for the required abstract data type; types that must be understood are: int32 (INTEGER), int64 (LONG INTEGER), seq32 (auto-incrementing int), seq64, bool (boolean), string:$length (text up to 255 chars, length is optional, default is 255; VARCHAR($length)), text (unlimited text)

DbEngine::dbName ( )
abstract

returns the name of the database the instance is connected to

DbEngine::deleteRows (   $table,
  $where 
)
abstract

delete database values; returns the amount of rows deleted or false if an error occurred; use sqlDelete to create the SQL statement!

DbEngine::dumpBackup ( )

dump a backup (returned as string)

DbEngine::escapeBlob (   $s)

escapes blobs; the default uses addslashes and encloses the value in ''; it is recommended to overwrite this with the proper escaping procedure for the target DB

DbEngine::escapeBool (   $s)

escapes a boolean value; the default translates 0, '0', 'f', 'false', 'n', 'no', false to FALSE and numerics !=0, 't', 'true', 'y', 'yes', true to TRUE; any other value (incl. the PHP constant null) is translated to NULL

DbEngine::escapeColumn (   $table,
  $col,
  $val 
)

generic escape routine: queries the schema for the correct escape mechanism and then returns the appropriately escaped value

DbEngine::escapeInt (   $i)

escapes integers; the default implementation just makes sure it is an int (false and null are translated to NULL)

DbEngine::escapeIntList ( array  $il)

escapes a list of integers; uses escapeInt for each element; automatically adds parentheses

DbEngine::escapeListColumn ( array  $il,
  $table,
  $col 
)

escapes a list of values for a specific column; uses escapeInt for each element; automatically adds parentheses

DbEngine::escapeString (   $s)

escapes strings; the default uses addslashes and encloses the value in ''; it is recommended to overwrite this with the proper escaping procedure for the target DB (false and null are translated to NULL)

DbEngine::escapeStringList ( array  $il)

escapes a list of strings; uses escapeInt for each element; automatically adds parentheses

DbEngine::exploreBackup ( )

explore the backup settings and database and return an index to the current data as structured text; each line has the following format: S T tablename [min max [groupSize]] V base64value E

-> S/E mark the start/end of the data -> T is a table description line -> min/max are minimal/maximal integer values of the backup key, if both are "-" then it is a string column -> groupSize is the recommended size of backup groups (in different key values) for this table -> V is a single value of the backup key if the preceding table has a string backup key

DbEngine::getConfig (   $key)

returns a configuration setting

DbEngine::hasTable (   $tablename)
abstract

returns whether the table exists; must be implemented by driver

DbEngine::insert (   $table,
array  $values 
)
abstract

insert values into a table; returns false on failure, the new primary key if a sequence was set, true otherwise; use sqlInsert to create the SQL statement!

DbEngine::isConnected ( )
abstract

check whether the DB object is connected to an actual database

DbEngine::isNull (   $val)

returns whether the result value is NULL; the default interprets only the special value null as NULL

DbEngine::lastError ( )
abstract

returns the error string of the last operation

DbEngine::lockDB (   $writelock)
protected

locks the database - only used by the backup functions; if necessary should also start a transaction; default just starts a transaction

DbEngine::needVersion ( )

returns the version of the DB layout that is required by this version of Magic Smoke

DbEngine::restoreData (   $file,
  $overwrite 
)

called from admin.php: restore a backup

DbEngine::rollbackTransaction ( )
abstract

ends a transaction with a rollback; must be implemented by driver; returns true on success; use sqlRollbackTransaction to create the SQL statement!

DbEngine::select (   $table,
  $cols,
  $where = "",
  $orderby = "" 
)
abstract

gets some data from the database; $table is the name of the table, $cols is the list of columns to return or "*" for all, $where is the where clause of the SQL-statement, $orderby may contain additional ORDER BY or GROUP BY clauses; returns array of rows, which are in *_fetch_array format; returns false on error; use sqlSelect to create the SQL statement!; make sure that NULL values are returned as PHP value null (most DB drivers already do this)

DbEngine::setAdminPassCode (   $u,
  $p 
)

set the admin passcode; used by the config.php file if admin access is allowed

DbEngine::setConfig (   $key,
  $val 
)

sets a config setting

DbEngine::setTransactionUpdating (   $tm)

set the transaction mode: true if it is an updating transaction

DbEngine::showCreateDb ( )

shows how the database would be created, used by admin.php only!!

DbEngine::sqlBeginTransaction ( )

returns the SQL92 statement for beginning a transaction; overwrite this to implement DB specific syntax

DbEngine::sqlCommitTransaction ( )

returns the SQL92 statement for committing a transaction; overwrite this to implement DB specific syntax

DbEngine::sqlCreateColumn (   $tablename,
  $columnname,
  $columndef,
  $flags = self::COLUMN_CREATE_ALL 
)
protected

creates SQL92 part of a statement for creating a single column

DbEngine::sqlCreateTable (   $tablename,
  $table 
)
protected

creates a SQL92 statement for creating a table; overwrite this to implement DB specific syntax

DbEngine::sqlCreateTablePrimaryKey ( array  $cols)
protected

creates primary key statement for sqlCreateTable; overwrite this to implement DB specific syntax

DbEngine::sqlCreateTableUniqueConstraint ( array  $constraints)
protected

creates the complex unique constraints; overwrite this to implement DB specific syntax

DbEngine::sqlDelete (   $table,
  $where 
)
protected

creates a SQL92 statement for deletes; overwrite this to implement DB specific syntax

DbEngine::sqlInsert (   $table,
array  $values 
)
protected

creates a SQL92 statement for inserts; overwrite this to implement DB specific syntax

DbEngine::sqlRollbackTransaction ( )

returns the SQL92 statement for rolling a transaction back; overwrite this to implement DB specific syntax

DbEngine::sqlSelect (   $table,
  $cols,
  $where,
  $orderby 
)

creates a SQL92 statement for selects; overwrite this to implement DB specific syntax; the concrete DB implementation should append "for update" to the select statement if $this->transmode is true and the DB supports it

DbEngine::sqlUpdate (   $table,
array  $values,
  $where 
)
protected

creates a SQL92 statement for updates; overwrite this to implement DB specific syntax

DbEngine::syncSequence (   $table)

synchronize the sequence of one database table; overwrite to actually do something

DbEngine::syncSequences ( )

synchronize all sequences with current data

DbEngine::tableName (   $tname)

transform an internally used table name to the actual table name in the DB; the default implementation returns exactly what it gets

DbEngine::transactionIsUpdating ( )

returns whether the DB driver currently believes to be in RW transaction mode

DbEngine::tryConnect ( )
abstract

connect to the database, must be overwritten by DB driver

DbEngine::unlockDB ( )
protected

unlocks the database - only used by the backup functions; if necessary should also commit a transaction; default just commits

DbEngine::update (   $table,
array  $values,
  $where 
)
abstract

update database values; returns how many rows have been changed or false for failure; use sqlUpdate to create the SQL statement!

DbEngine::upgradeDb (   $doexec = true)

Upgrades the database, used by admin.php.

DbEngine::upgradeTable (   $tablename,
  $doexec 
)
abstractprotected

helper for upgradeDb -> upgrades a single table

Member Data Documentation

DbEngine::$transmode =false
protected

transaction RO/RW mode: false=assume readonly, true=assume inserts/updates

const DbEngine::COLUMN_CREATE_ALL = 0xffff
const DbEngine::COLUMN_CREATE_CONSTRAINT = 64
const DbEngine::COLUMN_CREATE_DEFAULT = 16
const DbEngine::COLUMN_CREATE_FKEY = 8
const DbEngine::COLUMN_CREATE_INDEX = 32
const DbEngine::COLUMN_CREATE_KEY = 12
const DbEngine::COLUMN_CREATE_NULL = 2
const DbEngine::COLUMN_CREATE_PKEY = 4
const DbEngine::COLUMN_CREATE_TYPE = 1

The documentation for this class was generated from the following file: