Public Member Functions | Protected Member Functions | Protected Attributes

DbEngine Class Reference

Abstract base class for database engines. More...

Inheritance diagram for DbEngine:
MysqlEngine PGsqlEngine

List of all members.

Public Member Functions

 beginTransaction ()
 begins a transaction; must be implemented by driver; use sqlBeginTransaction to create the SQL statement!
 canAdministrate ()
 returns whether a passcode is known and admin.php may be used
 canUseDb ()
 tries to find out whether the connected DB version is usable
 checkAdmin ()
 check admin credentials
 commitTransaction ()
 ends a transaction successfully; must be implemented by driver; returns true on success; use sqlCommitTransaction to create the SQL statement!
 createDb ()
 creates the database, used by admin.php only!!
 deleteRows ($table, $where)
 delete database values; returns the amount of rows deleted or false if an error occurred; use sqlDelete to create the SQL statement!
 dumpBackup ()
 dump a backup (returned as string)
 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
 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.
 escapeColumn ($table, $col, $val)
 generic escape routine: queries the schema for the correct escape mechanism and then returns the appropriately escaped value
 escapeInt ($i)
 escapes integers; the default implementation just makes sure it is an int (false and null are translated to NULL)
 escapeIntList (array $il)
 escapes a list of integers; uses escapeInt for each element; automatically adds parentheses
 escapeListColumn (array $il, $table, $col)
 escapes a list of values for a specific column; uses escapeInt for each element; automatically adds parentheses
 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)
 escapeStringList (array $il)
 escapes a list of strings; uses escapeInt for each element; automatically adds parentheses
 getConfig ($key)
 returns a configuration setting
 hasTable ($tablename)
 returns whether the table exists; must be implemented by driver
 insert ($table, array $values)
 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!
 isNull ($val)
 returns whether the result value is NULL; the default interprets only the special value null as NULL
 lastError ()
 returns the error string of the last operation
 needVersion ()
 returns the version of the DB layout that is required by this version of Magic Smoke
 restoreData ($file, $overwrite)
 called from admin.php: restore a backup
 rollbackTransaction ()
 ends a transaction with a rollback; must be implemented by driver; returns true on success; use sqlRollbackTransaction to create the SQL statement!
 select ($table, $cols, $where="", $orderby="")
 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)
 setAdminPassCode ($u, $p)
 set the admin passcode; used by the config.php file if admin access is allowed
 setConfig ($key, $val)
 sets a config setting
 setTransactionUpdating ($tm)
 set the transaction mode: true if it is an updating transaction
 showCreateDb ()
 shows how the database would be created, used by admin.php only!!
 sqlBeginTransaction ()
 returns the SQL92 statement for beginning a transaction; overwrite this to implement DB specific syntax
 sqlCommitTransaction ()
 returns the SQL92 statement for committing a transaction; overwrite this to implement DB specific syntax
 sqlRollbackTransaction ()
 returns the SQL92 statement for rolling a transaction back; overwrite this to implement DB specific syntax
 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
 syncSequence ($table)
 synchronize the sequence of one database table; overwrite to actually do something
 syncSequences ()
 synchronize all sequences with current data
 transactionIsUpdating ()
 returns whether the DB driver currently believes to be in RW transaction mode
 tryConnect ()
 connect to the database, must be overwritten by DB driver
 update ($table, array $values, $where)
 update database values; returns how many rows have been changed or false for failure; use sqlUpdate to create the SQL statement!

Protected Member Functions

 columnFlag ($flag, $col, $table)
 returns the correct name/coding of a flag: primarykey, notnull, unique (implies notnull), foreignkey:$table:$col, defaultint:$val, defaultstr:$val, index
 createTable ($tablename, $table)
 creates a table; the argument is an array of the form "col-name" => array("col-type", "flags"...); use sqlCreateTable() etc.
 createTableExtras ($tablename, $table)
 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.
 dataType ($type)
 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)
 lockDB ($writelock)
 locks the database - only used by the backup functions; if necessary should also start a transaction; default just starts a transaction
 sqlCreateTable ($tablename, $table)
 creates a SQL92 statement for creating a table; overwrite this to implement DB specific syntax
 sqlCreateTablePrimaryKey (array $cols)
 creates primary key statement for sqlCreateTable; overwrite this to implement DB specific syntax
 sqlDelete ($table, $where)
 creates a SQL92 statement for deletes; overwrite this to implement DB specific syntax
 sqlInsert ($table, array $values)
 creates a SQL92 statement for inserts; overwrite this to implement DB specific syntax
 sqlUpdate ($table, array $values, $where)
 creates a SQL92 statement for updates; overwrite this to implement DB specific syntax
 tableName ($tname)
 transform an internally used table name to the actual table name in the DB; the default implementation returns exactly what it gets
 unlockDB ()
 unlocks the database - only used by the backup functions; if necessary should also commit a transaction; default just commits

