Jelix 1.6.37

jDbTools
in package

Provides utilities methods for a database

Tags
subpackage

db

Table of Contents

IBD_EMPTY_TABLE_BEFORE  = 1
IBD_IGNORE_IF_EXIST  = 3
IBD_INSERT_ONLY_IF_TABLE_IS_EMPTY  = 2
IBD_NO_CHECK  = 0
IBD_UPDATE_IF_EXIST  = 4
$falseValue  : mixed
$trueValue  : mixed
$_conn  : jDbConnection
the database connector
$dbmsStyle  : mixed
regular expression to detect comments and end of query
$functionNameCorrespondence  : mixed
$keywordNameCorrespondence  : mixed
$typesInfo  : mixed
$unifiedToPhp  : mixed
__construct()  : mixed
encloseName()  : string
Enclose the field name
escapeValue()  : string
execSQLScript()  : mixed
getBooleanValue()  : string
getFieldList()  : array<string|int, jDbFieldProperties>
Retrieve the list of fields of a table
getNativeSQLFunction()  : string
Give the expression that works with the target database, corresponding to the given function name
getSQLColumnsList()  : string
getTableList()  : array<string|int, string>
returns the list of tables
getTypeInfo()  : array<string|int, mixed>
Get informations about the given SQL type
insertBulkData()  : int
Insert several records into a table
parseCREATETABLE()  : array<string|int, mixed>|bool
Parse a SQL CREATE TABLE statement and returns all of its components separately.
parseSQLFunctionAndConvert()  : mixed
parseSQLType()  : array<string|int, mixed>
Parse a SQL type and gives type, length.
stringToPhpValue()  : string
unifiedToPHPType()  : string
Return the PHP type corresponding to the given unified type
extractDateConverter()  : mixed

Constants

IBD_INSERT_ONLY_IF_TABLE_IS_EMPTY

public mixed IBD_INSERT_ONLY_IF_TABLE_IS_EMPTY = 2

Properties

$dbmsStyle

regular expression to detect comments and end of query

protected mixed $dbmsStyle = array('/^\s*#/', '/;\s*$/')

$functionNameCorrespondence

protected mixed $functionNameCorrespondence = array()

$keywordNameCorrespondence

protected mixed $keywordNameCorrespondence = array()

$unifiedToPhp

protected mixed $unifiedToPhp = array('boolean' => 'boolean', 'integer' => 'integer', 'float' => 'float', 'double' => 'float', 'numeric' => 'numeric', 'decimal' => 'decimal', 'date' => 'string', 'time' => 'string', 'datetime' => 'string', 'year' => 'string', 'char' => 'string', 'varchar' => 'string', 'text' => 'string', 'blob' => 'string', 'binary' => 'string', 'varbinary' => 'string')

Methods

encloseName()

Enclose the field name

public encloseName(string $fieldName) : string
Parameters
$fieldName : string

the field name

Tags
since
1.2
Return values
string

the enclosed field name

escapeValue()

public escapeValue(string $unifiedType, mixed $value[, mixed $checkNull = false ][, mixed $toPhpSource = false ]) : string
Parameters
$unifiedType : string

the unified type name

$value : mixed

the value

$checkNull : mixed = false
$toPhpSource : mixed = false
Tags
since
1.2
Return values
string

the value which is ready to include a SQL query string

execSQLScript()

public execSQLScript(mixed $file) : mixed
Parameters
$file : mixed
Return values
mixed

getBooleanValue()

public getBooleanValue(string|bool $value) : string
Parameters
$value : string|bool

a value which is a boolean

Tags
since
1.2
Return values
string

the string value representing a boolean in SQL

getFieldList()

Retrieve the list of fields of a table

public abstract getFieldList(string $tableName[, string $sequence = '' ][, string $schemaName = '' ]) : array<string|int, jDbFieldProperties>
Parameters
$tableName : string

the name of the table

$sequence : string = ''

the sequence used to auto increment the primary key

$schemaName : string = ''

the name of the schema (only for PostgreSQL)

Return values
array<string|int, jDbFieldProperties>

keys are field names

getNativeSQLFunction()

Give the expression that works with the target database, corresponding to the given function name

public getNativeSQLFunction(string $name[, string|null $parametersString = null ]) : string
Parameters
$name : string

a SQL function, maybe a SQL function of another database type

$parametersString : string|null = null

parameters given to the function. Null if no parenthesis

Return values
string

the SQL expression, possibly with a native SQL function corresponding to the given foreign SQL function

getSQLColumnsList()

public getSQLColumnsList(array<string|int, string> $columns) : string
Parameters
$columns : array<string|int, string>

list of column names

Tags
since
1.6.16
Return values
string

the list in SQL

getTableList()

returns the list of tables

public getTableList() : array<string|int, string>
Tags
throws
jException
Return values
array<string|int, string>

list of table names

getTypeInfo()

Get informations about the given SQL type

public getTypeInfo(string $nativeType) : array<string|int, mixed>
Parameters
$nativeType : string

the SQL type

Tags
since
1.2
Return values
array<string|int, mixed>

an array which contains characteristics of the type array ( 'nativetype', 'corresponding unifiedtype', minvalue, maxvalue, minlength, maxlength, autoincrement) minvalue, maxvalue, minlength, maxlength can be null.

insertBulkData()

Insert several records into a table

public insertBulkData(string $tableName, array<string|int, string> $columns, array<string|int, array<string|int, mixed>> $data[, string|array<string|int, string>|null $primaryKey = null ], int $options) : int
Parameters
$tableName : string
$columns : array<string|int, string>

the column names in which data will be inserted

$data : array<string|int, array<string|int, mixed>>

the data. each row is an array of values. Values are in the same order as $columns

$primaryKey : string|array<string|int, string>|null = null

the column names that are the primary key. Don't give the primary key if it is an autoincrement field, or if option is not IBD_*_IF_EXIST

$options : int

one of IDB_* const

Tags
since
1.6.16
Return values
int

number of records inserted/updated

parseCREATETABLE()

Parse a SQL CREATE TABLE statement and returns all of its components separately.

public parseCREATETABLE( $createTableStatement) : array<string|int, mixed>|bool
Parameters
$createTableStatement :
Tags
since
1.6.16
Return values
array<string|int, mixed>|bool

false if parsing has failed. Else an array : 'name' => the schema/table name, 'temporary'=> true if there is the temporary keywork , 'ifnotexists' => true if there is the IF NOT EXISTS statement, 'columns' => list of columns definitions, 'constraints' => list of table constraints definitions, 'options' => all options at the end of the CREATE TABLE statement.

parseSQLFunctionAndConvert()

public parseSQLFunctionAndConvert(mixed $expression) : mixed
Parameters
$expression : mixed
Return values
mixed

parseSQLType()

Parse a SQL type and gives type, length.

public parseSQLType(string $type) : array<string|int, mixed>

..

Parameters
$type : string
Return values
array<string|int, mixed>

[$realtype, $length, $precision, $scale, $otherTypeDef]

stringToPhpValue()

public stringToPhpValue(string $unifiedType, string $value[, mixed $checkNull = false ]) : string
Parameters
$unifiedType : string

the unified type name

$value : string

the value

$checkNull : mixed = false
Tags
since
1.2
Return values
string

the php value corresponding to the type

unifiedToPHPType()

Return the PHP type corresponding to the given unified type

public unifiedToPHPType(string $unifiedType) : string
Parameters
$unifiedType : string
Tags
throws
Exception
since
1.2
Return values
string

the php type

extractDateConverter()

protected extractDateConverter(mixed $parametersString) : mixed
Parameters
$parametersString : mixed
Return values
mixed

Search results