abstract class SqlHelper

Engine provides generic support for databases.

The class will have to be extended by completing the particularities of each of them.

Properties

protected string $tableQuote Character used as quotes to enclose the name of the table
protected string $fieldQuote Character used as quotes to enclose the name of a field
protected string $literalQuote Character used as quotes to enclose the literal fields
protected array $fieldTypes It contains an associative array in which each index is a type of virtual field, and its content is each of the types it represents.

Methods

__construct()

SqlHelper constructor.

string
quoteTableName(string $tableName, bool $usePrefix = true)

Returns the name of the table in quotes.

string
quoteFieldName(string $fieldName)

Returns the name of the field in quotes.

string
quoteLiteral(string|null $fieldName)

Returns the name of the field in quotes.

array
getTables()

Returns an array with the name of all the tables in the database.

string
getSqlTableExists(string $tableName)

Returns if table exists in the database.

string
getSQLField(string $fieldName, array $data)

TODO: Undocummented.

array
getColumns(string $tableName, bool $usePrefix = true)

Returns an array with all the columns of a table

string
getColumnsSql(string $tableName, bool $usePrefix)

SQL statement that returns the fields in the table

array
normalizeFields(array $fields)

Modifies the structure returned by the query generated with getColumnsSql to the normalized format that returns getColumns

array
getIndexes(string $tableName, bool $usePrefix = true)

Obtains information about the indices of the table in a normalized array and independent of the database engine

string
getIndexesSql(string $tableName, bool $usePrefix = true)

Obtain an array with the basic information about the indexes of the table, which will be supplemented with the restrictions later.

array
normalizeIndexes(array $fields)

Returns an array with the index information, and if there are, also constraints.

Details

at line 51
__construct()

SqlHelper constructor.

at line 73
string quoteTableName(string $tableName, bool $usePrefix = true)

Returns the name of the table in quotes.

Parameters

string $tableName
bool $usePrefix

Return Value

string

at line 87
string quoteFieldName(string $fieldName)

Returns the name of the field in quotes.

Parameters

string $fieldName

Return Value

string

at line 99
string quoteLiteral(string|null $fieldName)

Returns the name of the field in quotes.

Parameters

string|null $fieldName

Return Value

string

at line 109
abstract array getTables()

Returns an array with the name of all the tables in the database.

Return Value

array

at line 118
abstract string getSqlTableExists(string $tableName)

Returns if table exists in the database.

Parameters

string $tableName

Return Value

string

at line 128
abstract string getSQLField(string $fieldName, array $data)

TODO: Undocummented.

Parameters

string $fieldName
array $data

Return Value

string

at line 153
array getColumns(string $tableName, bool $usePrefix = true)

Returns an array with all the columns of a table

TODO: Review the types. The variants will depend on type + length.

'name_of_the_field' => { (Required type and length or bytes) 'type' => (string/integer/float/decimal/boolean/date/datetime/text/blob) 'length' => It is the number of characters that the field needs (optional if bytes exists) 'bytes' => Number of bytes occupied by the data (optional if length exists) (Optional) 'default' => Default value 'nullable' => True if it can be null 'primary' => True if it is the primary key 'autoincrement' => True if it is an autoincremental number 'zerofilled' => True if it completes zeros on the left }

Parameters

string $tableName
bool $usePrefix

Return Value

array

at line 175
abstract string getColumnsSql(string $tableName, bool $usePrefix)

SQL statement that returns the fields in the table

Parameters

string $tableName
bool $usePrefix

Return Value

string

at line 185
abstract array normalizeFields(array $fields)

Modifies the structure returned by the query generated with getColumnsSql to the normalized format that returns getColumns

Parameters

array $fields

Return Value

array

at line 196
array getIndexes(string $tableName, bool $usePrefix = true)

Obtains information about the indices of the table in a normalized array and independent of the database engine

Parameters

string $tableName
bool $usePrefix

Return Value

array

at line 228
abstract string getIndexesSql(string $tableName, bool $usePrefix = true)

Obtain an array with the basic information about the indexes of the table, which will be supplemented with the restrictions later.

Parameters

string $tableName
bool $usePrefix

Return Value

string

at line 237
abstract array normalizeIndexes(array $fields)

Returns an array with the index information, and if there are, also constraints.

Parameters

array $fields

Return Value

array