Protected Attributes

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

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!

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by createDb(), lockDB(), and setConfig().

DbEngine::canAdministrate (  ) 

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

Referenced by checkAdmin().

DbEngine::canUseDb (  ) 

tries to find out whether the connected DB version is usable

References getConfig(), hasTable(), and needVersion().

DbEngine::checkAdmin (  ) 

check admin credentials

References canAdministrate().

DbEngine::columnFlag ( flag,
col,
table 
) [protected]

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

Reimplemented in MysqlEngine, and PGsqlEngine.

DbEngine::commitTransaction (  )  [abstract]

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

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by createDb(), setConfig(), and unlockDB().

DbEngine::createDb (  ) 
DbEngine::createTable ( tablename,
table 
) [abstract, protected]

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

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by createDb().

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.

Reimplemented in MysqlEngine.

Referenced by sqlCreateTable().

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)

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by sqlCreateTable().

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!

Reimplemented in MysqlEngine, and PGsqlEngine.

DbEngine::dumpBackup (  ) 

dump a backup (returned as string)

References lockDB(), select(), and unlockDB().

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

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by escapeColumn().

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

Reimplemented in MysqlEngine.

Referenced by escapeColumn().

DbEngine::escapeColumn ( table,
col,
val 
)

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

References $dbScheme, escapeBlob(), escapeBool(), escapeInt(), and escapeString().

Referenced by escapeListColumn().

DbEngine::escapeInt ( i  ) 

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

Referenced by escapeColumn(), and escapeIntList().

DbEngine::escapeIntList ( array $  il  ) 

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

References escapeInt().

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

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

References escapeColumn().

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)

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by escapeColumn(), escapeStringList(), getConfig(), and setConfig().

DbEngine::escapeStringList ( array $  il  ) 

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

References escapeString().

DbEngine::getConfig ( key  ) 

returns a configuration setting

References escapeString(), and select().

Referenced by canUseDb().

DbEngine::hasTable ( tablename  )  [abstract]

returns whether the table exists; must be implemented by driver

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by canUseDb(), and restoreData().

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!

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by createDb(), and setConfig().

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

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by createDb().

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

Reimplemented in MysqlEngine, and PGsqlEngine.

References beginTransaction().

Referenced by dumpBackup(), and restoreData().

DbEngine::needVersion (  ) 

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

References $dbScheme.

Referenced by canUseDb().

DbEngine::restoreData ( file,
overwrite 
)

called from admin.php: restore a backup

References hasTable(), lockDB(), syncSequences(), and unlockDB().

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!

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by createDb().

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)

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by dumpBackup(), getConfig(), and setConfig().

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

References beginTransaction(), commitTransaction(), escapeString(), insert(), select(), and update().

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!!

References $dbScheme, sqlBeginTransaction(), sqlCommitTransaction(), sqlCreateTable(), and sqlInsert().

DbEngine::sqlBeginTransaction (  ) 

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

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by showCreateDb().

DbEngine::sqlCommitTransaction (  ) 

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

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by showCreateDb().

DbEngine::sqlCreateTable ( tablename,
table 
) [protected]

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

Reimplemented in MysqlEngine, and PGsqlEngine.

References createTableExtras(), dataType(), and sqlCreateTablePrimaryKey().

Referenced by createDb(), and showCreateDb().

DbEngine::sqlCreateTablePrimaryKey ( array $  cols  )  [protected]

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

Referenced by sqlCreateTable().

DbEngine::sqlDelete ( table,
where 
) [protected]

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

Referenced by PGsqlEngine::deleteRows(), and MysqlEngine::deleteRows().

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

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

References $dbScheme.

Referenced by PGsqlEngine::insert(), MysqlEngine::insert(), and showCreateDb().

DbEngine::sqlRollbackTransaction (  ) 

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

Reimplemented in MysqlEngine, and PGsqlEngine.

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

Referenced by PGsqlEngine::select(), and MysqlEngine::select().

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

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

References $dbScheme.

Referenced by PGsqlEngine::update(), and MysqlEngine::update().

DbEngine::syncSequence ( table  ) 

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

Reimplemented in PGsqlEngine.

Referenced by syncSequences().

DbEngine::syncSequences (  ) 

synchronize all sequences with current data

References syncSequence().

Referenced by restoreData().

DbEngine::tableName ( tname  )  [protected]

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

Reimplemented in MysqlEngine, and PGsqlEngine.

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

Reimplemented in MysqlEngine, and PGsqlEngine.

DbEngine::unlockDB (  )  [protected]

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

Reimplemented in MysqlEngine.

References commitTransaction().

Referenced by dumpBackup(), and restoreData().

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!

Reimplemented in MysqlEngine, and PGsqlEngine.

Referenced by setConfig().


Member Data Documentation

DbEngine::$transmode = false [protected]

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


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