phpBB API Documentation
Class

phpbb\db\tools

class tools

Database Tools for handling cross-db actions such as altering columns, etc.

Currently not supported is returning SQL for creating tables.

Properties

$sql_layer Current sql layer
object $db
array $dbms_type_map The Column types for every database we support
array $unsigned_types A list of types being unsigned for better reference in some db's
array $supported_dbms A list of supported DBMS.
$return_statements This is set to true if user only wants to return the 'to-be-executed' SQL statement(s) (as an array).

Methods

static array get_dbms_type_map()

Get the column types for every database we support

__construct(driver_interface $db, bool $return_statements = false)

Constructor.

null set_return_statements(bool $return_statements)

Setter for {@link $returnstatements returnstatements}.

array sql_list_tables()

Gets a list of tables in the database.

bool sql_table_exists(string $table_name)

Check if table exists

array sql_create_table(string $table_name, array $table_data)

Create SQL Table

perform_schema_changes($schema_changes)

Handle passed database update array.

array sql_list_columns(string $table)

Gets a list of columns of a table.

bool sql_column_exists(string $table, string $column_name)

Check whether a specified column exist in a table

bool sql_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

bool sql_unique_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

_sql_run_sql($statements)

Private method for performing sql statements (either execute them or return them)

sql_prepare_column_data($table_name, $column_name, $column_data)

Function to prepare some column information for better usage

array get_column_type(string $column_map_type)

Get the column's database type from the type map

sql_column_add($table_name, $column_name, $column_data, $inline = false)

Add new column

sql_column_remove($table_name, $column_name, $inline = false)

Drop column

sql_index_drop($table_name, $index_name)

Drop Index

sql_table_drop($table_name)

Drop Table

sql_create_primary_key($table_name, $column, $inline = false)

Add primary key

sql_create_unique_index($table_name, $index_name, $column)

Add unique index

sql_create_index($table_name, $index_name, $column)

Add index

sql_list_index($table_name)

List all of the indices that belong to a table, does not count: * UNIQUE indices * PRIMARY keys

sql_column_change($table_name, $column_name, $column_data, $inline = false)

Change column type (not name!)

array get_existing_indexes(string $table_name, string $column_name, bool $unique = false)

Get a list with existing indexes for the column

Details

at line 49
static public array get_dbms_type_map()

Get the column types for every database we support

Return Value

array

at line 318
public __construct(driver_interface $db, bool $return_statements = false)

Constructor.

Set DB Object and set {@link $returnstatements returnstatements}.

Parameters

driver_interface $db Database connection
bool $return_statements True if only statements should be returned and no SQL being executed

at line 368
public null set_return_statements(bool $return_statements)

Setter for {@link $returnstatements returnstatements}.

Parameters

bool $return_statements True if SQL should not be executed but returned as strings

Return Value

null

at line 378
public array sql_list_tables()

Gets a list of tables in the database.

Return Value

array Array of table names (all lower case)

at line 440
public bool sql_table_exists(string $table_name)

Check if table exists

Parameters

string $table_name The table name to check for

Return Value

bool true if table exists, else false

at line 462
public array sql_create_table(string $table_name, array $table_data)

Create SQL Table

Parameters

string $table_name The table name to create
array $table_data Array containing table data.

Return Value

array Statements if $return_statements is true.

at line 703
public perform_schema_changes($schema_changes)

Handle passed database update array.

Expected structure... Key being one of the following droptables: Drop tables addtables: Add tables changecolumns: Column changes (only type, not name) addcolumns: Add columns to a table dropkeys: Dropping keys dropcolumns: Removing/Dropping columns addprimarykeys: adding primary keys adduniqueindex: adding an unique index addindex: adding an index (can be column:indexsize if you need to provide size)

The values are in this format: {TABLE NAME} => array( {COLUMN NAME} => array({COLUMN TYPE}, {DEFAULT VALUE}, {OPTIONAL VARIABLES}), {KEY/INDEX NAME} => array({COLUMN NAMES}), )

For more information have a look at /develop/createschemafiles.php (only available through SVN)

Parameters

$schema_changes

at line 1088
public array sql_list_columns(string $table)

Gets a list of columns of a table.

Parameters

string $table Table name

Return Value

array Array of column names (all lower case)

at line 1183
public bool sql_column_exists(string $table, string $column_name)

Check whether a specified column exist in a table

Parameters

string $table Table to check
string $column_name Column to check

Return Value

bool True if column exists, false otherwise

at line 1198
public bool sql_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

Does not return PRIMARY KEY and UNIQUE indexes.

Parameters

string $table_name Table to check the index at
string $index_name The index name to check

Return Value

bool True if index exists, else false

at line 1295
public bool sql_unique_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

Does not return PRIMARY KEY indexes.

Parameters

string $table_name Table to check the index at
string $index_name The index name to check

Return Value

bool True if index exists, else false

at line 1408
public _sql_run_sql($statements)

Private method for performing sql statements (either execute them or return them)

Parameters

$statements

at line 1439
public sql_prepare_column_data($table_name, $column_name, $column_data)

Function to prepare some column information for better usage

Parameters

$table_name
$column_name
$column_data

at line 1647
public array get_column_type(string $column_map_type)

Get the column's database type from the type map

Parameters

string $column_map_type

Return Value

array column type for this database and map type without length

at line 1702
public sql_column_add($table_name, $column_name, $column_data, $inline = false)

Add new column

Parameters

$table_name
$column_name
$column_data
$inline

at line 1820
public sql_column_remove($table_name, $column_name, $inline = false)

Drop column

Parameters

$table_name
$column_name
$inline

at line 1949
public sql_index_drop($table_name, $index_name)

Drop Index

Parameters

$table_name
$index_name

at line 1979
public sql_table_drop($table_name)

Drop Table

Parameters

$table_name

at line 2032
public sql_create_primary_key($table_name, $column, $inline = false)

Add primary key

Parameters

$table_name
$column
$inline

at line 2116
public sql_create_unique_index($table_name, $index_name, $column)

Add unique index

Parameters

$table_name
$index_name
$column

at line 2153
public sql_create_index($table_name, $index_name, $column)

Add index

Parameters

$table_name
$index_name
$column

at line 2209
public sql_list_index($table_name)

List all of the indices that belong to a table, does not count: * UNIQUE indices * PRIMARY keys

Parameters

$table_name

at line 2305
public sql_column_change($table_name, $column_name, $column_data, $inline = false)

Change column type (not name!)

Parameters

$table_name
$column_name
$column_data
$inline

at line 2624
public array get_existing_indexes(string $table_name, string $column_name, bool $unique = false)

Get a list with existing indexes for the column

Parameters

string $table_name
string $column_name
bool $unique Should we get unique indexes or normal ones

Return Value

array Array with Index name => columns