SMWSQLHelpers Class Reference

List of all members.

Static Public Member Functions

static getStandardDBType ($input)
 Database backends often have different types that need to be used repeatedly in (Semantic) MediaWiki.
static setupTable ($rawTableName, array $fields, $db, $reportTo=null)
 Generic creation and updating function for database tables.
static setupIndex ($rawTableName, array $columns, $db)
 Make sure that each of the column descriptions in the given array is indexed by *one* index in the given DB table.

Static Protected Member Functions

static createTable ($tableName, array $fields, $db, $reportTo)
 Creates a new database table with the specified fields.
static updateTable ($tableName, array $fields, $db, $reportTo)
 Update a table given an array of field names and field types.
static getFields ($tableName, $db, $reportTo)
 Returns an array of fields (as keys) and their types (as values).
static updatePostgresField ($tableName, $name, $type, array $currentFields, $db, $reportTo)
 Update a single field given it's name and type and an array of current fields.
static updateMySqlField ($tableName, $name, $type, array $currentFields, $db, $reportTo, $position)
 Update a single field given it's name and type and an array of current fields.
static reportProgress ($msg, $receiver)
 Reports the given message to the reportProgress method of the $receiver.


Detailed Description

Definition at line 14 of file SMW_SQLHelpers.php.


Member Function Documentation

static SMWSQLHelpers::getStandardDBType ( input  )  [static]

Database backends often have different types that need to be used repeatedly in (Semantic) MediaWiki.

This function provides the preferred type (as a string) for various common kinds of columns. The input is one of the following strings: 'id' (page id numbers or similar), 'title' (title strings or similar), 'namespace' (namespace numbers), 'blob' (longer text blobs), 'iw' (interwiki prefixes).

Definition at line 24 of file SMW_SQLHelpers.php.

Referenced by SMWSQLStoreLight::setupTables(), and SMWSQLStore2::setupTables().

static SMWSQLHelpers::setupTable ( rawTableName,
array $  fields,
db,
reportTo = null 
) [static]

Generic creation and updating function for database tables.

Ideally, it would be able to modify a table's signature in arbitrary ways, but it will fail for some changes. Its string-based interface is somewhat too impoverished for a permanent solution. It would be possible to go for update scripts (specific to each change) in the style of MediaWiki instead.

Make sure the table of the given name has the given fields, provided as an array with entries fieldname => typeparams. typeparams should be in a normalised form and order to match to existing values.

The function returns an array that includes all columns that have been changed. For each such column, the array contains an entry columnname => action, where action is one of 'up', 'new', or 'del'

If progress reports during this operation are desired, then the parameter $reportTo should be given an object that has a method reportProgress(string) for doing so.

Note:
The function partly ignores the order in which fields are set up. Only if the type of some field changes will its order be adjusted explicitly.
Parameters:
string $tableName The table name. Does not need to have been passed to DatabaseBase->tableName yet.
array $columns The fields and their types the table should have.
DatabaseBase or Database $db
$reportTo Object to report back to.

Definition at line 64 of file SMW_SQLHelpers.php.

References $db.

Referenced by SMWSQLStore2::setupPropertyTables(), SMWSQLStoreLight::setupTables(), and SMWSQLStore2::setupTables().

static SMWSQLHelpers::createTable ( tableName,
array $  fields,
db,
reportTo 
) [static, protected]

Creates a new database table with the specified fields.

Parameters:
string $tableName The table name.
array $columns The fields and their types the table should have.
DatabaseBase or Database $db
$reportTo Object to report back to.

Definition at line 88 of file SMW_SQLHelpers.php.

References $db.

static SMWSQLHelpers::updateTable ( tableName,
array $  fields,
db,
reportTo 
) [static, protected]

Update a table given an array of field names and field types.

Parameters:
string $tableName The table name.
array $columns The fields and their types the table should have.
DatabaseBase or Database $db
$reportTo Object to report back to.

Definition at line 116 of file SMW_SQLHelpers.php.

References $db, and reportProgress().

static SMWSQLHelpers::getFields ( tableName,
db,
reportTo 
) [static, protected]

Returns an array of fields (as keys) and their types (as values).

Parameters:
string $tableName The table name.
DatabaseBase or Database $db
$reportTo Object to report back to.
Returns:
array

FIXME: updating "KEY" is not possible, the below query will fail in this case.

Definition at line 166 of file SMW_SQLHelpers.php.

References $db, END, and simplejson::encoder::text.

static SMWSQLHelpers::updatePostgresField ( tableName,
name,
type,
array $  currentFields,
db,
reportTo 
) [static, protected]

Update a single field given it's name and type and an array of current fields.

Postgres version.

Parameters:
string $tableName The table name.
string $name The field name.
string $type The field type and attributes.
array $currentFields List of fields as they have been found in the database.
DatabaseBase or Database $db
object $reportTo Object to report back to.

Definition at line 255 of file SMW_SQLHelpers.php.

References $db.

static SMWSQLHelpers::updateMySqlField ( tableName,
name,
type,
array $  currentFields,
db,
reportTo,
position 
) [static, protected]

Update a single field given it's name and type and an array of current fields.

MySQL version.

Parameters:
string $tableName The table name.
string $name The field name.
string $type The field type and attributes.
array $currentFields List of fields as they have been found in the database.
DatabaseBase or Database $db
object $reportTo Object to report back to.
string $position

Definition at line 304 of file SMW_SQLHelpers.php.

References $db.

static SMWSQLHelpers::setupIndex ( rawTableName,
array $  columns,
db 
) [static]

Make sure that each of the column descriptions in the given array is indexed by *one* index in the given DB table.

Parameters:
string $tableName The table name. Does not need to have been passed to DatabaseBase->tableName yet.
array $columns The field names to put indexes on
DatabaseBase or Database $db

Definition at line 331 of file SMW_SQLHelpers.php.

References $db.

Referenced by SMWSQLStore2::setupPropertyTables(), SMWSQLStoreLight::setupTables(), and SMWSQLStore2::setupTables().

static SMWSQLHelpers::reportProgress ( msg,
receiver 
) [static, protected]

Reports the given message to the reportProgress method of the $receiver.

Parameters:
string $msg
object $receiver

Definition at line 470 of file SMW_SQLHelpers.php.

Referenced by updateTable().


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

Generated on Sun Mar 18 07:15:44 2012 for Semantic MediaWiki by  doxygen 1.5.6