Jelix 1.8.13

jDbPgsqlTools extends jDbTools
in package

Provides utilities methods for a database.

Tags
subpackage

db_driver

Table of Contents

ARRAY_VALUE_TYPE_FLOAT  = 'float'
ARRAY_VALUE_TYPE_INT  = 'int'
ARRAY_VALUE_TYPE_TEXT  = 'text'
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
decodeArrayValue()  : mixed
encloseName()  : string
Enclose the field name.
encodeArrayValue()  : mixed
escapeValue()  : string
execSQLScript()  : mixed
execute a list of queries stored in a file.
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

ARRAY_VALUE_TYPE_FLOAT

public mixed ARRAY_VALUE_TYPE_FLOAT = 'float'
Tags

ARRAY_VALUE_TYPE_INT

public mixed ARRAY_VALUE_TYPE_INT = 'int'
Tags

ARRAY_VALUE_TYPE_TEXT

public mixed ARRAY_VALUE_TYPE_TEXT = 'text'
Tags

IBD_EMPTY_TABLE_BEFORE

public mixed IBD_EMPTY_TABLE_BEFORE = 1
Tags

IBD_INSERT_ONLY_IF_TABLE_IS_EMPTY

public mixed IBD_INSERT_ONLY_IF_TABLE_IS_EMPTY = 2
Tags

Properties

$dbmsStyle

regular expression to detect comments and end of query.

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

$functionNameCorrespondence

