Current File : /home/k/a/r/karenpetzb/www/items/category/Adapter.tar |
Http.php 0000604 00000016430 15071306214 0006173 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_File_Transfer
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: $
*/
require_once 'Zend/File/Transfer/Adapter/Abstract.php';
/**
* File transfer adapter class for the HTTP protocol
*
* @category Zend
* @package Zend_File_Transfer
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_File_Transfer_Adapter_Http extends Zend_File_Transfer_Adapter_Abstract
{
/**
* Constructor for Http File Transfers
*
* @param array $options OPTIONAL Options to set
*/
public function __construct($options = array())
{
if (ini_get('file_uploads') == false) {
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('File uploads are not allowed in your php config!');
}
$this->_files = $this->_prepareFiles($_FILES);
$this->addValidator('Upload', false, $this->_files);
if (is_array($options)) {
$this->setOptions($options);
}
}
/**
* Sets a validator for the class, erasing all previous set
*
* @param string|array $validator Validator to set
* @param string|array $files Files to limit this validator to
* @return Zend_File_Transfer_Adapter
*/
public function setValidators(array $validators, $files = null)
{
$this->clearValidators();
$this->addValidator('Upload', false, $this->_files);
return $this->addValidators($validators, $files);
}
/**
* Send the file to the client (Download)
*
* @param string|array $options Options for the file(s) to send
* @return void
* @throws Zend_File_Transfer_Exception Not implemented
*/
public function send($options = null)
{
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Method not implemented');
}
/**
* Receive the file from the client (Upload)
*
* @param string|array $files (Optional) Files to receive
* @return bool
*/
public function receive($files = null)
{
if (!$this->isValid($files)) {
return false;
}
$check = $this->_getFiles($files);
foreach ($check as $file => $content) {
if (!$content['received']) {
$directory = '';
$destination = $this->getDestination($file);
if ($destination !== null) {
$directory = $destination . DIRECTORY_SEPARATOR;
}
// Should never return false when it's tested by the upload validator
if (!move_uploaded_file($content['tmp_name'], ($directory . $content['name']))) {
if ($content['options']['ignoreNoFile']) {
$this->_files[$file]['received'] = true;
$this->_files[$file]['filtered'] = true;
continue;
}
$this->_files[$file]['received'] = false;
return false;
}
$this->_files[$file]['received'] = true;
}
if (!$content['filtered']) {
if (!$this->_filter($file)) {
$this->_files[$file]['filtered'] = false;
return false;
}
$this->_files[$file]['filtered'] = true;
}
}
return true;
}
/**
* Checks if the file was already sent
*
* @param string|array $file Files to check
* @return bool
* @throws Zend_File_Transfer_Exception Not implemented
*/
public function isSent($files = null)
{
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Method not implemented');
}
/**
* Checks if the file was already received
*
* @param string|array $files (Optional) Files to check
* @return bool
*/
public function isReceived($files = null)
{
$files = $this->_getFiles($files);
foreach ($files as $content) {
if ($content['received'] !== true) {
return false;
}
}
return true;
}
/**
* Checks if the file was already filtered
*
* @param string|array $files (Optional) Files to check
* @return bool
*/
public function isFiltered($files = null)
{
$files = $this->_getFiles($files);
foreach ($files as $content) {
if ($content['filtered'] !== true) {
return false;
}
}
return true;
}
/**
* Has a file been uploaded ?
*
* @param array|string|null $file
* @return bool
*/
public function isUploaded($files = null)
{
$files = $this->_getFiles($files);
foreach ($files as $file) {
if (empty($file['name'])) {
return false;
}
}
return true;
}
/**
* Returns the actual progress of file up-/downloads
*
* @return string Returns the state
* @return int
* @throws Zend_File_Transfer_Exception Not implemented
*/
public function getProgress()
{
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Method not implemented');
}
/**
* Prepare the $_FILES array to match the internal syntax of one file per entry
*
* @param array $files
* @return array
*/
protected function _prepareFiles(array $files = array())
{
$result = array();
foreach ($files as $form => $content) {
if (is_array($content['name'])) {
foreach ($content as $param => $file) {
foreach ($file as $number => $target) {
$result[$form . '_' . $number . '_'][$param] = $target;
$result[$form . '_' . $number . '_']['options'] = $this->_options;
$result[$form . '_' . $number . '_']['validated'] = false;
$result[$form . '_' . $number . '_']['received'] = false;
$result[$form . '_' . $number . '_']['filtered'] = false;
}
}
} else {
$result[$form] = $content;
$result[$form]['options'] = $this->_options;
$result[$form]['validated'] = false;
$result[$form]['received'] = false;
$result[$form]['filtered'] = false;
}
}
return $result;
}
}
Abstract.php 0000604 00000002403 15071306214 0007012 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Abstract.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Cipher_Symmetric_Interface
*/
require_once 'Zend/InfoCard/Cipher/Symmetric/Interface.php';
/**
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_InfoCard_Cipher_Symmetric_Adapter_Abstract
implements Zend_InfoCard_Cipher_Symmetric_Interface
{
}
Oracle.php 0000604 00000056711 15071336457 0006503 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Db_Adapter_Abstract
*/
require_once 'Zend/Db/Adapter/Abstract.php';
/**
* @see Zend_Db_Statement_Oracle
*/
require_once 'Zend/Db/Statement/Oracle.php';
/**
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Oracle extends Zend_Db_Adapter_Abstract
{
/**
* User-provided configuration.
*
* Basic keys are:
*
* username => (string) Connect to the database as this username.
* password => (string) Password associated with the username.
* dbname => Either the name of the local Oracle instance, or the
* name of the entry in tnsnames.ora to which you want to connect.
*
* @var array
*/
protected $_config = array(
'dbname' => null,
'username' => null,
'password' => null,
);
/**
* Keys are UPPERCASE SQL datatypes or the constants
* Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
*
* Values are:
* 0 = 32-bit integer
* 1 = 64-bit integer
* 2 = float or decimal
*
* @var array Associative array of datatypes to values 0, 1, or 2.
*/
protected $_numericDataTypes = array(
Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
'BINARY_DOUBLE' => Zend_Db::FLOAT_TYPE,
'BINARY_FLOAT' => Zend_Db::FLOAT_TYPE,
'NUMBER' => Zend_Db::FLOAT_TYPE,
);
/**
* @var integer
*/
protected $_execute_mode = OCI_COMMIT_ON_SUCCESS;
/**
* Default class name for a DB statement.
*
* @var string
*/
protected $_defaultStmtClass = 'Zend_Db_Statement_Oracle';
/**
* Check if LOB field are returned as string
* instead of OCI-Lob object
*
* @var boolean
*/
protected $_lobAsString = null;
/**
* Creates a connection resource.
*
* @return void
* @throws Zend_Db_Adapter_Oracle_Exception
*/
protected function _connect()
{
if (is_resource($this->_connection)) {
// connection already exists
return;
}
if (!extension_loaded('oci8')) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Adapter/Oracle/Exception.php';
throw new Zend_Db_Adapter_Oracle_Exception('The OCI8 extension is required for this adapter but the extension is not loaded');
}
if (isset($this->_config['dbname'])) {
$this->_connection = @oci_connect(
$this->_config['username'],
$this->_config['password'],
$this->_config['dbname']);
} else {
$this->_connection = oci_connect(
$this->_config['username'],
$this->_config['password']);
}
// check the connection
if (!$this->_connection) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Adapter/Oracle/Exception.php';
throw new Zend_Db_Adapter_Oracle_Exception(oci_error());
}
}
/**
* Test if a connection is active
*
* @return boolean
*/
public function isConnected()
{
return ((bool) (is_resource($this->_connection)
&& get_resource_type($this->_connection) == 'oci8 connection'));
}
/**
* Force the connection to close.
*
* @return void
*/
public function closeConnection()
{
if ($this->isConnected()) {
oci_close($this->_connection);
}
$this->_connection = null;
}
/**
* Activate/deactivate return of LOB as string
*
* @param string $lob_as_string
* @return Zend_Db_Adapter_Oracle
*/
public function setLobAsString($lobAsString)
{
$this->_lobAsString = (bool) $lobAsString;
return $this;
}
/**
* Return whether or not LOB are returned as string
*
* @return boolean
*/
public function getLobAsString()
{
if ($this->_lobAsString === null) {
// if never set by user, we use driver option if it exists otherwise false
if (isset($this->_config['driver_options']) &&
isset($this->_config['driver_options']['lob_as_string'])) {
$this->_lobAsString = (bool) $this->_config['driver_options']['lob_as_string'];
} else {
$this->_lobAsString = false;
}
}
return $this->_lobAsString;
}
/**
* Returns an SQL statement for preparation.
*
* @param string $sql The SQL statement with placeholders.
* @return Zend_Db_Statement_Oracle
*/
public function prepare($sql)
{
$this->_connect();
$stmtClass = $this->_defaultStmtClass;
Zend_Loader::loadClass($stmtClass);
$stmt = new $stmtClass($this, $sql);
if ($stmt instanceof Zend_Db_Statement_Oracle) {
$stmt->setLobAsString($this->getLobAsString());
}
$stmt->setFetchMode($this->_fetchMode);
return $stmt;
}
/**
* Quote a raw string.
*
* @param string $value Raw string
* @return string Quoted string
*/
protected function _quote($value)
{
if (is_int($value) || is_float($value)) {
return $value;
}
$value = str_replace("'", "''", $value);
return "'" . addcslashes($value, "\000\n\r\\\032") . "'";
}
/**
* Quote a table identifier and alias.
*
* @param string|array|Zend_Db_Expr $ident The identifier or expression.
* @param string $alias An alias for the table.
* @param boolean $auto If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
* @return string The quoted identifier and alias.
*/
public function quoteTableAs($ident, $alias = null, $auto = false)
{
// Oracle doesn't allow the 'AS' keyword between the table identifier/expression and alias.
return $this->_quoteIdentifierAs($ident, $alias, $auto, ' ');
}
/**
* Return the most recent value from the specified sequence in the database.
* This is supported only on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return string
*/
public function lastSequenceId($sequenceName)
{
$this->_connect();
$sql = 'SELECT '.$this->quoteIdentifier($sequenceName, true).'.CURRVAL FROM dual';
$value = $this->fetchOne($sql);
return $value;
}
/**
* Generate a new value from the specified sequence in the database, and return it.
* This is supported only on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return string
*/
public function nextSequenceId($sequenceName)
{
$this->_connect();
$sql = 'SELECT '.$this->quoteIdentifier($sequenceName, true).'.NEXTVAL FROM dual';
$value = $this->fetchOne($sql);
return $value;
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* As a convention, on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
* from the arguments and returns the last id generated by that sequence.
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
* returns the last value generated for such a column, and the table name
* argument is disregarded.
*
* Oracle does not support IDENTITY columns, so if the sequence is not
* specified, this method returns null.
*
* @param string $tableName OPTIONAL Name of table.
* @param string $primaryKey OPTIONAL Name of primary key column.
* @return string
*/
public function lastInsertId($tableName = null, $primaryKey = null)
{
if ($tableName !== null) {
$sequenceName = $tableName;
if ($primaryKey) {
$sequenceName .= "_$primaryKey";
}
$sequenceName .= '_seq';
return $this->lastSequenceId($sequenceName);
}
// No support for IDENTITY columns; return null
return null;
}
/**
* Returns a list of the tables in the database.
*
* @return array
*/
public function listTables()
{
$this->_connect();
$data = $this->fetchCol('SELECT table_name FROM all_tables');
return $data;
}
/**
* Returns the column descriptions for a table.
*
* The return value is an associative array keyed by the column name,
* as returned by the RDBMS.
*
* The value of each array element is an associative array
* with the following keys:
*
* SCHEMA_NAME => string; name of schema
* TABLE_NAME => string;
* COLUMN_NAME => string; column name
* COLUMN_POSITION => number; ordinal position of column in table
* DATA_TYPE => string; SQL datatype name of column
* DEFAULT => string; default expression of column, null if none
* NULLABLE => boolean; true if column can have nulls
* LENGTH => number; length of CHAR/VARCHAR
* SCALE => number; scale of NUMERIC/DECIMAL
* PRECISION => number; precision of NUMERIC/DECIMAL
* UNSIGNED => boolean; unsigned property of an integer type
* PRIMARY => boolean; true if column is part of the primary key
* PRIMARY_POSITION => integer; position of column in primary key
* IDENTITY => integer; true if column is auto-generated with unique values
*
* @todo Discover integer unsigned property.
*
* @param string $tableName
* @param string $schemaName OPTIONAL
* @return array
*/
public function describeTable($tableName, $schemaName = null)
{
$version = $this->getServerVersion();
if (is_null($version) || version_compare($version, '9.0.0', '>=')) {
$sql = "SELECT TC.TABLE_NAME, TC.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,
TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH,
TC.DATA_SCALE, TC.DATA_PRECISION, C.CONSTRAINT_TYPE, CC.POSITION
FROM ALL_TAB_COLUMNS TC
LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C
ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND C.CONSTRAINT_TYPE = 'P'))
ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME
WHERE UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)";
$bind[':TBNAME'] = $tableName;
if ($schemaName) {
$sql .= ' AND UPPER(TC.OWNER) = UPPER(:SCNAME)';
$bind[':SCNAME'] = $schemaName;
}
$sql .= ' ORDER BY TC.COLUMN_ID';
} else {
$subSql="SELECT AC.OWNER, AC.TABLE_NAME, ACC.COLUMN_NAME, AC.CONSTRAINT_TYPE, ACC.POSITION
from ALL_CONSTRAINTS AC, ALL_CONS_COLUMNS ACC
WHERE ACC.CONSTRAINT_NAME = AC.CONSTRAINT_NAME
AND ACC.TABLE_NAME = AC.TABLE_NAME
AND ACC.OWNER = AC.OWNER
AND AC.CONSTRAINT_TYPE = 'P'
AND UPPER(AC.TABLE_NAME) = UPPER(:TBNAME)";
$bind[':TBNAME'] = $tableName;
if ($schemaName) {
$subSql .= ' AND UPPER(ACC.OWNER) = UPPER(:SCNAME)';
$bind[':SCNAME'] = $schemaName;
}
$sql="SELECT TC.TABLE_NAME, TC.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,
TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH,
TC.DATA_SCALE, TC.DATA_PRECISION, CC.CONSTRAINT_TYPE, CC.POSITION
FROM ALL_TAB_COLUMNS TC, ($subSql) CC
WHERE UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)
AND TC.OWNER = CC.OWNER(+) AND TC.TABLE_NAME = CC.TABLE_NAME(+) AND TC.COLUMN_NAME = CC.COLUMN_NAME(+)";
if ($schemaName) {
$sql .= ' AND UPPER(TC.OWNER) = UPPER(:SCNAME)';
}
$sql .= ' ORDER BY TC.COLUMN_ID';
}
$stmt = $this->query($sql, $bind);
/**
* Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection
*/
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
$table_name = 0;
$owner = 1;
$column_name = 2;
$data_type = 3;
$data_default = 4;
$nullable = 5;
$column_id = 6;
$data_length = 7;
$data_scale = 8;
$data_precision = 9;
$constraint_type = 10;
$position = 11;
$desc = array();
foreach ($result as $key => $row) {
list ($primary, $primaryPosition, $identity) = array(false, null, false);
if ($row[$constraint_type] == 'P') {
$primary = true;
$primaryPosition = $row[$position];
/**
* Oracle does not support auto-increment keys.
*/
$identity = false;
}
$desc[$this->foldCase($row[$column_name])] = array(
'SCHEMA_NAME' => $this->foldCase($row[$owner]),
'TABLE_NAME' => $this->foldCase($row[$table_name]),
'COLUMN_NAME' => $this->foldCase($row[$column_name]),
'COLUMN_POSITION' => $row[$column_id],
'DATA_TYPE' => $row[$data_type],
'DEFAULT' => $row[$data_default],
'NULLABLE' => (bool) ($row[$nullable] == 'Y'),
'LENGTH' => $row[$data_length],
'SCALE' => $row[$data_scale],
'PRECISION' => $row[$data_precision],
'UNSIGNED' => null, // @todo
'PRIMARY' => $primary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
}
/**
* Leave autocommit mode and begin a transaction.
*
* @return void
*/
protected function _beginTransaction()
{
$this->_setExecuteMode(OCI_DEFAULT);
}
/**
* Commit a transaction and return to autocommit mode.
*
* @return void
* @throws Zend_Db_Adapter_Oracle_Exception
*/
protected function _commit()
{
if (!oci_commit($this->_connection)) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Adapter/Oracle/Exception.php';
throw new Zend_Db_Adapter_Oracle_Exception(oci_error($this->_connection));
}
$this->_setExecuteMode(OCI_COMMIT_ON_SUCCESS);
}
/**
* Roll back a transaction and return to autocommit mode.
*
* @return void
* @throws Zend_Db_Adapter_Oracle_Exception
*/
protected function _rollBack()
{
if (!oci_rollback($this->_connection)) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Adapter/Oracle/Exception.php';
throw new Zend_Db_Adapter_Oracle_Exception(oci_error($this->_connection));
}
$this->_setExecuteMode(OCI_COMMIT_ON_SUCCESS);
}
/**
* Set the fetch mode.
*
* @todo Support FETCH_CLASS and FETCH_INTO.
*
* @param integer $mode A fetch mode.
* @return void
* @throws Zend_Db_Adapter_Oracle_Exception
*/
public function setFetchMode($mode)
{
switch ($mode) {
case Zend_Db::FETCH_NUM: // seq array
case Zend_Db::FETCH_ASSOC: // assoc array
case Zend_Db::FETCH_BOTH: // seq+assoc array
case Zend_Db::FETCH_OBJ: // object
$this->_fetchMode = $mode;
break;
case Zend_Db::FETCH_BOUND: // bound to PHP variable
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Adapter/Oracle/Exception.php';
throw new Zend_Db_Adapter_Oracle_Exception('FETCH_BOUND is not supported yet');
break;
default:
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Adapter/Oracle/Exception.php';
throw new Zend_Db_Adapter_Oracle_Exception("Invalid fetch mode '$mode' specified");
break;
}
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
*
* @param string $sql
* @param integer $count
* @param integer $offset OPTIONAL
* @return string
* @throws Zend_Db_Adapter_Oracle_Exception
*/
public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count <= 0) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Adapter/Oracle/Exception.php';
throw new Zend_Db_Adapter_Oracle_Exception("LIMIT argument count=$count is not valid");
}
$offset = intval($offset);
if ($offset < 0) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Adapter/Oracle/Exception.php';
throw new Zend_Db_Adapter_Oracle_Exception("LIMIT argument offset=$offset is not valid");
}
/**
* Oracle does not implement the LIMIT clause as some RDBMS do.
* We have to simulate it with subqueries and ROWNUM.
* Unfortunately because we use the column wildcard "*",
* this puts an extra column into the query result set.
*/
$limit_sql = "SELECT z2.*
FROM (
SELECT ROWNUM AS zend_db_rownum, z1.*
FROM (
" . $sql . "
) z1
) z2
WHERE z2.zend_db_rownum BETWEEN " . ($offset+1) . " AND " . ($offset+$count);
return $limit_sql;
}
/**
* @param integer $mode
* @throws Zend_Db_Adapter_Oracle_Exception
*/
private function _setExecuteMode($mode)
{
switch($mode) {
case OCI_COMMIT_ON_SUCCESS:
case OCI_DEFAULT:
case OCI_DESCRIBE_ONLY:
$this->_execute_mode = $mode;
break;
default:
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Adapter/Oracle/Exception.php';
throw new Zend_Db_Adapter_Oracle_Exception("Invalid execution mode '$mode' specified");
break;
}
}
/**
* @return int
*/
public function _getExecuteMode()
{
return $this->_execute_mode;
}
/**
* Inserts a table row with specified data.
*
* Oracle does not support anonymous ('?') binds.
*
* @param mixed $table The table to insert data into.
* @param array $bind Column-value pairs.
* @return int The number of affected rows.
*/
public function insert($table, array $bind)
{
$i = 0;
// extract and quote col names from the array keys
$cols = array();
$vals = array();
foreach ($bind as $col => $val) {
$cols[] = $this->quoteIdentifier($col, true);
if ($val instanceof Zend_Db_Expr) {
$vals[] = $val->__toString();
unset($bind[$col]);
} else {
$vals[] = ':'.$col.$i;
unset($bind[$col]);
$bind[':'.$col.$i] = $val;
}
$i++;
}
// build the statement
$sql = "INSERT INTO "
. $this->quoteIdentifier($table, true)
. ' (' . implode(', ', $cols) . ') '
. 'VALUES (' . implode(', ', $vals) . ')';
// execute the statement and return the number of affected rows
$stmt = $this->query($sql, $bind);
$result = $stmt->rowCount();
return $result;
}
/**
* Updates table rows with specified data based on a WHERE clause.
*
* @param mixed $table The table to update.
* @param array $bind Column-value pairs.
* @param array|string $where UPDATE WHERE clause(s).
* @return int The number of affected rows.
*/
public function update($table, array $bind, $where = '')
{
$i = 0;
// build "col = ?" pairs for the statement
$set = array();
foreach ($bind as $col => $val) {
if ($val instanceof Zend_Db_Expr) {
$val = $val->__toString();
unset($bind[$col]);
} else {
unset($bind[$col]);
$bind[':'.$col.$i] = $val;
$val = ':'.$col.$i;
}
$set[] = $this->quoteIdentifier($col, true) . ' = ' . $val;
$i++;
}
if (is_array($where)) {
$where = implode(' AND ', $where);
}
// build the statement
$sql = "UPDATE "
. $this->quoteIdentifier($table, true)
. ' SET ' . implode(', ', $set)
. (($where) ? " WHERE $where" : '');
// execute the statement and return the number of affected rows
$stmt = $this->query($sql, $bind);
$result = $stmt->rowCount();
return $result;
}
/**
* Check if the adapter supports real SQL parameters.
*
* @param string $type 'positional' or 'named'
* @return bool
*/
public function supportsParameters($type)
{
switch ($type) {
case 'named':
return true;
case 'positional':
default:
return false;
}
}
/**
* Retrieve server version in PHP style
*
* @return string
*/
public function getServerVersion()
{
$this->_connect();
$version = oci_server_version($this->_connection);
if ($version !== false) {
$matches = null;
if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $version, $matches)) {
return $matches[1];
} else {
return null;
}
} else {
return null;
}
}
}
Db2.php 0000604 00000064774 15071336457 0005715 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
*/
/**
* @see Zend_Db
*/
require_once 'Zend/Db.php';
/**
* @see Zend_Db_Adapter_Abstract
*/
require_once 'Zend/Db/Adapter/Abstract.php';
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Db_Statement_Db2
*/
require_once 'Zend/Db/Statement/Db2.php';
/**
* @package Zend_Db
* @copyright Copyright (c) 2005-2008 Zend Technologies Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract
{
/**
* User-provided configuration.
*
* Basic keys are:
*
* username => (string) Connect to the database as this username.
* password => (string) Password associated with the username.
* host => (string) What host to connect to (default 127.0.0.1)
* dbname => (string) The name of the database to user
* protocol => (string) Protocol to use, defaults to "TCPIP"
* port => (integer) Port number to use for TCP/IP if protocol is "TCPIP"
* persistent => (boolean) Set TRUE to use a persistent connection (db2_pconnect)
* os => (string) This should be set to 'i5' if the db is on an os400/i5
* schema => (string) The default schema the connection should use
*
* @var array
*/
protected $_config = array(
'dbname' => null,
'username' => null,
'password' => null,
'host' => 'localhost',
'port' => '50000',
'protocol' => 'TCPIP',
'persistent' => false,
'os' => null,
'schema' => null
);
/**
* Execution mode
*
* @var int execution flag (DB2_AUTOCOMMIT_ON or DB2_AUTOCOMMIT_OFF)
*/
protected $_execute_mode = DB2_AUTOCOMMIT_ON;
/**
* Default class name for a DB statement.
*
* @var string
*/
protected $_defaultStmtClass = 'Zend_Db_Statement_Db2';
protected $_isI5 = false;
/**
* Keys are UPPERCASE SQL datatypes or the constants
* Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
*
* Values are:
* 0 = 32-bit integer
* 1 = 64-bit integer
* 2 = float or decimal
*
* @var array Associative array of datatypes to values 0, 1, or 2.
*/
protected $_numericDataTypes = array(
Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
'INTEGER' => Zend_Db::INT_TYPE,
'SMALLINT' => Zend_Db::INT_TYPE,
'BIGINT' => Zend_Db::BIGINT_TYPE,
'DECIMAL' => Zend_Db::FLOAT_TYPE,
'NUMERIC' => Zend_Db::FLOAT_TYPE
);
/**
* Creates a connection resource.
*
* @return void
*/
protected function _connect()
{
if (is_resource($this->_connection)) {
// connection already exists
return;
}
if (!extension_loaded('ibm_db2')) {
/**
* @see Zend_Db_Adapter_Db2_Exception
*/
require_once 'Zend/Db/Adapter/Db2/Exception.php';
throw new Zend_Db_Adapter_Db2_Exception('The IBM DB2 extension is required for this adapter but the extension is not loaded');
}
$this->_determineI5();
if ($this->_config['persistent']) {
// use persistent connection
$conn_func_name = 'db2_pconnect';
} else {
// use "normal" connection
$conn_func_name = 'db2_connect';
}
if (!isset($this->_config['driver_options']['autocommit'])) {
// set execution mode
$this->_config['driver_options']['autocommit'] = &$this->_execute_mode;
}
if (isset($this->_config['options'][Zend_Db::CASE_FOLDING])) {
$caseAttrMap = array(
Zend_Db::CASE_NATURAL => DB2_CASE_NATURAL,
Zend_Db::CASE_UPPER => DB2_CASE_UPPER,
Zend_Db::CASE_LOWER => DB2_CASE_LOWER
);
$this->_config['driver_options']['DB2_ATTR_CASE'] = $caseAttrMap[$this->_config['options'][Zend_Db::CASE_FOLDING]];
}
if ($this->_config['host'] !== 'localhost' && !$this->_isI5) {
// if the host isn't localhost, use extended connection params
$dbname = 'DRIVER={IBM DB2 ODBC DRIVER}' .
';DATABASE=' . $this->_config['dbname'] .
';HOSTNAME=' . $this->_config['host'] .
';PORT=' . $this->_config['port'] .
';PROTOCOL=' . $this->_config['protocol'] .
';UID=' . $this->_config['username'] .
';PWD=' . $this->_config['password'] .';';
$this->_connection = $conn_func_name(
$dbname,
null,
null,
$this->_config['driver_options']
);
} else {
// host is localhost, so use standard connection params
$this->_connection = $conn_func_name(
$this->_config['dbname'],
$this->_config['username'],
$this->_config['password'],
$this->_config['driver_options']
);
}
// check the connection
if (!$this->_connection) {
/**
* @see Zend_Db_Adapter_Db2_Exception
*/
require_once 'Zend/Db/Adapter/Db2/Exception.php';
throw new Zend_Db_Adapter_Db2_Exception(db2_conn_errormsg(), db2_conn_error());
}
}
/**
* Test if a connection is active
*
* @return boolean
*/
public function isConnected()
{
return ((bool) (is_resource($this->_connection)
&& get_resource_type($this->_connection) == 'DB2 Connection'));
}
/**
* Force the connection to close.
*
* @return void
*/
public function closeConnection()
{
if ($this->isConnected()) {
db2_close($this->_connection);
}
$this->_connection = null;
}
/**
* Returns an SQL statement for preparation.
*
* @param string $sql The SQL statement with placeholders.
* @return Zend_Db_Statement_Db2
*/
public function prepare($sql)
{
$this->_connect();
$stmtClass = $this->_defaultStmtClass;
Zend_Loader::loadClass($stmtClass);
$stmt = new $stmtClass($this, $sql);
$stmt->setFetchMode($this->_fetchMode);
return $stmt;
}
/**
* Gets the execution mode
*
* @return int the execution mode (DB2_AUTOCOMMIT_ON or DB2_AUTOCOMMIT_OFF)
*/
public function _getExecuteMode()
{
return $this->_execute_mode;
}
/**
* @param integer $mode
* @return void
*/
public function _setExecuteMode($mode)
{
switch ($mode) {
case DB2_AUTOCOMMIT_OFF:
case DB2_AUTOCOMMIT_ON:
$this->_execute_mode = $mode;
db2_autocommit($this->_connection, $mode);
break;
default:
/**
* @see Zend_Db_Adapter_Db2_Exception
*/
require_once 'Zend/Db/Adapter/Db2/Exception.php';
throw new Zend_Db_Adapter_Db2_Exception("execution mode not supported");
break;
}
}
/**
* Quote a raw string.
*
* @param string $value Raw string
* @return string Quoted string
*/
protected function _quote($value)
{
if (is_int($value) || is_float($value)) {
return $value;
}
/**
* Use db2_escape_string() if it is present in the IBM DB2 extension.
* But some supported versions of PHP do not include this function,
* so fall back to default quoting in the parent class.
*/
if (function_exists('db2_escape_string')) {
return "'" . db2_escape_string($value) . "'";
}
return parent::_quote($value);
}
/**
* @return string
*/
public function getQuoteIdentifierSymbol()
{
$this->_connect();
$info = db2_server_info($this->_connection);
if ($info) {
$identQuote = $info->IDENTIFIER_QUOTE_CHAR;
} else {
// db2_server_info() does not return result on some i5 OS version
if ($this->_isI5) {
$identQuote ="'";
}
}
return $identQuote;
}
/**
* Returns a list of the tables in the database.
* @param string $schema OPTIONAL
* @return array
*/
public function listTables($schema = null)
{
$this->_connect();
if ($schema === null && $this->_config['schema'] != null) {
$schema = $this->_config['schema'];
}
$tables = array();
if (!$this->_isI5) {
if ($schema) {
$stmt = db2_tables($this->_connection, null, $schema);
} else {
$stmt = db2_tables($this->_connection);
}
while ($row = db2_fetch_assoc($stmt)) {
$tables[] = $row['TABLE_NAME'];
}
} else {
$tables = $this->_i5listTables($schema);
}
return $tables;
}
/**
* Returns the column descriptions for a table.
*
* The return value is an associative array keyed by the column name,
* as returned by the RDBMS.
*
* The value of each array element is an associative array
* with the following keys:
*
* SCHEMA_NAME => string; name of database or schema
* TABLE_NAME => string;
* COLUMN_NAME => string; column name
* COLUMN_POSITION => number; ordinal position of column in table
* DATA_TYPE => string; SQL datatype name of column
* DEFAULT => string; default expression of column, null if none
* NULLABLE => boolean; true if column can have nulls
* LENGTH => number; length of CHAR/VARCHAR
* SCALE => number; scale of NUMERIC/DECIMAL
* PRECISION => number; precision of NUMERIC/DECIMAL
* UNSIGNED => boolean; unsigned property of an integer type
* DB2 not supports UNSIGNED integer.
* PRIMARY => boolean; true if column is part of the primary key
* PRIMARY_POSITION => integer; position of column in primary key
* IDENTITY => integer; true if column is auto-generated with unique values
*
* @param string $tableName
* @param string $schemaName OPTIONAL
* @return array
*/
public function describeTable($tableName, $schemaName = null)
{
// Ensure the connection is made so that _isI5 is set
$this->_connect();
if ($schemaName === null && $this->_config['schema'] != null) {
$schemaName = $this->_config['schema'];
}
if (!$this->_isI5) {
$sql = "SELECT DISTINCT c.tabschema, c.tabname, c.colname, c.colno,
c.typename, c.default, c.nulls, c.length, c.scale,
c.identity, tc.type AS tabconsttype, k.colseq
FROM syscat.columns c
LEFT JOIN (syscat.keycoluse k JOIN syscat.tabconst tc
ON (k.tabschema = tc.tabschema
AND k.tabname = tc.tabname
AND tc.type = 'P'))
ON (c.tabschema = k.tabschema
AND c.tabname = k.tabname
AND c.colname = k.colname)
WHERE "
. $this->quoteInto('UPPER(c.tabname) = UPPER(?)', $tableName);
if ($schemaName) {
$sql .= $this->quoteInto(' AND UPPER(c.tabschema) = UPPER(?)', $schemaName);
}
$sql .= " ORDER BY c.colno";
} else {
// DB2 On I5 specific query
$sql = "SELECT DISTINCT C.TABLE_SCHEMA, C.TABLE_NAME, C.COLUMN_NAME, C.ORDINAL_POSITION,
C.DATA_TYPE, C.COLUMN_DEFAULT, C.NULLS ,C.LENGTH, C.SCALE, LEFT(C.IDENTITY,1),
LEFT(tc.TYPE, 1) AS tabconsttype, k.COLSEQ
FROM QSYS2.SYSCOLUMNS C
LEFT JOIN (QSYS2.syskeycst k JOIN QSYS2.SYSCST tc
ON (k.TABLE_SCHEMA = tc.TABLE_SCHEMA
AND k.TABLE_NAME = tc.TABLE_NAME
AND LEFT(tc.type,1) = 'P'))
ON (C.TABLE_SCHEMA = k.TABLE_SCHEMA
AND C.TABLE_NAME = k.TABLE_NAME
AND C.COLUMN_NAME = k.COLUMN_NAME)
WHERE "
. $this->quoteInto('UPPER(C.TABLE_NAME) = UPPER(?)', $tableName);
if ($schemaName) {
$sql .= $this->quoteInto(' AND UPPER(C.TABLE_SCHEMA) = UPPER(?)', $schemaName);
}
$sql .= " ORDER BY C.ORDINAL_POSITION FOR FETCH ONLY";
}
$desc = array();
$stmt = $this->query($sql);
/**
* To avoid case issues, fetch using FETCH_NUM
*/
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
/**
* The ordering of columns is defined by the query so we can map
* to variables to improve readability
*/
$tabschema = 0;
$tabname = 1;
$colname = 2;
$colno = 3;
$typename = 4;
$default = 5;
$nulls = 6;
$length = 7;
$scale = 8;
$identityCol = 9;
$tabconstType = 10;
$colseq = 11;
foreach ($result as $key => $row) {
list ($primary, $primaryPosition, $identity) = array(false, null, false);
if ($row[$tabconstType] == 'P') {
$primary = true;
$primaryPosition = $row[$colseq];
}
/**
* In IBM DB2, an column can be IDENTITY
* even if it is not part of the PRIMARY KEY.
*/
if ($row[$identityCol] == 'Y') {
$identity = true;
}
// only colname needs to be case adjusted
$desc[$this->foldCase($row[$colname])] = array(
'SCHEMA_NAME' => $this->foldCase($row[$tabschema]),
'TABLE_NAME' => $this->foldCase($row[$tabname]),
'COLUMN_NAME' => $this->foldCase($row[$colname]),
'COLUMN_POSITION' => (!$this->_isI5) ? $row[$colno]+1 : $row[$colno],
'DATA_TYPE' => $row[$typename],
'DEFAULT' => $row[$default],
'NULLABLE' => (bool) ($row[$nulls] == 'Y'),
'LENGTH' => $row[$length],
'SCALE' => $row[$scale],
'PRECISION' => ($row[$typename] == 'DECIMAL' ? $row[$length] : 0),
'UNSIGNED' => false,
'PRIMARY' => $primary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
}
/**
* Return the most recent value from the specified sequence in the database.
* This is supported only on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return string
*/
public function lastSequenceId($sequenceName)
{
$this->_connect();
if (!$this->_isI5) {
$quotedSequenceName = $this->quoteIdentifier($sequenceName, true);
$sql = 'SELECT PREVVAL FOR ' . $quotedSequenceName . ' AS VAL FROM SYSIBM.SYSDUMMY1';
} else {
$quotedSequenceName = $sequenceName;
$sql = 'SELECT PREVVAL FOR ' . $this->quoteIdentifier($sequenceName, true) . ' AS VAL FROM QSYS2.QSQPTABL';
}
$value = $this->fetchOne($sql);
return (string) $value;
}
/**
* Generate a new value from the specified sequence in the database, and return it.
* This is supported only on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return string
*/
public function nextSequenceId($sequenceName)
{
$this->_connect();
$sql = 'SELECT NEXTVAL FOR '.$this->quoteIdentifier($sequenceName, true).' AS VAL FROM SYSIBM.SYSDUMMY1';
$value = $this->fetchOne($sql);
return (string) $value;
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* As a convention, on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
* from the arguments and returns the last id generated by that sequence.
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
* returns the last value generated for such a column, and the table name
* argument is disregarded.
*
* The IDENTITY_VAL_LOCAL() function gives the last generated identity value
* in the current process, even if it was for a GENERATED column.
*
* @param string $tableName OPTIONAL
* @param string $primaryKey OPTIONAL
* @param string $idType OPTIONAL used for i5 platform to define sequence/idenity unique value
* @return string
*/
public function lastInsertId($tableName = null, $primaryKey = null, $idType = null)
{
$this->_connect();
if ($this->_isI5) {
return (string) $this->_i5LastInsertId($tableName, $idType);
}
if ($tableName !== null) {
$sequenceName = $tableName;
if ($primaryKey) {
$sequenceName .= "_$primaryKey";
}
$sequenceName .= '_seq';
return $this->lastSequenceId($sequenceName);
}
$sql = 'SELECT IDENTITY_VAL_LOCAL() AS VAL FROM SYSIBM.SYSDUMMY1';
$value = $this->fetchOne($sql);
return (string) $value;
}
/**
* Begin a transaction.
*
* @return void
*/
protected function _beginTransaction()
{
$this->_setExecuteMode(DB2_AUTOCOMMIT_OFF);
}
/**
* Commit a transaction.
*
* @return void
*/
protected function _commit()
{
if (!db2_commit($this->_connection)) {
/**
* @see Zend_Db_Adapter_Db2_Exception
*/
require_once 'Zend/Db/Adapter/Db2/Exception.php';
throw new Zend_Db_Adapter_Db2_Exception(
db2_conn_errormsg($this->_connection),
db2_conn_error($this->_connection));
}
$this->_setExecuteMode(DB2_AUTOCOMMIT_ON);
}
/**
* Rollback a transaction.
*
* @return void
*/
protected function _rollBack()
{
if (!db2_rollback($this->_connection)) {
/**
* @see Zend_Db_Adapter_Db2_Exception
*/
require_once 'Zend/Db/Adapter/Db2/Exception.php';
throw new Zend_Db_Adapter_Db2_Exception(
db2_conn_errormsg($this->_connection),
db2_conn_error($this->_connection));
}
$this->_setExecuteMode(DB2_AUTOCOMMIT_ON);
}
/**
* Set the fetch mode.
*
* @param integer $mode
* @return void
* @throws Zend_Db_Adapter_Db2_Exception
*/
public function setFetchMode($mode)
{
switch ($mode) {
case Zend_Db::FETCH_NUM: // seq array
case Zend_Db::FETCH_ASSOC: // assoc array
case Zend_Db::FETCH_BOTH: // seq+assoc array
case Zend_Db::FETCH_OBJ: // object
$this->_fetchMode = $mode;
break;
case Zend_Db::FETCH_BOUND: // bound to PHP variable
/**
* @see Zend_Db_Adapter_Db2_Exception
*/
require_once 'Zend/Db/Adapter/Db2/Exception.php';
throw new Zend_Db_Adapter_Db2_Exception('FETCH_BOUND is not supported yet');
break;
default:
/**
* @see Zend_Db_Adapter_Db2_Exception
*/
require_once 'Zend/Db/Adapter/Db2/Exception.php';
throw new Zend_Db_Adapter_Db2_Exception("Invalid fetch mode '$mode' specified");
break;
}
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
*
* @param string $sql
* @param integer $count
* @param integer $offset OPTIONAL
* @return string
*/
public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count <= 0) {
/**
* @see Zend_Db_Adapter_Db2_Exception
*/
require_once 'Zend/Db/Adapter/Db2/Exception.php';
throw new Zend_Db_Adapter_Db2_Exception("LIMIT argument count=$count is not valid");
}
$offset = intval($offset);
if ($offset < 0) {
/**
* @see Zend_Db_Adapter_Db2_Exception
*/
require_once 'Zend/Db/Adapter/Db2/Exception.php';
throw new Zend_Db_Adapter_Db2_Exception("LIMIT argument offset=$offset is not valid");
}
if ($offset == 0) {
$limit_sql = $sql . " FETCH FIRST $count ROWS ONLY";
return $limit_sql;
}
/**
* DB2 does not implement the LIMIT clause as some RDBMS do.
* We have to simulate it with subqueries and ROWNUM.
* Unfortunately because we use the column wildcard "*",
* this puts an extra column into the query result set.
*/
$limit_sql = "SELECT z2.*
FROM (
SELECT ROW_NUMBER() OVER() AS \"ZEND_DB_ROWNUM\", z1.*
FROM (
" . $sql . "
) z1
) z2
WHERE z2.zend_db_rownum BETWEEN " . ($offset+1) . " AND " . ($offset+$count);
return $limit_sql;
}
/**
* Check if the adapter supports real SQL parameters.
*
* @param string $type 'positional' or 'named'
* @return bool
*/
public function supportsParameters($type)
{
if ($type == 'positional') {
return true;
}
// if its 'named' or anything else
return false;
}
/**
* Retrieve server version in PHP style
*
* @return string
*/
public function getServerVersion()
{
$this->_connect();
$server_info = db2_server_info($this->_connection);
if ($server_info !== false) {
$version = $server_info->DBMS_VER;
if ($this->_isI5) {
$version = (int) substr($version, 0, 2) . '.' . (int) substr($version, 2, 2) . '.' . (int) substr($version, 4);
}
return $version;
} else {
return null;
}
}
/**
* Return whether or not this is running on i5
*
* @return bool
*/
public function isI5()
{
if ($this->_isI5 === null) {
$this->_determineI5();
}
return (bool) $this->_isI5;
}
/**
* Check the connection parameters according to verify
* type of used OS
*
* @return void
*/
protected function _determineI5()
{
// first us the compiled flag.
$this->_isI5 = (php_uname('s') == 'OS400') ? true : false;
// if this is set, then us it
if (isset($this->_config['os'])){
if (strtolower($this->_config['os']) === 'i5') {
$this->_isI5 = true;
} else {
// any other value passed in, its null
$this->_isI5 = false;
}
}
}
/**
* Db2 On I5 specific method
*
* Returns a list of the tables in the database .
* Used only for DB2/400.
*
* @return array
*/
protected function _i5listTables($schema = null)
{
//list of i5 libraries.
$tables = array();
if ($schema) {
$tablesStatement = db2_tables($this->_connection, null, $schema);
while ($rowTables = db2_fetch_assoc($tablesStatement) ) {
if ($rowTables['TABLE_NAME'] !== null) {
$tables[] = $rowTables['TABLE_NAME'];
}
}
} else {
$schemaStatement = db2_tables($this->_connection);
while ($schema = db2_fetch_assoc($schemaStatement)) {
if ($schema['TABLE_SCHEM'] !== null) {
// list of the tables which belongs to the selected library
$tablesStatement = db2_tables($this->_connection, NULL, $schema['TABLE_SCHEM']);
if (is_resource($tablesStatement)) {
while ($rowTables = db2_fetch_assoc($tablesStatement) ) {
if ($rowTables['TABLE_NAME'] !== null) {
$tables[] = $rowTables['TABLE_NAME'];
}
}
}
}
}
}
return $tables;
}
protected function _i5LastInsertId($objectName = null, $idType = null)
{
if ($objectName === null) {
$sql = 'SELECT IDENTITY_VAL_LOCAL() AS VAL FROM QSYS2.QSQPTABL';
$value = $this->fetchOne($sql);
return $value;
}
if (strtoupper($idType) === 'S'){
//check i5_lib option
$sequenceName = $objectName;
return $this->lastSequenceId($sequenceName);
}
//returns last identity value for the specified table
//if (strtoupper($idType) === 'I') {
$tableName = $objectName;
return $this->fetchOne('SELECT IDENTITY_VAL_LOCAL() from ' . $this->quoteIdentifier($tableName));
}
}
Exception.php 0000604 00000002225 15071336457 0007223 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Exception
*/
require_once 'Zend/InfoCard/Exception.php';
/**
* @category Zend
* @subpackage Zend_InfoCard_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_InfoCard_Adapter_Exception extends Zend_InfoCard_Exception
{
}
Pdo/Mssql.php 0000604 00000031147 15071336457 0007113 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Mssql.php 13280 2008-12-15 20:48:08Z mikaelkael $
*/
/**
* @see Zend_Db_Adapter_Pdo_Abstract
*/
require_once 'Zend/Db/Adapter/Pdo/Abstract.php';
/**
* Class for connecting to Microsoft SQL Server databases and performing common operations.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Abstract
{
/**
* PDO type.
*
* @var string
*/
protected $_pdoType = 'mssql';
/**
* Keys are UPPERCASE SQL datatypes or the constants
* Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
*
* Values are:
* 0 = 32-bit integer
* 1 = 64-bit integer
* 2 = float or decimal
*
* @var array Associative array of datatypes to values 0, 1, or 2.
*/
protected $_numericDataTypes = array(
Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
'INT' => Zend_Db::INT_TYPE,
'SMALLINT' => Zend_Db::INT_TYPE,
'TINYINT' => Zend_Db::INT_TYPE,
'BIGINT' => Zend_Db::BIGINT_TYPE,
'DECIMAL' => Zend_Db::FLOAT_TYPE,
'FLOAT' => Zend_Db::FLOAT_TYPE,
'MONEY' => Zend_Db::FLOAT_TYPE,
'NUMERIC' => Zend_Db::FLOAT_TYPE,
'REAL' => Zend_Db::FLOAT_TYPE,
'SMALLMONEY' => Zend_Db::FLOAT_TYPE
);
/**
* Creates a PDO DSN for the adapter from $this->_config settings.
*
* @return string
*/
protected function _dsn()
{
// baseline of DSN parts
$dsn = $this->_config;
// don't pass the username and password in the DSN
unset($dsn['username']);
unset($dsn['password']);
unset($dsn['driver_options']);
if (isset($dsn['port'])) {
$seperator = ':';
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$seperator = ',';
}
$dsn['host'] .= $seperator . $dsn['port'];
unset($dsn['port']);
}
// this driver supports multiple DSN prefixes
// @see http://www.php.net/manual/en/ref.pdo-dblib.connection.php
if (isset($dsn['pdoType'])) {
switch (strtolower($dsn['pdoType'])) {
case 'freetds':
case 'sybase':
$this->_pdoType = 'sybase';
break;
case 'mssql':
$this->_pdoType = 'mssql';
break;
case 'dblib':
default:
$this->_pdoType = 'dblib';
break;
}
unset($dsn['pdoType']);
}
// use all remaining parts in the DSN
foreach ($dsn as $key => $val) {
$dsn[$key] = "$key=$val";
}
$dsn = $this->_pdoType . ':' . implode(';', $dsn);
return $dsn;
}
/**
* @return void
*/
protected function _connect()
{
if ($this->_connection) {
return;
}
parent::_connect();
$this->_connection->exec('SET QUOTED_IDENTIFIER ON');
}
/**
* Begin a transaction.
*
* It is necessary to override the abstract PDO transaction functions here, as
* the PDO driver for MSSQL does not support transactions.
*/
protected function _beginTransaction()
{
$this->_connect();
$this->_connection->exec('BEGIN TRANSACTION');
return true;
}
/**
* Commit a transaction.
*
* It is necessary to override the abstract PDO transaction functions here, as
* the PDO driver for MSSQL does not support transactions.
*/
protected function _commit()
{
$this->_connect();
$this->_connection->exec('COMMIT TRANSACTION');
return true;
}
/**
* Roll-back a transaction.
*
* It is necessary to override the abstract PDO transaction functions here, as
* the PDO driver for MSSQL does not support transactions.
*/
protected function _rollBack() {
$this->_connect();
$this->_connection->exec('ROLLBACK TRANSACTION');
return true;
}
/**
* Returns a list of the tables in the database.
*
* @return array
*/
public function listTables()
{
$sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
return $this->fetchCol($sql);
}
/**
* Returns the column descriptions for a table.
*
* The return value is an associative array keyed by the column name,
* as returned by the RDBMS.
*
* The value of each array element is an associative array
* with the following keys:
*
* SCHEMA_NAME => string; name of database or schema
* TABLE_NAME => string;
* COLUMN_NAME => string; column name
* COLUMN_POSITION => number; ordinal position of column in table
* DATA_TYPE => string; SQL datatype name of column
* DEFAULT => string; default expression of column, null if none
* NULLABLE => boolean; true if column can have nulls
* LENGTH => number; length of CHAR/VARCHAR
* SCALE => number; scale of NUMERIC/DECIMAL
* PRECISION => number; precision of NUMERIC/DECIMAL
* UNSIGNED => boolean; unsigned property of an integer type
* PRIMARY => boolean; true if column is part of the primary key
* PRIMARY_POSITION => integer; position of column in primary key
* PRIMARY_AUTO => integer; position of auto-generated column in primary key
*
* @todo Discover column primary key position.
* @todo Discover integer unsigned property.
*
* @param string $tableName
* @param string $schemaName OPTIONAL
* @return array
*/
public function describeTable($tableName, $schemaName = null)
{
/**
* Discover metadata information about this table.
*/
$sql = "exec sp_columns @table_name = " . $this->quoteIdentifier($tableName, true);
$stmt = $this->query($sql);
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
$table_name = 2;
$column_name = 3;
$type_name = 5;
$precision = 6;
$length = 7;
$scale = 8;
$nullable = 10;
$column_def = 12;
$column_position = 16;
/**
* Discover primary key column(s) for this table.
*/
$sql = "exec sp_pkeys @table_name = " . $this->quoteIdentifier($tableName, true);
$stmt = $this->query($sql);
$primaryKeysResult = $stmt->fetchAll(Zend_Db::FETCH_NUM);
$primaryKeyColumn = array();
$pkey_column_name = 3;
$pkey_key_seq = 4;
foreach ($primaryKeysResult as $pkeysRow) {
$primaryKeyColumn[$pkeysRow[$pkey_column_name]] = $pkeysRow[$pkey_key_seq];
}
$desc = array();
$p = 1;
foreach ($result as $key => $row) {
$identity = false;
$words = explode(' ', $row[$type_name], 2);
if (isset($words[0])) {
$type = $words[0];
if (isset($words[1])) {
$identity = (bool) preg_match('/identity/', $words[1]);
}
}
$isPrimary = array_key_exists($row[$column_name], $primaryKeyColumn);
if ($isPrimary) {
$primaryPosition = $primaryKeyColumn[$row[$column_name]];
} else {
$primaryPosition = null;
}
$desc[$this->foldCase($row[$column_name])] = array(
'SCHEMA_NAME' => null, // @todo
'TABLE_NAME' => $this->foldCase($row[$table_name]),
'COLUMN_NAME' => $this->foldCase($row[$column_name]),
'COLUMN_POSITION' => (int) $row[$column_position],
'DATA_TYPE' => $type,
'DEFAULT' => $row[$column_def],
'NULLABLE' => (bool) $row[$nullable],
'LENGTH' => $row[$length],
'SCALE' => $row[$scale],
'PRECISION' => $row[$precision],
'UNSIGNED' => null, // @todo
'PRIMARY' => $isPrimary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
*
* @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html
*
* @param string $sql
* @param integer $count
* @param integer $offset OPTIONAL
* @throws Zend_Db_Adapter_Exception
* @return string
*/
public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count <= 0) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
}
$offset = intval($offset);
if ($offset < 0) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
}
$orderby = stristr($sql, 'ORDER BY');
if ($orderby !== false) {
$sort = (stripos($orderby, ' desc') !== false) ? 'desc' : 'asc';
$order = str_ireplace('ORDER BY', '', $orderby);
$order = trim(preg_replace('/\bASC\b|\bDESC\b/i', '', $order));
}
$sql = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . ($count+$offset) . ' ', $sql);
$sql = 'SELECT * FROM (SELECT TOP ' . $count . ' * FROM (' . $sql . ') AS inner_tbl';
if ($orderby !== false) {
$sql .= ' ORDER BY ' . $order . ' ';
$sql .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC';
}
$sql .= ') AS outer_tbl';
if ($orderby !== false) {
$sql .= ' ORDER BY ' . $order . ' ' . $sort;
}
return $sql;
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* As a convention, on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
* from the arguments and returns the last id generated by that sequence.
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
* returns the last value generated for such a column, and the table name
* argument is disregarded.
*
* Microsoft SQL Server does not support sequences, so the arguments to
* this method are ignored.
*
* @param string $tableName OPTIONAL Name of table.
* @param string $primaryKey OPTIONAL Name of primary key column.
* @return string
* @throws Zend_Db_Adapter_Exception
*/
public function lastInsertId($tableName = null, $primaryKey = null)
{
$sql = 'SELECT SCOPE_IDENTITY()';
return (int)$this->fetchOne($sql);
}
/**
* Retrieve server version in PHP style
* Pdo_Mssql doesn't support getAttribute(PDO::ATTR_SERVER_VERSION)
* @return string
*/
public function getServerVersion()
{
try {
$stmt = $this->query("SELECT SERVERPROPERTY('productversion')");
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
if (count($result)) {
return $result[0][0];
}
return null;
} catch (PDOException $e) {
return null;
}
}
} Pdo/Abstract.php 0000604 00000023430 15071336457 0007553 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Abstract.php 13281 2008-12-15 20:53:30Z mikaelkael $
*/
/**
* @see Zend_Db_Adapter_Abstract
*/
require_once 'Zend/Db/Adapter/Abstract.php';
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Db_Statement_Pdo
*/
require_once 'Zend/Db/Statement/Pdo.php';
/**
* Class for connecting to SQL databases and performing common operations using PDO.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
{
/**
* Default class name for a DB statement.
*
* @var string
*/
protected $_defaultStmtClass = 'Zend_Db_Statement_Pdo';
/**
* Creates a PDO DSN for the adapter from $this->_config settings.
*
* @return string
*/
protected function _dsn()
{
// baseline of DSN parts
$dsn = $this->_config;
// don't pass the username, password, and driver_options in the DSN
unset($dsn['username']);
unset($dsn['password']);
unset($dsn['options']);
unset($dsn['driver_options']);
// use all remaining parts in the DSN
foreach ($dsn as $key => $val) {
$dsn[$key] = "$key=$val";
}
return $this->_pdoType . ':' . implode(';', $dsn);
}
/**
* Creates a PDO object and connects to the database.
*
* @return void
* @throws Zend_Db_Adapter_Exception
*/
protected function _connect()
{
// if we already have a PDO object, no need to re-connect.
if ($this->_connection) {
return;
}
// get the dsn first, because some adapters alter the $_pdoType
$dsn = $this->_dsn();
// check for PDO extension
if (!extension_loaded('pdo')) {
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
}
// check the PDO driver is available
if (!in_array($this->_pdoType, PDO::getAvailableDrivers())) {
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception('The ' . $this->_pdoType . ' driver is not currently installed');
}
// create PDO connection
$q = $this->_profiler->queryStart('connect', Zend_Db_Profiler::CONNECT);
try {
$this->_connection = new PDO(
$dsn,
$this->_config['username'],
$this->_config['password'],
$this->_config['driver_options']
);
$this->_profiler->queryEnd($q);
// set the PDO connection to perform case-folding on array keys, or not
$this->_connection->setAttribute(PDO::ATTR_CASE, $this->_caseFolding);
// always use exceptions.
$this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception($e->getMessage());
}
}
/**
* Test if a connection is active
*
* @return boolean
*/
public function isConnected()
{
return ((bool) ($this->_connection instanceof PDO));
}
/**
* Force the connection to close.
*
* @return void
*/
public function closeConnection()
{
$this->_connection = null;
}
/**
* Prepares an SQL statement.
*
* @param string $sql The SQL statement with placeholders.
* @param array $bind An array of data to bind to the placeholders.
* @return PDOStatement
*/
public function prepare($sql)
{
$this->_connect();
$stmtClass = $this->_defaultStmtClass;
Zend_Loader::loadClass($stmtClass);
$stmt = new $stmtClass($this, $sql);
$stmt->setFetchMode($this->_fetchMode);
return $stmt;
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* As a convention, on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
* from the arguments and returns the last id generated by that sequence.
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
* returns the last value generated for such a column, and the table name
* argument is disregarded.
*
* On RDBMS brands that don't support sequences, $tableName and $primaryKey
* are ignored.
*
* @param string $tableName OPTIONAL Name of table.
* @param string $primaryKey OPTIONAL Name of primary key column.
* @return string
*/
public function lastInsertId($tableName = null, $primaryKey = null)
{
$this->_connect();
return $this->_connection->lastInsertId();
}
/**
* Special handling for PDO query().
* All bind parameter names must begin with ':'
*
* @param string|Zend_Db_Select $sql The SQL statement with placeholders.
* @param array $bind An array of data to bind to the placeholders.
* @return Zend_Db_Statement_Pdo
* @throws Zend_Db_Adapter_Exception To re-throw PDOException.
*/
public function query($sql, $bind = array())
{
if (is_array($bind)) {
foreach ($bind as $name => $value) {
if (!is_int($name) && !preg_match('/^:/', $name)) {
$newName = ":$name";
unset($bind[$name]);
$bind[$newName] = $value;
}
}
}
try {
return parent::query($sql, $bind);
} catch (PDOException $e) {
/**
* @see Zend_Db_Statement_Exception
*/
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage());
}
}
/**
* Quote a raw string.
*
* @param string $value Raw string
* @return string Quoted string
*/
protected function _quote($value)
{
if (is_int($value) || is_float($value)) {
return $value;
}
$this->_connect();
return $this->_connection->quote($value);
}
/**
* Begin a transaction.
*/
protected function _beginTransaction()
{
$this->_connect();
$this->_connection->beginTransaction();
}
/**
* Commit a transaction.
*/
protected function _commit()
{
$this->_connect();
$this->_connection->commit();
}
/**
* Roll-back a transaction.
*/
protected function _rollBack() {
$this->_connect();
$this->_connection->rollBack();
}
/**
* Set the PDO fetch mode.
*
* @todo Support FETCH_CLASS and FETCH_INTO.
*
* @param int $mode A PDO fetch mode.
* @return void
* @throws Zend_Db_Adapter_Exception
*/
public function setFetchMode($mode)
{
//check for PDO extension
if (!extension_loaded('pdo')) {
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
}
switch ($mode) {
case PDO::FETCH_LAZY:
case PDO::FETCH_ASSOC:
case PDO::FETCH_NUM:
case PDO::FETCH_BOTH:
case PDO::FETCH_NAMED:
case PDO::FETCH_OBJ:
$this->_fetchMode = $mode;
break;
default:
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("Invalid fetch mode '$mode' specified");
break;
}
}
/**
* Check if the adapter supports real SQL parameters.
*
* @param string $type 'positional' or 'named'
* @return bool
*/
public function supportsParameters($type)
{
switch ($type) {
case 'positional':
case 'named':
default:
return true;
}
}
/**
* Retrieve server version in PHP style
*
* @return string
*/
public function getServerVersion()
{
$this->_connect();
$version = $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION);
$matches = null;
if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $version, $matches)) {
return $matches[1];
} else {
return null;
}
}
}
Pdo/Ibm.php 0000604 00000027102 15071336457 0006517 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Ibm.php 13280 2008-12-15 20:48:08Z mikaelkael $
*/
/** @see Zend_Db_Adapter_Pdo_Abstract */
require_once 'Zend/Db/Adapter/Pdo/Abstract.php';
/** @see Zend_Db_Abstract_Pdo_Ibm_Db2 */
require_once 'Zend/Db/Adapter/Pdo/Ibm/Db2.php';
/** @see Zend_Db_Abstract_Pdo_Ibm_Ids */
require_once 'Zend/Db/Adapter/Pdo/Ibm/Ids.php';
/** @see Zend_Db_Statement_Pdo_Ibm */
require_once 'Zend/Db/Statement/Pdo/Ibm.php';
/**
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Pdo_Ibm extends Zend_Db_Adapter_Pdo_Abstract
{
/**
* PDO type.
*
* @var string
*/
protected $_pdoType = 'ibm';
/**
* The IBM data server connected to
*
* @var string
*/
protected $_serverType = null;
/**
* Keys are UPPERCASE SQL datatypes or the constants
* Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
*
* Values are:
* 0 = 32-bit integer
* 1 = 64-bit integer
* 2 = float or decimal
*
* @var array Associative array of datatypes to values 0, 1, or 2.
*/
protected $_numericDataTypes = array(
Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
'INTEGER' => Zend_Db::INT_TYPE,
'SMALLINT' => Zend_Db::INT_TYPE,
'BIGINT' => Zend_Db::BIGINT_TYPE,
'DECIMAL' => Zend_Db::FLOAT_TYPE,
'DEC' => Zend_Db::FLOAT_TYPE,
'REAL' => Zend_Db::FLOAT_TYPE,
'NUMERIC' => Zend_Db::FLOAT_TYPE,
'DOUBLE PRECISION' => Zend_Db::FLOAT_TYPE,
'FLOAT' => Zend_Db::FLOAT_TYPE
);
/**
* Creates a PDO object and connects to the database.
*
* The IBM data server is set.
* Current options are DB2 or IDS
* @todo also differentiate between z/OS and i/5
*
* @return void
* @throws Zend_Db_Adapter_Exception
*/
public function _connect()
{
if ($this->_connection) {
return;
}
parent::_connect();
$this->getConnection()->setAttribute(Zend_Db::ATTR_STRINGIFY_FETCHES, true);
try {
if ($this->_serverType === null) {
$server = substr($this->getConnection()->getAttribute(PDO::ATTR_SERVER_INFO), 0, 3);
switch ($server) {
case 'DB2':
$this->_serverType = new Zend_Db_Adapter_Pdo_Ibm_Db2($this);
// Add DB2-specific numeric types
$this->_numericDataTypes['DECFLOAT'] = Zend_Db::FLOAT_TYPE;
$this->_numericDataTypes['DOUBLE'] = Zend_Db::FLOAT_TYPE;
$this->_numericDataTypes['NUM'] = Zend_Db::FLOAT_TYPE;
break;
case 'IDS':
$this->_serverType = new Zend_Db_Adapter_Pdo_Ibm_Ids($this);
// Add IDS-specific numeric types
$this->_numericDataTypes['SERIAL'] = Zend_Db::INT_TYPE;
$this->_numericDataTypes['SERIAL8'] = Zend_Db::BIGINT_TYPE;
$this->_numericDataTypes['INT8'] = Zend_Db::BIGINT_TYPE;
$this->_numericDataTypes['SMALLFLOAT'] = Zend_Db::FLOAT_TYPE;
$this->_numericDataTypes['MONEY'] = Zend_Db::FLOAT_TYPE;
break;
}
}
} catch (PDOException $e) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
$error = strpos($e->getMessage(), 'driver does not support that attribute');
if ($error) {
throw new Zend_Db_Adapter_Exception("PDO_IBM driver extension is downlevel. Please use driver release version 1.2.1 or later");
} else {
throw new Zend_Db_Adapter_Exception($e->getMessage());
}
}
}
/**
* Creates a PDO DSN for the adapter from $this->_config settings.
*
* @return string
*/
protected function _dsn()
{
$this->_checkRequiredOptions($this->_config);
// check if using full connection string
if (array_key_exists('host', $this->_config)) {
$dsn = ';DATABASE=' . $this->_config['dbname']
. ';HOSTNAME=' . $this->_config['host']
. ';PORT=' . $this->_config['port']
// PDO_IBM supports only DB2 TCPIP protocol
. ';PROTOCOL=' . 'TCPIP;';
} else {
// catalogued connection
$dsn = $this->_config['dbname'];
}
return $this->_pdoType . ': ' . $dsn;
}
/**
* Checks required options
*
* @param array $config
* @throws Zend_Db_Adapter_Exception
* @return void
*/
protected function _checkRequiredOptions(array $config)
{
parent::_checkRequiredOptions($config);
if (array_key_exists('host', $this->_config) &&
!array_key_exists('port', $config)) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("Configuration must have a key for 'port' when 'host' is specified");
}
}
/**
* Prepares an SQL statement.
*
* @param string $sql The SQL statement with placeholders.
* @param array $bind An array of data to bind to the placeholders.
* @return PDOStatement
*/
public function prepare($sql)
{
$this->_connect();
$stmtClass = $this->_defaultStmtClass;
$stmt = new $stmtClass($this, $sql);
$stmt->setFetchMode($this->_fetchMode);
return $stmt;
}
/**
* Returns a list of the tables in the database.
*
* @return array
*/
public function listTables()
{
$this->_connect();
return $this->_serverType->listTables();
}
/**
* Returns the column descriptions for a table.
*
* The return value is an associative array keyed by the column name,
* as returned by the RDBMS.
*
* The value of each array element is an associative array
* with the following keys:
*
* SCHEMA_NAME => string; name of database or schema
* TABLE_NAME => string;
* COLUMN_NAME => string; column name
* COLUMN_POSITION => number; ordinal position of column in table
* DATA_TYPE => string; SQL datatype name of column
* DEFAULT => string; default expression of column, null if none
* NULLABLE => boolean; true if column can have nulls
* LENGTH => number; length of CHAR/VARCHAR
* SCALE => number; scale of NUMERIC/DECIMAL
* PRECISION => number; precision of NUMERIC/DECIMAL
* UNSIGNED => boolean; unsigned property of an integer type
* PRIMARY => boolean; true if column is part of the primary key
* PRIMARY_POSITION => integer; position of column in primary key
*
* @todo Discover integer unsigned property.
*
* @param string $tableName
* @param string $schemaName OPTIONAL
* @return array
*/
public function describeTable($tableName, $schemaName = null)
{
$this->_connect();
return $this->_serverType->describeTable($tableName, $schemaName);
}
/**
* Inserts a table row with specified data.
* Special handling for PDO_IBM
* remove empty slots
*
* @param mixed $table The table to insert data into.
* @param array $bind Column-value pairs.
* @return int The number of affected rows.
*/
public function insert($table, array $bind)
{
$this->_connect();
$newbind = array();
if (is_array($bind)) {
foreach ($bind as $name => $value) {
if(!is_null($value)) {
$newbind[$name] = $value;
}
}
}
return parent::insert($table, $newbind);
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
*
* @param string $sql
* @param integer $count
* @param integer $offset OPTIONAL
* @return string
*/
public function limit($sql, $count, $offset = 0)
{
$this->_connect();
return $this->_serverType->limit($sql, $count, $offset);
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT
* column.
*
* @param string $tableName OPTIONAL
* @param string $primaryKey OPTIONAL
* @return integer
*/
public function lastInsertId($tableName = null, $primaryKey = null)
{
$this->_connect();
if ($tableName !== null) {
$sequenceName = $tableName;
if ($primaryKey) {
$sequenceName .= "_$primaryKey";
}
$sequenceName .= '_seq';
return $this->lastSequenceId($sequenceName);
}
$id = $this->getConnection()->lastInsertId();
return $id;
}
/**
* Return the most recent value from the specified sequence in the database.
*
* @param string $sequenceName
* @return integer
*/
public function lastSequenceId($sequenceName)
{
$this->_connect();
return $this->_serverType->lastSequenceId($sequenceName);
}
/**
* Generate a new value from the specified sequence in the database,
* and return it.
*
* @param string $sequenceName
* @return integer
*/
public function nextSequenceId($sequenceName)
{
$this->_connect();
return $this->_serverType->nextSequenceId($sequenceName);
}
/**
* Retrieve server version in PHP style
* Pdo_Idm doesn't support getAttribute(PDO::ATTR_SERVER_VERSION)
* @return string
*/
public function getServerVersion()
{
try {
$stmt = $this->query('SELECT service_level, fixpack_num FROM TABLE (sysproc.env_get_inst_info()) as INSTANCEINFO');
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
if (count($result)) {
$matches = null;
if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $result[0][0], $matches)) {
return $matches[1];
} else {
return null;
}
}
return null;
} catch (PDOException $e) {
return null;
}
}
}
Pdo/Ibm/Db2.php 0000604 00000016601 15071336457 0007130 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Db2.php 9101 2008-03-30 19:54:38Z thomas $
*/
/** @see Zend_Db_Adapter_Pdo_Ibm */
require_once 'Zend/Db/Adapter/Pdo/Ibm.php';
/** @see Zend_Db_Statement_Pdo_Ibm */
require_once 'Zend/Db/Statement/Pdo/Ibm.php';
/**
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Pdo_Ibm_Db2
{
/**
* @var Zend_Db_Adapter_Abstract
*/
protected $_adapter = null;
/**
* Construct the data server class.
*
* It will be used to generate non-generic SQL
* for a particular data server
*
* @param Zend_Db_Adapter_Abstract $adapter
*/
public function __construct($adapter)
{
$this->_adapter = $adapter;
}
/**
* Returns a list of the tables in the database.
*
* @return array
*/
public function listTables()
{
$sql = "SELECT tabname "
. "FROM SYSCAT.TABLES ";
return $this->_adapter->fetchCol($sql);
}
/**
* DB2 catalog lookup for describe table
*
* @param string $tableName
* @param string $schemaName OPTIONAL
* @return array
*/
public function describeTable($tableName, $schemaName = null)
{
$sql = "SELECT DISTINCT c.tabschema, c.tabname, c.colname, c.colno,
c.typename, c.default, c.nulls, c.length, c.scale,
c.identity, tc.type AS tabconsttype, k.colseq
FROM syscat.columns c
LEFT JOIN (syscat.keycoluse k JOIN syscat.tabconst tc
ON (k.tabschema = tc.tabschema
AND k.tabname = tc.tabname
AND tc.type = 'P'))
ON (c.tabschema = k.tabschema
AND c.tabname = k.tabname
AND c.colname = k.colname)
WHERE "
. $this->_adapter->quoteInto('UPPER(c.tabname) = UPPER(?)', $tableName);
if ($schemaName) {
$sql .= $this->_adapter->quoteInto(' AND UPPER(c.tabschema) = UPPER(?)', $schemaName);
}
$sql .= " ORDER BY c.colno";
$desc = array();
$stmt = $this->_adapter->query($sql);
/**
* To avoid case issues, fetch using FETCH_NUM
*/
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
/**
* The ordering of columns is defined by the query so we can map
* to variables to improve readability
*/
$tabschema = 0;
$tabname = 1;
$colname = 2;
$colno = 3;
$typename = 4;
$default = 5;
$nulls = 6;
$length = 7;
$scale = 8;
$identityCol = 9;
$tabconstype = 10;
$colseq = 11;
foreach ($result as $key => $row) {
list ($primary, $primaryPosition, $identity) = array(false, null, false);
if ($row[$tabconstype] == 'P') {
$primary = true;
$primaryPosition = $row[$colseq];
}
/**
* In IBM DB2, an column can be IDENTITY
* even if it is not part of the PRIMARY KEY.
*/
if ($row[$identityCol] == 'Y') {
$identity = true;
}
$desc[$this->_adapter->foldCase($row[$colname])] = array(
'SCHEMA_NAME' => $this->_adapter->foldCase($row[$tabschema]),
'TABLE_NAME' => $this->_adapter->foldCase($row[$tabname]),
'COLUMN_NAME' => $this->_adapter->foldCase($row[$colname]),
'COLUMN_POSITION' => $row[$colno]+1,
'DATA_TYPE' => $row[$typename],
'DEFAULT' => $row[$default],
'NULLABLE' => (bool) ($row[$nulls] == 'Y'),
'LENGTH' => $row[$length],
'SCALE' => $row[$scale],
'PRECISION' => ($row[$typename] == 'DECIMAL' ? $row[$length] : 0),
'UNSIGNED' => false,
'PRIMARY' => $primary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
}
/**
* Adds a DB2-specific LIMIT clause to the SELECT statement.
*
* @param string $sql
* @param integer $count
* @param integer $offset OPTIONAL
* @throws Zend_Db_Adapter_Exception
* @return string
*/
public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count < 0) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
} else {
$offset = intval($offset);
if ($offset < 0) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
}
if ($offset == 0 && $count > 0) {
$limit_sql = $sql . " FETCH FIRST $count ROWS ONLY";
return $limit_sql;
}
/**
* DB2 does not implement the LIMIT clause as some RDBMS do.
* We have to simulate it with subqueries and ROWNUM.
* Unfortunately because we use the column wildcard "*",
* this puts an extra column into the query result set.
*/
$limit_sql = "SELECT z2.*
FROM (
SELECT ROW_NUMBER() OVER() AS \"ZEND_DB_ROWNUM\", z1.*
FROM (
" . $sql . "
) z1
) z2
WHERE z2.zend_db_rownum BETWEEN " . ($offset+1) . " AND " . ($offset+$count);
}
return $limit_sql;
}
/**
* DB2-specific last sequence id
*
* @param string $sequenceName
* @return integer
*/
public function lastSequenceId($sequenceName)
{
$sql = 'SELECT PREVVAL FOR '.$this->_adapter->quoteIdentifier($sequenceName).' AS VAL FROM SYSIBM.SYSDUMMY1';
$value = $this->_adapter->fetchOne($sql);
return $value;
}
/**
* DB2-specific sequence id value
*
* @param string $sequenceName
* @return integer
*/
public function nextSequenceId($sequenceName)
{
$sql = 'SELECT NEXTVAL FOR '.$this->_adapter->quoteIdentifier($sequenceName).' AS VAL FROM SYSIBM.SYSDUMMY1';
$value = $this->_adapter->fetchOne($sql);
return $value;
}
}
Pdo/Ibm/Ids.php 0000604 00000022167 15071336457 0007244 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: $
*/
/** @see Zend_Db_Adapter_Pdo_Ibm */
require_once 'Zend/Db/Adapter/Pdo/Ibm.php';
/** @see Zend_Db_Statement_Pdo_Ibm */
require_once 'Zend/Db/Statement/Pdo/Ibm.php';
/**
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Pdo_Ibm_Ids
{
/**
* @var Zend_Db_Adapter_Abstract
*/
protected $_adapter = null;
/**
* Construct the data server class.
*
* It will be used to generate non-generic SQL
* for a particular data server
*
* @param Zend_Db_Adapter_Abstract $adapter
*/
public function __construct($adapter)
{
$this->_adapter = $adapter;
}
/**
* Returns a list of the tables in the database.
*
* @return array
*/
public function listTables()
{
$sql = "SELECT tabname "
. "FROM systables ";
return $this->_adapter->fetchCol($sql);
}
/**
* IDS catalog lookup for describe table
*
* @param string $tableName
* @param string $schemaName OPTIONAL
* @return array
*/
public function describeTable($tableName, $schemaName = null)
{
// this is still a work in progress
$sql= "SELECT DISTINCT t.owner, t.tabname, c.colname, c.colno, c.coltype,
d.default, c.collength, t.tabid
FROM syscolumns c
JOIN systables t ON c.tabid = t.tabid
LEFT JOIN sysdefaults d ON c.tabid = d.tabid AND c.colno = d.colno
WHERE "
. $this->_adapter->quoteInto('UPPER(t.tabname) = UPPER(?)', $tableName);
if ($schemaName) {
$sql .= $this->_adapter->quoteInto(' AND UPPER(t.owner) = UPPER(?)', $schemaName);
}
$sql .= " ORDER BY c.colno";
$desc = array();
$stmt = $this->_adapter->query($sql);
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
/**
* The ordering of columns is defined by the query so we can map
* to variables to improve readability
*/
$tabschema = 0;
$tabname = 1;
$colname = 2;
$colno = 3;
$typename = 4;
$default = 5;
$length = 6;
$tabid = 7;
$primaryCols = null;
foreach ($result as $key => $row) {
$primary = false;
$primaryPosition = null;
if (!$primaryCols) {
$primaryCols = $this->_getPrimaryInfo($row[$tabid]);
}
if (array_key_exists($row[$colno], $primaryCols)) {
$primary = true;
$primaryPosition = $primaryCols[$row[$colno]];
}
$identity = false;
if ($row[$typename] == 6 + 256 ||
$row[$typename] == 18 + 256) {
$identity = true;
}
$desc[$this->_adapter->foldCase($row[$colname])] = array (
'SCHEMA_NAME' => $this->_adapter->foldCase($row[$tabschema]),
'TABLE_NAME' => $this->_adapter->foldCase($row[$tabname]),
'COLUMN_NAME' => $this->_adapter->foldCase($row[$colname]),
'COLUMN_POSITION' => $row[$colno],
'DATA_TYPE' => $this->_getDataType($row[$typename]),
'DEFAULT' => $row[$default],
'NULLABLE' => (bool) !($row[$typename] - 256 >= 0),
'LENGTH' => $row[$length],
'SCALE' => ($row[$typename] == 5 ? $row[$length]&255 : 0),
'PRECISION' => ($row[$typename] == 5 ? (int)($row[$length]/256) : 0),
'UNSIGNED' => false,
'PRIMARY' => $primary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
}
/**
* Map number representation of a data type
* to a string
*
* @param int $typeNo
* @return string
*/
protected function _getDataType($typeNo)
{
$typemap = array(
0 => "CHAR",
1 => "SMALLINT",
2 => "INTEGER",
3 => "FLOAT",
4 => "SMALLFLOAT",
5 => "DECIMAL",
6 => "SERIAL",
7 => "DATE",
8 => "MONEY",
9 => "NULL",
10 => "DATETIME",
11 => "BYTE",
12 => "TEXT",
13 => "VARCHAR",
14 => "INTERVAL",
15 => "NCHAR",
16 => "NVARCHAR",
17 => "INT8",
18 => "SERIAL8",
19 => "SET",
20 => "MULTISET",
21 => "LIST",
22 => "Unnamed ROW",
40 => "Variable-length opaque type",
4118 => "Named ROW"
);
if ($typeNo - 256 >= 0) {
$typeNo = $typeNo - 256;
}
return $typemap[$typeNo];
}
/**
* Helper method to retrieve primary key column
* and column location
*
* @param int $tabid
* @return array
*/
protected function _getPrimaryInfo($tabid)
{
$sql = "SELECT i.part1, i.part2, i.part3, i.part4, i.part5, i.part6,
i.part7, i.part8, i.part9, i.part10, i.part11, i.part12,
i.part13, i.part14, i.part15, i.part16
FROM sysindexes i
JOIN sysconstraints c ON c.idxname = i.idxname
WHERE i.tabid = " . $tabid . " AND c.constrtype = 'P'";
$stmt = $this->_adapter->query($sql);
$results = $stmt->fetchAll();
$cols = array();
// this should return only 1 row
// unless there is no primary key,
// in which case, the empty array is returned
if ($results) {
$row = $results[0];
} else {
return $cols;
}
$position = 0;
foreach ($row as $key => $colno) {
$position++;
if ($colno == 0) {
return $cols;
} else {
$cols[$colno] = $position;
}
}
}
/**
* Adds an IDS-specific LIMIT clause to the SELECT statement.
*
* @param string $sql
* @param integer $count
* @param integer $offset OPTIONAL
* @throws Zend_Db_Adapter_Exception
* @return string
*/
public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count < 0) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
} else if ($count == 0) {
$limit_sql = str_ireplace("SELECT", "SELECT * FROM (SELECT", $sql);
$limit_sql .= ") WHERE 0 = 1";
} else {
$offset = intval($offset);
if ($offset < 0) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
}
if ($offset == 0) {
$limit_sql = str_ireplace("SELECT", "SELECT FIRST $count", $sql);
} else {
$limit_sql = str_ireplace("SELECT", "SELECT SKIP $offset LIMIT $count", $sql);
}
}
return $limit_sql;
}
/**
* IDS-specific last sequence id
*
* @param string $sequenceName
* @return integer
*/
public function lastSequenceId($sequenceName)
{
$sql = 'SELECT '.$this->_adapter->quoteIdentifier($sequenceName).'.CURRVAL FROM '
.'systables WHERE tabid = 1';
$value = $this->_adapter->fetchOne($sql);
return $value;
}
/**
* IDS-specific sequence id value
*
* @param string $sequenceName
* @return integer
*/
public function nextSequenceId($sequenceName)
{
$sql = 'SELECT '.$this->_adapter->quoteIdentifier($sequenceName).'.NEXTVAL FROM '
.'systables WHERE tabid = 1';
$value = $this->_adapter->fetchOne($sql);
return $value;
}
}
Pdo/Sqlite.php 0000604 00000023534 15071336457 0007256 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Sqlite.php 9101 2008-03-30 19:54:38Z thomas $
*/
/**
* @see Zend_Db_Adapter_Pdo_Abstract
*/
require_once 'Zend/Db/Adapter/Pdo/Abstract.php';
/**
* Class for connecting to SQLite2 and SQLite3 databases and performing common operations.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Pdo_Sqlite extends Zend_Db_Adapter_Pdo_Abstract
{
/**
* PDO type
*
* @var string
*/
protected $_pdoType = 'sqlite';
/**
* Keys are UPPERCASE SQL datatypes or the constants
* Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
*
* Values are:
* 0 = 32-bit integer
* 1 = 64-bit integer
* 2 = float or decimal
*
* @var array Associative array of datatypes to values 0, 1, or 2.
*/
protected $_numericDataTypes = array(
Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
'INTEGER' => Zend_Db::BIGINT_TYPE,
'REAL' => Zend_Db::FLOAT_TYPE
);
/**
* Constructor.
*
* $config is an array of key/value pairs containing configuration
* options. Note that the SQLite options are different than most of
* the other PDO adapters in that no username or password are needed.
* Also, an extra config key "sqlite2" specifies compatibility mode.
*
* dbname => (string) The name of the database to user (required,
* use :memory: for memory-based database)
*
* sqlite2 => (boolean) PDO_SQLITE defaults to SQLite 3. For compatibility
* with an older SQLite 2 database, set this to TRUE.
*
* @param array $config An array of configuration keys.
*/
public function __construct(array $config = array())
{
if (isset($config['sqlite2']) && $config['sqlite2']) {
$this->_pdoType = 'sqlite2';
}
// SQLite uses no username/password. Stub to satisfy parent::_connect()
$this->_config['username'] = null;
$this->_config['password'] = null;
return parent::__construct($config);
}
/**
* Check for config options that are mandatory.
* Throw exceptions if any are missing.
*
* @param array $config
* @throws Zend_Db_Adapter_Exception
*/
protected function _checkRequiredOptions(array $config)
{
// we need at least a dbname
if (! array_key_exists('dbname', $config)) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'dbname' that names the database instance");
}
}
/**
* DSN builder
*/
protected function _dsn()
{
return $this->_pdoType .':'. $this->_config['dbname'];
}
/**
* Special configuration for SQLite behavior: make sure that result sets
* contain keys like 'column' instead of 'table.column'.
*
* @throws Zend_Db_Adapter_Exception
*/
protected function _connect()
{
/**
* if we already have a PDO object, no need to re-connect.
*/
if ($this->_connection) {
return;
}
parent::_connect();
$retval = $this->_connection->exec('PRAGMA full_column_names=0');
if ($retval === false) {
$error = $this->_connection->errorInfo();
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception($error[2]);
}
$retval = $this->_connection->exec('PRAGMA short_column_names=1');
if ($retval === false) {
$error = $this->_connection->errorInfo();
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception($error[2]);
}
}
/**
* Returns a list of the tables in the database.
*
* @return array
*/
public function listTables()
{
$sql = "SELECT name FROM sqlite_master WHERE type='table' "
. "UNION ALL SELECT name FROM sqlite_temp_master "
. "WHERE type='table' ORDER BY name";
return $this->fetchCol($sql);
}
/**
* Returns the column descriptions for a table.
*
* The return value is an associative array keyed by the column name,
* as returned by the RDBMS.
*
* The value of each array element is an associative array
* with the following keys:
*
* SCHEMA_NAME => string; name of database or schema
* TABLE_NAME => string;
* COLUMN_NAME => string; column name
* COLUMN_POSITION => number; ordinal position of column in table
* DATA_TYPE => string; SQL datatype name of column
* DEFAULT => string; default expression of column, null if none
* NULLABLE => boolean; true if column can have nulls
* LENGTH => number; length of CHAR/VARCHAR
* SCALE => number; scale of NUMERIC/DECIMAL
* PRECISION => number; precision of NUMERIC/DECIMAL
* UNSIGNED => boolean; unsigned property of an integer type
* PRIMARY => boolean; true if column is part of the primary key
* PRIMARY_POSITION => integer; position of column in primary key
* IDENTITY => integer; true if column is auto-generated with unique values
*
* @param string $tableName
* @param string $schemaName OPTIONAL
* @return array
*/
public function describeTable($tableName, $schemaName = null)
{
if ($schemaName) {
$sql = "PRAGMA $schemaName.table_info($tableName)";
} else {
$sql = "PRAGMA table_info($tableName)";
}
$stmt = $this->query($sql);
/**
* Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection
*/
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
$cid = 0;
$name = 1;
$type = 2;
$notnull = 3;
$dflt_value = 4;
$pk = 5;
$desc = array();
$p = 1;
foreach ($result as $key => $row) {
list($length, $scale, $precision, $primary, $primaryPosition, $identity) =
array(null, null, null, false, null, false);
if (preg_match('/^((?:var)?char)\((\d+)\)/i', $row[$type], $matches)) {
$row[$type] = $matches[1];
$length = $matches[2];
} else if (preg_match('/^decimal\((\d+),(\d+)\)/i', $row[$type], $matches)) {
$row[$type] = 'DECIMAL';
$precision = $matches[1];
$scale = $matches[2];
}
if ((bool) $row[$pk]) {
$primary = true;
$primaryPosition = $p;
/**
* SQLite INTEGER primary key is always auto-increment.
*/
$identity = (bool) ($row[$type] == 'INTEGER');
++$p;
}
$desc[$this->foldCase($row[$name])] = array(
'SCHEMA_NAME' => $this->foldCase($schemaName),
'TABLE_NAME' => $this->foldCase($tableName),
'COLUMN_NAME' => $this->foldCase($row[$name]),
'COLUMN_POSITION' => $row[$cid]+1,
'DATA_TYPE' => $row[$type],
'DEFAULT' => $row[$dflt_value],
'NULLABLE' => ! (bool) $row[$notnull],
'LENGTH' => $length,
'SCALE' => $scale,
'PRECISION' => $precision,
'UNSIGNED' => null, // Sqlite3 does not support unsigned data
'PRIMARY' => $primary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
*
* @param string $sql
* @param integer $count
* @param integer $offset OPTIONAL
* @return string
*/
public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count <= 0) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
}
$offset = intval($offset);
if ($offset < 0) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
}
$sql .= " LIMIT $count";
if ($offset > 0) {
$sql .= " OFFSET $offset";
}
return $sql;
}
}
Pdo/Pgsql.php 0000604 00000025741 15071336457 0007105 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Pgsql.php 9101 2008-03-30 19:54:38Z thomas $
*/
/**
* @see Zend_Db_Adapter_Pdo_Abstract
*/
require_once 'Zend/Db/Adapter/Pdo/Abstract.php';
/**
* Class for connecting to PostgreSQL databases and performing common operations.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Abstract
{
/**
* PDO type.
*
* @var string
*/
protected $_pdoType = 'pgsql';
/**
* Keys are UPPERCASE SQL datatypes or the constants
* Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
*
* Values are:
* 0 = 32-bit integer
* 1 = 64-bit integer
* 2 = float or decimal
*
* @var array Associative array of datatypes to values 0, 1, or 2.
*/
protected $_numericDataTypes = array(
Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
'INTEGER' => Zend_Db::INT_TYPE,
'SERIAL' => Zend_Db::INT_TYPE,
'SMALLINT' => Zend_Db::INT_TYPE,
'BIGINT' => Zend_Db::BIGINT_TYPE,
'BIGSERIAL' => Zend_Db::BIGINT_TYPE,
'DECIMAL' => Zend_Db::FLOAT_TYPE,
'DOUBLE PRECISION' => Zend_Db::FLOAT_TYPE,
'NUMERIC' => Zend_Db::FLOAT_TYPE,
'REAL' => Zend_Db::FLOAT_TYPE
);
/**
* Returns a list of the tables in the database.
*
* @return array
*/
public function listTables()
{
// @todo use a better query with joins instead of subqueries
$sql = "SELECT c.relname AS table_name "
. "FROM pg_class c, pg_user u "
. "WHERE c.relowner = u.usesysid AND c.relkind = 'r' "
. "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
. "AND c.relname !~ '^(pg_|sql_)' "
. "UNION "
. "SELECT c.relname AS table_name "
. "FROM pg_class c "
. "WHERE c.relkind = 'r' "
. "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
. "AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner) "
. "AND c.relname !~ '^pg_'";
return $this->fetchCol($sql);
}
/**
* Returns the column descriptions for a table.
*
* The return value is an associative array keyed by the column name,
* as returned by the RDBMS.
*
* The value of each array element is an associative array
* with the following keys:
*
* SCHEMA_NAME => string; name of database or schema
* TABLE_NAME => string;
* COLUMN_NAME => string; column name
* COLUMN_POSITION => number; ordinal position of column in table
* DATA_TYPE => string; SQL datatype name of column
* DEFAULT => string; default expression of column, null if none
* NULLABLE => boolean; true if column can have nulls
* LENGTH => number; length of CHAR/VARCHAR
* SCALE => number; scale of NUMERIC/DECIMAL
* PRECISION => number; precision of NUMERIC/DECIMAL
* UNSIGNED => boolean; unsigned property of an integer type
* PRIMARY => boolean; true if column is part of the primary key
* PRIMARY_POSITION => integer; position of column in primary key
* IDENTITY => integer; true if column is auto-generated with unique values
*
* @todo Discover integer unsigned property.
*
* @param string $tableName
* @param string $schemaName OPTIONAL
* @return array
*/
public function describeTable($tableName, $schemaName = null)
{
$sql = "SELECT
a.attnum,
n.nspname,
c.relname,
a.attname AS colname,
t.typname AS type,
a.atttypmod,
FORMAT_TYPE(a.atttypid, a.atttypmod) AS complete_type,
d.adsrc AS default_value,
a.attnotnull AS notnull,
a.attlen AS length,
co.contype,
ARRAY_TO_STRING(co.conkey, ',') AS conkey
FROM pg_attribute AS a
JOIN pg_class AS c ON a.attrelid = c.oid
JOIN pg_namespace AS n ON c.relnamespace = n.oid
JOIN pg_type AS t ON a.atttypid = t.oid
LEFT OUTER JOIN pg_constraint AS co ON (co.conrelid = c.oid
AND a.attnum = ANY(co.conkey) AND co.contype = 'p')
LEFT OUTER JOIN pg_attrdef AS d ON d.adrelid = c.oid AND d.adnum = a.attnum
WHERE a.attnum > 0 AND c.relname = ".$this->quote($tableName);
if ($schemaName) {
$sql .= " AND n.nspname = ".$this->quote($schemaName);
}
$sql .= ' ORDER BY a.attnum';
$stmt = $this->query($sql);
// Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
$attnum = 0;
$nspname = 1;
$relname = 2;
$colname = 3;
$type = 4;
$atttypemod = 5;
$complete_type = 6;
$default_value = 7;
$notnull = 8;
$length = 9;
$contype = 10;
$conkey = 11;
$desc = array();
foreach ($result as $key => $row) {
if ($row[$type] == 'varchar') {
if (preg_match('/character varying(?:\((\d+)\))?/', $row[$complete_type], $matches)) {
if (isset($matches[1])) {
$row[$length] = $matches[1];
} else {
$row[$length] = null; // unlimited
}
}
}
list($primary, $primaryPosition, $identity) = array(false, null, false);
if ($row[$contype] == 'p') {
$primary = true;
$primaryPosition = array_search($row[$attnum], explode(',', $row[$conkey])) + 1;
$identity = (bool) (preg_match('/^nextval/', $row[$default_value]));
}
$desc[$this->foldCase($row[$colname])] = array(
'SCHEMA_NAME' => $this->foldCase($row[$nspname]),
'TABLE_NAME' => $this->foldCase($row[$relname]),
'COLUMN_NAME' => $this->foldCase($row[$colname]),
'COLUMN_POSITION' => $row[$attnum],
'DATA_TYPE' => $row[$type],
'DEFAULT' => $row[$default_value],
'NULLABLE' => (bool) ($row[$notnull] != 't'),
'LENGTH' => $row[$length],
'SCALE' => null, // @todo
'PRECISION' => null, // @todo
'UNSIGNED' => null, // @todo
'PRIMARY' => $primary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
*
* @param string $sql
* @param integer $count
* @param integer $offset OPTIONAL
* @return string
*/
public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count <= 0) {
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
}
$offset = intval($offset);
if ($offset < 0) {
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
}
$sql .= " LIMIT $count";
if ($offset > 0) {
$sql .= " OFFSET $offset";
}
return $sql;
}
/**
* Return the most recent value from the specified sequence in the database.
* This is supported only on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return string
*/
public function lastSequenceId($sequenceName)
{
$this->_connect();
$value = $this->fetchOne("SELECT CURRVAL(".$this->quote($sequenceName).")");
return $value;
}
/**
* Generate a new value from the specified sequence in the database, and return it.
* This is supported only on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return string
*/
public function nextSequenceId($sequenceName)
{
$this->_connect();
$value = $this->fetchOne("SELECT NEXTVAL(".$this->quote($sequenceName).")");
return $value;
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* As a convention, on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
* from the arguments and returns the last id generated by that sequence.
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
* returns the last value generated for such a column, and the table name
* argument is disregarded.
*
* @param string $tableName OPTIONAL Name of table.
* @param string $primaryKey OPTIONAL Name of primary key column.
* @return string
*/
public function lastInsertId($tableName = null, $primaryKey = null)
{
if ($tableName !== null) {
$sequenceName = $tableName;
if ($primaryKey) {
$sequenceName .= "_$primaryKey";
}
$sequenceName .= '_seq';
return $this->lastSequenceId($sequenceName);
}
return $this->_connection->lastInsertId($tableName);
}
}
Pdo/Oci.php 0000604 00000032635 15071336457 0006531 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Oci.php 13284 2008-12-15 21:41:49Z mikaelkael $
*/
/**
* @see Zend_Db_Adapter_Pdo_Abstract
*/
require_once 'Zend/Db/Adapter/Pdo/Abstract.php';
/**
* Class for connecting to Oracle databases and performing common operations.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Pdo_Oci extends Zend_Db_Adapter_Pdo_Abstract
{
/**
* PDO type.
*
* @var string
*/
protected $_pdoType = 'oci';
/**
* Keys are UPPERCASE SQL datatypes or the constants
* Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
*
* Values are:
* 0 = 32-bit integer
* 1 = 64-bit integer
* 2 = float or decimal
*
* @var array Associative array of datatypes to values 0, 1, or 2.
*/
protected $_numericDataTypes = array(
Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
'BINARY_DOUBLE' => Zend_Db::FLOAT_TYPE,
'BINARY_FLOAT' => Zend_Db::FLOAT_TYPE,
'NUMBER' => Zend_Db::FLOAT_TYPE
);
/**
* Creates a PDO DSN for the adapter from $this->_config settings.
*
* @return string
*/
protected function _dsn()
{
// baseline of DSN parts
$dsn = $this->_config;
$tns = 'dbname=(DESCRIPTION=';
if (isset($dsn['host'])) {
$tns .= '(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=' . $dsn['host'] . ')';
if (isset($dsn['port'])) {
$tns .= '(PORT=' . $dsn['port'] . ')';
} else {
$tns .= '(PORT=1521)';
}
$tns .= '))';
}
$tns .= '(CONNECT_DATA=(SID=' . $dsn['dbname'] . ')))';
if (isset($dsn['charset']))
{
$tns .= ';charset=' . $dsn['charset'];
}
return $this->_pdoType . ':' . $tns;
}
/**
* Quote a raw string.
* Most PDO drivers have an implementation for the quote() method,
* but the Oracle OCI driver must use the same implementation as the
* Zend_Db_Adapter_Abstract class.
*
* @param string $value Raw string
* @return string Quoted string
*/
protected function _quote($value)
{
if (is_int($value) || is_float($value)) {
return $value;
}
$value = str_replace("'", "''", $value);
return "'" . addcslashes($value, "\000\n\r\\\032") . "'";
}
/**
* Quote a table identifier and alias.
*
* @param string|array|Zend_Db_Expr $ident The identifier or expression.
* @param string $alias An alias for the table.
* @return string The quoted identifier and alias.
*/
public function quoteTableAs($ident, $alias = null, $auto = false)
{
// Oracle doesn't allow the 'AS' keyword between the table identifier/expression and alias.
return $this->_quoteIdentifierAs($ident, $alias, $auto, ' ');
}
/**
* Returns a list of the tables in the database.
*
* @return array
*/
public function listTables()
{
$data = $this->fetchCol('SELECT table_name FROM all_tables');
return $data;
}
/**
* Returns the column descriptions for a table.
*
* The return value is an associative array keyed by the column name,
* as returned by the RDBMS.
*
* The value of each array element is an associative array
* with the following keys:
*
* SCHEMA_NAME => string; name of schema
* TABLE_NAME => string;
* COLUMN_NAME => string; column name
* COLUMN_POSITION => number; ordinal position of column in table
* DATA_TYPE => string; SQL datatype name of column
* DEFAULT => string; default expression of column, null if none
* NULLABLE => boolean; true if column can have nulls
* LENGTH => number; length of CHAR/VARCHAR
* SCALE => number; scale of NUMERIC/DECIMAL
* PRECISION => number; precision of NUMERIC/DECIMAL
* UNSIGNED => boolean; unsigned property of an integer type
* PRIMARY => boolean; true if column is part of the primary key
* PRIMARY_POSITION => integer; position of column in primary key
* IDENTITY => integer; true if column is auto-generated with unique values
*
* @todo Discover integer unsigned property.
*
* @param string $tableName
* @param string $schemaName OPTIONAL
* @return array
*/
public function describeTable($tableName, $schemaName = null)
{
$version = $this->getServerVersion();
if (is_null($version) || version_compare($version, '9.0.0', '>=')) {
$sql = "SELECT TC.TABLE_NAME, TC.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,
TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH,
TC.DATA_SCALE, TC.DATA_PRECISION, C.CONSTRAINT_TYPE, CC.POSITION
FROM ALL_TAB_COLUMNS TC
LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C
ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND C.CONSTRAINT_TYPE = 'P'))
ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME
WHERE UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)";
$bind[':TBNAME'] = $tableName;
if ($schemaName) {
$sql .= ' AND UPPER(TC.OWNER) = UPPER(:SCNAME)';
$bind[':SCNAME'] = $schemaName;
}
$sql .= ' ORDER BY TC.COLUMN_ID';
} else {
$subSql="SELECT AC.OWNER, AC.TABLE_NAME, ACC.COLUMN_NAME, AC.CONSTRAINT_TYPE, ACC.POSITION
from ALL_CONSTRAINTS AC, ALL_CONS_COLUMNS ACC
WHERE ACC.CONSTRAINT_NAME = AC.CONSTRAINT_NAME
AND ACC.TABLE_NAME = AC.TABLE_NAME
AND ACC.OWNER = AC.OWNER
AND AC.CONSTRAINT_TYPE = 'P'
AND UPPER(AC.TABLE_NAME) = UPPER(:TBNAME)";
$bind[':TBNAME'] = $tableName;
if ($schemaName) {
$subSql .= ' AND UPPER(ACC.OWNER) = UPPER(:SCNAME)';
$bind[':SCNAME'] = $schemaName;
}
$sql="SELECT TC.TABLE_NAME, TC.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,
TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH,
TC.DATA_SCALE, TC.DATA_PRECISION, CC.CONSTRAINT_TYPE, CC.POSITION
FROM ALL_TAB_COLUMNS TC, ($subSql) CC
WHERE UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)
AND TC.OWNER = CC.OWNER(+) AND TC.TABLE_NAME = CC.TABLE_NAME(+) AND TC.COLUMN_NAME = CC.COLUMN_NAME(+)";
if ($schemaName) {
$sql .= ' AND UPPER(TC.OWNER) = UPPER(:SCNAME)';
}
$sql .= ' ORDER BY TC.COLUMN_ID';
}
$stmt = $this->query($sql, $bind);
/**
* Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection
*/
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
$table_name = 0;
$owner = 1;
$column_name = 2;
$data_type = 3;
$data_default = 4;
$nullable = 5;
$column_id = 6;
$data_length = 7;
$data_scale = 8;
$data_precision = 9;
$constraint_type = 10;
$position = 11;
$desc = array();
foreach ($result as $key => $row) {
list ($primary, $primaryPosition, $identity) = array(false, null, false);
if ($row[$constraint_type] == 'P') {
$primary = true;
$primaryPosition = $row[$position];
/**
* Oracle does not support auto-increment keys.
*/
$identity = false;
}
$desc[$this->foldCase($row[$column_name])] = array(
'SCHEMA_NAME' => $this->foldCase($row[$owner]),
'TABLE_NAME' => $this->foldCase($row[$table_name]),
'COLUMN_NAME' => $this->foldCase($row[$column_name]),
'COLUMN_POSITION' => $row[$column_id],
'DATA_TYPE' => $row[$data_type],
'DEFAULT' => $row[$data_default],
'NULLABLE' => (bool) ($row[$nullable] == 'Y'),
'LENGTH' => $row[$data_length],
'SCALE' => $row[$data_scale],
'PRECISION' => $row[$data_precision],
'UNSIGNED' => null, // @todo
'PRIMARY' => $primary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
}
/**
* Return the most recent value from the specified sequence in the database.
* This is supported only on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return integer
*/
public function lastSequenceId($sequenceName)
{
$this->_connect();
$value = $this->fetchOne('SELECT '.$this->quoteIdentifier($sequenceName, true).'.CURRVAL FROM dual');
return $value;
}
/**
* Generate a new value from the specified sequence in the database, and return it.
* This is supported only on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return integer
*/
public function nextSequenceId($sequenceName)
{
$this->_connect();
$value = $this->fetchOne('SELECT '.$this->quoteIdentifier($sequenceName, true).'.NEXTVAL FROM dual');
return $value;
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* As a convention, on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
* from the arguments and returns the last id generated by that sequence.
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
* returns the last value generated for such a column, and the table name
* argument is disregarded.
*
* Oracle does not support IDENTITY columns, so if the sequence is not
* specified, this method returns null.
*
* @param string $tableName OPTIONAL Name of table.
* @param string $primaryKey OPTIONAL Name of primary key column.
* @return string
* @throws Zend_Db_Adapter_Oracle_Exception
*/
public function lastInsertId($tableName = null, $primaryKey = null)
{
if ($tableName !== null) {
$sequenceName = $tableName;
if ($primaryKey) {
$sequenceName .= $this->foldCase("_$primaryKey");
}
$sequenceName .= $this->foldCase('_seq');
return $this->lastSequenceId($sequenceName);
}
// No support for IDENTITY columns; return null
return null;
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
*
* @param string $sql
* @param integer $count
* @param integer $offset
* @throws Zend_Db_Adapter_Exception
* @return string
*/
public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count <= 0) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
}
$offset = intval($offset);
if ($offset < 0) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
}
/**
* Oracle does not implement the LIMIT clause as some RDBMS do.
* We have to simulate it with subqueries and ROWNUM.
* Unfortunately because we use the column wildcard "*",
* this puts an extra column into the query result set.
*/
$limit_sql = "SELECT z2.*
FROM (
SELECT ROWNUM AS zend_db_rownum, z1.*
FROM (
" . $sql . "
) z1
) z2
WHERE z2.zend_db_rownum BETWEEN " . ($offset+1) . " AND " . ($offset+$count);
return $limit_sql;
}
}
Pdo/Mysql.php 0000604 00000020377 15071336457 0007124 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Mysql.php 12842 2008-11-25 22:07:48Z mikaelkael $
*/
/**
* @see Zend_Db_Adapter_Pdo_Abstract
*/
require_once 'Zend/Db/Adapter/Pdo/Abstract.php';
/**
* Class for connecting to MySQL databases and performing common operations.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Abstract
{
/**
* PDO type.
*
* @var string
*/
protected $_pdoType = 'mysql';
/**
* Keys are UPPERCASE SQL datatypes or the constants
* Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
*
* Values are:
* 0 = 32-bit integer
* 1 = 64-bit integer
* 2 = float or decimal
*
* @var array Associative array of datatypes to values 0, 1, or 2.
*/
protected $_numericDataTypes = array(
Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
'INT' => Zend_Db::INT_TYPE,
'INTEGER' => Zend_Db::INT_TYPE,
'MEDIUMINT' => Zend_Db::INT_TYPE,
'SMALLINT' => Zend_Db::INT_TYPE,
'TINYINT' => Zend_Db::INT_TYPE,
'BIGINT' => Zend_Db::BIGINT_TYPE,
'SERIAL' => Zend_Db::BIGINT_TYPE,
'DEC' => Zend_Db::FLOAT_TYPE,
'DECIMAL' => Zend_Db::FLOAT_TYPE,
'DOUBLE' => Zend_Db::FLOAT_TYPE,
'DOUBLE PRECISION' => Zend_Db::FLOAT_TYPE,
'FIXED' => Zend_Db::FLOAT_TYPE,
'FLOAT' => Zend_Db::FLOAT_TYPE
);
/**
* @return string
*/
public function getQuoteIdentifierSymbol()
{
return "`";
}
/**
* Returns a list of the tables in the database.
*
* @return array
*/
public function listTables()
{
return $this->fetchCol('SHOW TABLES');
}
/**
* Returns the column descriptions for a table.
*
* The return value is an associative array keyed by the column name,
* as returned by the RDBMS.
*
* The value of each array element is an associative array
* with the following keys:
*
* SCHEMA_NAME => string; name of database or schema
* TABLE_NAME => string;
* COLUMN_NAME => string; column name
* COLUMN_POSITION => number; ordinal position of column in table
* DATA_TYPE => string; SQL datatype name of column
* DEFAULT => string; default expression of column, null if none
* NULLABLE => boolean; true if column can have nulls
* LENGTH => number; length of CHAR/VARCHAR
* SCALE => number; scale of NUMERIC/DECIMAL
* PRECISION => number; precision of NUMERIC/DECIMAL
* UNSIGNED => boolean; unsigned property of an integer type
* PRIMARY => boolean; true if column is part of the primary key
* PRIMARY_POSITION => integer; position of column in primary key
* IDENTITY => integer; true if column is auto-generated with unique values
*
* @param string $tableName
* @param string $schemaName OPTIONAL
* @return array
*/
public function describeTable($tableName, $schemaName = null)
{
// @todo use INFORMATION_SCHEMA someday when MySQL's
// implementation has reasonably good performance and
// the version with this improvement is in wide use.
if ($schemaName) {
$sql = 'DESCRIBE ' . $this->quoteIdentifier("$schemaName.$tableName", true);
} else {
$sql = 'DESCRIBE ' . $this->quoteIdentifier($tableName, true);
}
$stmt = $this->query($sql);
// Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
$field = 0;
$type = 1;
$null = 2;
$key = 3;
$default = 4;
$extra = 5;
$desc = array();
$i = 1;
$p = 1;
foreach ($result as $row) {
list($length, $scale, $precision, $unsigned, $primary, $primaryPosition, $identity)
= array(null, null, null, null, false, null, false);
if (preg_match('/unsigned/', $row[$type])) {
$unsigned = true;
}
if (preg_match('/^((?:var)?char)\((\d+)\)/', $row[$type], $matches)) {
$row[$type] = $matches[1];
$length = $matches[2];
} else if (preg_match('/^decimal\((\d+),(\d+)\)/', $row[$type], $matches)) {
$row[$type] = 'decimal';
$precision = $matches[1];
$scale = $matches[2];
} else if (preg_match('/^float\((\d+),(\d+)\)/', $row[$type], $matches)) {
$row[$type] = 'float';
$precision = $matches[1];
$scale = $matches[2];
} else if (preg_match('/^((?:big|medium|small|tiny)?int)\((\d+)\)/', $row[$type], $matches)) {
$row[$type] = $matches[1];
// The optional argument of a MySQL int type is not precision
// or length; it is only a hint for display width.
}
if (strtoupper($row[$key]) == 'PRI') {
$primary = true;
$primaryPosition = $p;
if ($row[$extra] == 'auto_increment') {
$identity = true;
} else {
$identity = false;
}
++$p;
}
$desc[$this->foldCase($row[$field])] = array(
'SCHEMA_NAME' => null, // @todo
'TABLE_NAME' => $this->foldCase($tableName),
'COLUMN_NAME' => $this->foldCase($row[$field]),
'COLUMN_POSITION' => $i,
'DATA_TYPE' => $row[$type],
'DEFAULT' => $row[$default],
'NULLABLE' => (bool) ($row[$null] == 'YES'),
'LENGTH' => $length,
'SCALE' => $scale,
'PRECISION' => $precision,
'UNSIGNED' => $unsigned,
'PRIMARY' => $primary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
++$i;
}
return $desc;
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
*
* @param string $sql
* @param integer $count
* @param integer $offset OPTIONAL
* @throws Zend_Db_Adapter_Exception
* @return string
*/
public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count <= 0) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
}
$offset = intval($offset);
if ($offset < 0) {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
}
$sql .= " LIMIT $count";
if ($offset > 0) {
$sql .= " OFFSET $offset";
}
return $sql;
}
}
Mysqli.php 0000604 00000041421 15071336457 0006544 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Mysqli.php 13281 2008-12-15 20:53:30Z mikaelkael $
*/
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Db_Adapter_Abstract
*/
require_once 'Zend/Db/Adapter/Abstract.php';
/**
* @see Zend_Db_Profiler
*/
require_once 'Zend/Db/Profiler.php';
/**
* @see Zend_Db_Select
*/
require_once 'Zend/Db/Select.php';
/**
* @see Zend_Db_Statement_Mysqli
*/
require_once 'Zend/Db/Statement/Mysqli.php';
/**
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
{
/**
* Keys are UPPERCASE SQL datatypes or the constants
* Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
*
* Values are:
* 0 = 32-bit integer
* 1 = 64-bit integer
* 2 = float or decimal
*
* @var array Associative array of datatypes to values 0, 1, or 2.
*/
protected $_numericDataTypes = array(
Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
'INT' => Zend_Db::INT_TYPE,
'INTEGER' => Zend_Db::INT_TYPE,
'MEDIUMINT' => Zend_Db::INT_TYPE,
'SMALLINT' => Zend_Db::INT_TYPE,
'TINYINT' => Zend_Db::INT_TYPE,
'BIGINT' => Zend_Db::BIGINT_TYPE,
'SERIAL' => Zend_Db::BIGINT_TYPE,
'DEC' => Zend_Db::FLOAT_TYPE,
'DECIMAL' => Zend_Db::FLOAT_TYPE,
'DOUBLE' => Zend_Db::FLOAT_TYPE,
'DOUBLE PRECISION' => Zend_Db::FLOAT_TYPE,
'FIXED' => Zend_Db::FLOAT_TYPE,
'FLOAT' => Zend_Db::FLOAT_TYPE
);
/**
* @var Zend_Db_Statement_Mysqli
*/
protected $_stmt = null;
/**
* Default class name for a DB statement.
*
* @var string
*/
protected $_defaultStmtClass = 'Zend_Db_Statement_Mysqli';
/**
* Quote a raw string.
*
* @param mixed $value Raw string
*
* @return string Quoted string
*/
protected function _quote($value)
{
if (is_int($value) || is_float($value)) {
return $value;
}
$this->_connect();
return "'" . $this->_connection->real_escape_string($value) . "'";
}
/**
* Returns the symbol the adapter uses for delimiting identifiers.
*
* @return string
*/
public function getQuoteIdentifierSymbol()
{
return "`";
}
/**
* Returns a list of the tables in the database.
*
* @return array
*/
public function listTables()
{
$result = array();
// Use mysqli extension API, because SHOW doesn't work
// well as a prepared statement on MySQL 4.1.
$sql = 'SHOW TABLES';
if ($queryResult = $this->getConnection()->query($sql)) {
while ($row = $queryResult->fetch_row()) {
$result[] = $row[0];
}
$queryResult->close();
} else {
/**
* @see Zend_Db_Adapter_Mysqli_Exception
*/
require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
throw new Zend_Db_Adapter_Mysqli_Exception($this->getConnection()->error);
}
return $result;
}
/**
* Returns the column descriptions for a table.
*
* The return value is an associative array keyed by the column name,
* as returned by the RDBMS.
*
* The value of each array element is an associative array
* with the following keys:
*
* SCHEMA_NAME => string; name of database or schema
* TABLE_NAME => string;
* COLUMN_NAME => string; column name
* COLUMN_POSITION => number; ordinal position of column in table
* DATA_TYPE => string; SQL datatype name of column
* DEFAULT => string; default expression of column, null if none
* NULLABLE => boolean; true if column can have nulls
* LENGTH => number; length of CHAR/VARCHAR
* SCALE => number; scale of NUMERIC/DECIMAL
* PRECISION => number; precision of NUMERIC/DECIMAL
* UNSIGNED => boolean; unsigned property of an integer type
* PRIMARY => boolean; true if column is part of the primary key
* PRIMARY_POSITION => integer; position of column in primary key
* IDENTITY => integer; true if column is auto-generated with unique values
*
* @param string $tableName
* @param string $schemaName OPTIONAL
* @return array
*/
public function describeTable($tableName, $schemaName = null)
{
/**
* @todo use INFORMATION_SCHEMA someday when
* MySQL's implementation isn't too slow.
*/
if ($schemaName) {
$sql = 'DESCRIBE ' . $this->quoteIdentifier("$schemaName.$tableName", true);
} else {
$sql = 'DESCRIBE ' . $this->quoteIdentifier($tableName, true);
}
/**
* Use mysqli extension API, because DESCRIBE doesn't work
* well as a prepared statement on MySQL 4.1.
*/
if ($queryResult = $this->getConnection()->query($sql)) {
while ($row = $queryResult->fetch_assoc()) {
$result[] = $row;
}
$queryResult->close();
} else {
/**
* @see Zend_Db_Adapter_Mysqli_Exception
*/
require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
throw new Zend_Db_Adapter_Mysqli_Exception($this->getConnection()->error);
}
$desc = array();
$row_defaults = array(
'Length' => null,
'Scale' => null,
'Precision' => null,
'Unsigned' => null,
'Primary' => false,
'PrimaryPosition' => null,
'Identity' => false
);
$i = 1;
$p = 1;
foreach ($result as $key => $row) {
$row = array_merge($row_defaults, $row);
if (preg_match('/unsigned/', $row['Type'])) {
$row['Unsigned'] = true;
}
if (preg_match('/^((?:var)?char)\((\d+)\)/', $row['Type'], $matches)) {
$row['Type'] = $matches[1];
$row['Length'] = $matches[2];
} else if (preg_match('/^decimal\((\d+),(\d+)\)/', $row['Type'], $matches)) {
$row['Type'] = 'decimal';
$row['Precision'] = $matches[1];
$row['Scale'] = $matches[2];
} else if (preg_match('/^float\((\d+),(\d+)\)/', $row['Type'], $matches)) {
$row['Type'] = 'float';
$row['Precision'] = $matches[1];
$row['Scale'] = $matches[2];
} else if (preg_match('/^((?:big|medium|small|tiny)?int)\((\d+)\)/', $row['Type'], $matches)) {
$row['Type'] = $matches[1];
/**
* The optional argument of a MySQL int type is not precision
* or length; it is only a hint for display width.
*/
}
if (strtoupper($row['Key']) == 'PRI') {
$row['Primary'] = true;
$row['PrimaryPosition'] = $p;
if ($row['Extra'] == 'auto_increment') {
$row['Identity'] = true;
} else {
$row['Identity'] = false;
}
++$p;
}
$desc[$this->foldCase($row['Field'])] = array(
'SCHEMA_NAME' => null, // @todo
'TABLE_NAME' => $this->foldCase($tableName),
'COLUMN_NAME' => $this->foldCase($row['Field']),
'COLUMN_POSITION' => $i,
'DATA_TYPE' => $row['Type'],
'DEFAULT' => $row['Default'],
'NULLABLE' => (bool) ($row['Null'] == 'YES'),
'LENGTH' => $row['Length'],
'SCALE' => $row['Scale'],
'PRECISION' => $row['Precision'],
'UNSIGNED' => $row['Unsigned'],
'PRIMARY' => $row['Primary'],
'PRIMARY_POSITION' => $row['PrimaryPosition'],
'IDENTITY' => $row['Identity']
);
++$i;
}
return $desc;
}
/**
* Creates a connection to the database.
*
* @return void
* @throws Zend_Db_Adapter_Mysqli_Exception
*/
protected function _connect()
{
if ($this->_connection) {
return;
}
if (!extension_loaded('mysqli')) {
/**
* @see Zend_Db_Adapter_Mysqli_Exception
*/
require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
throw new Zend_Db_Adapter_Mysqli_Exception('The Mysqli extension is required for this adapter but the extension is not loaded');
}
if (isset($this->_config['port'])) {
$port = (integer) $this->_config['port'];
} else {
$port = null;
}
$this->_connection = mysqli_init();
if(!empty($this->_config['driver_options'])) {
foreach($this->_config['driver_options'] as $option=>$value) {
if(is_string($option)) {
// Suppress warnings here
// Ignore it if it's not a valid constant
$option = @constant(strtoupper($option));
if(is_null($option))
continue;
}
mysqli_options($this->_connection, $option, $value);
}
}
// Suppress connection warnings here.
// Throw an exception instead.
$_isConnected = @mysqli_real_connect(
$this->_connection,
$this->_config['host'],
$this->_config['username'],
$this->_config['password'],
$this->_config['dbname'],
$port
);
if ($_isConnected === false || mysqli_connect_errno()) {
/**
* @see Zend_Db_Adapter_Mysqli_Exception
*/
require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error());
}
}
/**
* Test if a connection is active
*
* @return boolean
*/
public function isConnected()
{
return ((bool) ($this->_connection instanceof mysqli));
}
/**
* Force the connection to close.
*
* @return void
*/
public function closeConnection()
{
if ($this->isConnected()) {
$this->_connection->close();
}
$this->_connection = null;
}
/**
* Prepare a statement and return a PDOStatement-like object.
*
* @param string $sql SQL query
* @return Zend_Db_Statement_Mysqli
*/
public function prepare($sql)
{
$this->_connect();
if ($this->_stmt) {
$this->_stmt->close();
}
$stmtClass = $this->_defaultStmtClass;
Zend_Loader::loadClass($stmtClass);
$stmt = new $stmtClass($this, $sql);
if ($stmt === false) {
return false;
}
$stmt->setFetchMode($this->_fetchMode);
$this->_stmt = $stmt;
return $stmt;
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* As a convention, on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
* from the arguments and returns the last id generated by that sequence.
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
* returns the last value generated for such a column, and the table name
* argument is disregarded.
*
* MySQL does not support sequences, so $tableName and $primaryKey are ignored.
*
* @param string $tableName OPTIONAL Name of table.
* @param string $primaryKey OPTIONAL Name of primary key column.
* @return string
* @todo Return value should be int?
*/
public function lastInsertId($tableName = null, $primaryKey = null)
{
$mysqli = $this->_connection;
return (string) $mysqli->insert_id;
}
/**
* Begin a transaction.
*
* @return void
*/
protected function _beginTransaction()
{
$this->_connect();
$this->_connection->autocommit(false);
}
/**
* Commit a transaction.
*
* @return void
*/
protected function _commit()
{
$this->_connect();
$this->_connection->commit();
$this->_connection->autocommit(true);
}
/**
* Roll-back a transaction.
*
* @return void
*/
protected function _rollBack()
{
$this->_connect();
$this->_connection->rollback();
$this->_connection->autocommit(true);
}
/**
* Set the fetch mode.
*
* @param int $mode
* @return void
* @throws Zend_Db_Adapter_Mysqli_Exception
*/
public function setFetchMode($mode)
{
switch ($mode) {
case Zend_Db::FETCH_LAZY:
case Zend_Db::FETCH_ASSOC:
case Zend_Db::FETCH_NUM:
case Zend_Db::FETCH_BOTH:
case Zend_Db::FETCH_NAMED:
case Zend_Db::FETCH_OBJ:
$this->_fetchMode = $mode;
break;
case Zend_Db::FETCH_BOUND: // bound to PHP variable
/**
* @see Zend_Db_Adapter_Mysqli_Exception
*/
require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
throw new Zend_Db_Adapter_Mysqli_Exception('FETCH_BOUND is not supported yet');
break;
default:
/**
* @see Zend_Db_Adapter_Mysqli_Exception
*/
require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
throw new Zend_Db_Adapter_Mysqli_Exception("Invalid fetch mode '$mode' specified");
}
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
*
* @param string $sql
* @param int $count
* @param int $offset OPTIONAL
* @return string
*/
public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count <= 0) {
/**
* @see Zend_Db_Adapter_Mysqli_Exception
*/
require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
throw new Zend_Db_Adapter_Mysqli_Exception("LIMIT argument count=$count is not valid");
}
$offset = intval($offset);
if ($offset < 0) {
/**
* @see Zend_Db_Adapter_Mysqli_Exception
*/
require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
throw new Zend_Db_Adapter_Mysqli_Exception("LIMIT argument offset=$offset is not valid");
}
$sql .= " LIMIT $count";
if ($offset > 0) {
$sql .= " OFFSET $offset";
}
return $sql;
}
/**
* Check if the adapter supports real SQL parameters.
*
* @param string $type 'positional' or 'named'
* @return bool
*/
public function supportsParameters($type)
{
switch ($type) {
case 'positional':
return true;
case 'named':
default:
return false;
}
}
/**
* Retrieve server version in PHP style
*
*@return string
*/
public function getServerVersion()
{
$this->_connect();
$version = $this->_connection->server_version;
$major = (int) ($version / 10000);
$minor = (int) ($version % 10000 / 100);
$revision = (int) ($version % 100);
return $major . '.' . $minor . '.' . $revision;
}
}
Db2/Exception.php 0000604 00000002430 15071336457 0007630 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
/**
* Zend_Db_Adapter_Db2_Exception
*
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Db2_Exception extends Zend_Db_Adapter_Exception
{
protected $code = '00000';
protected $message = 'unknown exception';
function __construct($msg = 'unknown exception', $state = '00000') {
$this->message = $msg;
$this->code = $state;
}
}
Oracle/Exception.php 0000604 00000003602 15071336457 0010430 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
/**
* Zend_Db_Adapter_Oracle_Exception
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Oracle_Exception extends Zend_Db_Adapter_Exception
{
protected $message = 'Unknown exception';
protected $code = 0;
function __construct($error = null, $code = 0) {
if (is_array($error)) {
if (!isset($error['offset'])) {
$this->message = $error['code'] .' '. $error['message'];
} else {
$this->message = $error['code'] .' '. $error['message']." "
. substr($error['sqltext'], 0, $error['offset'])
. "*"
. substr($error['sqltext'], $error['offset']);
}
$this->code = $error['code'];
} else if (is_string($error)) {
$this->message = $error;
}
if (!$this->code && $code) {
$this->code = $code;
}
}
}
Mysqli/Exception.php 0000604 00000002140 15071336457 0010475 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
*/
/**
* Zend
*/
require_once 'Zend/Db/Adapter/Exception.php';
/**
* Zend_Db_Adapter_Mysqli_Exception
*
* @category Zend
* @package Zend_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Adapter_Mysqli_Exception extends Zend_Db_Adapter_Exception
{
}
Qt.php 0000604 00000013304 15071400505 0005633 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Translate_Adapter_Qt extends Zend_Translate_Adapter {
// Internal variables
private $_file = false;
private $_cleared = array();
private $_transunit = null;
private $_source = null;
private $_target = null;
private $_scontent = null;
private $_tcontent = null;
private $_stag = false;
private $_ttag = true;
/**
* Generates the Qt adapter
* This adapter reads with php's xml_parser
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data (QT file reader)
*
* @param string $locale Locale/Language to add data for, identical with locale identifier,
* see Zend_Locale for more information
* @param string $filename QT file to add, full path must be given for access
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = $options + $this->_options;
if ($options['clear'] || !isset($this->_translate[$locale])) {
$this->_translate[$locale] = array();
}
if (!is_readable($filename)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
}
$this->_target = $locale;
$encoding = $this->_findEncoding($filename);
$this->_file = xml_parser_create($encoding);
xml_set_object($this->_file, $this);
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");
if (!xml_parse($this->_file, file_get_contents($filename))) {
$ex = sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($this->_file)),
xml_get_current_line_number($this->_file));
xml_parser_free($this->_file);
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($ex);
}
}
private function _startElement($file, $name, $attrib)
{
switch(strtolower($name)) {
case 'message':
$this->_source = null;
$this->_stag = false;
$this->_ttag = false;
$this->_scontent = null;
$this->_tcontent = null;
break;
case 'source':
$this->_stag = true;
break;
case 'translation':
$this->_ttag = true;
break;
default:
break;
}
}
private function _endElement($file, $name)
{
switch (strtolower($name)) {
case 'source':
$this->_stag = false;
break;
case 'translation':
if (!empty($this->_scontent) and !empty($this->_tcontent) or
(isset($this->_translate[$this->_target][$this->_scontent]) === false)) {
$this->_translate[$this->_target][$this->_scontent] = $this->_tcontent;
}
$this->_ttag = false;
break;
default:
break;
}
}
private function _contentElement($file, $data)
{
if ($this->_stag === true) {
$this->_scontent .= $data;
}
if ($this->_ttag === true) {
$this->_tcontent .= $data;
}
}
private function _findEncoding($filename)
{
$file = file_get_contents($filename, null, null, 0, 100);
if (strpos($file, "encoding") !== false) {
$encoding = substr($file, strpos($file, "encoding") + 9);
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
return $encoding;
}
return 'UTF-8';
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return "Qt";
}
}
XmlTm.php 0000604 00000012207 15071400505 0006311 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Translate_Adapter_XmlTm extends Zend_Translate_Adapter {
// Internal variables
private $_file = false;
private $_cleared = array();
private $_lang = null;
private $_content = null;
private $_tag = null;
/**
* Generates the xmltm adapter
* This adapter reads with php's xml_parser
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data (XMLTM file reader)
*
* @param string $locale Locale/Language to add data for, identical with locale identifier,
* see Zend_Locale for more information
* @param string $filename XMLTM file to add, full path must be given for access
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = $options + $this->_options;
$this->_lang = $locale;
if ($options['clear'] || !isset($this->_translate[$locale])) {
$this->_translate[$locale] = array();
}
if (!is_readable($filename)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
}
$encoding = $this->_findEncoding($filename);
$this->_file = xml_parser_create($encoding);
xml_set_object($this->_file, $this);
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");
if (!xml_parse($this->_file, file_get_contents($filename))) {
$ex = sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($this->_file)),
xml_get_current_line_number($this->_file));
xml_parser_free($this->_file);
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($ex);
}
}
private function _startElement($file, $name, $attrib)
{
switch(strtolower($name)) {
case 'tm:tu':
$this->_tag = $attrib['id'];
$this->_content = null;
break;
default:
break;
}
}
private function _endElement($file, $name)
{
switch (strtolower($name)) {
case 'tm:tu':
if (!empty($this->_tag) and !empty($this->_content) or
(isset($this->_translate[$this->_lang][$this->_tag]) === false)) {
$this->_translate[$this->_lang][$this->_tag] = $this->_content;
}
$this->_tag = null;
$this->_content = null;
break;
default:
break;
}
}
private function _contentElement($file, $data)
{
if (($this->_tag !== null)) {
$this->_content .= $data;
}
}
private function _findEncoding($filename)
{
$file = file_get_contents($filename, null, null, 0, 100);
if (strpos($file, "encoding") !== false) {
$encoding = substr($file, strpos($file, "encoding") + 9);
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
return $encoding;
}
return 'UTF-8';
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return "XmlTm";
}
}
Tmx.php 0000604 00000014307 15071400505 0006023 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Translate_Adapter_Tmx extends Zend_Translate_Adapter {
// Internal variables
private $_file = false;
private $_cleared = array();
private $_tu = null;
private $_tuv = null;
private $_seg = null;
private $_content = null;
/**
* Generates the tmx adapter
* This adapter reads with php's xml_parser
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data (TMX file reader)
*
* @param string $filename TMX file to add, full path must be given for access
* @param string $locale Locale has no effect for TMX because TMX defines all languages within
* the source file
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = $this->_options + $options;
if ($options['clear']) {
$this->_translate = array();
}
if (!is_readable($filename)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
}
$encoding = $this->_findEncoding($filename);
$this->_file = xml_parser_create($encoding);
xml_set_object($this->_file, $this);
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");
if (!xml_parse($this->_file, file_get_contents($filename))) {
$ex = sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($this->_file)),
xml_get_current_line_number($this->_file));
xml_parser_free($this->_file);
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($ex);
}
}
private function _startElement($file, $name, $attrib)
{
if ($this->_seg !== null) {
$this->_content .= "<".$name;
foreach($attrib as $key => $value) {
$this->_content .= " $key=\"$value\"";
}
$this->_content .= ">";
} else {
switch(strtolower($name)) {
case 'tu':
if (isset($attrib['tuid']) === true) {
$this->_tu = $attrib['tuid'];
}
break;
case 'tuv':
if (isset($attrib['xml:lang']) === true) {
$this->_tuv = $attrib['xml:lang'];
if (isset($this->_translate[$this->_tuv]) === false) {
$this->_translate[$this->_tuv] = array();
}
}
break;
case 'seg':
$this->_seg = true;
$this->_content = null;
break;
default:
break;
}
}
}
private function _endElement($file, $name)
{
if (($this->_seg !== null) and ($name !== 'seg')) {
$this->_content .= "</".$name.">";
} else {
switch (strtolower($name)) {
case 'tu':
$this->_tu = null;
break;
case 'tuv':
$this->_tuv = null;
break;
case 'seg':
$this->_seg = null;
if (!empty($this->_content) or (isset($this->_translate[$this->_tuv][$this->_tu]) === false)) {
$this->_translate[$this->_tuv][$this->_tu] = $this->_content;
}
break;
default:
break;
}
}
}
private function _contentElement($file, $data)
{
if (($this->_seg !== null) and ($this->_tu !== null) and ($this->_tuv !== null)) {
$this->_content .= $data;
}
}
private function _findEncoding($filename)
{
$file = file_get_contents($filename, null, null, 0, 100);
if (strpos($file, "encoding") !== false) {
$encoding = substr($file, strpos($file, "encoding") + 9);
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
return $encoding;
}
return 'UTF-8';
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return "Tmx";
}
}
Csv.php 0000604 00000006277 15071400505 0006015 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Translate_Adapter_Csv extends Zend_Translate_Adapter {
/**
* Generates the adapter
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options Options for this adapter
*/
public function __construct($data, $locale = null, array $options = array())
{
$this->_options['delimiter'] = ";";
$this->_options['length'] = 0;
$this->_options['enclosure'] = '"';
parent::__construct($data, $locale, $options);
}
/**
* Load translation data
*
* @param string|array $filename Filename and full path to the translation source
* @param string $locale Locale/Language to add data for, identical with locale identifier,
* see Zend_Locale for more information
* @param array $option OPTIONAL Options to use
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = $options + $this->_options;
if ($options['clear'] || !isset($this->_translate[$locale])) {
$this->_translate[$locale] = array();
}
$this->_file = @fopen($filename, 'rb');
if (!$this->_file) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.');
}
while(($data = fgetcsv($this->_file, $options['length'], $options['delimiter'], $options['enclosure'])) !== false) {
if (substr($data[0], 0, 1) === '#') {
continue;
}
if (isset($data[1]) !== true) {
continue;
}
$this->_translate[$locale][$data[0]] = $data[1];
}
}
/**
* returns the adapters name
*
* @return string
*/
public function toString()
{
return "Csv";
}
}
Gettext.php 0000604 00000013203 15071400505 0006671 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Translate_Adapter_Gettext extends Zend_Translate_Adapter {
// Internal variables
private $_bigEndian = false;
private $_file = false;
private $_adapterInfo = array();
/**
* Generates the adapter
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Read values from the MO file
*
* @param string $bytes
*/
private function _readMOData($bytes)
{
if ($this->_bigEndian === false) {
return unpack('V' . $bytes, fread($this->_file, 4 * $bytes));
} else {
return unpack('N' . $bytes, fread($this->_file, 4 * $bytes));
}
}
/**
* Load translation data (MO file reader)
*
* @param string $filename MO file to add, full path must be given for access
* @param string $locale New Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$this->_bigEndian = false;
$options = $options + $this->_options;
if ($options['clear'] || !isset($this->_translate[$locale])) {
$this->_translate[$locale] = array();
}
$this->_file = @fopen($filename, 'rb');
if (!$this->_file) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.');
}
if (@filesize($filename) < 10) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('\'' . $filename . '\' is not a gettext file');
}
// get Endian
$input = $this->_readMOData(1);
if (strtolower(substr(dechex($input[1]), -8)) == "950412de") {
$this->_bigEndian = false;
} else if (strtolower(substr(dechex($input[1]), -8)) == "de120495") {
$this->_bigEndian = true;
} else {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('\'' . $filename . '\' is not a gettext file');
}
// read revision - not supported for now
$input = $this->_readMOData(1);
// number of bytes
$input = $this->_readMOData(1);
$total = $input[1];
// number of original strings
$input = $this->_readMOData(1);
$OOffset = $input[1];
// number of translation strings
$input = $this->_readMOData(1);
$TOffset = $input[1];
// fill the original table
fseek($this->_file, $OOffset);
$origtemp = $this->_readMOData(2 * $total);
fseek($this->_file, $TOffset);
$transtemp = $this->_readMOData(2 * $total);
for($count = 0; $count < $total; ++$count) {
if ($origtemp[$count * 2 + 1] != 0) {
fseek($this->_file, $origtemp[$count * 2 + 2]);
$original = @fread($this->_file, $origtemp[$count * 2 + 1]);
} else {
$original = '';
}
if ($transtemp[$count * 2 + 1] != 0) {
fseek($this->_file, $transtemp[$count * 2 + 2]);
$this->_translate[$locale][$original] = fread($this->_file, $transtemp[$count * 2 + 1]);
}
}
$this->_translate[$locale][''] = trim($this->_translate[$locale]['']);
if (empty($this->_translate[$locale][''])) {
$this->_adapterInfo[$filename] = 'No adapter information available';
} else {
$this->_adapterInfo[$filename] = $this->_translate[$locale][''];
}
unset($this->_translate[$locale]['']);
}
/**
* Returns the adapter informations
*
* @return array Each loaded adapter information as array value
*/
public function getAdapterInfo()
{
return $this->_adapterInfo;
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return "Gettext";
}
}
Ini.php 0000604 00000005266 15071400505 0005776 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Translate_Adapter_Ini extends Zend_Translate_Adapter
{
/**
* Generates the adapter
*
* @param array $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data
*
* @param string|array $data
* @param string $locale Locale/Language to add data for, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to use
*/
protected function _loadTranslationData($data, $locale, array $options = array())
{
if (!file_exists($data)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception("Ini file '".$data."' not found");
}
$inidata = parse_ini_file($data, false);
$options = array_merge($this->_options, $options);
if (($options['clear'] == true) || !isset($this->_translate[$locale])) {
$this->_translate[$locale] = array();
}
$this->_translate[$locale] = array_merge($this->_translate[$locale], $inidata);
}
/**
* returns the adapters name
*
* @return string
*/
public function toString()
{
return "Ini";
}
}
Tbx.php 0000604 00000014234 15071400505 0006007 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Translate_Adapter_Tbx extends Zend_Translate_Adapter {
// Internal variables
private $_file = false;
private $_cleared = array();
private $_langset = null;
private $_termentry = null;
private $_content = null;
private $_term = null;
/**
* Generates the tbx adapter
* This adapter reads with php's xml_parser
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data (TBX file reader)
*
* @param string $filename TBX file to add, full path must be given for access
* @param string $locale Locale has no effect for TBX because TBX defines all languages within
* the source file
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = $options + $this->_options;
if ($options['clear']) {
$this->_translate = array();
}
if (!is_readable($filename)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
}
$encoding = $this->_findEncoding($filename);
$this->_file = xml_parser_create($encoding);
xml_set_object($this->_file, $this);
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");
if (!xml_parse($this->_file, file_get_contents($filename))) {
$ex = sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($this->_file)),
xml_get_current_line_number($this->_file));
xml_parser_free($this->_file);
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($ex);
}
}
private function _startElement($file, $name, $attrib)
{
if ($this->_term !== null) {
$this->_content .= "<".$name;
foreach($attrib as $key => $value) {
$this->_content .= " $key=\"$value\"";
}
$this->_content .= ">";
} else {
switch(strtolower($name)) {
case 'termentry':
$this->_termentry = null;
break;
case 'langset':
if (isset($attrib['xml:lang']) === true) {
$this->_langset = $attrib['xml:lang'];
if (isset($this->_translate[$this->_langset]) === false) {
$this->_translate[$this->_langset] = array();
}
}
break;
case 'term':
$this->_term = true;
$this->_content = null;
break;
default:
break;
}
}
}
private function _endElement($file, $name)
{
if (($this->_term !== null) and ($name != "term")) {
$this->_content .= "</".$name.">";
} else {
switch (strtolower($name)) {
case 'langset':
$this->_langset = null;
break;
case 'term':
$this->_term = null;
if (empty($this->_termentry)) {
$this->_termentry = $this->_content;
}
if (!empty($this->_content) or (isset($this->_translate[$this->_langset][$this->_termentry]) === false)) {
$this->_translate[$this->_langset][$this->_termentry] = $this->_content;
}
break;
default:
break;
}
}
}
private function _contentElement($file, $data)
{
if ($this->_term !== null) {
$this->_content .= $data;
}
}
private function _findEncoding($filename)
{
$file = file_get_contents($filename, null, null, 0, 100);
if (strpos($file, "encoding") !== false) {
$encoding = substr($file, strpos($file, "encoding") + 9);
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
return $encoding;
}
return 'UTF-8';
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return "Tbx";
}
}
Xliff.php 0000604 00000017322 15071400505 0006323 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Translate_Adapter_Xliff extends Zend_Translate_Adapter {
// Internal variables
private $_file = false;
private $_cleared = array();
private $_transunit = null;
private $_source = null;
private $_target = null;
private $_scontent = null;
private $_tcontent = null;
private $_stag = false;
private $_ttag = false;
/**
* Generates the xliff adapter
* This adapter reads with php's xml_parser
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data (XLIFF file reader)
*
* @param string $locale Locale/Language to add data for, identical with locale identifier,
* see Zend_Locale for more information
* @param string $filename XLIFF file to add, full path must be given for access
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = $options + $this->_options;
if ($options['clear']) {
$this->_translate = array();
}
if (!is_readable($filename)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
}
$encoding = $this->_findEncoding($filename);
$this->_target = $locale;
$this->_file = xml_parser_create($encoding);
xml_set_object($this->_file, $this);
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");
if (!xml_parse($this->_file, file_get_contents($filename))) {
$ex = sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($this->_file)),
xml_get_current_line_number($this->_file));
xml_parser_free($this->_file);
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($ex);
}
}
private function _startElement($file, $name, $attrib)
{
if ($this->_stag === true) {
$this->_scontent .= "<".$name;
foreach($attrib as $key => $value) {
$this->_scontent .= " $key=\"$value\"";
}
$this->_scontent .= ">";
} else if ($this->_ttag === true) {
$this->_tcontent .= "<".$name;
foreach($attrib as $key => $value) {
$this->_tcontent .= " $key=\"$value\"";
}
$this->_tcontent .= ">";
} else {
switch(strtolower($name)) {
case 'file':
$this->_source = $attrib['source-language'];
if (isset($attrib['target-language'])) {
$this->_target = $attrib['target-language'];
}
$this->_translate[$this->_source] = array();
$this->_translate[$this->_target] = array();
break;
case 'trans-unit':
$this->_transunit = true;
break;
case 'source':
if ($this->_transunit === true) {
$this->_scontent = null;
$this->_stag = true;
$this->_ttag = false;
}
break;
case 'target':
if ($this->_transunit === true) {
$this->_tcontent = null;
$this->_ttag = true;
$this->_stag = false;
}
break;
default:
break;
}
}
}
private function _endElement($file, $name)
{
if (($this->_stag === true) and ($name !== 'source')) {
$this->_scontent .= "</".$name.">";
} else if (($this->_ttag === true) and ($name !== 'target')) {
$this->_tcontent .= "</".$name.">";
} else {
switch (strtolower($name)) {
case 'trans-unit':
$this->_transunit = null;
$this->_scontent = null;
$this->_tcontent = null;
break;
case 'source':
if (!empty($this->_scontent) and !empty($this->_tcontent) or
(isset($this->_translate[$this->_source][$this->_scontent]) === false)) {
$this->_translate[$this->_source][$this->_scontent] = $this->_scontent;
}
$this->_stag = false;
break;
case 'target':
if (!empty($this->_scontent) and !empty($this->_tcontent) or
(isset($this->_translate[$this->_source][$this->_scontent]) === false)) {
$this->_translate[$this->_target][$this->_scontent] = $this->_tcontent;
}
$this->_ttag = false;
break;
default:
break;
}
}
}
private function _contentElement($file, $data)
{
if (($this->_transunit !== null) and ($this->_source !== null) and ($this->_stag === true)) {
$this->_scontent .= $data;
}
if (($this->_transunit !== null) and ($this->_target !== null) and ($this->_ttag === true)) {
$this->_tcontent .= $data;
}
}
private function _findEncoding($filename)
{
$file = file_get_contents($filename, null, null, 0, 100);
if (strpos($file, "encoding") !== false) {
$encoding = substr($file, strpos($file, "encoding") + 9);
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
return $encoding;
}
return 'UTF-8';
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return "Xliff";
}
}
Array.php 0000604 00000004031 15071400505 0006322 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Array.php 10013 2008-07-09 21:08:06Z norm2782 $
*/
/**
* @see Zend_Paginator_Adapter_Interface
*/
require_once 'Zend/Paginator/Adapter/Interface.php';
/**
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Paginator_Adapter_Array implements Zend_Paginator_Adapter_Interface
{
/**
* Array
*
* @var array
*/
protected $_array = null;
/**
* Item count
*
* @var integer
*/
protected $_count = null;
/**
* Constructor.
*
* @param array $array Array to paginate
*/
public function __construct(array $array)
{
$this->_array = $array;
$this->_count = count($array);
}
/**
* Returns an array of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return array
*/
public function getItems($offset, $itemCountPerPage)
{
return array_slice($this->_array, $offset, $itemCountPerPage);
}
/**
* Returns the total number of rows in the array.
*
* @return integer
*/
public function count()
{
return $this->_count;
}
} Firebird/Exception.php 0000604 00000002226 15071410477 0010745 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package ZendX_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: $
*/
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
/**
* ZendX_Db_Adapter_Firebird_Exception
*
* @category ZendX
* @package ZendX_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class ZendX_Db_Adapter_Firebird_Exception extends Zend_Db_Adapter_Exception
{
}
Firebird.php 0000604 00000046702 15071410477 0007016 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category ZendX
* @package ZendX_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: $
*/
/**
* @see Zend_Db_Adapter_Abstract
*/
require_once 'Zend/Db/Adapter/Abstract.php';
/**
* @see Zend_Db_Profiler
*/
require_once 'Zend/Db/Profiler.php';
/**
* @see Zend_Db_Select
*/
require_once 'Zend/Db/Select.php';
/**
* @see Zend_Db_Statement_Firebird
*/
require_once 'ZendX/Db/Statement/Firebird.php';
/**
* @category ZendX
* @package ZendX_Db
* @subpackage Adapter
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class ZendX_Db_Adapter_Firebird extends Zend_Db_Adapter_Abstract
{
/**
* Specifies whether the adapter automatically quotes identifiers.
* If true, most SQL generated by Zend_Db classes applies
* identifier quoting automatically.
* If false, developer must quote identifiers themselves
* by calling quoteIdentifier().
*
* @var bool
*/
protected $_autoQuoteIdentifiers = true;
/**
* The transaction resource.
*
* @var transaction
*/
protected $_transResource = null;
/**
* Return the status of current transaction.
* @return bool
*/
public function getTransaction()
{
return (is_resource($this->_transResource) ? $this->_transResource : null);
}
/**
* Keys are UPPERCASE SQL datatypes or the constants
* Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
*
* Values are:
* 0 = 32-bit integer
* 1 = 64-bit integer
* 2 = float or decimal
*
* @var array Associative array of datatypes to values 0, 1, or 2.
*/
protected $_numericDataTypes = array(
Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
'SMALLINT' => Zend_Db::INT_TYPE,
'INT' => Zend_Db::INT_TYPE,
'INTEGER' => Zend_Db::INT_TYPE,
'BIGINT' => Zend_Db::BIGINT_TYPE,
'INT64' => Zend_Db::BIGINT_TYPE,
'DECIMAL' => Zend_Db::FLOAT_TYPE,
'DOUBLE PRECISION' => Zend_Db::FLOAT_TYPE,
'DOUBLE' => Zend_Db::FLOAT_TYPE,
'NUMERIC' => Zend_Db::FLOAT_TYPE,
'FLOAT' => Zend_Db::FLOAT_TYPE
);
/**
* Quote a raw string.
*
* @param string $value Raw string
* @return string Quoted string
*/
protected function _quote($value)
{
if (is_int($value) || is_float($value)) {
return $value;
}
$value = str_replace("'", "''", $value);
return "'" . $value . "'";
}
/**
* Returns a list of the tables in the database.
*
* @return array
*/
public function listTables()
{
$data = $this->fetchCol('SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG = 0');
foreach($data as &$v)
$v = trim($v);
return $data;
}
/**
* Returns the column descriptions for a table.
*
* The return value is an associative array keyed by the column name,
* as returned by the RDBMS.
*
* The value of each array element is an associative array
* with the following keys:
*
* SCHEMA_NAME => string; name of database or schema
* TABLE_NAME => string;
* COLUMN_NAME => string; column name
* COLUMN_POSITION => number; ordinal position of column in table
* DATA_TYPE => string; SQL datatype name of column
* DEFAULT => string; default expression of column, null if none
* NULLABLE => boolean; true if column can have nulls
* LENGTH => number; length of CHAR/VARCHAR
* SCALE => number; scale of NUMERIC/DECIMAL
* PRECISION => number; precision of NUMERIC/DECIMAL
* UNSIGNED => boolean; unsigned property of an integer type
* PRIMARY => boolean; true if column is part of the primary key
* PRIMARY_POSITION => integer; position of column in primary key
* IDENTITY => integer; true if column is auto-generated with unique values
*
* @param string $tableName
* @param string $schemaName OPTIONAL
* @return array
*/
public function describeTable($tableName, $schemaName = null)
{
$fieldMaps = array(
'TEXT' => 'CHAR',
'VARYING' => 'VARCHAR',
'SHORT' => 'SMALLINT',
'LONG' => 'INTEGER',
'FLOAT' => 'FLOAT',
'INT64' => array(0 => 'BIGINT', 'NUMERIC', 'DECIMAL'),
'DATE' => 'DATE',
'TIME' => 'TIME',
'BLOB' => 'BLOB',
'DOUBLE' => 'DOUBLE PRECISION',
'TIMESTAMP' => 'TIMESTAMP'
);
$sql = 'select
RF.RDB$RELATION_NAME, \'\', RF.RDB$FIELD_NAME, T.RDB$TYPE_NAME,
RF.RDB$DEFAULT_VALUE, RF.RDB$NULL_FLAG, RF.RDB$FIELD_POSITION,
F.RDB$CHARACTER_LENGTH, F.RDB$FIELD_SCALE, F.RDB$FIELD_PRECISION,
IXS.RDB$FIELD_POSITION, IXS.RDB$FIELD_POSITION, F.RDB$FIELD_SUB_TYPE
from RDB$RELATION_FIELDS RF
left join RDB$RELATION_CONSTRAINTS RC
on (RF.RDB$RELATION_NAME = RC.RDB$RELATION_NAME and RC.RDB$CONSTRAINT_TYPE = \'PRIMARY KEY\')
left join RDB$INDEX_SEGMENTS IXS
on (IXS.RDB$FIELD_NAME = RF.RDB$FIELD_NAME and RC.RDB$INDEX_NAME = IXS.RDB$INDEX_NAME)
inner join RDB$FIELDS F on (RF.RDB$FIELD_SOURCE = F.RDB$FIELD_NAME)
inner join RDB$TYPES T on (T.RDB$TYPE = F.RDB$FIELD_TYPE and T.RDB$FIELD_NAME = \'RDB$FIELD_TYPE\')
where ' . $this->quoteInto('(UPPER(RF.RDB$RELATION_NAME) = UPPER(?)) ', $tableName) . '
order by RF.RDB$FIELD_POSITION';
$stmt = $this->query($sql);
/**
* Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection
*/
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
$table_name = 0;
$owner = 1;
$column_name = 2;
$data_type = 3;
$data_default = 4;
$nullable = 5;
$column_id = 6;
$data_length = 7;
$data_scale = 8;
$data_precision = 9;
$constraint_type = 10;
$position = 11;
$sub_type = 12;
$desc = array();
foreach ($result as $key => $row) {
list ($primary, $primaryPosition, $identity) = array(false, null, false);
if (strlen($row[$constraint_type])) {
$primary = true;
$primaryPosition = $row[$position];
/**
* Firebird does not support auto-increment keys.
*/
$identity = false;
}
$dataType = trim($row[$data_type]);
$newType = $fieldMaps[$dataType];
if (is_array($newType) && $dataType == 'INT64')
$newType = $newType[$row[$sub_type]];
$row[$data_type] = $newType;
$desc[trim($row[$column_name])] = array(
'SCHEMA_NAME' => '',
'TABLE_NAME' => trim($row[$table_name]),
'COLUMN_NAME' => trim($row[$column_name]),
'COLUMN_POSITION' => $row[$column_id] +1,
'DATA_TYPE' => $row[$data_type],
'DEFAULT' => $row[$data_default],
'NULLABLE' => (bool) ($row[$nullable] != '1'),
'LENGTH' => $row[$data_length],
'SCALE' => ($row[$data_scale] == 0 ? null : $row[$data_scale]),
'PRECISION' => ($row[$data_precision] == 0 ? null : $row[$data_precision]),
'UNSIGNED' => false,
'PRIMARY' => $primary,
'PRIMARY_POSITION' => ($primary ? $primaryPosition+1 : null),
'IDENTITY' => $identity
);
}
return $desc;
}
/**
* Format a connection string to connect to database
*
* @return void
*/
protected function _formatDbConnString($host, $port, $dbname)
{
if (is_numeric($port))
$port = '/' . (integer) $port;
if ($dbname)
$dbname = ':' . $dbname;
return $host . $port . $dbname;
}
/**
* Creates a connection to the database.
*
* @return void
* @throws ZendX_Db_Adapter_Firebird_Exception
*/
protected function _connect()
{
if (isset($this->_connection) && is_resource($this->_connection)) {
return;
}
if (!extension_loaded('interbase')) {
/**
* @see ZendX_Db_Adapter_Firebird_Exception
*/
require_once 'ZendX/Db/Adapter/Firebird/Exception.php';
throw new ZendX_Db_Adapter_Firebird_Exception('The Interbase extension is required for this adapter but the extension is not loaded');
}
// Suppress connection warnings here.
// Throw an exception instead.
$this->_connection = @ibase_connect(
$this->_formatDbConnString($this->_config['host'],$this->_config['port'] ,$this->_config['dbname']),
$this->_config['username'],
$this->_config['password'],
$this->_config['charset'],
$this->_config['buffers'],
$this->_config['dialect'],
$this->_config['role']
);
if ($this->_connection === false) {
/**
* @see ZendX_Db_Adapter_Firebird_Exception
*/
require_once 'ZendX/Db/Adapter/Firebird/Exception.php';
throw new ZendX_Db_Adapter_Firebird_Exception(ibase_errmsg());
}
}
/**
* Force the connection to close.
*
* @return void
*/
public function closeConnection()
{
if (is_resource($this->_transResource)) {
ibase_rollback($this->_transResource);
}
$this->_transResource = null;
if (is_resource($this->_connection)) {
unset($this->_connection);
}
//$this->_connection = false;
}
/**
* Prepare a statement and return a Statement resource.
*
* @param string $sql SQL query
* @return ZendX_Db_Statement_Firebird
*/
public function prepare($sql)
{
$this->_connect();
$stmt = new ZendX_Db_Statement_Firebird($this, $sql);
if ($stmt === false) {
return false;
}
$stmt->setFetchMode($this->_fetchMode);
return $stmt;
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* As a convention, on RDBMS brands that support sequences
* (e.g. Firebird, Oracle, PostgreSQL, DB2), this method forms the name of a sequence
* from the arguments and returns the last id generated by that sequence.
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
* returns the last value generated for such a column, and the table name
* argument is disregarded.
*
* Firebird does not support IDENTITY columns, so if the sequence is not
* specified, this method returns null.
*
* @param string $tableName OPTIONAL Name of table.
* @param string $primaryKey OPTIONAL Name of primary key column.
* @return string
* @throws ZendX_Db_Adapter_Firebird_Exception
*/
public function lastInsertId($tableName = null, $primaryKey = null)
{
if ($tableName !== null) {
$sequenceName = $tableName;
if ($primaryKey) {
$sequenceName .= "_$primaryKey";
}
$sequenceName .= '_seq';
return $this->lastSequenceId($sequenceName);
}
// No support for IDENTITY columns; return null
return null;
}
/**
* Begin a transaction.
*
* @return void
*/
protected function _beginTransaction()
{
$this->_connect();
if (is_resource($this->_transResource)){
return;
}
$this->_transResource = ibase_trans(IBASE_DEFAULT, $this->_connection);
}
/**
* Commit a transaction.
*
* @return void
*/
protected function _commit()
{
if (false === ibase_commit(is_resource($this->_transResource) ? $this->_transResource : $this->_connection)) {
/**
* @see ZendX_Db_Adapter_Firebird_Exception
*/
require_once 'ZendX/Db/Adapter/Firebird/Exception.php';
throw new ZendX_Db_Adapter_Firebird_Exception(ibase_errmsg());
}
$this->_transResource = null;
}
/**
* Roll-back a transaction.
*
* @return void
*/
protected function _rollBack()
{
if (false === ibase_rollback(is_resource($this->_transResource) ? $this->_transResource : $this->_connection)) {
/**
* @see ZendX_Db_Adapter_Firebird_Exception
*/
require_once 'ZendX/Db/Adapter/Firebird/Exception.php';
throw new ZendX_Db_Adapter_Firebird_Exception(ibase_errmsg());
}
$this->_transResource = null;
}
/**
* Set the fetch mode.
*
* @param int $mode
* @return void
*/
public function setFetchMode($mode)
{
switch ($mode) {
case Zend_Db::FETCH_LAZY:
case Zend_Db::FETCH_ASSOC:
case Zend_Db::FETCH_NUM:
case Zend_Db::FETCH_BOTH:
case Zend_Db::FETCH_NAMED:
case Zend_Db::FETCH_OBJ:
case Zend_Db::FETCH_BOUND: // bound to PHP variable
$this->_fetchMode = $mode;
break;
default:
/**
* @see ZendX_Db_Adapter_Firebird_Exception
*/
require_once 'ZendX/Db/Adapter/Firebird/Exception.php';
throw new ZendX_Db_Adapter_Firebird_Exception("Invalid fetch mode '$mode' specified");
}
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
*
* @param string $sql
* @param integer $count
* @param integer $offset
* @throws Zend_Db_Adapter_Exception
* @return string
*/
public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count <= 0) {
/**
* @see ZendX_Db_Adapter_Firebird_Exception
*/
require_once 'ZendX/Db/Adapter/Firebird/Exception.php';
throw new ZendX_Db_Adapter_Firebird_Exception("LIMIT argument count=$count is not valid");
}
$offset = intval($offset);
if ($offset < 0) {
/**
* @see ZendX_Db_Adapter_Firebird_Exception
*/
require_once 'ZendX/Db/Adapter/Firebird/Exception.php';
throw new ZendX_Db_Adapter_Firebird_Exception("LIMIT argument offset=$offset is not valid");
}
if (trim($sql) == ''){
//Only compatible with FB 2.0 or newer
//ZF 1.5.0 don't support limit sql syntax that don't only append texto to sql, fixed in 1.5.1
$sql .= " rows $count";
if ($offset > 0)
$sql .= " to $offset";
}
else
$sql = substr_replace($sql, "select first $count skip $offset ", stripos($sql, 'select'), 6);
return $sql;
}
/**
* Quote a table identifier and alias.
*
* @param string|array|Zend_Db_Expr $ident The identifier or expression.
* @param string $alias An alias for the table.
* @param boolean $auto If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
* @return string The quoted identifier and alias.
*/
public function quoteTableAs($ident, $alias = null, $auto=false)
{
// Firebird doesn't allow the 'AS' keyword between the table identifier/expression and alias.
return $this->_quoteIdentifierAs($ident, $alias, $auto, ' ');
}
/**
* Return the most recent value from the specified sequence in the database.
* This is supported only on RDBMS brands that support sequences
* (e.g. Firebird, Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return string
*/
public function lastSequenceId($sequenceName)
{
$this->_connect();
$sql = 'SELECT GEN_ID('.$this->quoteIdentifier($sequenceName).', 0) FROM RDB$DATABASE';
$value = $this->fetchOne($sql);
return $value;
}
/**
* Generate a new value from the specified sequence in the database, and return it.
* This is supported only on RDBMS brands that support sequences
* (e.g. Firebird, Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return integer
*/
public function nextSequenceId($sequenceName)
{
$this->_connect();
$sql = 'SELECT GEN_ID('.$this->quoteIdentifier($sequenceName).', 1) FROM RDB$DATABASE';
$value = $this->fetchOne($sql);
return $value;
}
/**
* Check if the adapter supports real SQL parameters.
*
* @param string $type 'positional' or 'named'
* @return bool
*/
public function supportsParameters($type)
{
switch ($type) {
case 'positional':
return true;
case 'named':
default:
return false;
}
}
/**
* Test if a connection is active
*
* @return boolean
*/
public function isConnected()
{
return ((bool) (is_resource($this->_connection)
&& get_resource_type($this->_connection) == 'Firebird/InterBase link'));
}
/**
* Retrieve server version in PHP style
*
* @return string
*/
public function getServerVersion()
{
$this->_connect();
$service = ibase_service_attach($this->_formatDbConnString($this->_config['host'], $this->_config['port'], ''), $this->_config['username'], $this->_config['password']);
if ($service != FALSE) {
$server_info = ibase_server_info($service, IBASE_SVC_SERVER_VERSION);
ibase_service_detach($service);
$matches = null;
if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $server_info, $matches)) {
return $matches[1];
} else {
return null;
}
} else {
return null;
}
}
} Rsa.php 0000604 00000007543 15071530524 0006011 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Rsa.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Cipher_Pki_Adapter_Abstract
*/
require_once 'Zend/InfoCard/Cipher/Pki/Adapter/Abstract.php';
/**
* Zend_InfoCard_Cipher_Pki_Rsa_Interface
*/
require_once 'Zend/InfoCard/Cipher/Pki/Rsa/Interface.php';
/**
* RSA Public Key Encryption Cipher Object for the InfoCard component. Relies on OpenSSL
* to implement the RSA algorithm
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_InfoCard_Cipher_Pki_Adapter_Rsa
extends Zend_InfoCard_Cipher_Pki_Adapter_Abstract
implements Zend_InfoCard_Cipher_Pki_Rsa_Interface
{
/**
* Object Constructor
*
* @param integer $padding The type of Padding to use
*/
public function __construct($padding = Zend_InfoCard_Cipher_Pki_Adapter_Abstract::NO_PADDING)
{
// Can't test this..
// @codeCoverageIgnoreStart
if(!extension_loaded('openssl')) {
throw new Zend_InfoCard_Cipher_Exception("Use of this PKI RSA Adapter requires the openssl extension loaded");
}
// @codeCoverageIgnoreEnd
$this->setPadding($padding);
}
/**
* Decrypts RSA encrypted data using the given private key
*
* @throws Zend_InfoCard_Cipher_Exception
* @param string $encryptedData The encrypted data in binary format
* @param string $privateKey The private key in binary format
* @param string $password The private key passphrase
* @param integer $padding The padding to use during decryption (of not provided object value will be used)
* @return string The decrypted data
*/
public function decrypt($encryptedData, $privateKey, $password = null, $padding = null)
{
$private_key = openssl_pkey_get_private(array($privateKey, $password));
if(!$private_key) {
throw new Zend_InfoCard_Cipher_Exception("Failed to load private key");
}
if(!is_null($padding)) {
try {
$this->setPadding($padding);
} catch(Exception $e) {
openssl_free_key($private_key);
throw $e;
}
}
switch($this->getPadding()) {
case self::NO_PADDING:
$openssl_padding = OPENSSL_NO_PADDING;
break;
case self::OAEP_PADDING:
$openssl_padding = OPENSSL_PKCS1_OAEP_PADDING;
break;
}
$result = openssl_private_decrypt($encryptedData, $decryptedData, $private_key, $openssl_padding);
openssl_free_key($private_key);
if(!$result) {
throw new Zend_InfoCard_Cipher_Exception("Unable to Decrypt Value using provided private key");
}
if($this->getPadding() == self::NO_PADDING) {
$decryptedData = substr($decryptedData, 2);
$start = strpos($decryptedData, 0) + 1;
$decryptedData = substr($decryptedData, $start);
}
return $decryptedData;
}
}
Interface.php 0000604 00000002716 15071544665 0007174 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 12519 2008-11-10 18:41:24Z alexander $
*/
/**
* Interface for pagination adapters.
*
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Paginator_Adapter_Interface extends Countable
{
/**
* Returns the total number of rows in the collection.
*
* @return integer
*/
//public function count();
/**
* Returns an collection of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return array
*/
public function getItems($offset, $itemCountPerPage);
} Default.php 0000604 00000005552 15071544665 0006661 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Default.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Adapter_Interface
*/
require_once 'Zend/InfoCard/Adapter/Interface.php';
/**
* Zend_InfoCard_Adapter_Exception
*/
require_once 'Zend/InfoCard/Adapter/Exception.php';
/**
* The default InfoCard component Adapter which serves as a pass-thru placeholder
* for developers. Initially developed to provide a callback mechanism to store and retrieve
* assertions as part of the validation process it can be used anytime callback facilities
* are necessary
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_InfoCard_Adapter_Default implements Zend_InfoCard_Adapter_Interface
{
/**
* Store the assertion (pass-thru does nothing)
*
* @param string $assertionURI The assertion type URI
* @param string $assertionID The specific assertion ID
* @param array $conditions An array of claims to store associated with the assertion
* @return bool Always returns true (would return false on store failure)
*/
public function storeAssertion($assertionURI, $assertionID, $conditions)
{
return true;
}
/**
* Retrieve an assertion (pass-thru does nothing)
*
* @param string $assertionURI The assertion type URI
* @param string $assertionID The assertion ID to retrieve
* @return mixed False if the assertion ID was not found for that URI, or an array of
* conditions associated with that assertion if found (always returns false)
*/
public function retrieveAssertion($assertionURI, $assertionID)
{
return false;
}
/**
* Remove an assertion (pass-thru does nothing)
*
* @param string $assertionURI The assertion type URI
* @param string $assertionID The assertion ID to remove
* @return bool Always returns true (false on removal failure)
*/
public function removeAssertion($assertionURI, $assertionID)
{
return null;
}
}
Aes128cbc.php 0000604 00000002545 15071545134 0006677 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Aes128cbc.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Cipher_Symmetric_Adapter_Aes256cbc
*/
require_once 'Zend/InfoCard/Cipher/Symmetric/Adapter/Aes256cbc.php';
/**
* Implements AES128 with CBC encryption implemented using the mCrypt extension
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_InfoCard_Cipher_Symmetric_Adapter_Aes128cbc
extends Zend_InfoCard_Cipher_Symmetric_Adapter_Aes256cbc
{
}
Aes256cbc.php 0000604 00000007126 15071545134 0006701 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Aes256cbc.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Cipher_Symmetric_Adapter_Abstract
*/
require_once 'Zend/InfoCard/Cipher/Symmetric/Adapter/Abstract.php';
/**
* Zend_InfoCard_Cipher_Symmetric_Aes256cbc_Interface
*/
require_once 'Zend/InfoCard/Cipher/Symmetric/Aes256cbc/Interface.php';
/**
* Zend_InfoCard_Cipher_Exception
*/
require_once 'Zend/InfoCard/Cipher/Exception.php';
/**
* Implements AES256 with CBC encryption implemented using the mCrypt extension
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_InfoCard_Cipher_Symmetric_Adapter_Aes256cbc
extends Zend_InfoCard_Cipher_Symmetric_Adapter_Abstract
implements Zend_InfoCard_Cipher_Symmetric_Aes256cbc_Interface
{
/**
* The MCRYPT Cipher constant for this encryption
*/
const MCRYPT_CIPHER = MCRYPT_RIJNDAEL_128;
/**
* The MCRYPT Mode constant for this encryption
*/
const MCRYPT_MODE = MCRYPT_MODE_CBC;
/**
* The default length of the IV to use
*/
const IV_LENGTH = 16;
/**
* The object constructor
*
* @throws Zend_InfoCard_Cipher_Exception
*/
public function __construct()
{
// Can't test for this
// @codeCoverageIgnoreStart
if(!extension_loaded('mcrypt')) {
throw new Zend_InfoCard_Cipher_Exception("Use of the AES256CBC Cipher requires the mcrypt extension");
}
// @codeCoveregIgnoreEnd
}
/**
* Decrypts data using the AES Algorithm using the mCrypt extension
*
* @throws Zend_InfoCard_Cipher_Exception
* @param string $encryptedData The encrypted data in binary format
* @param string $decryptionKey The decryption key
* @param integer $iv_length The IV length to use
* @return string the decrypted data with any terminating nulls removed
*/
public function decrypt($encryptedData, $decryptionKey, $iv_length = null)
{
$iv_length = is_null($iv_length) ? self::IV_LENGTH : $iv_length;
$mcrypt_iv = null;
if($iv_length > 0) {
$mcrypt_iv = substr($encryptedData, 0, $iv_length);
$encryptedData = substr($encryptedData, $iv_length);
}
$decrypted = mcrypt_decrypt(self::MCRYPT_CIPHER, $decryptionKey, $encryptedData, self::MCRYPT_MODE, $mcrypt_iv);
if(!$decrypted) {
throw new Zend_InfoCard_Cipher_Exception("Failed to decrypt data using AES256CBC Algorithm");
}
$decryptedLength = strlen($decrypted);
$paddingLength = substr($decrypted, $decryptedLength -1, 1);
$decrypted = substr($decrypted, 0, $decryptedLength - ord($paddingLength));
return rtrim($decrypted, "\0");
}
}
DbSelect.php 0000604 00000014760 15071551417 0006754 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DbSelect.php 12287 2008-11-04 21:49:22Z mikaelkael $
*/
/**
* @see Zend_Paginator_Adapter_Interface
*/
require_once 'Zend/Paginator/Adapter/Interface.php';
/**
* @see Zend_Db
*/
require_once 'Zend/Db.php';
/**
* @see Zend_Db_Select
*/
require_once 'Zend/Db/Select.php';
/**
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Paginator_Adapter_DbSelect implements Zend_Paginator_Adapter_Interface
{
/**
* Name of the row count column
*
* @var string
*/
const ROW_COUNT_COLUMN = 'zend_paginator_row_count';
/**
* Database query
*
* @var Zend_Db_Select
*/
protected $_select = null;
/**
* Total item count
*
* @var integer
*/
protected $_rowCount = null;
/**
* Constructor.
*
* @param Zend_Db_Select $select The select query
*/
public function __construct(Zend_Db_Select $select)
{
$this->_select = $select;
}
/**
* Sets the total row count, either directly or through a supplied
* query. Without setting this, {@link getPages()} selects the count
* as a subquery (SELECT COUNT ... FROM (SELECT ...)). While this
* yields an accurate count even with queries containing clauses like
* LIMIT, it can be slow in some circumstances. For example, in MySQL,
* subqueries are generally slow when using the InnoDB storage engine.
* Users are therefore encouraged to profile their queries to find
* the solution that best meets their needs.
*
* @param Zend_Db_Select|integer $totalRowCount Total row count integer
* or query
* @return Zend_Paginator_Adapter_DbSelect $this
* @throws Zend_Paginator_Exception
*/
public function setRowCount($rowCount)
{
if ($rowCount instanceof Zend_Db_Select) {
$columns = $rowCount->getPart(Zend_Db_Select::COLUMNS);
$countColumnPart = $columns[0][1];
if ($countColumnPart instanceof Zend_Db_Expr) {
$countColumnPart = $countColumnPart->__toString();
}
// The select query can contain only one column, which should be the row count column
if (false === strpos($countColumnPart, self::ROW_COUNT_COLUMN)) {
/**
* @see Zend_Paginator_Exception
*/
require_once 'Zend/Paginator/Exception.php';
throw new Zend_Paginator_Exception('Row count column not found');
}
$result = $rowCount->query(Zend_Db::FETCH_ASSOC)->fetch();
$this->_rowCount = count($result) > 0 ? $result[self::ROW_COUNT_COLUMN] : 0;
} else if (is_integer($rowCount)) {
$this->_rowCount = $rowCount;
} else {
/**
* @see Zend_Paginator_Exception
*/
require_once 'Zend/Paginator/Exception.php';
throw new Zend_Paginator_Exception('Invalid row count');
}
return $this;
}
/**
* Returns an array of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return array
*/
public function getItems($offset, $itemCountPerPage)
{
$this->_select->limit($itemCountPerPage, $offset);
return $this->_select->query()->fetchAll();
}
/**
* Returns the total number of rows in the result set.
*
* @return integer
*/
public function count()
{
if ($this->_rowCount === null) {
$rowCount = clone $this->_select;
/**
* The DISTINCT and GROUP BY queries only work when selecting one column.
* The question is whether any RDBMS supports DISTINCT for multiple columns, without workarounds.
*/
if (true === $rowCount->getPart(Zend_Db_Select::DISTINCT)) {
$columnParts = $rowCount->getPart(Zend_Db_Select::COLUMNS);
$columns = array();
foreach ($columnParts as $part) {
if ($part[1] == '*' || $part[1] instanceof Zend_Db_Expr) {
$columns[] = $part[1];
} else {
$columns[] = $rowCount->getAdapter()->quoteIdentifier($part[1], true);
}
}
if (count($columns) == 1 && $columns[0] == '*') {
$groupPart = null;
} else {
$groupPart = implode(',', $columns);
}
} else {
$groupParts = $rowCount->getPart(Zend_Db_Select::GROUP);
foreach ($groupParts as &$part) {
if (!($part == '*' || $part instanceof Zend_Db_Expr)) {
$part = $rowCount->getAdapter()->quoteIdentifier($part, true);
}
}
$groupPart = implode(',', $groupParts);
}
$countPart = empty($groupPart) ? 'COUNT(*)' : 'COUNT(DISTINCT ' . $groupPart . ')';
$expression = new Zend_Db_Expr($countPart . ' AS ' . $rowCount->getAdapter()->quoteIdentifier(self::ROW_COUNT_COLUMN));
$rowCount->__toString(); // Workaround for ZF-3719 and related
$rowCount->reset(Zend_Db_Select::COLUMNS)
->reset(Zend_Db_Select::ORDER)
->reset(Zend_Db_Select::LIMIT_OFFSET)
->reset(Zend_Db_Select::GROUP)
->reset(Zend_Db_Select::DISTINCT)
->columns($expression);
$this->setRowCount($rowCount);
}
return $this->_rowCount;
}
}
Null.php 0000604 00000003604 15071551417 0006174 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Null.php 10792 2008-08-08 03:11:03Z mratzloff $
*/
/**
* @see Zend_Paginator_Adapter_Interface
*/
require_once 'Zend/Paginator/Adapter/Interface.php';
/**
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Paginator_Adapter_Null implements Zend_Paginator_Adapter_Interface
{
/**
* Item count
*
* @var integer
*/
protected $_count = null;
/**
* Constructor.
*
* @param array $count Total item count
*/
public function __construct($count = 0)
{
$this->_count = $count;
}
/**
* Returns an array of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return array
*/
public function getItems($offset, $itemCountPerPage)
{
return array_fill(0, $itemCountPerPage, null);
}
/**
* Returns the total number of rows in the array.
*
* @return integer
*/
public function count()
{
return $this->_count;
}
} DbTableSelect.php 0000604 00000003124 15071551417 0007714 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DbTableSelect.php 11735 2008-10-08 14:00:24Z norm2782 $
*/
/**
* @see Zend_Paginator_Adapter_DbSelect
*/
require_once 'Zend/Paginator/Adapter/DbSelect.php';
/**
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Paginator_Adapter_DbTableSelect extends Zend_Paginator_Adapter_DbSelect
{
/**
* Returns a Zend_Db_Table_Rowset_Abstract of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return Zend_Db_Table_Rowset_Abstract
*/
public function getItems($offset, $itemCountPerPage)
{
$this->_select->limit($itemCountPerPage, $offset);
return $this->_select->getTable()->fetchAll($this->_select);
}
} Iterator.php 0000604 00000005036 15071551417 0007054 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Iterator.php 11222 2008-09-04 03:18:34Z mratzloff $
*/
/**
* @see Zend_Paginator_Adapter_Interface
*/
require_once 'Zend/Paginator/Adapter/Interface.php';
/**
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Paginator_Adapter_Iterator implements Zend_Paginator_Adapter_Interface
{
/**
* Iterator which implements Countable
*
* @var Iterator
*/
protected $_iterator = null;
/**
* Item count
*
* @var integer
*/
protected $_count = null;
/**
* Constructor.
*
* @param Iterator $iterator Iterator to paginate
* @throws Zend_Paginator_Exception
*/
public function __construct(Iterator $iterator)
{
if (!$iterator instanceof Countable) {
/**
* @see Zend_Paginator_Exception
*/
require_once 'Zend/Paginator/Exception.php';
throw new Zend_Paginator_Exception('Iterator must implement Countable');
}
$this->_iterator = $iterator;
$this->_count = count($iterator);
}
/**
* Returns an iterator of items for a page, or an empty array.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return LimitIterator|array
*/
public function getItems($offset, $itemCountPerPage)
{
if ($this->_count == 0) {
return array();
}
return new LimitIterator($this->_iterator, $offset, $itemCountPerPage);
}
/**
* Returns the total number of rows in the collection.
*
* @return integer
*/
public function count()
{
return $this->_count;
}
}