ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
MDB2_Driver_pgsql Class Reference
+ Inheritance diagram for MDB2_Driver_pgsql:
+ Collaboration diagram for MDB2_Driver_pgsql:

Public Member Functions

 __construct ()
 Constructor.
 errorInfo ($error=null)
 This method is used to collect information about an error.
 escape ($text, $escape_wildcards=false)
 Quotes a string so it can be safely used in a query.
 beginTransaction ($savepoint=null)
 Start a transaction or set a savepoint.
 commit ($savepoint=null)
 Commit the database changes done during a transaction that is in progress or release a savepoint.
 rollback ($savepoint=null)
 Cancel any database changes done during a transaction or since a specific savepoint that is in progress.
 setTransactionIsolation ($isolation)
 Set the transacton isolation level.
 _doConnect ($database_name, $persistent=false)
 Does the grunt work of connecting to the database.
 connect ()
 Connect to the database.
 setCharset ($charset, $connection=null)
 Set the charset on the current connection.
 disconnect ($force=true)
 Log out and disconnect from the database.
standaloneQuery ($query, $types=null, $is_manip=false)
 execute a query as DBA
_doQuery ($query, $is_manip=false, $connection=null, $database_name=null)
 Execute a query.
 _affectedRows ($connection, $result=null)
 Returns the number of rows affected.
 _modifyQuery ($query, $is_manip, $limit, $offset)
 Changes a query string for various DBMS specific reasons.
 _modifyManipQuery ($query, $limit)
 Changes a manip query string for various DBMS specific reasons.
 getServerVersion ($native=false)
 return version information about the server
prepare ($query, $types=null, $result_types=null, $lobs=array())
 Prepares a query for multiple execution with execute().
 getSequenceName ($sqn)
 adds sequence name formatting to a sequence name
 nextID ($seq_name, $ondemand=true)
 Returns the next free id of a sequence.
 lastInsertID ($table=null, $field=null)
 Returns the autoincrement ID if supported or $id or fetches the current ID in a sequence called: $table.
 currID ($seq_name)
 Returns the current id of a sequence.
- Public Member Functions inherited from MDB2_Driver_Common
 MDB2_Driver_Common ()
 PHP 4 Constructor.
 __destruct ()
 Destructor.
 free ()
 Free the internal references so that the instance can be destroyed.
 __toString ()
 String conversation.
raiseError ($code=null, $mode=null, $options=null, $userinfo=null, $method=null)
 This method is used to communicate an error and invoke error callbacks etc.
 resetWarnings ()
 reset the warning array
 getWarnings ()
 Get all warnings in reverse order.
 setFetchMode ($fetchmode, $object_class= 'stdClass')
 Sets which fetch mode should be used by default on queries on this connection.
 setOption ($option, $value)
 set the option for the db class
 getOption ($option)
 Returns the value of an option.
 debug ($message, $scope= '', $context=array())
 set a debug message
 getDebugOutput ()
 output debug info
 escapePattern ($text)
 Quotes pattern (% and _) characters in a string)
 quoteIdentifier ($str, $check_option=false)
 Quote a string so it can be safely used as a table or column name.
 getAsKeyword ()
 Gets the string to alias column.
 getConnection ()
 Returns a native connection.
 _fixResultArrayValues (&$row, $mode)
 Do all necessary conversions on result arrays to fix DBMS quirks.
loadModule ($module, $property=null, $phptype_specific=null)
 loads a module
 __call ($method, $params)
 Calls a module method using the __call magic method.
 inTransaction ($ignore_nested=false)
 If a transaction is currently open.
 setTransactionIsolation ($isolation, $options=array())
 Set the transacton isolation level.
 beginNestedTransaction ()
 Start a nested transaction.
 completeNestedTransaction ($force_rollback=false)
 Finish a nested transaction by rolling back if an error occured or committing otherwise.
 failNestedTransaction ($error=null, $immediately=false)
 Force setting nested transaction to failed.
 getNestedTransactionError ()
 The first error that occured since the transaction start.
 setDatabase ($name)
 Select a different database.
 getDatabase ()
 Get the current database.
 setDSN ($dsn)
 set the DSN
 getDSN ($type= 'string', $hidepw=false)
 return the DSN as a string
exec ($query)
 Execute a manipulation query to the database and return the number of affected rows.
query ($query, $types=null, $result_class=true, $result_wrap_class=false)
 Send a query to the database and return any results.
_wrapResult ($result, $types=array(), $result_class=true, $result_wrap_class=false, $limit=null, $offset=null)
 wrap a result set into the correct class
 setLimit ($limit, $offset=null)
 set the range of the next query
 subSelect ($query, $type=false)
 simple subselect emulation: leaves the query untouched for all RDBMS that support subselects
 replace ($table, $fields)
 Execute a SQL REPLACE query.
 _skipDelimitedStrings ($query, $position, $p_position)
 Utility method, used by prepare() to avoid replacing placeholders within delimited strings.
 quote ($value, $type=null, $quote=true, $escape_wildcards=false)
 Convert a text value into a DBMS specific format that is suitable to compose query statements.
 getDeclaration ($type, $name, $field)
 Obtain DBMS specific SQL code portion needed to declare of the given type.
 compareDefinition ($current, $previous)
 Obtain an array of changes that may need to applied.
 supports ($feature)
 Tell whether a DB implementation or its backend extension supports a given feature.
 getIndexName ($idx)
 adds index name formatting to a index name
 queryOne ($query, $type=null, $colnum=0)
 Execute the specified query, fetch the value from the first column of the first row of the result set and then frees the result set.
 queryRow ($query, $types=null, $fetchmode=MDB2_FETCHMODE_DEFAULT)
 Execute the specified query, fetch the values from the first row of the result set into an array and then frees the result set.
 queryCol ($query, $type=null, $colnum=0)
 Execute the specified query, fetch the value from the first column of each row of the result set into an array and then frees the result set.
 queryAll ($query, $types=null, $fetchmode=MDB2_FETCHMODE_DEFAULT, $rekey=false, $force_array=false, $group=false)
 Execute the specified query, fetch all the rows of the result set into a two dimensional array and then frees the result set.
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor.
 _PEAR ()
 Destructor (the emulated type of...).
getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them.
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes.
 isError ($data, $code=null)
 Tell whether a value is a PEAR error.
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled.
 expectError ($code= '*')
 This method is used to tell which errors you expect to get.
 popExpect ()
 This method pops one element off the expected error codes stack.
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available.
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack.
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied.
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options.
 staticPushErrorHandling ($mode, $options=null)
 staticPopErrorHandling ()
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack.
 popErrorHandling ()
 Pop the last error handler used.
 loadExtension ($ext)
 OS independant PHP extension load.

Data Fields

 $string_quoting = array('start' => "'", 'end' => "'", 'escape' => "'", 'escape_pattern' => '\\')
 $identifier_quoting = array('start' => '"', 'end' => '"', 'escape' => '"')
- Data Fields inherited from MDB2_Driver_Common
 $db_index = 0
 $dsn = array()
 $connected_dsn = array()
 $connection = 0
 $opened_persistent
 $database_name = ''
 $connected_database_name = ''
 $connected_server_info = ''
 $supported
 $options
 $string_quoting = array('start' => "'", 'end' => "'", 'escape' => false, 'escape_pattern' => false)
 $identifier_quoting = array('start' => '"', 'end' => '"', 'escape' => '"')
 $sql_comments
 $wildcards = array('%', '_')
 $as_keyword = ' AS '
 $warnings = array()
 $debug_output = ''
 $in_transaction = false
 $nested_transaction_counter = null
 $has_transaction_error = false
 $offset = 0
 $limit = 0
 $phptype
 $dbsyntax
 $last_query
 $fetchmode = MDB2_FETCHMODE_ORDERED
 $modules = array()
 $destructor_registered = true
- Data Fields inherited from PEAR
 $_debug = false
 $_default_error_mode = null
 $_default_error_options = null
 $_default_error_handler = ''
 $_error_class = 'PEAR_Error'
 $_expected_errors = array()

Detailed Description

Definition at line 55 of file pgsql.php.

Constructor & Destructor Documentation

MDB2_Driver_pgsql::__construct ( )

Constructor.

Reimplemented from MDB2_Driver_Common.

Definition at line 67 of file pgsql.php.

{
$this->phptype = 'pgsql';
$this->dbsyntax = 'pgsql';
$this->supported['sequences'] = true;
$this->supported['indexes'] = true;
$this->supported['affected_rows'] = true;
$this->supported['summary_functions'] = true;
$this->supported['order_by_text'] = true;
$this->supported['transactions'] = true;
$this->supported['savepoints'] = true;
$this->supported['current_id'] = true;
$this->supported['limit_queries'] = true;
$this->supported['LOBs'] = true;
$this->supported['replace'] = 'emulated';
$this->supported['sub_selects'] = true;
$this->supported['auto_increment'] = 'emulated';
$this->supported['primary_key'] = true;
$this->supported['result_introspection'] = true;
$this->supported['prepared_statements'] = true;
$this->supported['identifier_quoting'] = true;
$this->supported['pattern_escaping'] = true;
$this->supported['new_link'] = true;
$this->options['multi_query'] = false;
}

Member Function Documentation

MDB2_Driver_pgsql::_affectedRows (   $connection,
  $result = null 
)

Returns the number of rows affected.

Parameters
resource$result
resource$connection
Returns
mixed MDB2 Error Object or the number of rows affected private

Reimplemented from MDB2_Driver_Common.

Definition at line 650 of file pgsql.php.

References MDB2_Driver_Common\$connection, $result, MDB2_Driver_Common\getConnection(), and PEAR\isError().

Referenced by standaloneQuery().

{
if (is_null($connection)) {
return $connection;
}
}
return @pg_affected_rows($result);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_pgsql::_doConnect (   $database_name,
  $persistent = false 
)

Does the grunt work of connecting to the database.

Returns
mixed connection resource on success, MDB2 Error Object on failure protected

Definition at line 360 of file pgsql.php.

