Postgres
extends Driver
in package
uses
SqlDialectTrait
Class Postgres
Table of Contents
Constants
- MAX_ALIAS_LENGTH = 63
- RETRY_ERROR_CODES = []
Properties
- $_autoQuoting : bool
- Indicates whether the driver is doing automatic identifier quoting for all queries
- $_baseConfig : array<string, mixed>
- Base configuration settings for Postgres driver
- $_config : array<string, mixed>
- Configuration data.
- $_connection : PDO
- Instance of PDO.
- $_endQuote : string
- String used to end a database identifier quoting to make it safe
- $_schemaDialect : PostgresSchemaDialect|null
- The schema dialect class for this driver
- $_startQuote : string
- String used to start a database identifier quoting to make it safe
- $_version : string|null
- The server version
- $connectRetries : int
- The last number of connection retry attempts.
Methods
- __construct() : mixed
- Constructor
- __debugInfo() : array<string, mixed>
- Returns an array that can be used to describe the internal state of this object.
- __destruct() : mixed
- Destructor
- beginTransaction() : bool
- Starts a transaction.
- commitTransaction() : bool
- Commits a transaction.
- compileQuery() : array<string|int, mixed>
- Transforms the passed query to this Driver's dialect and returns an instance of the transformed query and the full compiled SQL string.
- connect() : bool
- Establishes a connection to the database server
- disableAutoQuoting() : $this
- Disable auto quoting of identifiers in queries.
- disableForeignKeySQL() : string
- Get the SQL for disabling foreign keys.
- disconnect() : void
- Disconnects from database server.
- enableAutoQuoting() : $this
- Sets whether this driver should automatically quote identifiers in queries.
- enabled() : bool
- Returns whether php is able to use this driver for connecting to database
- enableForeignKeySQL() : string
- Get the SQL for enabling foreign keys.
- getConnection() : PDO
- Get the internal PDO connection instance.
- getConnectRetries() : int
- Returns the number of connection retry attempts made.
- getMaxAliasLength() : int|null
- Returns the maximum alias length allowed.
- inTransaction() : bool
- Returns whether a transaction is active for connection.
- isAutoQuotingEnabled() : bool
- Returns whether this driver should automatically quote identifiers in queries.
- isConnected() : bool
- Checks whether the driver is connected.
- lastInsertId() : string|int
- Returns last id generated for a table or sequence in database.
- newCompiler() : PostgresCompiler
- Returns an instance of a QueryCompiler.
- newTableSchema() : TableSchema
- Constructs new TableSchema.
- prepare() : StatementInterface
- Prepares a sql statement to be executed.
- queryTranslator() : Closure
- Returns a callable function that will be used to transform a passed Query object.
- quote() : string
- Returns a value in a safe representation to be used in a query string
- quoteIdentifier() : string
- Quotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words.
- rollbackTransaction() : bool
- Rollbacks a transaction.
- schema() : string
- Returns the schema name that's being used.
- schemaDialect() : SchemaDialect
- Get the schema dialect.
- schemaValue() : string
- Escapes values for use in schema definitions.
- setConnection() : $this
- Set the internal PDO connection instance.
- setEncoding() : void
- Sets connection encoding
- setSchema() : void
- Sets connection default schema, if any relation defined in a query is not fully qualified postgres will fallback to looking the relation into defined default schema
- supports() : bool
- Returns whether the driver supports the feature.
- supportsCTEs() : bool
- Returns true if the server supports common table expressions.
- supportsDynamicConstraints() : bool
- Returns whether the driver supports adding or dropping constraints to already created tables.
- supportsQuoting() : bool
- Checks if the driver supports quoting, as PDO_ODBC does not support it.
- supportsSavePoints() : bool
- Returns whether this driver supports save points for nested transactions.
- version() : string
- Returns connected server version.
- _connect() : bool
- Establishes a connection to the database server
- _expressionTranslators() : array<string|int, mixed>
- _insertQueryTranslator() : Query
- _transformDistinct() : Query
- _transformFunctionExpression() : void
- Receives a FunctionExpression and changes it so that it conforms to this SQL dialect.
- _transformIdentifierExpression() : void
- Changes identifer expression into postgresql format.
- _transformStringExpression() : void
- Changes string expression into postgresql format.
Constants
MAX_ALIAS_LENGTH
protected
int|null
MAX_ALIAS_LENGTH
= 63
Maximum alias length or null if no limit
Tags
RETRY_ERROR_CODES
protected
array<string|int, int>
RETRY_ERROR_CODES
= []
DB-specific error codes that allow connect retry
Properties
$_autoQuoting
Indicates whether the driver is doing automatic identifier quoting for all queries
protected
bool
$_autoQuoting
= false
$_baseConfig
Base configuration settings for Postgres driver
protected
array<string, mixed>
$_baseConfig
= ['persistent' => true, 'host' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'cake', 'schema' => 'public', 'port' => 5432, 'encoding' => 'utf8', 'timezone' => null, 'flags' => [], 'init' => []]
$_config
Configuration data.
protected
array<string, mixed>
$_config
$_connection
Instance of PDO.
protected
PDO
$_connection
$_endQuote
String used to end a database identifier quoting to make it safe
protected
string
$_endQuote
= '"'
$_schemaDialect
The schema dialect class for this driver
protected
PostgresSchemaDialect|null
$_schemaDialect
$_startQuote
String used to start a database identifier quoting to make it safe
protected
string
$_startQuote
= '"'
$_version
The server version
protected
string|null
$_version
$connectRetries
The last number of connection retry attempts.
protected
int
$connectRetries
= 0
Methods
__construct()
Constructor
public
__construct([array<string, mixed> $config = [] ]) : mixed
Parameters
- $config : array<string, mixed> = []
-
The configuration for the driver.
Tags
__debugInfo()
Returns an array that can be used to describe the internal state of this object.
public
__debugInfo() : array<string, mixed>
Return values
array<string, mixed>__destruct()
Destructor
public
__destruct() : mixed
beginTransaction()
Starts a transaction.
public
beginTransaction() : bool
Tags
Return values
bool —True on success, false otherwise.
commitTransaction()
Commits a transaction.
public
commitTransaction() : bool
Tags
Return values
bool —True on success, false otherwise.
compileQuery()
Transforms the passed query to this Driver's dialect and returns an instance of the transformed query and the full compiled SQL string.
public
compileQuery(Query $query, ValueBinder $binder) : array<string|int, mixed>
Parameters
- $query : Query
-
The query to compile.
- $binder : ValueBinder
-
The value binder to use.
Tags
Return values
array<string|int, mixed> —containing 2 entries. The first entity is the transformed query and the second one the compiled SQL.
connect()
Establishes a connection to the database server
public
connect() : bool
Return values
bool —true on success
disableAutoQuoting()
Disable auto quoting of identifiers in queries.
public
disableAutoQuoting() : $this
Tags
Return values
$thisdisableForeignKeySQL()
Get the SQL for disabling foreign keys.
public
disableForeignKeySQL() : string
Tags
Return values
stringdisconnect()
Disconnects from database server.
public
disconnect() : void
Tags
enableAutoQuoting()
Sets whether this driver should automatically quote identifiers in queries.
public
enableAutoQuoting([bool $enable = true ]) : $this
Parameters
- $enable : bool = true
-
Whether to enable auto quoting
Tags
Return values
$thisenabled()
Returns whether php is able to use this driver for connecting to database
public
enabled() : bool
Return values
bool —true if it is valid to use this driver
enableForeignKeySQL()
Get the SQL for enabling foreign keys.
public
enableForeignKeySQL() : string
Tags
Return values
stringgetConnection()
Get the internal PDO connection instance.
public
getConnection() : PDO
Return values
PDOgetConnectRetries()
Returns the number of connection retry attempts made.
public
getConnectRetries() : int
Return values
intgetMaxAliasLength()
Returns the maximum alias length allowed.
public
getMaxAliasLength() : int|null
This can be different from the maximum identifier length for columns.
Return values
int|null —Maximum alias length or null if no limit
inTransaction()
Returns whether a transaction is active for connection.
public
inTransaction() : bool
Return values
boolisAutoQuotingEnabled()
Returns whether this driver should automatically quote identifiers in queries.
public
isAutoQuotingEnabled() : bool
Tags
Return values
boolisConnected()
Checks whether the driver is connected.
public
isConnected() : bool
Tags
Return values
boollastInsertId()
Returns last id generated for a table or sequence in database.
public
lastInsertId([string|null $table = null ][, string|null $column = null ]) : string|int
Parameters
- $table : string|null = null
-
table name or sequence to get last insert value from.
- $column : string|null = null
-
the name of the column representing the primary key.
Tags
Return values
string|intnewCompiler()
Returns an instance of a QueryCompiler.
public
newCompiler() : PostgresCompiler
Return values
PostgresCompilernewTableSchema()
Constructs new TableSchema.
public
newTableSchema(string $table[, array<string|int, mixed> $columns = [] ]) : TableSchema
Parameters
- $table : string
-
The table name.
- $columns : array<string|int, mixed> = []
-
The list of columns for the schema.
Tags
Return values
TableSchemaprepare()
Prepares a sql statement to be executed.
public
prepare(mixed $query) : StatementInterface
Parameters
- $query : mixed
-
The query to turn into a prepared statement.
Tags
Return values
StatementInterfacequeryTranslator()
Returns a callable function that will be used to transform a passed Query object.
public
abstract queryTranslator(string $type) : Closure
Parameters
- $type : string
-
The type of query to be transformed (select, insert, update, delete).
Tags
Return values
Closurequote()
Returns a value in a safe representation to be used in a query string
public
quote(mixed $value[, mixed $type = PDO::PARAM_STR ]) : string
Parameters
- $value : mixed
-
The value to quote.
- $type : mixed = PDO::PARAM_STR
-
Must be one of the \PDO::PARAM_* constants
Tags
Return values
stringquoteIdentifier()
Quotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words.
public
abstract quoteIdentifier(string $identifier) : string
Parameters
- $identifier : string
-
The identifier expression to quote.
Tags
Return values
stringrollbackTransaction()
Rollbacks a transaction.
public
rollbackTransaction() : bool
Tags
Return values
bool —True on success, false otherwise.
schema()
Returns the schema name that's being used.
public
schema() : string
Tags
Return values
stringschemaDialect()
Get the schema dialect.
public
schemaDialect() : SchemaDialect
Tags
Return values
SchemaDialectschemaValue()
Escapes values for use in schema definitions.
public
schemaValue(mixed $value) : string
Parameters
- $value : mixed
-
The value to escape.
Tags
Return values
string —String for use in schema definitions.
setConnection()
Set the internal PDO connection instance.
public
setConnection(PDO $connection) : $this
Parameters
- $connection : PDO
-
PDO instance.
Tags
Return values
$thissetEncoding()
Sets connection encoding
public
setEncoding(string $encoding) : void
Parameters
- $encoding : string
-
The encoding to use.
setSchema()
Sets connection default schema, if any relation defined in a query is not fully qualified postgres will fallback to looking the relation into defined default schema
public
setSchema(string $schema) : void
Parameters
- $schema : string
-
The schema names to set
search_path
to.
supports()
Returns whether the driver supports the feature.
public
supports(string $feature) : bool
Parameters
- $feature : string
-
Driver feature name
Tags
Return values
boolsupportsCTEs()
Returns true if the server supports common table expressions.
public
supportsCTEs() : bool
Use supports(DriverInterface::FEATURE_QUOTE)
instead
Return values
boolsupportsDynamicConstraints()
Returns whether the driver supports adding or dropping constraints to already created tables.
public
supportsDynamicConstraints() : bool
Tags
Return values
bool —True if driver supports dynamic constraints.
supportsQuoting()
Checks if the driver supports quoting, as PDO_ODBC does not support it.
public
supportsQuoting() : bool
Use supports(DriverInterface::FEATURE_QUOTE)
instead
Return values
boolsupportsSavePoints()
Returns whether this driver supports save points for nested transactions.
public
supportsSavePoints() : bool
Tags
Return values
bool —True if save points are supported, false otherwise.
version()
Returns connected server version.
public
version() : string
Return values
string_connect()
Establishes a connection to the database server
protected
_connect(string $dsn, array<string, mixed> $config) : bool
Parameters
- $dsn : string
-
A Driver-specific PDO-DSN
- $config : array<string, mixed>
-
configuration to be used for creating connection
Return values
bool —true on success
_expressionTranslators()
protected
_expressionTranslators() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>_insertQueryTranslator()
protected
_insertQueryTranslator(Query $query) : Query
Parameters
- $query : Query
Tags
Return values
Query_transformDistinct()
protected
_transformDistinct(Query $query) : Query
Parameters
- $query : Query
Tags
Return values
Query_transformFunctionExpression()
Receives a FunctionExpression and changes it so that it conforms to this SQL dialect.
protected
_transformFunctionExpression(FunctionExpression $expression) : void
Parameters
- $expression : FunctionExpression
-
The function expression to convert to postgres SQL.
_transformIdentifierExpression()
Changes identifer expression into postgresql format.
protected
_transformIdentifierExpression(IdentifierExpression $expression) : void
Parameters
- $expression : IdentifierExpression
-
The expression to tranform.
_transformStringExpression()
Changes string expression into postgresql format.
protected
_transformStringExpression(StringExpression $expression) : void
Parameters
- $expression : StringExpression
-
The string expression to tranform.