📄 pgsql.php
字号:
// {{{ nextResult() /** * Move the internal pgsql result pointer to the next available result * * @param a valid fbsql result resource * * @access public * * @return true if a result is available otherwise return false */ function nextResult($result) { return false; } // }}} // {{{ fetchInto() /** * Places a row from the result set into the given array * * Formating of the array and the data therein are configurable. * See DB_result::fetchInto() for more information. * * This method is not meant to be called directly. Use * DB_result::fetchInto() instead. It can't be declared "protected" * because DB_result is a separate object. * * @param resource $result the query result resource * @param array $arr the referenced array to put the data in * @param int $fetchmode how the resulting array should be indexed * @param int $rownum the row number to fetch (0 = first row) * * @return mixed DB_OK on success, NULL when the end of a result set is * reached or on failure * * @see DB_result::fetchInto() */ function fetchInto($result, &$arr, $fetchmode, $rownum = null) { $result_int = (int)$result; $rownum = ($rownum !== null) ? $rownum : $this->row[$result_int]; if ($rownum >= $this->_num_rows[$result_int]) { return null; } if ($fetchmode & DB_FETCHMODE_ASSOC) { $arr = @pg_fetch_array($result, $rownum, PGSQL_ASSOC); if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { $arr = array_change_key_case($arr, CASE_LOWER); } } else { $arr = @pg_fetch_row($result, $rownum); } if (!$arr) { return null; } if ($this->options['portability'] & DB_PORTABILITY_RTRIM) { $this->_rtrimArrayValues($arr); } if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { $this->_convertNullArrayValuesToEmpty($arr); } $this->row[$result_int] = ++$rownum; return DB_OK; } // }}} // {{{ freeResult() /** * Deletes the result set and frees the memory occupied by the result set * * This method is not meant to be called directly. Use * DB_result::free() instead. It can't be declared "protected" * because DB_result is a separate object. * * @param resource $result PHP's query result resource * * @return bool TRUE on success, FALSE if $result is invalid * * @see DB_result::free() */ function freeResult($result) { if (is_resource($result)) { unset($this->row[(int)$result]); unset($this->_num_rows[(int)$result]); $this->affected = 0; return @pg_freeresult($result); } return false; } // }}} // {{{ quote() /** * @deprecated Deprecated in release 1.6.0 * @internal */ function quote($str) { return $this->quoteSmart($str); } // }}} // {{{ quoteSmart() /** * Formats input so it can be safely used in a query * * @param mixed $in the data to be formatted * * @return mixed the formatted data. The format depends on the input's * PHP type: * + null = the string <samp>NULL</samp> * + boolean = string <samp>TRUE</samp> or <samp>FALSE</samp> * + integer or double = the unquoted number * + other (including strings and numeric strings) = * the data escaped according to MySQL's settings * then encapsulated between single quotes * * @see DB_common::quoteSmart() * @since Method available since Release 1.6.0 */ function quoteSmart($in) { if (is_int($in) || is_double($in)) { return $in; } elseif (is_bool($in)) { return $in ? 'TRUE' : 'FALSE'; } elseif (is_null($in)) { return 'NULL'; } else { return "'" . $this->escapeSimple($in) . "'"; } } // }}} // {{{ escapeSimple() /** * Escapes a string according to the current DBMS's standards * * {@internal PostgreSQL treats a backslash as an escape character, * so they are escaped as well. * * Not using pg_escape_string() yet because it requires PostgreSQL * to be at version 7.2 or greater.}} * * @param string $str the string to be escaped * * @return string the escaped string * * @see DB_common::quoteSmart() * @since Method available since Release 1.6.0 */ function escapeSimple($str) { return str_replace("'", "''", str_replace('\\', '\\\\', $str)); } // }}} // {{{ numCols() /** * Gets the number of columns in a result set * * This method is not meant to be called directly. Use * DB_result::numCols() instead. It can't be declared "protected" * because DB_result is a separate object. * * @param resource $result PHP's query result resource * * @return int the number of columns. A DB_Error object on failure. * * @see DB_result::numCols() */ function numCols($result) { $cols = @pg_numfields($result); if (!$cols) { return $this->pgsqlRaiseError(); } return $cols; } // }}} // {{{ numRows() /** * Gets the number of rows in a result set * * This method is not meant to be called directly. Use * DB_result::numRows() instead. It can't be declared "protected" * because DB_result is a separate object. * * @param resource $result PHP's query result resource * * @return int the number of rows. A DB_Error object on failure. * * @see DB_result::numRows() */ function numRows($result) { $rows = @pg_numrows($result); if ($rows === null) { return $this->pgsqlRaiseError(); } return $rows; } // }}} // {{{ autoCommit() /** * Enables or disables automatic commits * * @param bool $onoff true turns it on, false turns it off * * @return int DB_OK on success. A DB_Error object if the driver * doesn't support auto-committing transactions. */ function autoCommit($onoff = false) { // XXX if $this->transaction_opcount > 0, we should probably // issue a warning here. $this->autocommit = $onoff ? true : false; return DB_OK; } // }}} // {{{ commit() /** * Commits the current transaction * * @return int DB_OK on success. A DB_Error object on failure. */ function commit() { if ($this->transaction_opcount > 0) { // (disabled) hack to shut up error messages from libpq.a //@fclose(@fopen("php://stderr", "w")); $result = @pg_exec($this->connection, 'end;'); $this->transaction_opcount = 0; if (!$result) { return $this->pgsqlRaiseError(); } } return DB_OK; } // }}} // {{{ rollback() /** * Reverts the current transaction * * @return int DB_OK on success. A DB_Error object on failure. */ function rollback() { if ($this->transaction_opcount > 0) { $result = @pg_exec($this->connection, 'abort;'); $this->transaction_opcount = 0; if (!$result) { return $this->pgsqlRaiseError(); } } return DB_OK; } // }}} // {{{ affectedRows() /** * Determines the number of rows affected by a data maniuplation query * * 0 is returned for queries that don't manipulate data. * * @return int the number of rows. A DB_Error object on failure. */ function affectedRows() { return $this->affected; } // }}} // {{{ nextId() /** * Returns the next free id in a sequence * * @param string $seq_name name of the sequence * @param boolean $ondemand when true, the seqence is automatically * created if it does not exist * * @return int the next id number in the sequence. * A DB_Error object on failure. * * @see DB_common::nextID(), DB_common::getSequenceName(), * DB_pgsql::createSequence(), DB_pgsql::dropSequence() */ function nextId($seq_name, $ondemand = true) { $seqname = $this->getSequenceName($seq_name); $repeat = false; do { $this->pushErrorHandling(PEAR_ERROR_RETURN); $result =& $this->query("SELECT NEXTVAL('${seqname}')"); $this->popErrorHandling(); if ($ondemand && DB::isError($result) && $result->getCode() == DB_ERROR_NOSUCHTABLE) { $repeat = true; $this->pushErrorHandling(PEAR_ERROR_RETURN); $result = $this->createSequence($seq_name); $this->popErrorHandling(); if (DB::isError($result)) { return $this->raiseError($result); } } else { $repeat = false; } } while ($repeat); if (DB::isError($result)) { return $this->raiseError($result); } $arr = $result->fetchRow(DB_FETCHMODE_ORDERED); $result->free(); return $arr[0]; } // }}} // {{{ createSequence() /** * Creates a new sequence * * @param string $seq_name name of the new sequence * * @return int DB_OK on success. A DB_Error object on failure. * * @see DB_common::createSequence(), DB_common::getSequenceName(), * DB_pgsql::nextID(), DB_pgsql::dropSequence() */ function createSequence($seq_name) { $seqname = $this->getSequenceName($seq_name); $result = $this->query("CREATE SEQUENCE ${seqname}"); return $result; } // }}} // {{{ dropSequence() /** * Deletes a sequence * * @param string $seq_name name of the sequence to be deleted * * @return int DB_OK on success. A DB_Error object on failure. * * @see DB_common::dropSequence(), DB_common::getSequenceName(), * DB_pgsql::nextID(), DB_pgsql::createSequence()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -