class sqlite3 extends 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

from  tools
object $db from  tools
array $dbms_type_map

The Column types for every database we support

from  tools
array $unsigned_types

A list of types being unsigned for better reference in some db's

from  tools
$return_statements

This is set to true if user only wants to return the 'to-be-executed' SQL statement(s) (as an array).

from  tools

Methods

static array
get_dbms_type_map()

Get the column types for every database we support

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

Constructor. Set DB Object and set $return_statements return_statements.

from  tools
null
set_return_statements(bool $return_statements)

Setter for $return_statements return_statements.

from  tools
array
sql_list_tables()

Gets a list of tables in the database.

from  tools
bool
sql_table_exists(string $table_name)

Check if table exists

array|true
sql_create_table(string $table_name, array $table_data)

Create SQL Table

from  tools
null
perform_schema_changes(array $schema_changes)

Handle passed database update array.

from  tools
array
sql_list_columns(string $table_name)

Gets a list of columns of a table.

from  tools
bool
sql_column_exists(string $table_name, string $column_name)

Check whether a specified column exist in a table

from  tools
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.

from  tools
bool
sql_unique_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

from  tools
array
get_column_type(string $column_map_type)

Get the column's database type from the type map

from  tools
array|true
sql_column_add(string $table_name, string $column_name, array $column_data, bool $inline = false)

Add new column

from  tools
array|true
sql_column_remove(string $table_name, string $column_name, bool $inline = false)

Drop column

from  tools
array|true
sql_index_drop(string $table_name, string $index_name)

Drop Index

from  tools
array|true
sql_table_drop(string $table_name)

Drop Table

from  tools
array|true
sql_create_primary_key(string $table_name, string|array $column, bool $inline = false)

Add primary key

from  tools
array|true
sql_create_unique_index(string $table_name, string $index_name, string|array $column)

Add unique index

from  tools
array|true
sql_create_index(string $table_name, string $index_name, string|array $column)

Add index

from  tools
string
check_index_name_length(string $table_name, string $index_name, bool $throw_error = true)

Check whether the index name is too long

from  tools
int
get_max_index_name_length()

Get maximum index name length. Might vary depending on db type

from  tools
array
sql_list_index(string $table_name)

List all of the indices that belong to a table

from  tools
string
strip_table_name_from_index_name($table_name, $index_name)

Removes table_name from the index_name if it is at the beginning

from  tools
array|true
sql_column_change(string $table_name, string $column_name, array $column_data, bool $inline = false)

Change column type (not name!)

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

Get a list with existing indexes for the column

from  tools
array
sqlite_get_recreate_table_queries(string $table_name, string $remove_column = '')

Returns the Queries which are required to recreate a table including indexes

from  tools

Details

in tools at line 43
static array get_dbms_type_map()

Get the column types for every database we support

Return Value

array

in tools at line 159
__construct(driver_interface $db, bool $return_statements = false)

Constructor. Set DB Object and set $return_statements return_statements.

Parameters

driver_interface $db

Database connection

bool $return_statements

True if only statements should be returned and no SQL being executed

in tools at line 185
null set_return_statements(bool $return_statements)

Setter for $return_statements return_statements.

Parameters

bool $return_statements

True if SQL should not be executed but returned as strings

Return Value

null

in tools at line 193
array sql_list_tables()

Gets a list of tables in the database.

Return Value

array

Array of table names (all lower case)

at line 25
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

in tools at line 248
array|true 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|true

Statements to run, or true if the statements have been executed

in tools at line 400
null perform_schema_changes(array $schema_changes)

Handle passed database update array.

Expected structure... Key being one of the following drop_tables: Drop tables add_tables: Add tables change_columns: Column changes (only type, not name) add_columns: Add columns to a table drop_keys: Dropping keys drop_columns: Removing/Dropping columns add_primary_keys: adding primary keys add_unique_index: adding an unique index add_index: adding an index (can be column:index_size 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}), )

Parameters

array $schema_changes

Return Value

null

in tools at line 781
array sql_list_columns(string $table_name)

Gets a list of columns of a table.

Parameters

string $table_name

Table name

Return Value

array

Array of column names (all lower case)

in tools at line 849
bool sql_column_exists(string $table_name, string $column_name)

Check whether a specified column exist in a table

Parameters

string $table_name

Table to check

string $column_name

Column to check

Return Value

bool

True if column exists, false otherwise

in tools at line 859
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

in tools at line 918
bool sql_unique_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

NOTE: Does not return normal and 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

in tools at line 1134
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

in tools at line 1190
array|true sql_column_add(string $table_name, string $column_name, array $column_data, bool $inline = false)

Add new column

Parameters

string $table_name

Table to modify

string $column_name

Name of the column to add

array $column_data

Column data

bool $inline

Whether the query should actually be run, or return a string for adding the column

Return Value

array|true

Statements to run, or true if the statements have been executed

in tools at line 1223
array|true sql_column_remove(string $table_name, string $column_name, bool $inline = false)

Drop column

Parameters

string $table_name

Table to modify

string $column_name

Name of the column to drop

bool $inline

Whether the query should actually be run, or return a string for deleting the column

Return Value

array|true

Statements to run, or true if the statements have been executed

in tools at line 1301
array|true sql_index_drop(string $table_name, string $index_name)

Drop Index

Parameters

string $table_name

Table to modify

string $index_name

Name of the index to delete

Return Value

array|true

Statements to run, or true if the statements have been executed

in tools at line 1325
array|true sql_table_drop(string $table_name)

Drop Table

Parameters

string $table_name

The table name to drop

Return Value

array|true

Statements to run, or true if the statements have been executed

in tools at line 1362
array|true sql_create_primary_key(string $table_name, string|array $column, bool $inline = false)

Add primary key

Parameters

string $table_name

Table to modify

string|array $column

Either a string with a column name, or an array with columns

bool $inline

Whether the query should actually be run, or return a string for creating the key

Return Value

array|true

Statements to run, or true if the statements have been executed

in tools at line 1433
array|true sql_create_unique_index(string $table_name, string $index_name, string|array $column)

Add unique index

Parameters

string $table_name

Table to modify

string $index_name

Name of the unique index to create

string|array $column

Either a string with a column name, or an array with columns

Return Value

array|true

Statements to run, or true if the statements have been executed

in tools at line 1457
array|true sql_create_index(string $table_name, string $index_name, string|array $column)

Add index

Parameters

string $table_name

Table to modify

string $index_name

Name of the index to create

string|array $column

Either a string with a column name, or an array with columns

Return Value

array|true

Statements to run, or true if the statements have been executed

in tools at line 1488
protected string check_index_name_length(string $table_name, string $index_name, bool $throw_error = true)

Check whether the index name is too long

Parameters

string $table_name
string $index_name
bool $throw_error

Return Value

string

The index name, shortened if too long

in tools at line 1524
protected int get_max_index_name_length()

Get maximum index name length. Might vary depending on db type

Return Value

int

Maximum index name length

in tools at line 1532
array sql_list_index(string $table_name)

List all of the indices that belong to a table

NOTE: does not list

  • UNIQUE indices
  • PRIMARY keys

Parameters

string $table_name

Table to check

Return Value

array

Array with index names

in tools at line 1589
protected string strip_table_name_from_index_name($table_name, $index_name)

Removes table_name from the index_name if it is at the beginning

Parameters

$table_name
$index_name

Return Value

string

in tools at line 1597
array|true sql_column_change(string $table_name, string $column_name, array $column_data, bool $inline = false)

Change column type (not name!)

Parameters

string $table_name

Table to modify

string $column_name

Name of the column to modify

array $column_data

Column data

bool $inline

Whether the query should actually be run, or return a string for modifying the column

Return Value

array|true

Statements to run, or true if the statements have been executed

in tools at line 1749
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

in tools at line 1818
protected array sqlite_get_recreate_table_queries(string $table_name, string $remove_column = '')

Returns the Queries which are required to recreate a table including indexes

Parameters

string $table_name
string $remove_column

When we drop a column, we remove the column from all indexes. If the index has no other column, we drop it completly.

Return Value

array