protected mixed $functionNameCorrespondence = array( // sqlsrv, -> date+time 'sysdatetime' => 'CURRENT_TIMESTAMP(0)', // sqlsrv, -> date+time+offset 'sysdatetimeoffset' => 'LOCALTIMESTAMP(0)', // sqlsrv, -> date+time at utc 'sysutcdatetime' => 'current_timestamp()', // sqlsrv -> date+time 'getdate' => 'current_timestamp()', // sqlsrv -> date+time at utc 'getutcdate' => 'current_timestamp()', // sqlsrv,mysql (datetime)-> integer 'day' => 'extract(day FROM TIMESTAMP %!p)', // sqlsrv,mysql (datetime)-> integer 'month' => 'extract(month FROM TIMESTAMP %!p)', // sqlsrv, mysql (datetime)-> integer 'year' => 'extract(year FROM TIMESTAMP %!p)', // mysql -> date 'curdate' => 'current_date', // mysql -> date 'current_date' => 'current_date', // mysql -> time 'curtime' => 'current_time', // mysql -> time 'current_time' => 'current_time', // mysql,pgsql -> date+time 'now' => 'current_timestamp', // mysql date+time 'current_timestamp' => 'current_timestamp', // mysql (datetime)->date, sqlite (timestring, modifier)->date 'date' => 'date %!p', // mysql = day() 'dayofmonth' => 'extract(day FROM TIMESTAMP %!p)', // mysql -> date+time 'localtime' => 'current_timestamp', // mysql -> date+time 'localtimestamp' => 'current_timestamp', // mysql utc current date 'utc_date' => 'current_date', // mysql utc current time 'utc_time' => 'current_time', // mysql utc current date+time 'utc_timestamp' => 'current_timestamp', // mysql (datetime)->time, , sqlite (timestring, modifier)->time 'time' => 'time %!p', // mysql (datetime/time)-> hour 'hour' => 'extract(hour FROM TIMESTAMP %!p)', // mysql (datetime/time)-> minute 'minute' => 'extract(minute FROM TIMESTAMP %!p)', // mysql (datetime/time)-> second 'second' => 'extract(second FROM TIMESTAMP %!p)', // sqlite (timestring, modifier)->datetime 'datetime' => 'timestamp %!p', // oci, mysql (year|month|day|hour|minute|second FROM <datetime>)->value , // pgsql (year|month|day|hour|minute|second FROM TIMESTAMP <datetime>)->value 'extract' => '!extractDateConverter', // pgsql ('year'|'month'|'day'|'hour'|'minute'|'second', TIMESTAMP <datetime>)->value //'date_part' => '!extractDateConverter', // sqlsrv (year||month|day|hour|minute|second, <datetime>)->value 'datepart' => '!extractDateConverter', )
Tags

$keywordNameCorrespondence

protected mixed $keywordNameCorrespondence = array( // sqlsrv,mysql,oci,pgsql -> date+time //'current_timestamp' => '', // mysql,oci,pgsql -> date //'current_date' => '', // mysql -> time, pgsql -> time+timezone //'current_time' => '', // oci -> date+fractional secon + timezone 'systimestamp' => 'current_time', // oci -> date+time+tz 'sysdate' => 'current_timestamp', )
Tags

$typesInfo

protected mixed $typesInfo = array( // type native type unified type minvalue maxvalue minlength maxlength 'bool' => array('boolean', 'boolean', 0, 1, \null, \null), 'boolean' => array('boolean', 'boolean', 0, 1, \null, \null), 'bit' => array('smallint', 'integer', 0, 1, \null, \null), 'tinyint' => array('smallint', 'integer', -128, 127, \null, \null), 'smallint' => array('smallint', 'integer', -32768, 32767, \null, \null), 'mediumint' => array('integer', 'integer', -8388608, 8388607, \null, \null), 'integer' => array('integer', 'integer', -2147483648, 2147483647, \null, \null), 'int' => array('integer', 'integer', -2147483648, 2147483647, \null, \null), 'bigint' => array('bigint', 'numeric', '-9223372036854775808', '9223372036854775807', \null, \null), 'serial' => array('serial', 'integer', -2147483648, 2147483647, \null, \null), 'bigserial' => array('bigserial', 'numeric', '-9223372036854775808', '9223372036854775807', \null, \null), 'autoincrement' => array('serial', 'integer', -2147483648, 2147483647, \null, \null), // for old dao files 'bigautoincrement' => array('bigserial', 'numeric', '-9223372036854775808', '9223372036854775807', \null, \null), // for old dao files 'float' => array('real', 'float', \null, \null, \null, \null), //4bytes 'money' => array('money', 'float', \null, \null, \null, \null), //4bytes 'smallmoney' => array('money', 'float', \null, \null, \null, \null), 'double precision' => array('double precision', 'decimal', \null, \null, \null, \null), //8bytes 'double' => array('double precision', 'decimal', \null, \null, \null, \null), //8bytes 'real' => array('real', 'float', \null, \null, \null, \null), //8bytes 'number' => array('double', 'decimal', \null, \null, \null, \null), //8bytes 'binary_float' => array('real', 'float', \null, \null, \null, \null), //4bytes 'binary_double' => array('double', 'decimal', \null, \null, \null, \null), //8bytes 'numeric' => array('numeric', 'numeric', \null, \null, \null, \null), 'decimal' => array('decimal', 'decimal', \null, \null, \null, \null), 'dec' => array('decimal', 'decimal', \null, \null, \null, \null), 'date' => array('date', 'date', \null, \null, 10, 10), 'time' => array('time', 'time', \null, \null, 8, 8), 'datetime' => array('timestamp', 'datetime', \null, \null, 19, 19), 'datetime2' => array('timestamp', 'datetime', \null, \null, 19, 27), // sqlsrv / 9999-12-31 23:59:59.9999999 'datetimeoffset' => array('timestamp with timezone', 'datetime', \null, \null, 19, 34), // sqlsrv / 9999-12-31 23:59:59.9999999 +14:00 'smalldatetime' => array('timestamp', 'datetime', \null, \null, 19, 19), // sqlsrv / 2079-06-06 23:59 'timestamp' => array('timestamp', 'datetime', \null, \null, 19, 19), // oracle/pgsql timestamp 'utimestamp' => array('timestamp', 'integer', 0, 2147483647, \null, \null), // mysql timestamp 'year' => array('year', 'year', \null, \null, 2, 4), 'interval' => array('interval', 'integer', \null, \null, 19, 19), 'char' => array('char', 'char', \null, \null, 0, 255), 'nchar' => array('nchar', 'char', \null, \null, 0, 255), 'varchar' => array('varchar', 'varchar', \null, \null, 0, 0), 'varchar2' => array('varchar', 'varchar', \null, \null, 0, 0), 'nvarchar2' => array('nvarchar', 'varchar', \null, \null, 0, 0), 'character' => array('character', 'varchar', \null, \null, 0, 0), 'character varying' => array('character varying', 'varchar', \null, \null, 0, 0), 'name' => array('name', 'varchar', \null, \null, 0, 64), 'longvarchar' => array('varchar', 'varchar', \null, \null, 0, 0), 'string' => array('varchar', 'varchar', \null, \null, 0, 0), // for old dao files 'tinytext' => array('text', 'text', \null, \null, 0, 255), 'text' => array('text', 'text', \null, \null, 0, 0), 'ntext' => array('text', 'text', \null, \null, 0, 0), 'mediumtext' => array('text', 'text', \null, \null, 0, 0), 'longtext' => array('text', 'text', \null, \null, 0, 0), 'long' => array('text', 'text', \null, \null, 0, 0), 'clob' => array('text', 'text', \null, \null, 0, 0), 'nclob' => array('text', 'text', \null, \null, 0, 0), 'tinyblob' => array('bytea', 'blob', \null, \null, 0, 255), 'blob' => array('bytea', 'blob', \null, \null, 0, 65535), 'mediumblob' => array('bytea', 'blob', \null, \null, 0, 16777215), 'longblob' => array('bytea', 'blob', \null, \null, 0, 0), 'bfile' => array('bytea', 'blob', \null, \null, 0, 0), 'bytea' => array('bytea', 'varbinary', \null, \null, 0, 0), 'binary' => array('bytea', 'binary', \null, \null, 0, 255), 'varbinary' => array('bytea', 'varbinary', \null, \null, 0, 255), 'raw' => array('bytea', 'varbinary', \null, \null, 0, 2000), 'long raw' => array('bytea', 'varbinary', \null, \null, 0, 0), 'image' => array('bytea', 'varbinary', \null, \null, 0, 0), 'enum' => array('varchar', 'varchar', \null, \null, 0, 65535), 'set' => array('varchar', 'varchar', \null, \null, 0, 65535), 'xmltype' => array('varchar', 'varchar', \null, \null, 0, 65535), 'xml' => array('text', 'text', \null, \null, 0, 0), 'point' => array('point', 'varchar', \null, \null, 0, 16), 'line' => array('line', 'varchar', \null, \null, 0, 32), 'lsed' => array('lsed', 'varchar', \null, \null, 0, 32), 'box' => array('box', 'varchar', \null, \null, 0, 32), 'path' => array('path', 'varchar', \null, \null, 0, 65535), 'polygon' => array('polygon', 'varchar', \null, \null, 0, 65535), 'circle' => array('circle', 'varchar', \null, \null, 0, 24), 'cidr' => array('cidr', 'varchar', \null, \null, 0, 24), 'inet' => array('inet', 'varchar', \null, \null, 0, 24), 'macaddr' => array('macaddr', 'integer', 0, 0xffffffffffff, \null, \null), 'bit varying' => array('bit varying', 'varchar', \null, \null, 0, 65535), 'arrays' => array('array', 'varchar', \null, \null, 0, 65535), 'complex types' => array('complex', 'varchar', \null, \null, 0, 65535), )
Tags

$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')
Tags

Methods

decodeArrayValue()

public decodeArrayValue(mixed $value) : mixed
Parameters
$value : mixed
Tags
Return values
mixed

encloseName()

Enclose the field name.

public encloseName(mixed $name) : string
Parameters
$name : mixed
Tags
Return values
string

the enclosed field name

encodeArrayValue()

public encodeArrayValue(array<string|int, mixed> $value, mixed $type) : mixed
Parameters
$value : array<string|int, mixed>
$type : mixed
Tags
Return values
mixed

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()

execute a list of queries stored in a file.

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

path of the sql file

Tags
Return values
mixed

getBooleanValue()

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

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 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

Tags
throws
Exception
Return values
array<string|int, jDbFieldProperties>

keys are field names and values are jDbFieldProperties objects

getNativeSQLFunction()

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

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

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

$parametersString : null|string = null

parameters given to the function. Null if no parenthesis

Tags
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[, null|string|array<string|int, string> $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 : null|string|array<string|int, string> = 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
Tags
Return values
mixed

parseSQLType()

Parse a SQL type and gives type, length.

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

..

Parameters
$type : string
Tags
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
Tags
Return values
mixed

Search results