References MDB2_Driver_Common\$connection, MDB2_Driver_Common\$database_name, $result, PEAR\isError(), MDB2_ERROR_CONNECT_FAILED, MDB2_Driver_Common\raiseError(), and setCharset().

Referenced by connect(), and standaloneQuery().

{
if ($database_name == '') {
$database_name = 'template1';
}
$protocol = $this->dsn['protocol'] ? $this->dsn['protocol'] : 'tcp';
$params = array('');
if ($protocol == 'tcp') {
if ($this->dsn['hostspec']) {
$params[0].= 'host=' . $this->dsn['hostspec'];
}
if ($this->dsn['port']) {
$params[0].= ' port=' . $this->dsn['port'];
}
} elseif ($protocol == 'unix') {
// Allow for pg socket in non-standard locations.
if ($this->dsn['socket']) {
$params[0].= 'host=' . $this->dsn['socket'];
}
if ($this->dsn['port']) {
$params[0].= ' port=' . $this->dsn['port'];
}
}
$params[0].= ' dbname=\'' . addslashes($database_name) . '\'';
}
if ($this->dsn['username']) {
$params[0].= ' user=\'' . addslashes($this->dsn['username']) . '\'';
}
if ($this->dsn['password']) {
$params[0].= ' password=\'' . addslashes($this->dsn['password']) . '\'';
}
if (!empty($this->dsn['options'])) {
$params[0].= ' options=' . $this->dsn['options'];
}
if (!empty($this->dsn['tty'])) {
$params[0].= ' tty=' . $this->dsn['tty'];
}
if (!empty($this->dsn['connect_timeout'])) {
$params[0].= ' connect_timeout=' . $this->dsn['connect_timeout'];
}
if (!empty($this->dsn['sslmode'])) {
$params[0].= ' sslmode=' . $this->dsn['sslmode'];
}
if (!empty($this->dsn['service'])) {
$params[0].= ' service=' . $this->dsn['service'];
}
if (!empty($this->dsn['new_link'])
&& ($this->dsn['new_link'] == 'true' || $this->dsn['new_link'] === true))
{
if (version_compare(phpversion(), '4.3.0', '>=')) {
$params[] = PGSQL_CONNECT_FORCE_NEW;
}
}
$connect_function = $persistent ? 'pg_pconnect' : 'pg_connect';
$connection = @call_user_func_array($connect_function, $params);
if (!$connection) {
return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null,
'unable to establish a connection', __FUNCTION__);
}
if (empty($this->dsn['disable_iso_date'])) {
if (!@pg_query($connection, "SET SESSION DATESTYLE = 'ISO'")) {
return $this->raiseError(null, null, null,
'Unable to set date style to iso', __FUNCTION__);
}
}
if (!empty($this->dsn['charset'])) {
$result = $this->setCharset($this->dsn['charset'], $connection);
return $result;
}
}
return $connection;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

& MDB2_Driver_pgsql::_doQuery (   $query,
  $is_manip = false,
  $connection = null,
  $database_name = null 
)

Execute a query.

Parameters
string$queryquery
boolean$is_manipif the query is a manipulation query
resource$connection
string$database_name
Returns
result or error object protected

Reimplemented from MDB2_Driver_Common.

Definition at line 599 of file pgsql.php.

References MDB2_Driver_Common\$connection, $query, $result, MDB2_Driver_Common\debug(), MDB2_Driver_Common\getConnection(), PEAR\isError(), and MDB2_Driver_Common\raiseError().

Referenced by beginTransaction(), commit(), prepare(), rollback(), setTransactionIsolation(), and standaloneQuery().

{
$this->last_query = $query;
$result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
if ($result) {
return $result;
}
}
if ($this->options['disable_query']) {
$result = $is_manip ? 0 : null;
return $result;
}
if (is_null($connection)) {
return $connection;
}
}
$function = $this->options['multi_query'] ? 'pg_send_query' : 'pg_query';
$result = @$function($connection, $query);
if (!$result) {
$err =& $this->raiseError(null, null, null,
'Could not execute statement', __FUNCTION__);
return $err;
} elseif ($this->options['multi_query']) {
if (!($result = @pg_get_result($connection))) {
$err =& $this->raiseError(null, null, null,
'Could not get the first result from a multi query', __FUNCTION__);
return $err;
}
}
$this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'post', 'result' => $result));
return $result;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_pgsql::_modifyManipQuery (   $query,
  $limit 
)

Changes a manip query string for various DBMS specific reasons.

Parameters
string$queryquery to modify
integer$limitlimit the number of rows
Returns
string modified query protected

Definition at line 703 of file pgsql.php.

References MDB2_Driver_Common\$limit, and $query.

Referenced by _modifyQuery().

{
$pos = strpos(strtolower($query), 'where');
$where = $pos ? substr($query, $pos) : '';
$manip_clause = '(\bDELETE\b\s+(?:\*\s+)?\bFROM\b|\bUPDATE\b)';
$from_clause = '([\w\.]+)';
$where_clause = '(?:(.*)\bWHERE\b\s+(.*))|(.*)';
$pattern = '/^'. $manip_clause . '\s+' . $from_clause .'(?:\s)*(?:'. $where_clause .')?$/i';
$matches = preg_match($pattern, $query, $match);
if ($matches) {
$manip = $match[1];
$from = $match[2];
$what = (count($matches) == 6) ? $match[5] : $match[3];
return $manip.' '.$from.' '.$what.' WHERE ctid=(SELECT ctid FROM '.$from.' '.$where.' LIMIT '.$limit.')';
}
//return error?
return $query;
}

+ Here is the caller graph for this function:

MDB2_Driver_pgsql::_modifyQuery (   $query,
  $is_manip,
  $limit,
  $offset 
)

Changes a query string for various DBMS specific reasons.

Parameters
string$queryquery to modify
boolean$is_manipif it is a DML query
integer$limitlimit the number of rows
integer$offsetstart reading from given offset
Returns
string modified query protected

Reimplemented from MDB2_Driver_Common.

Definition at line 674 of file pgsql.php.

References MDB2_Driver_Common\$limit, $query, and _modifyManipQuery().

Referenced by prepare(), and standaloneQuery().

{
if ($limit > 0
&& !preg_match('/LIMIT\s*\d(?:\s*(?:,|OFFSET)\s*\d+)?(?:[^\)]*)?$/i', $query)
) {
$query = rtrim($query);
if (substr($query, -1) == ';') {
$query = substr($query, 0, -1);
}
if ($is_manip) {
} else {
$query.= " LIMIT $limit OFFSET $offset";
}
}
return $query;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_pgsql::beginTransaction (   $savepoint = null)

Start a transaction or set a savepoint.

Parameters
stringname of a savepoint to set
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Reimplemented from MDB2_Driver_Common.

Definition at line 223 of file pgsql.php.

References $query, $result, _doQuery(), MDB2_Driver_Common\debug(), PEAR\isError(), MDB2_ERROR_INVALID, MDB2_OK, and MDB2_Driver_Common\raiseError().

{
$this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
if (!is_null($savepoint)) {
if (!$this->in_transaction) {
return $this->raiseError(MDB2_ERROR_INVALID, null, null,
'savepoint cannot be released when changes are auto committed', __FUNCTION__);
}
$query = 'SAVEPOINT '.$savepoint;
return $this->_doQuery($query, true);
} elseif ($this->in_transaction) {
return MDB2_OK; //nothing to do
}
if (!$this->destructor_registered && $this->opened_persistent) {
$this->destructor_registered = true;
register_shutdown_function('MDB2_closeOpenTransactions');
}
$result =& $this->_doQuery('BEGIN', true);
return $result;
}
$this->in_transaction = true;
return MDB2_OK;
}

+ Here is the call graph for this function:

MDB2_Driver_pgsql::commit (   $savepoint = null)

Commit the database changes done during a transaction that is in progress or release a savepoint.

This function may only be called when auto-committing is disabled, otherwise it will fail. Therefore, a new transaction is implicitly started after committing the pending changes.

Parameters
stringname of a savepoint to release
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Reimplemented from MDB2_Driver_Common.

Definition at line 262 of file pgsql.php.

References $query, $result, _doQuery(), MDB2_Driver_Common\debug(), PEAR\isError(), MDB2_ERROR_INVALID, MDB2_OK, and MDB2_Driver_Common\raiseError().

{
$this->debug('Committing transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
if (!$this->in_transaction) {
return $this->raiseError(MDB2_ERROR_INVALID, null, null,
'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__);
}
if (!is_null($savepoint)) {
$query = 'RELEASE SAVEPOINT '.$savepoint;
return $this->_doQuery($query, true);
}
$result =& $this->_doQuery('COMMIT', true);
return $result;
}
$this->in_transaction = false;
return MDB2_OK;
}

+ Here is the call graph for this function:

MDB2_Driver_pgsql::connect ( )

Connect to the database.

Returns
true on success, MDB2 Error Object on failure public

Reimplemented from MDB2_Driver_Common.

Definition at line 452 of file pgsql.php.

References MDB2_Driver_Common\$connection, MDB2_Driver_Common\$database_name, MDB2_Driver_Common\$dsn, MDB2_Driver_Common\$phptype, _doConnect(), disconnect(), PEAR\isError(), PEAR\loadExtension(), MDB2_ERROR_NOT_FOUND, MDB2_OK, and MDB2_Driver_Common\raiseError().

{
if (is_resource($this->connection)) {
if (count(array_diff($this->connected_dsn, $this->dsn)) == 0
&& $this->connected_database_name == $this->database_name
&& ($this->opened_persistent == $this->options['persistent'])
) {
return MDB2_OK;
}
$this->disconnect(false);
}
if (!PEAR::loadExtension($this->phptype)) {
return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__);
}
if ($this->database_name) {
$connection = $this->_doConnect($this->database_name, $this->options['persistent']);
return $connection;
}
$this->connection = $connection;
$this->connected_dsn = $this->dsn;
$this->connected_database_name = $this->database_name;
$this->opened_persistent = $this->options['persistent'];
$this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype;
}
return MDB2_OK;
}

+ Here is the call graph for this function:

MDB2_Driver_pgsql::currID (   $seq_name)

Returns the current id of a sequence.

Parameters
string$seq_namename of the sequence
Returns
mixed MDB2 Error Object or id public

Reimplemented from MDB2_Driver_Common.

Definition at line 1038 of file pgsql.php.

References getSequenceName(), MDB2_Driver_Common\queryOne(), and MDB2_Driver_Common\quoteIdentifier().

{
$sequence_name = $this->quoteIdentifier($this->getSequenceName($seq_name), true);
return $this->queryOne("SELECT last_value FROM $sequence_name", 'integer');
}

+ Here is the call graph for this function:

MDB2_Driver_pgsql::disconnect (   $force = true)

Log out and disconnect from the database.

Parameters
boolean$forceif the disconnect should be forced even if the connection is opened persistently
Returns
mixed true on success, false if not connected and error object on error public

Reimplemented from MDB2_Driver_Common.

Definition at line 523 of file pgsql.php.

References MDB2_Driver_Common\$connected_database_name, MDB2_Driver_Common\$connected_dsn, MDB2_Driver_Common\$database_name, MDB2_Driver_Common\$dsn, MDB2_Driver_Common\$opened_persistent, and rollback().

Referenced by connect().

{
if (is_resource($this->connection)) {
if ($this->in_transaction) {
$persistent = $this->options['persistent'];
$this->dsn = $this->connected_dsn;
$this->database_name = $this->connected_database_name;
$this->options['persistent'] = $this->opened_persistent;
$this->rollback();
$this->dsn = $dsn;
$this->database_name = $database_name;
$this->options['persistent'] = $persistent;
}
if (!$this->opened_persistent || $force) {
@pg_close($this->connection);
}
}
return parent::disconnect($force);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_pgsql::errorInfo (   $error = null)

This method is used to collect information about an error.

Parameters
integer$error
Returns
array public

Reimplemented from MDB2_Driver_Common.

Definition at line 107 of file pgsql.php.

References MDB2_ERROR, MDB2_ERROR_ACCESS_VIOLATION, MDB2_ERROR_ALREADY_EXISTS, MDB2_ERROR_CONNECT_FAILED, MDB2_ERROR_CONSTRAINT, MDB2_ERROR_CONSTRAINT_NOT_NULL, MDB2_ERROR_DIVZERO, MDB2_ERROR_INVALID, MDB2_ERROR_INVALID_NUMBER, MDB2_ERROR_NOSUCHFIELD, MDB2_ERROR_NOSUCHTABLE, MDB2_ERROR_NOT_FOUND, MDB2_ERROR_SYNTAX, and MDB2_ERROR_VALUE_COUNT_ON_ROW.

{
// Fall back to MDB2_ERROR if there was no mapping.
$error_code = MDB2_ERROR;
$native_msg = '';
if (is_resource($error)) {
$native_msg = @pg_result_error($error);
} elseif ($this->connection) {
$native_msg = @pg_last_error($this->connection);
if (!$native_msg && @pg_connection_status($this->connection) === PGSQL_CONNECTION_BAD) {
$native_msg = 'Database connection has been lost.';
}
}
static $error_regexps;
if (empty($error_regexps)) {
$error_regexps = array(
'/column .* (of relation .*)?does not exist/i'
'/(relation|sequence|table).*does not exist|class .* not found/i'
'/index .* does not exist/'
'/relation .* already exists/i'
'/(divide|division) by zero$/i'
'/pg_atoi: error in .*: can\'t parse /i'
'/invalid input syntax for( type)? (integer|numeric)/i'
'/value .* is out of range for type \w*int/i'
'/integer out of range/i'
'/value too long for type character/i'
'/attribute .* not found|relation .* does not have attribute/i'
'/column .* specified in USING clause does not exist in (left|right) table/i'
'/parser: parse error at or near/i'
'/syntax error at/'
'/column reference .* is ambiguous/i'
'/permission denied/'
'/violates not-null constraint/'
'/violates [\w ]+ constraint/'
'/referential integrity violation/'
'/more expressions than target columns/i'
);
}
if (is_numeric($error) && $error < 0) {
$error_code = $error;
} else {
foreach ($error_regexps as $regexp => $code) {
if (preg_match($regexp, $native_msg)) {
$error_code = $code;
break;
}
}
}
return array($error_code, null, $native_msg);
}
MDB2_Driver_pgsql::escape (   $text,
  $escape_wildcards = false 
)

Quotes a string so it can be safely used in a query.

It will quote the text so it can safely be used within a query.

Parameters
stringthe input string to quote
boolescape wildcards
Returns
string quoted string

public

Reimplemented from MDB2_Driver_Common.

Definition at line 195 of file pgsql.php.

References MDB2_Driver_Common\$connection, MDB2_Driver_Common\escapePattern(), MDB2_Driver_Common\getConnection(), and PEAR\isError().

{
if ($escape_wildcards) {
$text = $this->escapePattern($text);
}
return $connection;
}
if (version_compare(PHP_VERSION, '5.2.0RC5', '>=')) {
$text = @pg_escape_string($connection, $text);
} else {
$text = @pg_escape_string($text);
}
return $text;
}

+ Here is the call graph for this function:

MDB2_Driver_pgsql::getSequenceName (   $sqn)

adds sequence name formatting to a sequence name

Parameters
stringname of the sequence
Returns
string formatted sequence name

public

Reimplemented from MDB2_Driver_Common.

Definition at line 942 of file pgsql.php.

References $query, PEAR\isError(), MDB2_Driver_Common\queryOne(), and MDB2_Driver_Common\quote().

Referenced by currID(), lastInsertID(), and nextID().

{
list($table, $field) = explode('_', $sqn);
$query = "SELECT substring((SELECT substring(pg_get_expr(d.adbin, d.adrelid) for 128)
FROM pg_attrdef d
WHERE d.adrelid = a.attrelid
AND d.adnum = a.attnum
AND a.atthasdef
) FROM 'nextval[^\']*\'([^\']*)')
FROM pg_attribute a
LEFT JOIN pg_class c ON c.oid = a.attrelid
LEFT JOIN pg_attrdef d ON d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef
WHERE (c.relname = ".$this->quote($sqn, 'text');
if (!empty($field)) {
$query .= " OR (c.relname = ".$this->quote($table, 'text')." AND a.attname = ".$this->quote($field, 'text').")";
}
$query .= " )
AND NOT a.attisdropped
AND a.attnum > 0
AND pg_get_expr(d.adbin, d.adrelid) LIKE 'nextval%'
ORDER BY a.attnum";
$seqname = $this->queryOne($query);
if (!PEAR::isError($seqname) && !empty($seqname) && is_string($seqname)) {
return $seqname;
}
return sprintf($this->options['seqname_format'],
preg_replace('/[^\w\$.]/i', '_', $sqn));
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_pgsql::getServerVersion (   $native = false)

return version information about the server

Parameters
bool$nativedetermines if the raw version string should be returned
Returns
mixed array/string with version information or MDB2 error object public

Reimplemented from MDB2_Driver_Common.

Definition at line 733 of file pgsql.php.

References MDB2_Driver_Common\$connected_server_info, $query, PEAR\isError(), and MDB2_Driver_Common\queryOne().

{
$query = 'SHOW SERVER_VERSION';
if ($this->connected_server_info) {
} else {
$server_info = $this->queryOne($query, 'text');
if (PEAR::isError($server_info)) {
return $server_info;
}
}
// cache server_info
$this->connected_server_info = $server_info;
if (!$native && !PEAR::isError($server_info)) {
$tmp = explode('.', $server_info, 3);
if (empty($tmp[2])
&& isset($tmp[1])
&& preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)
) {
$server_info = array(
'major' => $tmp[0],
'minor' => $tmp2[1],
'patch' => null,
'extra' => $tmp2[2],
'native' => $server_info,
);
} else {
$server_info = array(
'major' => isset($tmp[0]) ? $tmp[0] : null,
'minor' => isset($tmp[1]) ? $tmp[1] : null,
'patch' => isset($tmp[2]) ? $tmp[2] : null,
'extra' => null,
'native' => $server_info,
);
}
}
return $server_info;
}

+ Here is the call graph for this function:

MDB2_Driver_pgsql::lastInsertID (   $table = null,
  $field = null 
)

Returns the autoincrement ID if supported or $id or fetches the current ID in a sequence called: $table.

(empty($field) ? '' : '_'.$field)

Parameters
string$tablename of the table into which a new row was inserted
string$fieldname of the field into which a new row was inserted
Returns
mixed MDB2 Error Object or id public

Reimplemented from MDB2_Driver_Common.

Definition at line 1018 of file pgsql.php.

References getSequenceName(), and MDB2_Driver_Common\queryOne().

{
if (empty($table) && empty($field)) {
return $this->queryOne('SELECT lastval()', 'integer');
}
$seq = $table.(empty($field) ? '' : '_'.$field);
$sequence_name = $this->getSequenceName($seq);
return $this->queryOne("SELECT currval('$sequence_name')", 'integer');
}

+ Here is the call graph for this function:

MDB2_Driver_pgsql::nextID (   $seq_name,
  $ondemand = true 
)

Returns the next free id of a sequence.

Parameters
string$seq_namename of the sequence
boolean$ondemandwhen true the sequence is automatic created, if it not exists
Returns
mixed MDB2 Error Object or id public

Reimplemented from MDB2_Driver_Common.

Definition at line 985 of file pgsql.php.

References $query, $result, PEAR\expectError(), getSequenceName(), PEAR\isError(), MDB2_Driver_Common\loadModule(), MDB2_ERROR_NOSUCHTABLE, PEAR\popExpect(), MDB2_Driver_Common\queryOne(), MDB2_Driver_Common\quoteIdentifier(), and MDB2_Driver_Common\raiseError().

{
$sequence_name = $this->quoteIdentifier($this->getSequenceName($seq_name), true);
$query = "SELECT NEXTVAL('$sequence_name')";
$result = $this->queryOne($query, 'integer');
$this->popExpect();
if ($ondemand && $result->getCode() == MDB2_ERROR_NOSUCHTABLE) {
$this->loadModule('Manager', null, true);
$result = $this->manager->createSequence($seq_name);
return $this->raiseError($result, null, null,
'on demand sequence could not be created', __FUNCTION__);
}
return $this->nextId($seq_name, false);
}
}
return $result;
}

+ Here is the call graph for this function:

& MDB2_Driver_pgsql::prepare (   $query,
  $types = null,
  $result_types = null,
  $lobs = array() 
)

Prepares a query for multiple execution with execute().

With some database backends, this is emulated. prepare() requires a generic query as string like 'INSERT INTO numbers VALUES(?,?)' or 'INSERT INTO numbers VALUES(:foo,:bar)'. The ? and :[a-zA-Z] and are placeholders which can be set using bindParam() and the query can be send off using the execute() method.

Parameters
string$querythe query to prepare
mixed$typesarray that contains the types of the placeholders
mixed$result_typesarray that contains the types of the columns in the result set or MDB2_PREPARE_RESULT, if set to MDB2_PREPARE_MANIP the query is handled as a manipulation query
mixed$lobskey (field) value (parameter) pair for all lob placeholders
Returns
mixed resource handle for the prepared query on success, a MDB2 error on failure public
See Also
bindParam, execute

Reimplemented from MDB2_Driver_Common.

Definition at line 795 of file pgsql.php.

References MDB2_Driver_Common\$connection, MDB2_Driver_Common\$limit, MDB2_Driver_Common\$offset, $query, $result, _doQuery(), _modifyQuery(), MDB2_Driver_Common\_skipDelimitedStrings(), MDB2_Driver_Common\debug(), MDB2_Driver_Common\getConnection(), PEAR\isError(), MDB2_Driver_Common\loadModule(), MDB2_ERROR_SYNTAX, MDB2_PREPARE_MANIP, and MDB2_Driver_Common\raiseError().

{
if ($this->options['emulate_prepared']) {
$obj =& parent::prepare($query, $types, $result_types, $lobs);
return $obj;
}
$is_manip = ($result_types === MDB2_PREPARE_MANIP);
$this->offset = $this->limit = 0;
$result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
if ($result) {
return $result;
}
}
$pgtypes = function_exists('pg_prepare') ? false : array();
if ($pgtypes !== false && !empty($types)) {
$this->loadModule('Datatype', null, true);
}
$query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
$placeholder_type_guess = $placeholder_type = null;
$question = '?';
$colon = ':';
$positions = array();
$position = $parameter = 0;
while ($position < strlen($query)) {
$q_position = strpos($query, $question, $position);
$c_position = strpos($query, $colon, $position);
if ($q_position && $c_position) {
$p_position = min($q_position, $c_position);
} elseif ($q_position) {
$p_position = $q_position;
} elseif ($c_position) {
$p_position = $c_position;
} else {
break;
}
if (is_null($placeholder_type)) {
$placeholder_type_guess = $query[$p_position];
}
$new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
if (PEAR::isError($new_pos)) {
return $new_pos;
}
if ($new_pos != $position) {
$position = $new_pos;
continue; //evaluate again starting from the new position
}
if ($query[$position] == $placeholder_type_guess) {
if (is_null($placeholder_type)) {
$placeholder_type = $query[$p_position];
$question = $colon = $placeholder_type;
if (!empty($types) && is_array($types)) {
if ($placeholder_type == ':') {
} else {
$types = array_values($types);
}
}
}
if ($placeholder_type_guess == '?') {
$length = 1;
$name = $parameter;
} else {
$name = preg_replace('/^.{'.($position+1).'}([a-z0-9_]+).*$/si', '\\1', $query);
if ($name === '') {
$err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
'named parameter with an empty name', __FUNCTION__);
return $err;
}
$length = strlen($name) + 1;
}
if ($pgtypes !== false) {
if (is_array($types) && array_key_exists($name, $types)) {
$pgtypes[] = $this->datatype->mapPrepareDatatype($types[$name]);
} elseif (is_array($types) && array_key_exists($parameter, $types)) {
$pgtypes[] = $this->datatype->mapPrepareDatatype($types[$parameter]);
} else {
$pgtypes[] = 'text';
}
}
if (($key_parameter = array_search($name, $positions))) {
$next_parameter = 1;
foreach ($positions as $key => $value) {
if ($key_parameter == $key) {
break;
}
++$next_parameter;
}
} else {
++$parameter;
$next_parameter = $parameter;
$positions[] = $name;
}
$query = substr_replace($query, '$'.$parameter, $position, $length);
$position = $p_position + strlen($parameter);
} else {
$position = $p_position;
}
}
return $connection;
}
$statement_name = sprintf($this->options['statement_format'], $this->phptype, md5(time() + rand()));
$statement_name = strtolower($statement_name);
if ($pgtypes === false) {
$result = @pg_prepare($connection, $statement_name, $query);
if (!$result) {
$err =& $this->raiseError(null, null, null,
'Unable to create prepared statement handle', __FUNCTION__);
return $err;
}
} else {
$types_string = '';
if ($pgtypes) {
$types_string = ' ('.implode(', ', $pgtypes).') ';
}
$query = 'PREPARE '.$statement_name.$types_string.' AS '.$query;
$statement =& $this->_doQuery($query, true, $connection);
if (PEAR::isError($statement)) {
return $statement;
}
}
$class_name = 'MDB2_Statement_'.$this->phptype;
$obj =& new $class_name($this, $statement_name, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
$this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
return $obj;
}

