ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
MDB2_Driver_pgsql Class Reference
+ Inheritance diagram for MDB2_Driver_pgsql:
+ Collaboration diagram for MDB2_Driver_pgsql:

Public Member Functions

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

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

◆ __construct()

MDB2_Driver_pgsql::__construct ( )

Constructor.

Reimplemented from MDB2_Driver_Common.

Definition at line 67 of file pgsql.php.

68 {
69 parent::__construct();
70
71 $this->phptype = 'pgsql';
72 $this->dbsyntax = 'pgsql';
73
74 $this->supported['sequences'] = true;
75 $this->supported['indexes'] = true;
76 $this->supported['affected_rows'] = true;
77 $this->supported['summary_functions'] = true;
78 $this->supported['order_by_text'] = true;
79 $this->supported['transactions'] = true;
80 $this->supported['savepoints'] = true;
81 $this->supported['current_id'] = true;
82 $this->supported['limit_queries'] = true;
83 $this->supported['LOBs'] = true;
84 $this->supported['replace'] = 'emulated';
85 $this->supported['sub_selects'] = true;
86 $this->supported['auto_increment'] = 'emulated';
87 $this->supported['primary_key'] = true;
88 $this->supported['result_introspection'] = true;
89 $this->supported['prepared_statements'] = true;
90 $this->supported['identifier_quoting'] = true;
91 $this->supported['pattern_escaping'] = true;
92 $this->supported['new_link'] = true;
93
94 $this->options['multi_query'] = false;
95 }

Member Function Documentation

◆ _affectedRows()

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 @access private

Reimplemented from MDB2_Driver_Common.

Definition at line 650 of file pgsql.php.

651 {
652 if (is_null($connection)) {
653 $connection = $this->getConnection();
655 return $connection;
656 }
657 }
658 return @pg_affected_rows($result);
659 }
$result
getConnection()
Returns a native connection.
Definition: MDB2.php:1733
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279

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

Referenced by standaloneQuery().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _doConnect()

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 @access protected

Definition at line 360 of file pgsql.php.

361 {
362 if ($database_name == '') {
363 $database_name = 'template1';
364 }
365
366 $protocol = $this->dsn['protocol'] ? $this->dsn['protocol'] : 'tcp';
367
368 $params = array('');
369 if ($protocol == 'tcp') {
370 if ($this->dsn['hostspec']) {
371 $params[0].= 'host=' . $this->dsn['hostspec'];
372 }
373 if ($this->dsn['port']) {
374 $params[0].= ' port=' . $this->dsn['port'];
375 }
376 } elseif ($protocol == 'unix') {
377 // Allow for pg socket in non-standard locations.
378 if ($this->dsn['socket']) {
379 $params[0].= 'host=' . $this->dsn['socket'];
380 }
381 if ($this->dsn['port']) {
382 $params[0].= ' port=' . $this->dsn['port'];
383 }
384 }
385 if ($database_name) {
386 $params[0].= ' dbname=\'' . addslashes($database_name) . '\'';
387 }
388 if ($this->dsn['username']) {
389 $params[0].= ' user=\'' . addslashes($this->dsn['username']) . '\'';
390 }
391 if ($this->dsn['password']) {
392 $params[0].= ' password=\'' . addslashes($this->dsn['password']) . '\'';
393 }
394 if (!empty($this->dsn['options'])) {
395 $params[0].= ' options=' . $this->dsn['options'];
396 }
397 if (!empty($this->dsn['tty'])) {
398 $params[0].= ' tty=' . $this->dsn['tty'];
399 }
400 if (!empty($this->dsn['connect_timeout'])) {
401 $params[0].= ' connect_timeout=' . $this->dsn['connect_timeout'];
402 }
403 if (!empty($this->dsn['sslmode'])) {
404 $params[0].= ' sslmode=' . $this->dsn['sslmode'];
405 }
406 if (!empty($this->dsn['service'])) {
407 $params[0].= ' service=' . $this->dsn['service'];
408 }
409
410 if (!empty($this->dsn['new_link'])
411 && ($this->dsn['new_link'] == 'true' || $this->dsn['new_link'] === true))
412 {
413 if (version_compare(phpversion(), '4.3.0', '>=')) {
414 $params[] = PGSQL_CONNECT_FORCE_NEW;
415 }
416 }
417
418 $connect_function = $persistent ? 'pg_pconnect' : 'pg_connect';
419
420 $connection = @call_user_func_array($connect_function, $params);
421 if (!$connection) {
422 return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null,
423 'unable to establish a connection', __FUNCTION__);
424 }
425
426 if (empty($this->dsn['disable_iso_date'])) {
427 if (!@pg_query($connection, "SET SESSION DATESTYLE = 'ISO'")) {
428 return $this->raiseError(null, null, null,
429 'Unable to set date style to iso', __FUNCTION__);
430 }
431 }
432
433 if (!empty($this->dsn['charset'])) {
434 $result = $this->setCharset($this->dsn['charset'], $connection);
435 if (PEAR::isError($result)) {
436 return $result;
437 }
438 }
439
440 return $connection;
441 }
const MDB2_ERROR_CONNECT_FAILED
Definition: MDB2.php:91
& raiseError($code=null, $mode=null, $options=null, $userinfo=null, $method=null)
This method is used to communicate an error and invoke error callbacks etc.
Definition: MDB2.php:1407
setCharset($charset, $connection=null)
Set the charset on the current connection.
Definition: pgsql.php:494
$params
Definition: example_049.php:96

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

Referenced by connect(), and standaloneQuery().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _doQuery()

& 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 @access protected

Reimplemented from MDB2_Driver_Common.

Definition at line 599 of file pgsql.php.

600 {
601 $this->last_query = $query;
602 $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
603 if ($result) {
604 if (PEAR::isError($result)) {
605 return $result;
606 }
607 $query = $result;
608 }
609 if ($this->options['disable_query']) {
610 $result = $is_manip ? 0 : null;
611 return $result;
612 }
613
614 if (is_null($connection)) {
615 $connection = $this->getConnection();
617 return $connection;
618 }
619 }
620
621 $function = $this->options['multi_query'] ? 'pg_send_query' : 'pg_query';
622 $result = @$function($connection, $query);
623 if (!$result) {
624 $err =& $this->raiseError(null, null, null,
625 'Could not execute statement', __FUNCTION__);
626 return $err;
627 } elseif ($this->options['multi_query']) {
628 if (!($result = @pg_get_result($connection))) {
629 $err =& $this->raiseError(null, null, null,
630 'Could not get the first result from a multi query', __FUNCTION__);
631 return $err;
632 }
633 }
634
635 $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'post', 'result' => $result));
636 return $result;
637 }
debug($message, $scope='', $context=array())
set a debug message
Definition: MDB2.php:1582

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _modifyManipQuery()

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 @access protected

Definition at line 703 of file pgsql.php.

704 {
705 $pos = strpos(strtolower($query), 'where');
706 $where = $pos ? substr($query, $pos) : '';
707
708 $manip_clause = '(\bDELETE\b\s+(?:\*\s+)?\bFROM\b|\bUPDATE\b)';
709 $from_clause = '([\w\.]+)';
710 $where_clause = '(?:(.*)\bWHERE\b\s+(.*))|(.*)';
711 $pattern = '/^'. $manip_clause . '\s+' . $from_clause .'(?:\s)*(?:'. $where_clause .')?$/i';
712 $matches = preg_match($pattern, $query, $match);
713 if ($matches) {
714 $manip = $match[1];
715 $from = $match[2];
716 $what = (count($matches) == 6) ? $match[5] : $match[3];
717 return $manip.' '.$from.' '.$what.' WHERE ctid=(SELECT ctid FROM '.$from.' '.$where.' LIMIT '.$limit.')';
718 }
719 //return error?
720 return $query;
721 }

References MDB2_Driver_Common\$limit, and $query.

Referenced by _modifyQuery().

+ Here is the caller graph for this function:

◆ _modifyQuery()

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 @access protected

Reimplemented from MDB2_Driver_Common.

Definition at line 674 of file pgsql.php.

675 {
676 if ($limit > 0
677 && !preg_match('/LIMIT\s*\d(?:\s*(?:,|OFFSET)\s*\d+)?(?:[^\‍)]*)?$/i', $query)
678 ) {
679 $query = rtrim($query);
680 if (substr($query, -1) == ';') {
681 $query = substr($query, 0, -1);
682 }
683 if ($is_manip) {
685 } else {
686 $query.= " LIMIT $limit OFFSET $offset";
687 }
688 }
689 return $query;
690 }
_modifyManipQuery($query, $limit)
Changes a manip query string for various DBMS specific reasons.
Definition: pgsql.php:703

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

Referenced by prepare(), and standaloneQuery().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ beginTransaction()

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

@access public

Reimplemented from MDB2_Driver_Common.

Definition at line 223 of file pgsql.php.

224 {
225 $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
226 if (!is_null($savepoint)) {
227 if (!$this->in_transaction) {
228 return $this->raiseError(MDB2_ERROR_INVALID, null, null,
229 'savepoint cannot be released when changes are auto committed', __FUNCTION__);
230 }
231 $query = 'SAVEPOINT '.$savepoint;
232 return $this->_doQuery($query, true);
233 } elseif ($this->in_transaction) {
234 return MDB2_OK; //nothing to do
235 }
236 if (!$this->destructor_registered && $this->opened_persistent) {
237 $this->destructor_registered = true;
238 register_shutdown_function('MDB2_closeOpenTransactions');
239 }
240 $result =& $this->_doQuery('BEGIN', true);
241 if (PEAR::isError($result)) {
242 return $result;
243 }
244 $this->in_transaction = true;
245 return MDB2_OK;
246 }
const MDB2_ERROR_INVALID
Definition: MDB2.php:75
const MDB2_OK
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these.
Definition: MDB2.php:67
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: pgsql.php:599

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

+ Here is the call graph for this function:

◆ commit()

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

@access public

Reimplemented from MDB2_Driver_Common.

Definition at line 262 of file pgsql.php.

263 {
264 $this->debug('Committing transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
265 if (!$this->in_transaction) {
266 return $this->raiseError(MDB2_ERROR_INVALID, null, null,
267 'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__);
268 }
269 if (!is_null($savepoint)) {
270 $query = 'RELEASE SAVEPOINT '.$savepoint;
271 return $this->_doQuery($query, true);
272 }
273
274 $result =& $this->_doQuery('COMMIT', true);
275 if (PEAR::isError($result)) {
276 return $result;
277 }
278 $this->in_transaction = false;
279 return MDB2_OK;
280 }

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

+ Here is the call graph for this function:

◆ connect()

MDB2_Driver_pgsql::connect ( )

Connect to the database.

Returns
true on success, MDB2 Error Object on failure @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 452 of file pgsql.php.

453 {
454 if (is_resource($this->connection)) {
455 if (count(array_diff($this->connected_dsn, $this->dsn)) == 0
456 && $this->connected_database_name == $this->database_name
457 && ($this->opened_persistent == $this->options['persistent'])
458 ) {
459 return MDB2_OK;
460 }
461 $this->disconnect(false);
462 }
463
464 if (!PEAR::loadExtension($this->phptype)) {
465 return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
466 'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__);
467 }
468
469 if ($this->database_name) {
470 $connection = $this->_doConnect($this->database_name, $this->options['persistent']);
472 return $connection;
473 }
474 $this->connection = $connection;
475 $this->connected_dsn = $this->dsn;
476 $this->connected_database_name = $this->database_name;
477 $this->opened_persistent = $this->options['persistent'];
478 $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype;
479 }
480 return MDB2_OK;
481 }
const MDB2_ERROR_NOT_FOUND
Definition: MDB2.php:71
_doConnect($database_name, $persistent=false)
Does the grunt work of connecting to the database.
Definition: pgsql.php:360
disconnect($force=true)
Log out and disconnect from the database.
Definition: pgsql.php:523
loadExtension($ext)
OS independant PHP extension load.
Definition: PEAR.php:745

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

+ Here is the call graph for this function:

◆ currID()

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 @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 1038 of file pgsql.php.

1039 {
1040 $sequence_name = $this->quoteIdentifier($this->getSequenceName($seq_name), true);
1041 return $this->queryOne("SELECT last_value FROM $sequence_name", 'integer');
1042 }
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...
Definition: MDB2.php:3203
quoteIdentifier($str, $check_option=false)
Quote a string so it can be safely used as a table or column name.
Definition: MDB2.php:1700
getSequenceName($sqn)
adds sequence name formatting to a sequence name
Definition: pgsql.php:942

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

+ Here is the call graph for this function:

◆ disconnect()

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 @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 523 of file pgsql.php.

524 {
525 if (is_resource($this->connection)) {
526 if ($this->in_transaction) {
529 $persistent = $this->options['persistent'];
530 $this->dsn = $this->connected_dsn;
531 $this->database_name = $this->connected_database_name;
532 $this->options['persistent'] = $this->opened_persistent;
533 $this->rollback();
534 $this->dsn = $dsn;
535 $this->database_name = $database_name;
536 $this->options['persistent'] = $persistent;
537 }
538
539 if (!$this->opened_persistent || $force) {
540 @pg_close($this->connection);
541 }
542 }
543 return parent::disconnect($force);
544 }
rollback($savepoint=null)
Cancel any database changes done during a transaction or since a specific savepoint that is in progre...
Definition: pgsql.php:296

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ errorInfo()

MDB2_Driver_pgsql::errorInfo (   $error = null)

This method is used to collect information about an error.

Parameters
integer$error
Returns
array @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 107 of file pgsql.php.

108 {
109 // Fall back to MDB2_ERROR if there was no mapping.
110 $error_code = MDB2_ERROR;
111
112 $native_msg = '';
113 if (is_resource($error)) {
114 $native_msg = @pg_result_error($error);
115 } elseif ($this->connection) {
116 $native_msg = @pg_last_error($this->connection);
117 if (!$native_msg && @pg_connection_status($this->connection) === PGSQL_CONNECTION_BAD) {
118 $native_msg = 'Database connection has been lost.';
119 $error_code = MDB2_ERROR_CONNECT_FAILED;
120 }
121 }
122
123 static $error_regexps;
124 if (empty($error_regexps)) {
125 $error_regexps = array(
126 '/column .* (of relation .*)?does not exist/i'
128 '/(relation|sequence|table).*does not exist|class .* not found/i'
130 '/index .* does not exist/'
132 '/relation .* already exists/i'
134 '/(divide|division) by zero$/i'
136 '/pg_atoi: error in .*: can\'t parse /i'
138 '/invalid input syntax for( type)? (integer|numeric)/i'
140 '/value .* is out of range for type \w*int/i'
142 '/integer out of range/i'
144 '/value too long for type character/i'
146 '/attribute .* not found|relation .* does not have attribute/i'
148 '/column .* specified in USING clause does not exist in (left|right) table/i'
150 '/parser: parse error at or near/i'
152 '/syntax error at/'
154 '/column reference .* is ambiguous/i'
156 '/permission denied/'
158 '/violates not-null constraint/'
160 '/violates [\w ]+ constraint/'
162 '/referential integrity violation/'
164 '/more expressions than target columns/i'
166 );
167 }
168 if (is_numeric($error) && $error < 0) {
169 $error_code = $error;
170 } else {
171 foreach ($error_regexps as $regexp => $code) {
172 if (preg_match($regexp, $native_msg)) {
173 $error_code = $code;
174 break;
175 }
176 }
177 }
178 return array($error_code, null, $native_msg);
179 }
const MDB2_ERROR_ACCESS_VIOLATION
Definition: MDB2.php:94
const MDB2_ERROR_CONSTRAINT_NOT_NULL
Definition: MDB2.php:96
const MDB2_ERROR_SYNTAX
Definition: MDB2.php:69
const MDB2_ERROR_VALUE_COUNT_ON_ROW
Definition: MDB2.php:89
const MDB2_ERROR_INVALID_NUMBER
Definition: MDB2.php:78
const MDB2_ERROR_ALREADY_EXISTS
Definition: MDB2.php:72
const MDB2_ERROR_DIVZERO
Definition: MDB2.php:80
const MDB2_ERROR_CONSTRAINT
Definition: MDB2.php:70
const MDB2_ERROR_NOSUCHFIELD
Definition: MDB2.php:86
const MDB2_ERROR
Definition: MDB2.php:68
const MDB2_ERROR_NOSUCHTABLE
Definition: MDB2.php:85
$code
Definition: example_050.php:99

References $code, 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.

◆ escape()

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

@access public

Reimplemented from MDB2_Driver_Common.

Definition at line 195 of file pgsql.php.

196 {
197 if ($escape_wildcards) {
198 $text = $this->escapePattern($text);
199 }
200 $connection = $this->getConnection();
202 return $connection;
203 }
204 if (version_compare(PHP_VERSION, '5.2.0RC5', '>=')) {
205 $text = @pg_escape_string($connection, $text);
206 } else {
207 $text = @pg_escape_string($text);
208 }
209 return $text;
210 }
escapePattern($text)
Quotes pattern (% and _) characters in a string)
Definition: MDB2.php:1652
$text

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

+ Here is the call graph for this function:

◆ getSequenceName()

MDB2_Driver_pgsql::getSequenceName (   $sqn)

adds sequence name formatting to a sequence name

Parameters
stringname of the sequence
Returns
string formatted sequence name

@access public

Reimplemented from MDB2_Driver_Common.

Definition at line 942 of file pgsql.php.

943 {
944 list($table, $field) = explode('_', $sqn);
945 $query = "SELECT substring((SELECT substring(pg_get_expr(d.adbin, d.adrelid) for 128)
946 FROM pg_attrdef d
947 WHERE d.adrelid = a.attrelid
948 AND d.adnum = a.attnum
949 AND a.atthasdef
950 ) FROM 'nextval[^\']*\'([^\']*)')
951 FROM pg_attribute a
952 LEFT JOIN pg_class c ON c.oid = a.attrelid
953 LEFT JOIN pg_attrdef d ON d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef
954 WHERE (c.relname = ".$this->quote($sqn, 'text');
955 if (!empty($field)) {
956 $query .= " OR (c.relname = ".$this->quote($table, 'text')." AND a.attname = ".$this->quote($field, 'text').")";
957 }
958 $query .= " )
959 AND NOT a.attisdropped
960 AND a.attnum > 0
961 AND pg_get_expr(d.adbin, d.adrelid) LIKE 'nextval%'
962 ORDER BY a.attnum";
963 $seqname = $this->queryOne($query);
964 if (!PEAR::isError($seqname) && !empty($seqname) && is_string($seqname)) {
965 return $seqname;
966 }
967
968 return sprintf($this->options['seqname_format'],
969 preg_replace('/[^\w\$.]/i', '_', $sqn));
970 }
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.
Definition: MDB2.php:3009

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getServerVersion()

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 @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 733 of file pgsql.php.

734 {
735 $query = 'SHOW SERVER_VERSION';
736 if ($this->connected_server_info) {
737 $server_info = $this->connected_server_info;
738 } else {
739 $server_info = $this->queryOne($query, 'text');
740 if (PEAR::isError($server_info)) {
741 return $server_info;
742 }
743 }
744 // cache server_info
745 $this->connected_server_info = $server_info;
746 if (!$native && !PEAR::isError($server_info)) {
747 $tmp = explode('.', $server_info, 3);
748 if (empty($tmp[2])
749 && isset($tmp[1])
750 && preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)
751 ) {
752 $server_info = array(
753 'major' => $tmp[0],
754 'minor' => $tmp2[1],
755 'patch' => null,
756 'extra' => $tmp2[2],
757 'native' => $server_info,
758 );
759 } else {
760 $server_info = array(
761 'major' => isset($tmp[0]) ? $tmp[0] : null,
762 'minor' => isset($tmp[1]) ? $tmp[1] : null,
763 'patch' => isset($tmp[2]) ? $tmp[2] : null,
764 'extra' => null,
765 'native' => $server_info,
766 );
767 }
768 }
769 return $server_info;
770 }

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

+ Here is the call graph for this function:

◆ lastInsertID()

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 @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 1018 of file pgsql.php.

1019 {
1020 if (empty($table) && empty($field)) {
1021 return $this->queryOne('SELECT lastval()', 'integer');
1022 }
1023 $seq = $table.(empty($field) ? '' : '_'.$field);
1024 $sequence_name = $this->getSequenceName($seq);
1025 return $this->queryOne("SELECT currval('$sequence_name')", 'integer');
1026 }

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

+ Here is the call graph for this function:

◆ nextID()

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 @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 985 of file pgsql.php.

986 {
987 $sequence_name = $this->quoteIdentifier($this->getSequenceName($seq_name), true);
988 $query = "SELECT NEXTVAL('$sequence_name')";
990 $result = $this->queryOne($query, 'integer');
991 $this->popExpect();
992 if (PEAR::isError($result)) {
993 if ($ondemand && $result->getCode() == MDB2_ERROR_NOSUCHTABLE) {
994 $this->loadModule('Manager', null, true);
995 $result = $this->manager->createSequence($seq_name);
996 if (PEAR::isError($result)) {
997 return $this->raiseError($result, null, null,
998 'on demand sequence could not be created', __FUNCTION__);
999 }
1000 return $this->nextId($seq_name, false);
1001 }
1002 }
1003 return $result;
1004 }
& loadModule($module, $property=null, $phptype_specific=null)
loads a module
Definition: MDB2.php:1840
popExpect()
This method pops one element off the expected error codes stack.
Definition: PEAR.php:409
expectError($code=' *')
This method is used to tell which errors you expect to get.
Definition: PEAR.php:390

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

+ Here is the call graph for this function:

◆ prepare()

& 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 @access public
See also
bindParam, execute

Reimplemented from MDB2_Driver_Common.

Definition at line 795 of file pgsql.php.

796 {
797 if ($this->options['emulate_prepared']) {
798 $obj =& parent::prepare($query, $types, $result_types, $lobs);
799 return $obj;
800 }
801 $is_manip = ($result_types === MDB2_PREPARE_MANIP);
804 $this->offset = $this->limit = 0;
805 $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
806 if ($result) {
807 if (PEAR::isError($result)) {
808 return $result;
809 }
810 $query = $result;
811 }
812 $pgtypes = function_exists('pg_prepare') ? false : array();
813 if ($pgtypes !== false && !empty($types)) {
814 $this->loadModule('Datatype', null, true);
815 }
816 $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
817 $placeholder_type_guess = $placeholder_type = null;
818 $question = '?';
819 $colon = ':';
820 $positions = array();
821 $position = $parameter = 0;
822 while ($position < strlen($query)) {
823 $q_position = strpos($query, $question, $position);
824 $c_position = strpos($query, $colon, $position);
825 if ($q_position && $c_position) {
826 $p_position = min($q_position, $c_position);
827 } elseif ($q_position) {
828 $p_position = $q_position;
829 } elseif ($c_position) {
830 $p_position = $c_position;
831 } else {
832 break;
833 }
834 if (is_null($placeholder_type)) {
835 $placeholder_type_guess = $query[$p_position];
836 }
837
838 $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
839 if (PEAR::isError($new_pos)) {
840 return $new_pos;
841 }
842 if ($new_pos != $position) {
843 $position = $new_pos;
844 continue; //evaluate again starting from the new position
845 }
846
847 if ($query[$position] == $placeholder_type_guess) {
848 if (is_null($placeholder_type)) {
849 $placeholder_type = $query[$p_position];
850 $question = $colon = $placeholder_type;
851 if (!empty($types) && is_array($types)) {
852 if ($placeholder_type == ':') {
853 } else {
854 $types = array_values($types);
855 }
856 }
857 }
858 if ($placeholder_type_guess == '?') {
859 $length = 1;
860 $name = $parameter;
861 } else {
862 $name = preg_replace('/^.{'.($position+1).'}([a-z0-9_]+).*$/si', '\\1', $query);
863 if ($name === '') {
864 $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
865 'named parameter with an empty name', __FUNCTION__);
866 return $err;
867 }
868 $length = strlen($name) + 1;
869 }
870 if ($pgtypes !== false) {
871 if (is_array($types) && array_key_exists($name, $types)) {
872 $pgtypes[] = $this->datatype->mapPrepareDatatype($types[$name]);
873 } elseif (is_array($types) && array_key_exists($parameter, $types)) {
874 $pgtypes[] = $this->datatype->mapPrepareDatatype($types[$parameter]);
875 } else {
876 $pgtypes[] = 'text';
877 }
878 }
879 if (($key_parameter = array_search($name, $positions))) {
880 $next_parameter = 1;
881 foreach ($positions as $key => $value) {
882 if ($key_parameter == $key) {
883 break;
884 }
885 ++$next_parameter;
886 }
887 } else {
888 ++$parameter;
889 $next_parameter = $parameter;
890 $positions[] = $name;
891 }
892 $query = substr_replace($query, '$'.$parameter, $position, $length);
893 $position = $p_position + strlen($parameter);
894 } else {
895 $position = $p_position;
896 }
897 }
898 $connection = $this->getConnection();
900 return $connection;
901 }
902
903 $statement_name = sprintf($this->options['statement_format'], $this->phptype, md5(time() + rand()));
904 $statement_name = strtolower($statement_name);
905 if ($pgtypes === false) {
906 $result = @pg_prepare($connection, $statement_name, $query);
907 if (!$result) {
908 $err =& $this->raiseError(null, null, null,
909 'Unable to create prepared statement handle', __FUNCTION__);
910 return $err;
911 }
912 } else {
913 $types_string = '';
914 if ($pgtypes) {
915 $types_string = ' ('.implode(', ', $pgtypes).') ';
916 }
917 $query = 'PREPARE '.$statement_name.$types_string.' AS '.$query;
918 $statement =& $this->_doQuery($query, true, $connection);
919 if (PEAR::isError($statement)) {
920 return $statement;
921 }
922 }
923
924 $class_name = 'MDB2_Statement_'.$this->phptype;
925 $obj =& new $class_name($this, $statement_name, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
926 $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
927 return $obj;
928 }
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare()
Definition: MDB2.php:109
_skipDelimitedStrings($query, $position, $p_position)
Utility method, used by prepare() to avoid replacing placeholders within delimited strings.
Definition: MDB2.php:2963
_modifyQuery($query, $is_manip, $limit, $offset)
Changes a query string for various DBMS specific reasons.
Definition: pgsql.php:674

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

+ Here is the call graph for this function:

◆ rollback()

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

@access public

Reimplemented from MDB2_Driver_Common.

Definition at line 296 of file pgsql.php.

297 {
298 $this->debug('Rolling back transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
299 if (!$this->in_transaction) {
300 return $this->raiseError(MDB2_ERROR_INVALID, null, null,
301 'rollback cannot be done changes are auto committed', __FUNCTION__);
302 }
303 if (!is_null($savepoint)) {
304 $query = 'ROLLBACK TO SAVEPOINT '.$savepoint;
305 return $this->_doQuery($query, true);
306 }
307
308 $query = 'ROLLBACK';
309 $result =& $this->_doQuery($query, true);
310 if (PEAR::isError($result)) {
311 return $result;
312 }
313 $this->in_transaction = false;
314 return MDB2_OK;
315 }

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

Referenced by disconnect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCharset()

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.

495 {
496 if (is_null($connection)) {
497 $connection = $this->getConnection();
499 return $connection;
500 }
501 }
502
503 $result = @pg_set_client_encoding($connection, $charset);
504 if ($result == -1) {
505 return $this->raiseError(null, null, null,
506 'Unable to set client charset: '.$charset, __FUNCTION__);
507 }
508 return MDB2_OK;
509 }

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

Referenced by _doConnect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTransactionIsolation()

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

@access public

Since
2.1.1

Definition at line 333 of file pgsql.php.

334 {
335 $this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true));
336 switch ($isolation) {
337 case 'READ UNCOMMITTED':
338 case 'READ COMMITTED':
339 case 'REPEATABLE READ':
340 case 'SERIALIZABLE':
341 break;
342 default:
343 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
344 'isolation level is not supported: '.$isolation, __FUNCTION__);
345 }
346
347 $query = "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL $isolation";
348 return $this->_doQuery($query, true);
349 }
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:73

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

+ Here is the call graph for this function:

◆ standaloneQuery()

& 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 @access public

Reimplemented from MDB2_Driver_Common.

Definition at line 559 of file pgsql.php.

560 {
561 $connection = $this->_doConnect('template1', false);
563 $err =& $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null,
564 'Cannot connect to template1', __FUNCTION__);
565 return $err;
566 }
567
570 $this->offset = $this->limit = 0;
571 $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
572
573 $result =& $this->_doQuery($query, $is_manip, $connection, false);
574 @pg_close($connection);
575 if (PEAR::isError($result)) {
576 return $result;
577 }
578
579 if ($is_manip) {
580 $affected_rows = $this->_affectedRows($connection, $result);
581 return $affected_rows;
582 }
583 $result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
584 return $result;
585 }
& _wrapResult($result, $types=array(), $result_class=true, $result_wrap_class=false, $limit=null, $offset=null)
wrap a result set into the correct class
Definition: MDB2.php:2541
_affectedRows($connection, $result=null)
Returns the number of rows affected.
Definition: pgsql.php:650

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

+ Here is the call graph for this function:

Field Documentation

◆ $identifier_quoting

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

Definition at line 60 of file pgsql.php.

◆ $string_quoting

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: