sqlite3
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
Constructor. Set DB Object and set $return_statements return_statements.
Setter for $return_statements return_statements.
Check if table exists
Check whether a specified column exist in a table
Check if a specified index exists in table. Does not return PRIMARY KEY and UNIQUE indexes.
Check if a specified index exists in table.
Get the column's database type from the type map
Add new column
Drop column
Add primary key
Add unique index
Add index
Check whether the index name is too long
Get maximum index name length. Might vary depending on db type
Removes table_name from the index_name if it is at the beginning
Change column type (not name!)
Get a list with existing indexes for the column
Returns the Queries which are required to recreate a table including indexes
Details
in
tools at line 43
static array
get_dbms_type_map()
Get the column types for every database we support
in
tools at line 159
__construct(driver_interface $db, bool $return_statements = false)
Constructor. Set DB Object and set $return_statements return_statements.
in
tools at line 185
null
set_return_statements(bool $return_statements)
Setter for $return_statements return_statements.
in
tools at line 193
array
sql_list_tables()
Gets a list of tables in the database.
at line 25
bool
sql_table_exists(string $table_name)
Check if table exists
in
tools at line 248
array|true
sql_create_table(string $table_name, array $table_data)
Create SQL Table
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}), )
in
tools at line 781
array
sql_list_columns(string $table_name)
Gets a list of columns of a table.
in
tools at line 849
bool
sql_column_exists(string $table_name, string $column_name)
Check whether a specified column exist in a table
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.
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
in
tools at line 1134
array
get_column_type(string $column_map_type)
Get the column's database type from the type map
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
in
tools at line 1223
array|true
sql_column_remove(string $table_name, string $column_name, bool $inline = false)
Drop column
in
tools at line 1301
array|true
sql_index_drop(string $table_name, string $index_name)
Drop Index
in
tools at line 1325
array|true
sql_table_drop(string $table_name)
Drop Table
in
tools at line 1362
array|true
sql_create_primary_key(string $table_name, string|array $column, bool $inline = false)
Add primary key
in
tools at line 1433
array|true
sql_create_unique_index(string $table_name, string $index_name, string|array $column)
Add unique index
in
tools at line 1457
array|true
sql_create_index(string $table_name, string $index_name, string|array $column)
Add index
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
in
tools at line 1524
protected int
get_max_index_name_length()
Get maximum index name length. Might vary depending on db type
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
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
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!)
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
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