+ Here is the call graph for this function:

MDB2_Driver_pgsql::rollback (   $savepoint = null)

Cancel any database changes done during a transaction or since a specific savepoint that is in progress.

This function may only be called when auto-committing is disabled, otherwise it will fail. Therefore, a new transaction is implicitly started after canceling the pending changes.

Parameters
stringname of a savepoint to rollback to
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Reimplemented from MDB2_Driver_Common.

Definition at line 296 of file pgsql.php.

References $query, $result, _doQuery(), MDB2_Driver_Common\debug(), PEAR\isError(), MDB2_ERROR_INVALID, MDB2_OK, and MDB2_Driver_Common\raiseError().

Referenced by disconnect().

{
$this->debug('Rolling back transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
if (!$this->in_transaction) {
return $this->raiseError(MDB2_ERROR_INVALID, null, null,
'rollback cannot be done changes are auto committed', __FUNCTION__);
}
if (!is_null($savepoint)) {
$query = 'ROLLBACK TO SAVEPOINT '.$savepoint;
return $this->_doQuery($query, true);
}
$query = 'ROLLBACK';
$result =& $this->_doQuery($query, true);
return $result;
}
$this->in_transaction = false;
return MDB2_OK;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_pgsql::setCharset (   $charset,
  $connection = null 
)

Set the charset on the current connection.

Parameters
stringcharset
resourceconnection handle
Returns
true on success, MDB2 Error Object on failure

Reimplemented from MDB2_Driver_Common.

Definition at line 494 of file pgsql.php.

References MDB2_Driver_Common\$connection, $result, MDB2_Driver_Common\getConnection(), PEAR\isError(), MDB2_OK, and MDB2_Driver_Common\raiseError().

Referenced by _doConnect().

{
if (is_null($connection)) {
return $connection;
}
}
$result = @pg_set_client_encoding($connection, $charset);
if ($result == -1) {
return $this->raiseError(null, null, null,
'Unable to set client charset: '.$charset, __FUNCTION__);
}
return MDB2_OK;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Driver_pgsql::setTransactionIsolation (   $isolation)

Set the transacton isolation level.

Parameters
stringstandard isolation level READ UNCOMMITTED (allows dirty reads) READ COMMITTED (prevents dirty reads) REPEATABLE READ (prevents nonrepeatable reads) SERIALIZABLE (prevents phantom reads)
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Since
2.1.1

Definition at line 333 of file pgsql.php.

References $query, _doQuery(), MDB2_Driver_Common\debug(), MDB2_ERROR_UNSUPPORTED, and MDB2_Driver_Common\raiseError().

{
$this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true));
switch ($isolation) {
case 'READ UNCOMMITTED':
case 'READ COMMITTED':
case 'REPEATABLE READ':
case 'SERIALIZABLE':
break;
default:
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'isolation level is not supported: '.$isolation, __FUNCTION__);
}
$query = "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL $isolation";
return $this->_doQuery($query, true);
}

+ Here is the call graph for this function:

& MDB2_Driver_pgsql::standaloneQuery (   $query,
  $types = null,
  $is_manip = false 
)

execute a query as DBA

Parameters
string$querythe SQL query
mixed$typesarray that contains the types of the columns in the result set
boolean$is_manipif the query is a manipulation query
Returns
mixed MDB2_OK on success, a MDB2 error on failure public

Reimplemented from MDB2_Driver_Common.

Definition at line 559 of file pgsql.php.

References MDB2_Driver_Common\$connection, MDB2_Driver_Common\$limit, MDB2_Driver_Common\$offset, $query, $result, _affectedRows(), _doConnect(), _doQuery(), _modifyQuery(), MDB2_Driver_Common\_wrapResult(), PEAR\isError(), MDB2_ERROR_CONNECT_FAILED, and MDB2_Driver_Common\raiseError().

{
$connection = $this->_doConnect('template1', false);
$err =& $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null,
'Cannot connect to template1', __FUNCTION__);
return $err;
}
$this->offset = $this->limit = 0;
$query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
$result =& $this->_doQuery($query, $is_manip, $connection, false);
@pg_close($connection);
return $result;
}
if ($is_manip) {
$affected_rows = $this->_affectedRows($connection, $result);
return $affected_rows;
}
$result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
return $result;
}

+ Here is the call graph for this function:

Field Documentation

MDB2_Driver_pgsql::$identifier_quoting = array('start' => '"', 'end' => '"', 'escape' => '"')

Definition at line 60 of file pgsql.php.

MDB2_Driver_pgsql::$string_quoting = array('start' => "'", 'end' => "'", 'escape' => "'", 'escape_pattern' => '\\')

Definition at line 58 of file pgsql.php.


The documentation for this class was generated from the following file: