Overview

Namespaces

  • None
  • Xmf
    • Database
    • Module
      • Helper
    • Template
  • Xoops
    • Auth
    • Core
      • Cache
      • Database
        • Logging
        • Schema
      • Exception
      • Handler
        • Scheme
      • Kernel
        • Dtype
        • Handlers
        • Model
      • Lists
      • Locale
        • Punic
      • Service
        • Contract
      • Session
      • Text
        • Sanitizer
          • Extensions
      • Theme
        • Plugins
    • Form
    • Html
    • Locale
    • Module
      • Helper
      • Plugin

Classes

  • TableLoad
  • Tables
  • Overview
  • Namespace
  • Class
  • Tree

Class Tables

Xmf\Database\Tables

inspired by Yii CDbMigration

Build a work queue of database changes needed to implement new and changed tables. Define table(s) you are dealing with and any desired change(s). If the changes are already in place (i.e. the new column already exists) no work is added. Then queueExecute() to process the whole set.

Namespace: Xmf\Database
Package: Xmf
Category: Xmf\Database\Tables
Copyright: 2011-2013 XOOPS Project (http://xoops.org)
License: GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
Author: Richard Griffith richard@geekwright.com
Version: Release: 1.0
Since: 1.0
Link: http://xoops.org
Located at oops_lib/Xmf/Database/Tables.php
Methods summary
public
# __construct( )

Constructor

Constructor

public string
# name( string $table )

Return a table name, prefixed with site table prefix

Return a table name, prefixed with site table prefix

Parameters

$table
table name to contain prefix

Returns

string
table name with prefix
public boolean
# addColumn( string $table, string $column, array $attributes, mixed $position = null )

Add new column for table to the work queue

Add new column for table to the work queue

Parameters

$table
table to contain the column
$column
name of column to add
$attributes
column_definition
$position

FIRST, string of column name to add new column after, or null for natural append

Returns

boolean
true if no errors, false if errors encountered
public boolean
# addPrimaryKey( string $table, string $column )

Add new primary key definition for table to work queue

Add new primary key definition for table to work queue

Parameters

$table
table
$column

column or comma separated list of columns to use as primary key

Returns

boolean
true if no errors, false if errors encountered
public boolean
# addTable( string $table )

Load table schema from database, or starts new empty schema if table does not exist

Load table schema from database, or starts new empty schema if table does not exist

Parameters

$table
table

Returns

boolean
true if no errors, false if errors encountered
public boolean
# useTable( string $table )

AddTable only if it exists

AddTable only if it exists

Parameters

$table
table

Returns

boolean
true if table exists, false otherwise
public boolean
# alterColumn( string $table, string $column, array $attributes, string $newName = '', mixed $position = null )

Add alter column operation to the work queue

Add alter column operation to the work queue

Parameters

$table
table containing the column
$column
column to alter
$attributes
new column_definition
$newName
new name for column, blank to keep same
$position

FIRST, string of column name to add new column after, or null for no change

Returns

boolean
true if no errors, false if errors encountered
public boolean
# copyTable( string $table, string $newTable, boolean $withData = false )

Loads table schema from database, and adds newTable with that schema to the queue

Loads table schema from database, and adds newTable with that schema to the queue

Parameters

$table
existing table
$newTable
new table
$withData
true to copy data, false for schema only

Returns

boolean
true if no errors, false if errors encountered
public boolean
# createIndex( string $name, string $table, string $column, boolean $unique = false )

Add new index definition for index to work queue

Add new index definition for index to work queue

Parameters

$name
name of index to add
$table
table indexed
$column

column or comma separated list of columns to use as the key

$unique
true if index is to be unique

Returns

boolean
true if no errors, false if errors encountered
public boolean
# dropColumn( string $table, string $column )

Add drop column operation to the work queue

Add drop column operation to the work queue

Parameters

$table
table containing the column
$column
column to drop

Returns

boolean
true if no errors, false if errors encountered
public boolean
# dropIndex( string $name, string $table )

Add drop index operation to the work queue

Add drop index operation to the work queue

Parameters

$name
name of index to drop
$table
table indexed

Returns

boolean
true if no errors, false if errors encountered
public boolean
# dropIndexes( string $table )

Add drop for all (non-PRIMARY) keys for a table to the work queue. This can be used to clean up indexes with automatic names.

Add drop for all (non-PRIMARY) keys for a table to the work queue. This can be used to clean up indexes with automatic names.

Parameters

$table
table indexed

Returns

boolean
true if no errors, false if errors encountered
public boolean
# dropPrimaryKey( string $table )

Add drop of PRIMARY key for a table to the work queue

Add drop of PRIMARY key for a table to the work queue

Parameters

$table
table

Returns

boolean
true if no errors, false if errors encountered
public boolean
# dropTable( string $table )

Add drop of table to the work queue

Add drop of table to the work queue

Parameters

$table
table

Returns

boolean
true if no errors, false if errors encountered
public boolean
# renameTable( string $table, string $newName )

Add rename table operation to the work queue

Add rename table operation to the work queue

Parameters

$table
table
$newName
new table name

Returns

boolean
true if no errors, false if errors encountered
public boolean
# setTableOptions( string $table, array $options )

Add alter table table_options (ENGINE, DEFAULT CHARSET, etc.) to work queue

Add alter table table_options (ENGINE, DEFAULT CHARSET, etc.) to work queue

Parameters

$table
table
$options
table_options

Returns

boolean
true if no errors, false if errors encountered
public
# queueReset( )

Clear the work queue

Clear the work queue

public boolean
# queueExecute( boolean $force = false )

Execute the work queue

Execute the work queue

Parameters

$force
true to force updates even if this is a 'GET' request

Returns

boolean
true if no errors, false if errors encountered
public boolean
# delete( string $table, mixed $criteria )

Create DELETE statement and add to queue

Create DELETE statement and add to queue

Parameters

$table
table
$criteria
string where clause or object criteria

Returns

boolean
true if no errors, false if errors encountered
public boolean|null
# insert( string $table, array $columns )

Create an INSERT SQL statement and add to queue.

Create an INSERT SQL statement and add to queue.

Parameters

$table
table
$columns
array of 'column'=>'value' entries

Returns

boolean|null
true if no errors, false if errors encountered
public boolean|null
# update( string $table, array $columns, mixed $criteria )

Creates and executes an UPDATE SQL statement.

Creates and executes an UPDATE SQL statement.

Parameters

$table
table
$columns
array of 'column'=>'value' entries
$criteria
string where clause or object criteria

Returns

boolean|null
true if no errors, false if errors encountered
public boolean
# truncate( string $table )

Add statement to Empty a table to the queue

Add statement to Empty a table to the queue

Parameters

$table
table

Returns

boolean
true if no errors, false if errors encountered
public string|null
# renderTableCreate( string $table, boolean $prefixed = false )

return SQL to create the table

return SQL to create the table

Parameters

$table
table
$prefixed
true to return with table name prefixed

Returns

string|null
string SQL to create table, or null if errors encountered
public string
# getLastError( )

Return message from last error encountered

Return message from last error encountered

Returns

string
last error message
public integer
# getLastErrNo( )

Return code from last error encountered

Return code from last error encountered

Returns

integer
last error number
public Xmf\Database\Tables
# dumpTables( )

dumpTables - development function to dump raw tables array

dumpTables - development function to dump raw tables array

Returns

Xmf\Database\Tables
tables
public array
# dumpQueue( )

dumpQueue - development function to dump the work queue

dumpQueue - development function to dump the work queue

Returns

array
work queue
Constants summary
integer POSITION_FIRST

for add/alter column position

for add/alter column position

# 1
Properties summary
protected string $lastError

last error message

last error message

#
protected integer $lastErrNo

last error number

last error number

#
API documentation generated by ApiGen