mirror of
https://github.com/atlanticbiomedical/portal-legacy.git
synced 2025-07-02 01:47:28 -04:00
initial commit
This commit is contained in:
478
lib/symfony/vendor/creole/drivers/mssql/MSSQLCallableStatement.php
vendored
Executable file
478
lib/symfony/vendor/creole/drivers/mssql/MSSQLCallableStatement.php
vendored
Executable file
@ -0,0 +1,478 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MSSQLCallableStatement.php,v 1.20 2005/09/16 13:09:50 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/drivers/mssql/MSSQLPreparedStatement.php';
|
||||
require_once 'creole/CallableStatement.php';
|
||||
include_once 'creole/CreoleTypes.php';
|
||||
|
||||
/**
|
||||
* MS SQL Server class to handle stored procedure execution.
|
||||
*
|
||||
* Developer note:
|
||||
*
|
||||
* There is no CallableStatement superclass. Unlike JDBC, Creole
|
||||
* uses abstract parent classes rather than interfaces -- in order
|
||||
* to minimize code duplication. Since PHP doesn't support multiple
|
||||
* inheritance, the DRIVERCallableStatement class cannot extend both
|
||||
* the DRIVERPreparedStatement class and the would-be abstract
|
||||
* CallableStatement class.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.20 $
|
||||
* @package creole.drivers.mssql
|
||||
*/
|
||||
class MSSQLCallableStatement extends MSSQLPreparedStatement implements CallableStatement {
|
||||
|
||||
/** Output variables */
|
||||
private $boundOutVars = array();
|
||||
|
||||
/**
|
||||
* Match Creole types to SQL Server types
|
||||
* @var array
|
||||
*/
|
||||
private static $typeMap = array(
|
||||
CreoleTypes::BOOLEAN => SQLBIT,
|
||||
CreoleTypes::BIGINT => SQLINT4,
|
||||
CreoleTypes::SMALLINT => SQLINT2,
|
||||
CreoleTypes::TINYINT => SQLINT2,
|
||||
CreoleTypes::INTEGER => SQLINT4,
|
||||
CreoleTypes::CHAR => SQLCHAR,
|
||||
CreoleTypes::VARCHAR => SQLVARCHAR,
|
||||
CreoleTypes::TEXT => SQLTEXT,
|
||||
CreoleTypes::FLOAT => SQLFLT8,
|
||||
CreoleTypes::DOUBLE => SQLFLT8,
|
||||
CreoleTypes::DATE => SQLVARCHAR,
|
||||
CreoleTypes::TIME => SQLVARCHAR,
|
||||
CreoleTypes::TIMESTAMP => SQLVARCHAR,
|
||||
CreoleTypes::VARBINARY => SQLVARCHAR,
|
||||
CreoleTypes::NUMERIC => SQLINT4,
|
||||
CreoleTypes::DECIMAL => SQLFLT8
|
||||
);
|
||||
|
||||
/**
|
||||
* Statement created by mssql_init()
|
||||
* @var resource
|
||||
*/
|
||||
private $stmt;
|
||||
|
||||
|
||||
/**
|
||||
* The result resource.
|
||||
* @var resource
|
||||
*/
|
||||
private $result;
|
||||
|
||||
/**
|
||||
* Construct new MSSQLCallableStatement.
|
||||
*
|
||||
* @param Connection $conn
|
||||
* @param resource $stmt
|
||||
*/
|
||||
public function __construct(Connection $conn, $stmt)
|
||||
{
|
||||
print " - > IN CONSTRUCTOR \n";
|
||||
$this->conn = $conn;
|
||||
$this->stmt = $stmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::getResource()
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return $this->stmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::close()
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
@mssql_free_statement($this->stmt);
|
||||
$this->rsFetchCount = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::executeQuery()
|
||||
*/
|
||||
function executeQuery($p1 = null, $fetchmode = null)
|
||||
{
|
||||
$params = null;
|
||||
if ($fetchmode !== null) {
|
||||
$params = $p1;
|
||||
} elseif ($p1 !== null) {
|
||||
if (is_array($p1)) $params = $p1;
|
||||
else $fetchmode = $p1;
|
||||
}
|
||||
|
||||
if ($params) {
|
||||
for($i=0,$cnt=count($params); $i < $cnt; $i++) {
|
||||
$this->set($i+1, $params[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->result = mssql_execute($this->stmt);
|
||||
if (!$this->result) {
|
||||
throw new SQLException('unable to execute callable statement', mssql_get_last_message());
|
||||
}
|
||||
|
||||
return new MSSQLResultSet($this->conn, $this->result, $fetchmode, $this->offset, $this->limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::getMoreResults()
|
||||
*/
|
||||
function getMoreResults()
|
||||
{
|
||||
$this->rsFetchCount++; // we track this because
|
||||
$hasMore = mssql_next_result($this->result);
|
||||
if ($this->resultSet) $this->resultSet->close();
|
||||
if ($hasMore) {
|
||||
$clazz = $this->resultClass;
|
||||
$this->resultSet = new $clazz($this, $this->result);
|
||||
} else {
|
||||
$this->resultSet = null;
|
||||
}
|
||||
return $hasMore;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::registerOutParameter()
|
||||
*/
|
||||
function registerOutParameter($paramIndex, $sqlType, $maxLength = null)
|
||||
{
|
||||
mssql_bind($this->stmt, $paramIndex, $this->boundOutVars[$paramIndex], self::$typeMap[$sqlType], true, false, $maxLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::setArray()
|
||||
*/
|
||||
function setArray($paramIndex, $value, $out = false)
|
||||
{
|
||||
if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
$value = serialize($value);
|
||||
mssql_bind($this->stmt, $paramIndex, $value, SQLTEXT, $out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::setBoolean()
|
||||
*/
|
||||
function setBoolean($paramIndex, $value, $out = false)
|
||||
{
|
||||
if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
$value = ($value) ? 1 : 0;
|
||||
mssql_bind($this->stmt, $paramIndex, $value, SQLBIT, $out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see CallableStatement::setBlob()
|
||||
*/
|
||||
function setBlob($paramIndex, $blob, $out = false)
|
||||
{
|
||||
if ($blob === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
if (is_object($blob)) {
|
||||
$blob = $blob->__toString();
|
||||
}
|
||||
if ($out) $this->boundOutVars[$paramIndex] = &$blob; // reference means that changes to value, will be reflected
|
||||
$data = unpack("H*hex", $blob);
|
||||
mssql_bind($this->stmt, $paramIndex, $data, SQLTEXT, $out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::setClob()
|
||||
*/
|
||||
function setClob($paramIndex, $clob, $out = false)
|
||||
{
|
||||
if ($clob === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
if (is_object($clob)) {
|
||||
$clob = $clob->__toString();
|
||||
}
|
||||
if ($out) $this->boundOutVars[$paramIndex] = &$clob; // reference means that changes to value, will be reflected
|
||||
mssql_bind($this->stmt, $paramIndex, $clob, SQLTEXT, $out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::setDate()
|
||||
*/
|
||||
function setDate($paramIndex, $value, $out = false)
|
||||
{
|
||||
if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
if (is_numeric($value)) $value = date("Y-m-d", $value);
|
||||
mssql_bind($this->stmt, $paramIndex, $value, SQLVARCHAR, $out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::setFloat()
|
||||
*/
|
||||
function setFloat($paramIndex, $value, $out = false)
|
||||
{
|
||||
if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
$value = (float) $value;
|
||||
mssql_bind($this->stmt, $paramIndex, $value, SQLFLT8, $out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::setInt()
|
||||
*/
|
||||
function setInt($paramIndex, $value, $out = false)
|
||||
{
|
||||
if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
$value = (int) $value;
|
||||
mssql_bind($this->stmt, $paramIndex, $value, SQLINT4, $out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::setNull()
|
||||
*/
|
||||
function setNull($paramIndex)
|
||||
{
|
||||
// hopefully type isn't essential here :)
|
||||
$value = null; // wants a var to pass by reference
|
||||
mssql_bind($this->stmt, $paramIndex, $value, $type=null, $out=false, $is_null=true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::setString()
|
||||
*/
|
||||
function setString($paramIndex, $value, $out = false)
|
||||
{
|
||||
if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
$value = (string) $value;
|
||||
mssql_bind($this->stmt, $paramIndex, $value, SQLVARCHAR, $out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::setTime()
|
||||
*/
|
||||
function setTime($paramIndex, $value, $out = false)
|
||||
{
|
||||
if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
if (is_numeric($value)) $value = date("H:i:s", $value);
|
||||
mssql_bind($this->stmt, $paramIndex, $value, SQLVARCHAR, $out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::setTimestamp()
|
||||
*/
|
||||
function setTimestamp($paramIndex, $value, $out = false)
|
||||
{
|
||||
if ($out) $this->boundOutVars[$paramIndex] = &$value; // reference means that changes to value, will be reflected
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
if (is_numeric($value)) $value = date('Y-m-d H:i:s', $value);
|
||||
mssql_bind($this->stmt, $paramIndex, $value, SQLVARCHAR, $out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::getArray()
|
||||
*/
|
||||
function getArray($paramIndex)
|
||||
{
|
||||
if (!array_key_exists($paramIndex, $this->boundOutVars)) {
|
||||
throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
|
||||
}
|
||||
if ($this->boundOutVars[$paramIndex] === null) { return null; }
|
||||
return (array) unserialize($this->boundOutVars[$paramIndex]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::getBoolean()
|
||||
*/
|
||||
function getBoolean($paramIndex)
|
||||
{
|
||||
if (!array_key_exists($paramIndex, $this->boundOutVars)) {
|
||||
throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
|
||||
}
|
||||
if ($this->boundOutVars[$paramIndex] === null) { return null; }
|
||||
return (boolean) $this->boundOutVars[$paramIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::getBlob()
|
||||
*/
|
||||
function getBlob($paramIndex)
|
||||
{
|
||||
if (!array_key_exists($paramIndex, $this->boundOutVars)) {
|
||||
throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
|
||||
}
|
||||
if ($this->boundOutVars[$paramIndex] === null) { return null; }
|
||||
require_once 'creole/util/Blob.php';
|
||||
$b = new Blob();
|
||||
$b->setContents($this->boundOutVars[$paramIndex]);
|
||||
return $b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::getClob()
|
||||
*/
|
||||
function getClob($paramIndex)
|
||||
{
|
||||
if (!array_key_exists($paramIndex, $this->boundOutVars)) {
|
||||
throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
|
||||
}
|
||||
if ($this->boundOutVars[$paramIndex] === null) { return null; }
|
||||
require_once 'creole/util/Clob.php';
|
||||
$c = new Clob();
|
||||
$c->setContents($this->boundOutVars[$paramIndex]);
|
||||
return $c;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::getDate()
|
||||
*/
|
||||
function getDate($paramIndex, $fmt = '%Y-%m-%d')
|
||||
{
|
||||
if (!array_key_exists($paramIndex, $this->boundOutVars)) {
|
||||
throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
|
||||
}
|
||||
if ($this->boundOutVars[$paramIndex] === null) { return null; }
|
||||
|
||||
$ts = strtotime($this->boundOutVars[$paramIndex]);
|
||||
if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
|
||||
throw new SQLException("Unable to convert value at column " . $paramIndex . " to timestamp: " . $this->boundOutVars[$paramIndex]);
|
||||
}
|
||||
if (strpos($format, '%') !== false) {
|
||||
return strftime($format, $ts);
|
||||
} else {
|
||||
return date($format, $ts);
|
||||
}
|
||||
|
||||
return $this->boundOutVars[$paramIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $paramIndex Column name (string) or index (int).
|
||||
* @return float
|
||||
*/
|
||||
function getFloat($paramIndex)
|
||||
{
|
||||
if (!array_key_exists($paramIndex, $this->boundOutVars)) {
|
||||
throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
|
||||
}
|
||||
if ($this->boundOutVars[$paramIndex] === null) { return null; }
|
||||
return (float) $this->boundOutVars[$paramIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::getInt()
|
||||
*/
|
||||
function getInt($paramIndex)
|
||||
{
|
||||
if (!array_key_exists($paramIndex, $this->boundOutVars)) {
|
||||
throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
|
||||
}
|
||||
if ($this->boundOutVars[$paramIndex] === null) { return null; }
|
||||
return (int) $this->boundOutVars[$paramIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::getString()
|
||||
*/
|
||||
function getString($paramIndex)
|
||||
{
|
||||
if (!array_key_exists($paramIndex, $this->boundOutVars)) {
|
||||
throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
|
||||
}
|
||||
if ($this->boundOutVars[$paramIndex] === null) { return null; }
|
||||
return (string) $this->boundOutVars[$paramIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::getTime()
|
||||
*/
|
||||
function getTime($paramIndex, $format='%X')
|
||||
{
|
||||
if (!array_key_exists($paramIndex, $this->boundOutVars)) {
|
||||
throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
|
||||
}
|
||||
if ($this->boundOutVars[$paramIndex] === null) { return null; }
|
||||
|
||||
$ts = strtotime($this->boundOutVars[$paramIndex]);
|
||||
if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
|
||||
throw new SQLException("Unable to convert value at column " . $paramIndex . " to timestamp: " . $this->boundOutVars[$paramIndex]);
|
||||
}
|
||||
if (strpos($format, '%') !== false) {
|
||||
return strftime($format, $ts);
|
||||
} else {
|
||||
return date($format, $ts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CallableStatement::getTimestamp()
|
||||
*/
|
||||
function getTimestamp($paramIndex, $format = 'Y-m-d H:i:s')
|
||||
{
|
||||
if (!array_key_exists($paramIndex, $this->boundOutVars)) {
|
||||
throw new SQLException('Requesting variable not bound to output var: '.$paramIndex);
|
||||
}
|
||||
if ($this->boundOutVars[$paramIndex] === null) { return null; }
|
||||
|
||||
$ts = strtotime($this->boundOutVars[$paramIndex]);
|
||||
if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
|
||||
throw new SQLException("Unable to convert value at column " . $paramIndex . " to timestamp: " . $this->boundOutVars[$paramIndex]);
|
||||
}
|
||||
if (strpos($format, '%') !== false) {
|
||||
return strftime($format, $ts);
|
||||
} else {
|
||||
return date($format, $ts);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
283
lib/symfony/vendor/creole/drivers/mssql/MSSQLConnection.php
vendored
Executable file
283
lib/symfony/vendor/creole/drivers/mssql/MSSQLConnection.php
vendored
Executable file
@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* $Id: MSSQLConnection.php,v 1.25 2005/10/17 19:03:51 dlawson_mi Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
|
||||
require_once 'creole/Connection.php';
|
||||
require_once 'creole/common/ConnectionCommon.php';
|
||||
include_once 'creole/drivers/mssql/MSSQLResultSet.php';
|
||||
|
||||
/**
|
||||
* MS SQL Server implementation of Connection.
|
||||
*
|
||||
* If you have trouble with BLOB / CLOB support
|
||||
* --------------------------------------------
|
||||
*
|
||||
* You may need to change some PHP ini settings. In particular, the following settings
|
||||
* set the text size to maximum which should get around issues with truncated data:
|
||||
* <code>
|
||||
* ini_set('mssql.textsize', 2147483647);
|
||||
* ini_set('mssql.textlimit', 2147483647);
|
||||
* </code>
|
||||
* We do not set these by default (anymore) because they do not apply to cases where MSSQL
|
||||
* is being used w/ FreeTDS.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @author Stig Bakken <ssb@fast.no>
|
||||
* @author Lukas Smith
|
||||
* @version $Revision: 1.25 $
|
||||
* @package creole.drivers.mssql
|
||||
*/
|
||||
class MSSQLConnection extends ConnectionCommon implements Connection {
|
||||
|
||||
/** Current database (used in mssql_select_db()). */
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* @see Connection::connect()
|
||||
*/
|
||||
function connect($dsninfo, $flags = 0)
|
||||
{
|
||||
if (!extension_loaded('mssql') && !extension_loaded('sybase') && !extension_loaded('sybase_ct')) {
|
||||
throw new SQLException('mssql extension not loaded');
|
||||
}
|
||||
|
||||
$this->dsn = $dsninfo;
|
||||
$this->flags = $flags;
|
||||
|
||||
$persistent = ($flags & Creole::PERSISTENT === Creole::PERSISTENT);
|
||||
|
||||
$user = $dsninfo['username'];
|
||||
$pw = $dsninfo['password'];
|
||||
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
|
||||
|
||||
if (PHP_OS == "WINNT" || PHP_OS == "WIN32") {
|
||||
$portDelimiter = ",";
|
||||
} else {
|
||||
$portDelimiter = ":";
|
||||
}
|
||||
|
||||
if(!empty($dsninfo['port'])) {
|
||||
$dbhost .= $portDelimiter.$dsninfo['port'];
|
||||
} else {
|
||||
$dbhost .= $portDelimiter.'1433';
|
||||
}
|
||||
|
||||
$connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect';
|
||||
|
||||
if ($dbhost && $user && $pw) {
|
||||
$conn = @$connect_function($dbhost, $user, $pw);
|
||||
} elseif ($dbhost && $user) {
|
||||
$conn = @$connect_function($dbhost, $user);
|
||||
} else {
|
||||
$conn = @$connect_function($dbhost);
|
||||
}
|
||||
if (!$conn) {
|
||||
throw new SQLException('connect failed', mssql_get_last_message());
|
||||
}
|
||||
|
||||
if ($dsninfo['database']) {
|
||||
if (!@mssql_select_db($dsninfo['database'], $conn)) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
$this->database = $dsninfo['database'];
|
||||
}
|
||||
|
||||
$this->dblink = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getDatabaseInfo()
|
||||
*/
|
||||
public function getDatabaseInfo()
|
||||
{
|
||||
require_once 'creole/drivers/mssql/metadata/MSSQLDatabaseInfo.php';
|
||||
return new MSSQLDatabaseInfo($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getIdGenerator()
|
||||
*/
|
||||
public function getIdGenerator()
|
||||
{
|
||||
require_once 'creole/drivers/mssql/MSSQLIdGenerator.php';
|
||||
return new MSSQLIdGenerator($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::prepareStatement()
|
||||
*/
|
||||
public function prepareStatement($sql)
|
||||
{
|
||||
require_once 'creole/drivers/mssql/MSSQLPreparedStatement.php';
|
||||
return new MSSQLPreparedStatement($this, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::createStatement()
|
||||
*/
|
||||
public function createStatement()
|
||||
{
|
||||
require_once 'creole/drivers/mssql/MSSQLStatement.php';
|
||||
return new MSSQLStatement($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns false since MSSQL doesn't support this method.
|
||||
*/
|
||||
public function applyLimit(&$sql, $offset, $limit)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::close()
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
$ret = @mssql_close($this->dblink);
|
||||
$this->dblink = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::executeQuery()
|
||||
*/
|
||||
function executeQuery($sql, $fetchmode = null)
|
||||
{
|
||||
$this->lastQuery = $sql;
|
||||
if (!@mssql_select_db($this->database, $this->dblink)) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
$result = @mssql_query($sql, $this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute query', mssql_get_last_message());
|
||||
}
|
||||
return new MSSQLResultSet($this, $result, $fetchmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::executeUpdate()
|
||||
*/
|
||||
function executeUpdate($sql)
|
||||
{
|
||||
|
||||
$this->lastQuery = $sql;
|
||||
if (!mssql_select_db($this->database, $this->dblink)) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
$result = @mssql_query($sql, $this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute update', mssql_get_last_message(), $sql);
|
||||
}
|
||||
|
||||
return $this->getUpdateCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a database transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function beginTrans()
|
||||
{
|
||||
$result = @mssql_query('BEGIN TRAN', $this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not begin transaction', mssql_get_last_message());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function commitTrans()
|
||||
{
|
||||
if (!@mssql_select_db($this->database, $this->dblink)) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
$result = @mssql_query('COMMIT TRAN', $this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not commit transaction', mssql_get_last_message());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll back (undo) the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function rollbackTrans()
|
||||
{
|
||||
if (!@mssql_select_db($this->database, $this->dblink)) {
|
||||
throw new SQLException('no database selected');
|
||||
}
|
||||
$result = @mssql_query('ROLLBACK TRAN', $this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not rollback transaction', mssql_get_last_message());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by the last query.
|
||||
* if the last query was a select, returns 0.
|
||||
*
|
||||
* @return int Number of rows affected by the last query
|
||||
* @throws SQLException
|
||||
*/
|
||||
function getUpdateCount()
|
||||
{
|
||||
$res = @mssql_query('select @@rowcount', $this->dblink);
|
||||
if (!$res) {
|
||||
throw new SQLException('Unable to get affected row count', mssql_get_last_message());
|
||||
}
|
||||
$ar = @mssql_fetch_row($res);
|
||||
if (!$ar) {
|
||||
$result = 0;
|
||||
} else {
|
||||
@mssql_free_result($res);
|
||||
$result = $ar[0];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a CallableStatement object for calling database stored procedures.
|
||||
*
|
||||
* @param string $sql
|
||||
* @return CallableStatement
|
||||
* @throws SQLException
|
||||
*/
|
||||
function prepareCall($sql)
|
||||
{
|
||||
require_once 'creole/drivers/mssql/MSSQLCallableStatement.php';
|
||||
$stmt = mssql_init($sql);
|
||||
if (!$stmt) {
|
||||
throw new SQLException('Unable to prepare statement', mssql_get_last_message(), $sql);
|
||||
}
|
||||
return new MSSQLCallableStatement($this, $stmt);
|
||||
}
|
||||
}
|
62
lib/symfony/vendor/creole/drivers/mssql/MSSQLIdGenerator.php
vendored
Executable file
62
lib/symfony/vendor/creole/drivers/mssql/MSSQLIdGenerator.php
vendored
Executable file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
require_once 'creole/IdGenerator.php';
|
||||
|
||||
/**
|
||||
* MSSQL IdGenerator implimenation.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.6 $
|
||||
* @package creole.drivers.mssql
|
||||
*/
|
||||
class MSSQLIdGenerator implements IdGenerator {
|
||||
|
||||
/** Connection object that instantiated this class */
|
||||
private $conn;
|
||||
|
||||
/**
|
||||
* Creates a new IdGenerator class, saves passed connection for use
|
||||
* later by getId() method.
|
||||
* @param Connection $conn
|
||||
*/
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isBeforeInsert()
|
||||
*/
|
||||
public function isBeforeInsert()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isAfterInsert()
|
||||
*/
|
||||
public function isAfterInsert()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::getIdMethod()
|
||||
*/
|
||||
public function getIdMethod()
|
||||
{
|
||||
return self::AUTOINCREMENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::getId()
|
||||
*/
|
||||
public function getId($unused = null)
|
||||
{
|
||||
$rs = $this->conn->executeQuery("SELECT SCOPE_IDENTITY()", ResultSet::FETCHMODE_NUM);
|
||||
$rs->next();
|
||||
return $rs->getInt(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
99
lib/symfony/vendor/creole/drivers/mssql/MSSQLPreparedStatement.php
vendored
Executable file
99
lib/symfony/vendor/creole/drivers/mssql/MSSQLPreparedStatement.php
vendored
Executable file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MSSQLPreparedStatement.php,v 1.13 2005/11/13 01:29:01 gamr Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/PreparedStatement.php';
|
||||
require_once 'creole/common/PreparedStatementCommon.php';
|
||||
|
||||
/**
|
||||
* MSSQL specific PreparedStatement functions.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.13 $
|
||||
* @package creole.drivers.mssql
|
||||
*/
|
||||
class MSSQLPreparedStatement extends PreparedStatementCommon implements PreparedStatement {
|
||||
|
||||
/**
|
||||
* MSSQL-specific implementation of setBlob().
|
||||
*
|
||||
* If you are having trouble getting BLOB data into the database, see the phpdoc comment
|
||||
* in the MSSQLConnection for some PHP ini values that may need to be set. (This also
|
||||
* applies to CLOB support.)
|
||||
*
|
||||
* @param int $paramIndex
|
||||
* @param mixed $value Blob object or string.
|
||||
* @return void
|
||||
*/
|
||||
function setBlob($paramIndex, $blob)
|
||||
{
|
||||
$this->sql_cache_valid = false;
|
||||
if ($blob === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
// they took magic __toString() out of PHP5.0.0; this sucks
|
||||
if (is_object($blob)) {
|
||||
$blob = $blob->__toString();
|
||||
}
|
||||
$data = unpack("H*hex", $blob);
|
||||
$this->boundInVars[$paramIndex] = '0x'.$data['hex']; // no surrounding quotes!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add quotes using str_replace.
|
||||
* This is not as thorough as MySQL.
|
||||
*/
|
||||
protected function escape($subject)
|
||||
{
|
||||
// use this instead of magic_quotes_sybase + addslashes(),
|
||||
// just in case multiple RDBMS being used at the same time
|
||||
return str_replace("'", "''", $subject);
|
||||
}
|
||||
|
||||
/**
|
||||
* MSSQL must emulate OFFSET/LIMIT support.
|
||||
*/
|
||||
public function executeQuery($p1 = null, $fetchmode = null)
|
||||
{
|
||||
$params = null;
|
||||
if ($fetchmode !== null) {
|
||||
$params = $p1;
|
||||
} elseif ($p1 !== null) {
|
||||
if (is_array($p1)) $params = $p1;
|
||||
else $fetchmode = $p1;
|
||||
}
|
||||
|
||||
if ($params) {
|
||||
for($i=0,$cnt=count($params); $i < $cnt; $i++) {
|
||||
$this->set($i+1, $params[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->updateCount = null; // reset
|
||||
$sql = $this->replaceParams();
|
||||
|
||||
$this->resultSet = $this->conn->executeQuery($sql, $fetchmode);
|
||||
$this->resultSet->_setOffset($this->offset);
|
||||
$this->resultSet->_setLimit($this->limit);
|
||||
return $this->resultSet;
|
||||
}
|
||||
}
|
159
lib/symfony/vendor/creole/drivers/mssql/MSSQLResultSet.php
vendored
Executable file
159
lib/symfony/vendor/creole/drivers/mssql/MSSQLResultSet.php
vendored
Executable file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MSSQLResultSet.php,v 1.21 2006/01/17 19:44:38 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/ResultSet.php';
|
||||
require_once 'creole/common/ResultSetCommon.php';
|
||||
|
||||
/**
|
||||
* MSSQL implementation of ResultSet.
|
||||
*
|
||||
* MS SQL does not support LIMIT or OFFSET natively so the methods
|
||||
* in here need to perform some adjustments and extra checking to make sure
|
||||
* that this behaves the same as RDBMS drivers using native OFFSET/LIMIT.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.21 $
|
||||
* @package creole.drivers.mssql
|
||||
*/
|
||||
class MSSQLResultSet extends ResultSetCommon implements ResultSet {
|
||||
|
||||
/**
|
||||
* Offset at which to start reading rows.
|
||||
* @var int
|
||||
*/
|
||||
private $offset = 0;
|
||||
|
||||
/**
|
||||
* Maximum rows to retrieve, or 0 if all.
|
||||
* @var int
|
||||
*/
|
||||
private $limit = 0;
|
||||
|
||||
/**
|
||||
* This MSSQL-only function exists to set offset after ResultSet is instantiated.
|
||||
* This function should be "protected" in Java sense: only available to classes in package.
|
||||
* THIS METHOD SHOULD NOT BE CALLED BY ANYTHING EXCEPTION DRIVER CLASSES.
|
||||
* @param int $offset New offset. If great than 0, then seek(0) will be called to move cursor.
|
||||
* @access protected
|
||||
*/
|
||||
public function _setOffset($offset)
|
||||
{
|
||||
$this->offset = $offset;
|
||||
if ($offset > 0) {
|
||||
$this->seek(0); // 0 becomes $offset by seek() method
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This MSSQL-only function exists to set limit after ResultSet is instantiated.
|
||||
* This function should be "protected" in Java sense: only available to classes in package.
|
||||
* THIS METHOD SHOULD NOT BE CALLED BY ANYTHING EXCEPTION DRIVER CLASSES.
|
||||
* @param int $limit New limit.
|
||||
* @access protected
|
||||
*/
|
||||
public function _setLimit($limit)
|
||||
{
|
||||
$this->limit = $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::seek()
|
||||
*/
|
||||
function seek($rownum)
|
||||
{
|
||||
// support emulated OFFSET
|
||||
$actual = $rownum + $this->offset;
|
||||
|
||||
if (($this->limit > 0 && $rownum >= $this->limit) || $rownum < 0) {
|
||||
// have to check for rownum < 0, because mssql_seek() won't
|
||||
// complain if the $actual is valid.
|
||||
return false;
|
||||
}
|
||||
|
||||
// MSSQL rows start w/ 0, but this works, because we are
|
||||
// looking to move the position _before_ the next desired position
|
||||
if (!@mssql_data_seek($this->result, $actual)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->cursorPos = $rownum;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::next()
|
||||
*/
|
||||
function next()
|
||||
{
|
||||
// support emulated LIMIT
|
||||
if ( $this->limit > 0 && ($this->cursorPos >= $this->limit) ) {
|
||||
$this->afterLast();
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->fields = mssql_fetch_array($this->result, $this->fetchmode);
|
||||
|
||||
if (!$this->fields) {
|
||||
if ($errmsg = mssql_get_last_message()) {
|
||||
throw new SQLException("Error fetching result", $errmsg);
|
||||
} else {
|
||||
// We've advanced beyond end of recordset.
|
||||
$this->afterLast();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->fetchmode === ResultSet::FETCHMODE_ASSOC && $this->lowerAssocCase) {
|
||||
$this->fields = array_change_key_case($this->fields, CASE_LOWER);
|
||||
}
|
||||
|
||||
// Advance cursor position
|
||||
$this->cursorPos++;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::getRecordCount()
|
||||
*/
|
||||
function getRecordCount()
|
||||
{
|
||||
$rows = @mssql_num_rows($this->result);
|
||||
if ($rows === null) {
|
||||
throw new SQLException('Error getting record count', mssql_get_last_message());
|
||||
}
|
||||
// adjust count based on emulated LIMIT/OFFSET
|
||||
$rows -= $this->offset;
|
||||
return ($this->limit > 0 && $rows > $this->limit ? $this->limit : $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::close()
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
$ret = @mssql_free_result($this->result);
|
||||
$this->result = false;
|
||||
$this->fields = array();
|
||||
$this->limit = 0;
|
||||
$this->offset = 0;
|
||||
}
|
||||
|
||||
}
|
72
lib/symfony/vendor/creole/drivers/mssql/MSSQLStatement.php
vendored
Executable file
72
lib/symfony/vendor/creole/drivers/mssql/MSSQLStatement.php
vendored
Executable file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MSSQLStatement.php,v 1.4 2004/06/13 02:31:07 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/common/StatementCommon.php';
|
||||
require_once 'creole/Statement.php';
|
||||
|
||||
/**
|
||||
* Class that contains MSSQL functionality for Statements.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.4 $
|
||||
* @package creole.drivers.mssql
|
||||
*/
|
||||
class MSSQLStatement extends StatementCommon implements Statement {
|
||||
|
||||
/**
|
||||
* Executes the SQL query in this PreparedStatement object and returns the resultset generated by the query.
|
||||
*
|
||||
* @param string $sql This method may optionally be called with the SQL statement.
|
||||
* @param int $fetchmode The mode to use when fetching the results (e.g. ResultSet::FETCHMODE_NUM, ResultSet::FETCHMODE_ASSOC).
|
||||
* @return object Creole::ResultSet
|
||||
* @throws SQLException If there is an error executing the specified query.
|
||||
*/
|
||||
public function executeQuery($sql, $fetchmode = null)
|
||||
{
|
||||
$this->updateCount = null;
|
||||
$this->resultSet = $this->conn->executeQuery($sql, $fetchmode);
|
||||
$this->resultSet->_setOffset($this->offset);
|
||||
$this->resultSet->_setLimit($this->limit);
|
||||
return $this->resultSet;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets next result set (if this behavior is supported by driver).
|
||||
* Some drivers (e.g. MSSQL) support returning multiple result sets -- e.g.
|
||||
* from stored procedures.
|
||||
*
|
||||
* This function also closes any current restult set.
|
||||
*
|
||||
* Default behavior is for this function to return false. Driver-specific
|
||||
* implementations of this class can override this method if they actually
|
||||
* support multiple result sets.
|
||||
*
|
||||
* @return boolean True if there is another result set, otherwise false.
|
||||
*/
|
||||
public function getMoreResults()
|
||||
{
|
||||
if ($this->resultSet) $this->resultSet->close();
|
||||
$this->resultSet = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
94
lib/symfony/vendor/creole/drivers/mssql/MSSQLTypes.php
vendored
Executable file
94
lib/symfony/vendor/creole/drivers/mssql/MSSQLTypes.php
vendored
Executable file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* $Id: MSSQLTypes.php,v 1.8 2004/07/27 23:16:50 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/CreoleTypes.php';
|
||||
|
||||
/**
|
||||
* MSSQL types / type map.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.8 $
|
||||
* @package creole.drivers.mssql
|
||||
*/
|
||||
class MSSQLTypes extends CreoleTypes {
|
||||
|
||||
/** Map PostgreSQL native types to Creole (JDBC) types. */
|
||||
private static $typeMap = array (
|
||||
"binary" => CreoleTypes::BINARY,
|
||||
"bit" => CreoleTypes::BOOLEAN,
|
||||
"char" => CreoleTypes::CHAR,
|
||||
"datetime" => CreoleTypes::TIMESTAMP,
|
||||
"decimal() identity" => CreoleTypes::DECIMAL,
|
||||
"decimal" => CreoleTypes::DECIMAL,
|
||||
"image" => CreoleTypes::LONGVARBINARY,
|
||||
"int" => CreoleTypes::INTEGER,
|
||||
"int identity" => CreoleTypes::INTEGER,
|
||||
"integer" => CreoleTypes::INTEGER,
|
||||
"money" => CreoleTypes::DECIMAL,
|
||||
"nchar" => CreoleTypes::CHAR,
|
||||
"ntext" => CreoleTypes::LONGVARCHAR,
|
||||
"numeric() identity" => CreoleTypes::NUMERIC,
|
||||
"numeric" => CreoleTypes::NUMERIC,
|
||||
"nvarchar" => CreoleTypes::VARCHAR,
|
||||
"real" => CreoleTypes::REAL,
|
||||
"float" => CreoleTypes::FLOAT,
|
||||
"smalldatetime" => CreoleTypes::TIMESTAMP,
|
||||
"smallint" => CreoleTypes::SMALLINT,
|
||||
"smallint identity" => CreoleTypes::SMALLINT,
|
||||
"smallmoney" => CreoleTypes::DECIMAL,
|
||||
"sysname" => CreoleTypes::VARCHAR,
|
||||
"text" => CreoleTypes::LONGVARCHAR,
|
||||
"timestamp" => CreoleTypes::BINARY,
|
||||
"tinyint identity" => CreoleTypes::TINYINT,
|
||||
"tinyint" => CreoleTypes::TINYINT,
|
||||
"uniqueidentifier" => CreoleTypes::CHAR,
|
||||
"varbinary" => CreoleTypes::VARBINARY,
|
||||
"varchar" => CreoleTypes::VARCHAR,
|
||||
"uniqueidentifier" => CreoleTypes::CHAR,
|
||||
// SQL Server 2000 only
|
||||
"bigint identity" => CreoleTypes::BIGINT,
|
||||
"bigint" => CreoleTypes::BIGINT,
|
||||
"sql_variant" => CreoleTypes::VARCHAR,
|
||||
);
|
||||
|
||||
/** Reverse lookup map, created on demand. */
|
||||
private static $reverseMap = null;
|
||||
|
||||
public static function getType($mssqlType)
|
||||
{
|
||||
$t = strtolower($mssqlType);
|
||||
if (isset(self::$typeMap[$t])) {
|
||||
return self::$typeMap[$t];
|
||||
} else {
|
||||
return CreoleTypes::OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getNativeType($creoleType)
|
||||
{
|
||||
if (self::$reverseMap === null) {
|
||||
self::$reverseMap = array_flip(self::$typeMap);
|
||||
}
|
||||
return @self::$reverseMap[$creoleType];
|
||||
}
|
||||
|
||||
}
|
69
lib/symfony/vendor/creole/drivers/mssql/metadata/MSSQLDatabaseInfo.php
vendored
Executable file
69
lib/symfony/vendor/creole/drivers/mssql/metadata/MSSQLDatabaseInfo.php
vendored
Executable file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MSSQLDatabaseInfo.php,v 1.11 2006/01/17 19:44:39 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/DatabaseInfo.php';
|
||||
|
||||
/**
|
||||
* MSSQL impementation of DatabaseInfo.
|
||||
*
|
||||
* @author Hans Lellelid
|
||||
* @version $Revision: 1.11 $
|
||||
* @package creole.drivers.mssql.metadata
|
||||
*/
|
||||
class MSSQLDatabaseInfo extends DatabaseInfo {
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function initTables()
|
||||
{
|
||||
include_once 'creole/drivers/mssql/metadata/MSSQLTableInfo.php';
|
||||
|
||||
$dsn = $this->conn->getDSN();
|
||||
|
||||
|
||||
if (!@mssql_select_db($this->dbname, $this->conn->getResource())) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
$result = mssql_query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME <> 'dtproperties'", $this->conn->getResource());
|
||||
|
||||
if (!$result) {
|
||||
throw new SQLException("Could not list tables", mssql_get_last_message());
|
||||
}
|
||||
|
||||
while ($row = mssql_fetch_row($result)) {
|
||||
$this->tables[strtoupper($row[0])] = new MSSQLTableInfo($this, $row[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
* @throws SQLException
|
||||
*/
|
||||
protected function initSequences()
|
||||
{
|
||||
// there are no sequences -- afaik -- in MSSQL.
|
||||
}
|
||||
|
||||
}
|
183
lib/symfony/vendor/creole/drivers/mssql/metadata/MSSQLTableInfo.php
vendored
Executable file
183
lib/symfony/vendor/creole/drivers/mssql/metadata/MSSQLTableInfo.php
vendored
Executable file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MSSQLTableInfo.php,v 1.14 2006/01/17 19:44:39 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/CreoleTypes.php';
|
||||
require_once 'creole/metadata/TableInfo.php';
|
||||
|
||||
/**
|
||||
* MSSQL implementation of TableInfo.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.14 $
|
||||
* @package creole.drivers.mssql.metadata
|
||||
*/
|
||||
class MSSQLTableInfo extends TableInfo {
|
||||
|
||||
/**
|
||||
* Loads the columns for this table.
|
||||
* @return void
|
||||
*/
|
||||
protected function initColumns()
|
||||
{
|
||||
include_once 'creole/metadata/ColumnInfo.php';
|
||||
include_once 'creole/drivers/mssql/MSSQLTypes.php';
|
||||
|
||||
if (!@mssql_select_db($this->dbname, $this->conn->getResource())) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
$res = mssql_query("sp_columns ".$this->name, $this->conn->getResource());
|
||||
if (!$res) {
|
||||
throw new SQLException('Could not get column names', mssql_get_last_message());
|
||||
}
|
||||
|
||||
while ($row = mssql_fetch_array($res)) {
|
||||
$name = $row['COLUMN_NAME'];
|
||||
$type = $row['TYPE_NAME'];
|
||||
$length = $row['LENGTH'];
|
||||
$is_nullable = $row['NULLABLE'];
|
||||
$default = $row['COLUMN_DEF'];
|
||||
$precision = $row['PRECISION'];
|
||||
$scale = $row['SCALE'];
|
||||
$identity = false;
|
||||
if (strtolower($type) == "int identity") {
|
||||
$identity = true;
|
||||
}
|
||||
$this->columns[$name] = new ColumnInfo($this, $name, MSSQLTypes::getType($type), $type, $length, $precision, $scale, $is_nullable, $default, $identity);
|
||||
}
|
||||
|
||||
$this->colsLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the indexes for this table.
|
||||
* @return void
|
||||
*/
|
||||
protected function initIndexes()
|
||||
{
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
include_once 'creole/metadata/IndexInfo.php';
|
||||
|
||||
if (!@mssql_select_db($this->dbname, $this->conn->getResource())) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
$res = mssql_query("sp_indexes_rowset ".$this->name, $this->conn->getResource());
|
||||
|
||||
while ($row = mssql_fetch_array($res)) {
|
||||
$name = $row['INDEX_NAME'];
|
||||
// All primary keys are indexes (right...?)
|
||||
if (!isset($this->indexes[$name])) {
|
||||
$this->indexes[$name] = new IndexInfo($name);
|
||||
}
|
||||
$this->indexes[$name]->addColumn($this->columns[ $row['COLUMN_NAME'] ]);
|
||||
}
|
||||
|
||||
$this->indexesLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the foreign keys for this table.
|
||||
* @return void
|
||||
*/
|
||||
protected function initForeignKeys()
|
||||
{
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
include_once 'creole/metadata/ForeignKeyInfo.php';
|
||||
|
||||
if (!@mssql_select_db($this->dbname, $this->conn->getResource())) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
$res = mssql_query("SELECT ccu1.TABLE_NAME, ccu1.COLUMN_NAME, ccu2.TABLE_NAME AS FK_TABLE_NAME, ccu2.COLUMN_NAME AS FK_COLUMN_NAME
|
||||
FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu1 INNER JOIN
|
||||
INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc1 ON tc1.CONSTRAINT_NAME = ccu1.CONSTRAINT_NAME AND
|
||||
CONSTRAINT_TYPE = 'Foreign Key' INNER JOIN
|
||||
INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1 ON rc1.CONSTRAINT_NAME = tc1.CONSTRAINT_NAME INNER JOIN
|
||||
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu2 ON ccu2.CONSTRAINT_NAME = rc1.UNIQUE_CONSTRAINT_NAME
|
||||
WHERE (ccu1.table_name = '".$this->name."')", $this->conn->getResource());
|
||||
|
||||
while($row = mssql_fetch_array($res)) {
|
||||
$name = $row['COLUMN_NAME'];
|
||||
$ftbl = $row['FK_TABLE_NAME'];
|
||||
$fcol = $row['FK_COLUMN_NAME'];
|
||||
|
||||
if (!isset($this->foreignKeys[$name])) {
|
||||
$this->foreignKeys[$name] = new ForeignKeyInfo($name);
|
||||
|
||||
if ($this->database->hasTable($ftbl)) {
|
||||
$foreignTable = $this->database->getTable($ftbl);
|
||||
} else {
|
||||
$foreignTable = new TableInfo($ltbl);
|
||||
$this->database->addTable($foreignTable);
|
||||
}
|
||||
|
||||
if ($foreignTable->hasColumn($fcol)) {
|
||||
$foreignCol = $foreignTable->getColumn($fcol);
|
||||
} else {
|
||||
$foreignCol = new ColumnInfo($foreignTable, $fcol);
|
||||
$foreignTable->addColumn($foreignCol);
|
||||
}
|
||||
|
||||
$this->foreignKeys[$name]->addReference($this->columns[$name], $foreignCol);
|
||||
}
|
||||
}
|
||||
|
||||
$this->fksLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the primary key info for this table.
|
||||
* @return void
|
||||
*/
|
||||
protected function initPrimaryKey()
|
||||
{
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
include_once 'creole/metadata/PrimaryKeyInfo.php';
|
||||
|
||||
if (!@mssql_select_db($this->dbname, $this->conn->getResource())) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
$res = mssql_query("SELECT COLUMN_NAME
|
||||
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
|
||||
INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ON
|
||||
INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_NAME = INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE.constraint_name
|
||||
WHERE (INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_TYPE = 'PRIMARY KEY') AND
|
||||
(INFORMATION_SCHEMA.TABLE_CONSTRAINTS.TABLE_NAME = '".$this->name."')", $this->conn->getResource());
|
||||
|
||||
// Loop through the returned results, grouping the same key_name together.
|
||||
// name of the primary key will be the first column name in the key.
|
||||
while($row = mssql_fetch_row($res)) {
|
||||
$name = $row[0];
|
||||
if (!isset($this->primaryKey)) {
|
||||
$this->primaryKey = new PrimaryKeyInfo($name);
|
||||
}
|
||||
$this->primaryKey->addColumn($this->columns[ $name ]);
|
||||
}
|
||||
|
||||
$this->pkLoaded = true;
|
||||
}
|
||||
|
||||
}
|
290
lib/symfony/vendor/creole/drivers/mysql/MySQLConnection.php
vendored
Executable file
290
lib/symfony/vendor/creole/drivers/mysql/MySQLConnection.php
vendored
Executable file
@ -0,0 +1,290 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLConnection.php,v 1.18 2004/09/01 14:00:28 dlawson_mi Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/Connection.php';
|
||||
require_once 'creole/common/ConnectionCommon.php';
|
||||
include_once 'creole/drivers/mysql/MySQLResultSet.php';
|
||||
|
||||
/**
|
||||
* MySQL implementation of Connection.
|
||||
*
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @author Stig Bakken <ssb@fast.no>
|
||||
* @author Lukas Smith
|
||||
* @version $Revision: 1.18 $
|
||||
* @package creole.drivers.mysql
|
||||
*/
|
||||
class MySQLConnection extends ConnectionCommon implements Connection {
|
||||
|
||||
/** Current database (used in mysql_select_db()). */
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* Connect to a database and log in as the specified user.
|
||||
*
|
||||
* @param $dsn the data source name (see DB::parseDSN for syntax)
|
||||
* @param $flags Any conneciton flags.
|
||||
* @access public
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
function connect($dsninfo, $flags = 0)
|
||||
{
|
||||
if (!extension_loaded('mysql')) {
|
||||
throw new SQLException('mysql extension not loaded');
|
||||
}
|
||||
|
||||
$this->dsn = $dsninfo;
|
||||
$this->flags = $flags;
|
||||
|
||||
$persistent = ($flags & Creole::PERSISTENT) === Creole::PERSISTENT;
|
||||
|
||||
if (isset($dsninfo['protocol']) && $dsninfo['protocol'] == 'unix') {
|
||||
$dbhost = ':' . $dsninfo['socket'];
|
||||
} else {
|
||||
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
|
||||
if (!empty($dsninfo['port'])) {
|
||||
$dbhost .= ':' . $dsninfo['port'];
|
||||
}
|
||||
}
|
||||
$user = $dsninfo['username'];
|
||||
$pw = $dsninfo['password'];
|
||||
|
||||
$encoding = !empty($dsninfo['encoding']) ? $dsninfo['encoding'] : null;
|
||||
|
||||
$connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect';
|
||||
|
||||
@ini_set('track_errors', true);
|
||||
if ($dbhost && $user && $pw) {
|
||||
$conn = @$connect_function($dbhost, $user, $pw);
|
||||
} elseif ($dbhost && $user) {
|
||||
$conn = @$connect_function($dbhost, $user);
|
||||
} elseif ($dbhost) {
|
||||
$conn = @$connect_function($dbhost);
|
||||
} else {
|
||||
$conn = false;
|
||||
}
|
||||
@ini_restore('track_errors');
|
||||
if (empty($conn)) {
|
||||
if (($err = @mysql_error()) != '') {
|
||||
throw new SQLException("connect failed", $err);
|
||||
} elseif (empty($php_errormsg)) {
|
||||
throw new SQLException("connect failed");
|
||||
} else {
|
||||
throw new SQLException("connect failed", $php_errormsg);
|
||||
}
|
||||
}
|
||||
|
||||
if ($dsninfo['database']) {
|
||||
if (!@mysql_select_db($dsninfo['database'], $conn)) {
|
||||
switch(mysql_errno($conn)) {
|
||||
case 1049:
|
||||
$exc = new SQLException("no such database", mysql_error($conn));
|
||||
break;
|
||||
case 1044:
|
||||
$exc = new SQLException("access violation", mysql_error($conn));
|
||||
break;
|
||||
default:
|
||||
$exc = new SQLException("cannot select database", mysql_error($conn));
|
||||
}
|
||||
|
||||
throw $exc;
|
||||
|
||||
}
|
||||
// fix to allow calls to different databases in the same script
|
||||
$this->database = $dsninfo['database'];
|
||||
}
|
||||
|
||||
$this->dblink = $conn;
|
||||
|
||||
if ($encoding) {
|
||||
$this->executeUpdate("SET NAMES " . $encoding);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getDatabaseInfo()
|
||||
*/
|
||||
public function getDatabaseInfo()
|
||||
{
|
||||
require_once 'creole/drivers/mysql/metadata/MySQLDatabaseInfo.php';
|
||||
return new MySQLDatabaseInfo($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getIdGenerator()
|
||||
*/
|
||||
public function getIdGenerator()
|
||||
{
|
||||
require_once 'creole/drivers/mysql/MySQLIdGenerator.php';
|
||||
return new MySQLIdGenerator($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::prepareStatement()
|
||||
*/
|
||||
public function prepareStatement($sql)
|
||||
{
|
||||
require_once 'creole/drivers/mysql/MySQLPreparedStatement.php';
|
||||
return new MySQLPreparedStatement($this, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::prepareCall()
|
||||
*/
|
||||
public function prepareCall($sql) {
|
||||
throw new SQLException('MySQL does not support stored procedures.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::createStatement()
|
||||
*/
|
||||
public function createStatement()
|
||||
{
|
||||
require_once 'creole/drivers/mysql/MySQLStatement.php';
|
||||
return new MySQLStatement($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::disconnect()
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
$ret = mysql_close($this->dblink);
|
||||
$this->dblink = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::applyLimit()
|
||||
*/
|
||||
public function applyLimit(&$sql, $offset, $limit)
|
||||
{
|
||||
if ( $limit > 0 ) {
|
||||
$sql .= " LIMIT " . ($offset > 0 ? $offset . ", " : "") . $limit;
|
||||
} else if ( $offset > 0 ) {
|
||||
$sql .= " LIMIT " . $offset . ", 18446744073709551615";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::executeQuery()
|
||||
*/
|
||||
function executeQuery($sql, $fetchmode = null)
|
||||
{
|
||||
$this->lastQuery = $sql;
|
||||
if ($this->database) {
|
||||
if (!@mysql_select_db($this->database, $this->dblink)) {
|
||||
throw new SQLException('No database selected', mysql_error($this->dblink));
|
||||
}
|
||||
}
|
||||
$result = @mysql_query($sql, $this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute query', mysql_error($this->dblink), $sql);
|
||||
}
|
||||
return new MySQLResultSet($this, $result, $fetchmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::executeUpdate()
|
||||
*/
|
||||
function executeUpdate($sql)
|
||||
{
|
||||
$this->lastQuery = $sql;
|
||||
|
||||
if ($this->database) {
|
||||
if (!@mysql_select_db($this->database, $this->dblink)) {
|
||||
throw new SQLException('No database selected', mysql_error($this->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
$result = @mysql_query($sql, $this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute update', mysql_error($this->dblink), $sql);
|
||||
}
|
||||
return (int) mysql_affected_rows($this->dblink);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a database transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function beginTrans()
|
||||
{
|
||||
$result = @mysql_query('SET AUTOCOMMIT=0', $this->dblink);
|
||||
$result = @mysql_query('BEGIN', $this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not begin transaction', mysql_error($this->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function commitTrans()
|
||||
{
|
||||
if ($this->database) {
|
||||
if (!@mysql_select_db($this->database, $this->dblink)) {
|
||||
throw new SQLException('No database selected', mysql_error($this->dblink));
|
||||
}
|
||||
}
|
||||
$result = @mysql_query('COMMIT', $this->dblink);
|
||||
$result = @mysql_query('SET AUTOCOMMIT=1', $this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Can not commit transaction', mysql_error($this->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll back (undo) the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function rollbackTrans()
|
||||
{
|
||||
if ($this->database) {
|
||||
if (!@mysql_select_db($this->database, $this->dblink)) {
|
||||
throw new SQLException('No database selected', mysql_error($this->dblink));
|
||||
}
|
||||
}
|
||||
$result = @mysql_query('ROLLBACK', $this->dblink);
|
||||
$result = @mysql_query('SET AUTOCOMMIT=1', $this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not rollback transaction', mysql_error($this->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by the data manipulation
|
||||
* query.
|
||||
*
|
||||
* @return int Number of rows affected by the last query.
|
||||
*/
|
||||
function getUpdateCount()
|
||||
{
|
||||
return (int) @mysql_affected_rows($this->dblink);
|
||||
}
|
||||
|
||||
}
|
75
lib/symfony/vendor/creole/drivers/mysql/MySQLIdGenerator.php
vendored
Executable file
75
lib/symfony/vendor/creole/drivers/mysql/MySQLIdGenerator.php
vendored
Executable file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
require_once 'creole/IdGenerator.php';
|
||||
|
||||
/**
|
||||
* MySQL IdGenerator implimenation.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.6 $
|
||||
* @package creole.drivers.mysql
|
||||
*/
|
||||
class MySQLIdGenerator implements IdGenerator {
|
||||
|
||||
/** Connection object that instantiated this class */
|
||||
private $conn;
|
||||
|
||||
/**
|
||||
* Creates a new IdGenerator class, saves passed connection for use
|
||||
* later by getId() method.
|
||||
* @param Connection $conn
|
||||
*/
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isBeforeInsert()
|
||||
*/
|
||||
public function isBeforeInsert()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isAfterInsert()
|
||||
*/
|
||||
public function isAfterInsert()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::getIdMethod()
|
||||
*/
|
||||
public function getIdMethod()
|
||||
{
|
||||
return self::AUTOINCREMENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last-generated auto-increment ID.
|
||||
*
|
||||
* Note that for very large values (2,147,483,648 to 9,223,372,036,854,775,807) a string
|
||||
* will be returned, because these numbers are larger than supported by PHP's native
|
||||
* numeric datatypes.
|
||||
*
|
||||
* @see IdGenerator::getId()
|
||||
*/
|
||||
public function getId($unused = null)
|
||||
{
|
||||
$insert_id = mysql_insert_id($this->conn->getResource());
|
||||
if ( $insert_id < 0 ) {
|
||||
$insert_id = null;
|
||||
$result = mysql_query('SELECT LAST_INSERT_ID()', $this->conn->getResource());
|
||||
if ( $result ) {
|
||||
$row = mysql_fetch_row($result);
|
||||
$insert_id = $row ? $row[0] : null;
|
||||
}
|
||||
}
|
||||
return $insert_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
44
lib/symfony/vendor/creole/drivers/mysql/MySQLPreparedStatement.php
vendored
Executable file
44
lib/symfony/vendor/creole/drivers/mysql/MySQLPreparedStatement.php
vendored
Executable file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLPreparedStatement.php,v 1.7 2005/12/10 13:46:55 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/PreparedStatement.php';
|
||||
require_once 'creole/common/PreparedStatementCommon.php';
|
||||
|
||||
/**
|
||||
* MySQL subclass for prepared statements.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.7 $
|
||||
* @package creole.drivers.mysql
|
||||
*/
|
||||
class MySQLPreparedStatement extends PreparedStatementCommon implements PreparedStatement {
|
||||
|
||||
/**
|
||||
* Quotes string using native mysql function (mysql_real_escape_string()).
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
protected function escape($str)
|
||||
{
|
||||
return mysql_real_escape_string($str, $this->conn->getResource());
|
||||
}
|
||||
|
||||
}
|
149
lib/symfony/vendor/creole/drivers/mysql/MySQLResultSet.php
vendored
Executable file
149
lib/symfony/vendor/creole/drivers/mysql/MySQLResultSet.php
vendored
Executable file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLResultSet.php,v 1.24 2006/01/17 19:44:39 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/ResultSet.php';
|
||||
require_once 'creole/common/ResultSetCommon.php';
|
||||
|
||||
/**
|
||||
* MySQL implementation of ResultSet class.
|
||||
*
|
||||
* MySQL supports OFFSET / LIMIT natively; this means that no adjustments or checking
|
||||
* are performed. We will assume that if the lmitSQL() operation failed that an
|
||||
* exception was thrown, and that OFFSET/LIMIT will never be emulated for MySQL.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.24 $
|
||||
* @package creole.drivers.mysql
|
||||
*/
|
||||
class MySQLResultSet extends ResultSetCommon implements ResultSet {
|
||||
|
||||
/**
|
||||
* @see ResultSet::seek()
|
||||
*/
|
||||
public function seek($rownum)
|
||||
{
|
||||
// MySQL rows start w/ 0, but this works, because we are
|
||||
// looking to move the position _before_ the next desired position
|
||||
if (!@mysql_data_seek($this->result, $rownum)) {
|
||||
return false;
|
||||
}
|
||||
$this->cursorPos = $rownum;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::next()
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
$this->fields = mysql_fetch_array($this->result, $this->fetchmode);
|
||||
|
||||
if (!$this->fields) {
|
||||
$errno = mysql_errno($this->conn->getResource());
|
||||
if (!$errno) {
|
||||
// We've advanced beyond end of recordset.
|
||||
$this->afterLast();
|
||||
return false;
|
||||
} else {
|
||||
throw new SQLException("Error fetching result", mysql_error($this->conn->getResource()));
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->fetchmode === ResultSet::FETCHMODE_ASSOC && $this->lowerAssocCase) {
|
||||
$this->fields = array_change_key_case($this->fields, CASE_LOWER);
|
||||
}
|
||||
|
||||
// Advance cursor position
|
||||
$this->cursorPos++;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::getRecordCount()
|
||||
*/
|
||||
function getRecordCount()
|
||||
{
|
||||
$rows = @mysql_num_rows($this->result);
|
||||
if ($rows === null) {
|
||||
throw new SQLException("Error fetching num rows", mysql_error($this->conn->getResource()));
|
||||
}
|
||||
return (int) $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::close()
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
if(is_resource($this->result))
|
||||
@mysql_free_result($this->result);
|
||||
$this->fields = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string version of column.
|
||||
* No rtrim() necessary for MySQL, as this happens natively.
|
||||
* @see ResultSet::getString()
|
||||
*/
|
||||
public function getString($column)
|
||||
{
|
||||
$idx = (is_int($column) ? $column - 1 : $column);
|
||||
if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
|
||||
if ($this->fields[$idx] === null) { return null; }
|
||||
return (string) $this->fields[$idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a unix epoch timestamp based on either a TIMESTAMP or DATETIME field.
|
||||
* @param mixed $column Column name (string) or index (int) starting with 1.
|
||||
* @return string
|
||||
* @throws SQLException - If the column specified is not a valid key in current field array.
|
||||
*/
|
||||
function getTimestamp($column, $format='Y-m-d H:i:s')
|
||||
{
|
||||
if (is_int($column)) { $column--; } // because Java convention is to start at 1
|
||||
if (!array_key_exists($column, $this->fields)) { throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column)); }
|
||||
if ($this->fields[$column] === null) { return null; }
|
||||
|
||||
$ts = strtotime($this->fields[$column]);
|
||||
if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
|
||||
// otherwise it's an ugly MySQL timestamp!
|
||||
// YYYYMMDDHHMMSS
|
||||
if (preg_match('/([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})/', $this->fields[$column], $matches)) {
|
||||
// YYYY MM DD HH MM SS
|
||||
// $1 $2 $3 $4 $5 $6
|
||||
$ts = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
|
||||
}
|
||||
}
|
||||
if ($ts === -1 || $ts === false) { // if it's still -1, then there's nothing to be done; use a different method.
|
||||
throw new SQLException("Unable to convert value at column " . (is_int($column) ? $column + 1 : $column) . " to timestamp: " . $this->fields[$column]);
|
||||
}
|
||||
if ($format === null) {
|
||||
return $ts;
|
||||
}
|
||||
if (strpos($format, '%') !== false) {
|
||||
return strftime($format, $ts);
|
||||
} else {
|
||||
return date($format, $ts);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
36
lib/symfony/vendor/creole/drivers/mysql/MySQLStatement.php
vendored
Executable file
36
lib/symfony/vendor/creole/drivers/mysql/MySQLStatement.php
vendored
Executable file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLStatement.php,v 1.1 2004/02/19 02:49:42 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/Statement.php';
|
||||
require_once 'creole/common/StatementCommon.php';
|
||||
|
||||
/**
|
||||
* MySQL Statement
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @author Stig Bakken <ssb@fast.no>
|
||||
* @author Lukas Smith
|
||||
* @version $Revision: 1.1 $
|
||||
* @package creole.drivers.mysql
|
||||
*/
|
||||
class MySQLStatement extends StatementCommon implements Statement {
|
||||
|
||||
}
|
102
lib/symfony/vendor/creole/drivers/mysql/MySQLTypes.php
vendored
Executable file
102
lib/symfony/vendor/creole/drivers/mysql/MySQLTypes.php
vendored
Executable file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* $Id: MySQLTypes.php,v 1.8 2005/02/10 09:22:40 pachanga Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/CreoleTypes.php';
|
||||
|
||||
/**
|
||||
* MySQL types / type map.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.8 $
|
||||
* @package creole.drivers.mysql
|
||||
*/
|
||||
class MySQLTypes extends CreoleTypes {
|
||||
|
||||
/** Map MySQL native types to Creole (JDBC) types. */
|
||||
private static $typeMap = array(
|
||||
'tinyint' => CreoleTypes::TINYINT,
|
||||
'smallint' => CreoleTypes::SMALLINT,
|
||||
'mediumint' => CreoleTypes::SMALLINT,
|
||||
'int' => CreoleTypes::INTEGER,
|
||||
'integer' => CreoleTypes::INTEGER,
|
||||
'bigint' => CreoleTypes::BIGINT,
|
||||
'int24' => CreoleTypes::BIGINT,
|
||||
'real' => CreoleTypes::REAL,
|
||||
'float' => CreoleTypes::FLOAT,
|
||||
'decimal' => CreoleTypes::DECIMAL,
|
||||
'numeric' => CreoleTypes::NUMERIC,
|
||||
'double' => CreoleTypes::DOUBLE,
|
||||
'char' => CreoleTypes::CHAR,
|
||||
'varchar' => CreoleTypes::VARCHAR,
|
||||
'date' => CreoleTypes::DATE,
|
||||
'time' => CreoleTypes::TIME,
|
||||
'year' => CreoleTypes::YEAR,
|
||||
'datetime' => CreoleTypes::TIMESTAMP,
|
||||
'timestamp' => CreoleTypes::TIMESTAMP,
|
||||
'tinyblob' => CreoleTypes::BINARY,
|
||||
'blob' => CreoleTypes::VARBINARY,
|
||||
'mediumblob' => CreoleTypes::VARBINARY,
|
||||
'longblob' => CreoleTypes::VARBINARY,
|
||||
'longtext' => CreoleTypes::LONGVARCHAR,
|
||||
'tinytext' => CreoleTypes::VARCHAR,
|
||||
'mediumtext' => CreoleTypes::LONGVARCHAR,
|
||||
'text' => CreoleTypes::LONGVARCHAR,
|
||||
'enum' => CreoleTypes::CHAR,
|
||||
'set' => CreoleTypes::CHAR,
|
||||
);
|
||||
|
||||
/** Reverse mapping, created on demand. */
|
||||
private static $reverseMap = null;
|
||||
|
||||
/**
|
||||
* This method returns the generic Creole (JDBC-like) type
|
||||
* when given the native db type.
|
||||
* @param string $nativeType DB native type (e.g. 'TEXT', 'byetea', etc.).
|
||||
* @return int Creole native type (e.g. CreoleTypes::LONGVARCHAR, CreoleTypes::BINARY, etc.).
|
||||
*/
|
||||
public static function getType($nativeType)
|
||||
{
|
||||
$t = strtolower($nativeType);
|
||||
if (isset(self::$typeMap[$t])) {
|
||||
return self::$typeMap[$t];
|
||||
} else {
|
||||
return CreoleTypes::OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will return a native type that corresponds to the specified
|
||||
* Creole (JDBC-like) type.
|
||||
* If there is more than one matching native type, then the LAST defined
|
||||
* native type will be returned.
|
||||
* @param int $creoleType
|
||||
* @return string Native type string.
|
||||
*/
|
||||
public static function getNativeType($creoleType)
|
||||
{
|
||||
if (self::$reverseMap === null) {
|
||||
self::$reverseMap = array_flip(self::$typeMap);
|
||||
}
|
||||
return @self::$reverseMap[$creoleType];
|
||||
}
|
||||
|
||||
}
|
66
lib/symfony/vendor/creole/drivers/mysql/metadata/MySQLDatabaseInfo.php
vendored
Executable file
66
lib/symfony/vendor/creole/drivers/mysql/metadata/MySQLDatabaseInfo.php
vendored
Executable file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLDatabaseInfo.php,v 1.13 2006/01/17 19:44:39 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/DatabaseInfo.php';
|
||||
|
||||
/**
|
||||
* MySQL implementation of DatabaseInfo.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.13 $
|
||||
* @package creole.drivers.mysql.metadata
|
||||
*/
|
||||
class MySQLDatabaseInfo extends DatabaseInfo {
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function initTables()
|
||||
{
|
||||
include_once 'creole/drivers/mysql/metadata/MySQLTableInfo.php';
|
||||
// using $this->dblink was causing tests to break
|
||||
// perhaps dblink is changed by another test ... ?
|
||||
$result = @mysql_query("SHOW TABLES FROM `" . $this->dbname . "`", $this->conn->getResource());
|
||||
|
||||
if (!$result) {
|
||||
throw new SQLException("Could not list tables", mysql_error($this->conn->getResource()));
|
||||
}
|
||||
|
||||
while ($row = mysql_fetch_row($result)) {
|
||||
$this->tables[strtoupper($row[0])] = new MySQLTableInfo($this, $row[0]);
|
||||
}
|
||||
|
||||
$this->tablesLoaded = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL does not support sequences.
|
||||
*
|
||||
* @return void
|
||||
* @throws SQLException
|
||||
*/
|
||||
protected function initSequences()
|
||||
{
|
||||
// throw new SQLException("MySQL does not support sequences natively.");
|
||||
}
|
||||
}
|
252
lib/symfony/vendor/creole/drivers/mysql/metadata/MySQLTableInfo.php
vendored
Executable file
252
lib/symfony/vendor/creole/drivers/mysql/metadata/MySQLTableInfo.php
vendored
Executable file
@ -0,0 +1,252 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLTableInfo.php,v 1.20 2006/01/17 19:44:39 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/TableInfo.php';
|
||||
|
||||
/**
|
||||
* MySQL implementation of TableInfo.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.20 $
|
||||
* @package creole.drivers.mysql.metadata
|
||||
*/
|
||||
class MySQLTableInfo extends TableInfo {
|
||||
|
||||
/** Loads the columns for this table. */
|
||||
protected function initColumns()
|
||||
{
|
||||
include_once 'creole/metadata/ColumnInfo.php';
|
||||
include_once 'creole/drivers/mysql/MySQLTypes.php';
|
||||
|
||||
if (!@mysql_select_db($this->dbname, $this->conn->getResource())) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
// To get all of the attributes we need, we use
|
||||
// the MySQL "SHOW COLUMNS FROM $tablename" SQL. We cannot
|
||||
// use the API functions (e.g. mysql_list_fields() because they
|
||||
// do not return complete information -- e.g. precision / scale, default
|
||||
// values).
|
||||
|
||||
$res = mysql_query("SHOW COLUMNS FROM `" . $this->name . "`", $this->conn->getResource());
|
||||
|
||||
$defaults = array();
|
||||
$nativeTypes = array();
|
||||
$precisions = array();
|
||||
|
||||
while($row = mysql_fetch_assoc($res)) {
|
||||
$name = $row['Field'];
|
||||
$is_nullable = ($row['Null'] == 'YES');
|
||||
$is_auto_increment = (strpos($row['Extra'], 'auto_increment') !== false);
|
||||
$size = null;
|
||||
$precision = null;
|
||||
$scale = null;
|
||||
|
||||
if (preg_match('/^(\w+)[\(]?([\d,]*)[\)]?( |$)/', $row['Type'], $matches)) {
|
||||
// colname[1] size/precision[2]
|
||||
$nativeType = $matches[1];
|
||||
if ($matches[2]) {
|
||||
if ( ($cpos = strpos($matches[2], ',')) !== false) {
|
||||
$size = (int) substr($matches[2], 0, $cpos);
|
||||
$precision = $size;
|
||||
$scale = (int) substr($matches[2], $cpos + 1);
|
||||
} else {
|
||||
$size = (int) $matches[2];
|
||||
}
|
||||
}
|
||||
} elseif (preg_match('/^(\w+)\(/', $row['Type'], $matches)) {
|
||||
$nativeType = $matches[1];
|
||||
} else {
|
||||
$nativeType = $row['Type'];
|
||||
}
|
||||
//BLOBs can't have any default values in MySQL
|
||||
$default = preg_match('~blob|text~', $nativeType) ? null : $row['Default'];
|
||||
$this->columns[$name] = new ColumnInfo($this,
|
||||
$name,
|
||||
MySQLTypes::getType($nativeType),
|
||||
$nativeType,
|
||||
$size,
|
||||
$precision,
|
||||
$scale,
|
||||
$is_nullable,
|
||||
$default,
|
||||
$is_auto_increment,
|
||||
$row);
|
||||
}
|
||||
|
||||
$this->colsLoaded = true;
|
||||
}
|
||||
|
||||
/** Loads the primary key information for this table. */
|
||||
protected function initPrimaryKey()
|
||||
{
|
||||
include_once 'creole/metadata/PrimaryKeyInfo.php';
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
|
||||
if (!@mysql_select_db($this->dbname, $this->conn->getResource())) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
// Primary Keys
|
||||
$res = mysql_query("SHOW KEYS FROM `" . $this->name . "`", $this->conn->getResource());
|
||||
|
||||
// Loop through the returned results, grouping the same key_name together
|
||||
// adding each column for that key.
|
||||
|
||||
while($row = mysql_fetch_assoc($res)) {
|
||||
// Skip any non-primary keys.
|
||||
if ($row['Key_name'] !== 'PRIMARY') {
|
||||
continue;
|
||||
}
|
||||
$name = $row["Column_name"];
|
||||
if (!isset($this->primaryKey)) {
|
||||
$this->primaryKey = new PrimaryKeyInfo($name, $row);
|
||||
}
|
||||
$this->primaryKey->addColumn($this->columns[$name]);
|
||||
}
|
||||
|
||||
$this->pkLoaded = true;
|
||||
}
|
||||
|
||||
/** Loads the indexes for this table. */
|
||||
protected function initIndexes() {
|
||||
|
||||
include_once 'creole/metadata/IndexInfo.php';
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
|
||||
if (!@mysql_select_db($this->dbname, $this->conn->getResource())) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
// Indexes
|
||||
$res = mysql_query("SHOW INDEX FROM `" . $this->name . "`", $this->conn->getResource());
|
||||
|
||||
// Loop through the returned results, grouping the same key_name together
|
||||
// adding each column for that key.
|
||||
|
||||
while($row = mysql_fetch_assoc($res)) {
|
||||
$colName = $row["Column_name"];
|
||||
$name = $row["Key_name"];
|
||||
|
||||
if($name == "PRIMARY") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($this->indexes[$name])) {
|
||||
$isUnique = ($row["Non_unique"] == 0);
|
||||
$this->indexes[$name] = new IndexInfo($name, $isUnique, $row);
|
||||
}
|
||||
$this->indexes[$name]->addColumn($this->columns[$colName]);
|
||||
}
|
||||
|
||||
$this->indexesLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load foreign keys for supporting versions of MySQL.
|
||||
* @author Tony Bibbs
|
||||
*/
|
||||
protected function initForeignKeys() {
|
||||
|
||||
// First make sure we have supported version of MySQL:
|
||||
$res = mysql_query("SELECT VERSION()");
|
||||
$row = mysql_fetch_row($res);
|
||||
|
||||
// Yes, it is OK to hardcode this...this was the first version of MySQL
|
||||
// that supported foreign keys
|
||||
if ($row[0] < '3.23.44') {
|
||||
$this->fksLoaded = true;
|
||||
return;
|
||||
}
|
||||
|
||||
include_once 'creole/metadata/ForeignKeyInfo.php';
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
if (!@mysql_select_db($this->dbname, $this->conn->getResource())) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
// Get the CREATE TABLE syntax
|
||||
$res = mysql_query("SHOW CREATE TABLE `" . $this->name . "`", $this->conn->getResource());
|
||||
$row = mysql_fetch_row($res);
|
||||
|
||||
// Get the information on all the foreign keys
|
||||
$regEx = '/FOREIGN KEY \(`([^`]*)`\) REFERENCES `([^`]*)` \(`([^`]*)`\)(.*)/';
|
||||
if (preg_match_all($regEx,$row[1],$matches)) {
|
||||
$tmpArray = array_keys($matches[0]);
|
||||
foreach ($tmpArray as $curKey) {
|
||||
$name = $matches[1][$curKey];
|
||||
$ftbl = $matches[2][$curKey];
|
||||
$fcol = $matches[3][$curKey];
|
||||
$fkey = $matches[4][$curKey];
|
||||
if (!isset($this->foreignKeys[$name])) {
|
||||
$this->foreignKeys[$name] = new ForeignKeyInfo($name);
|
||||
if ($this->database->hasTable($ftbl)) {
|
||||
$foreignTable = $this->database->getTable($ftbl);
|
||||
} else {
|
||||
$foreignTable = new MySQLTableInfo($this->database, $ftbl);
|
||||
$this->database->addTable($foreignTable);
|
||||
}
|
||||
if ($foreignTable->hasColumn($fcol)) {
|
||||
$foreignCol = $foreignTable->getColumn($fcol);
|
||||
} else {
|
||||
$foreignCol = new ColumnInfo($foreignTable, $fcol);
|
||||
$foreignTable->addColumn($foreignCol);
|
||||
}
|
||||
|
||||
//typical for mysql is RESTRICT
|
||||
$fkactions = array(
|
||||
'ON DELETE' => ForeignKeyInfo::RESTRICT,
|
||||
'ON UPDATE' => ForeignKeyInfo::RESTRICT,
|
||||
);
|
||||
|
||||
if ($fkey) {
|
||||
//split foreign key information -> search for ON DELETE and afterwords for ON UPDATE action
|
||||
foreach (array_keys($fkactions) as $fkaction) {
|
||||
$result = NULL;
|
||||
preg_match('/' . $fkaction . ' (' . ForeignKeyInfo::CASCADE . '|' . ForeignKeyInfo::SETNULL . ')/', $fkey, $result);
|
||||
if ($result && is_array($result) && isset($result[1])) {
|
||||
$fkactions[$fkaction] = $result[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->foreignKeys[$name]->addReference($this->columns[$name], $foreignCol, $fkactions['ON DELETE'], $fkactions['ON UPDATE']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->fksLoaded = true;
|
||||
|
||||
}
|
||||
|
||||
protected function initVendorSpecificInfo()
|
||||
{
|
||||
$res = mysql_query("SHOW TABLE STATUS LIKE '" . $this->name . "'", $this->conn->getResource());
|
||||
$this->vendorSpecificInfo = mysql_fetch_assoc($res);
|
||||
|
||||
$this->vendorLoaded = true;
|
||||
}
|
||||
|
||||
}
|
293
lib/symfony/vendor/creole/drivers/mysqli/MySQLiConnection.php
vendored
Executable file
293
lib/symfony/vendor/creole/drivers/mysqli/MySQLiConnection.php
vendored
Executable file
@ -0,0 +1,293 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLiConnection.php,v 1.7 2004/09/18 09:29:22 sb Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/Connection.php';
|
||||
require_once 'creole/common/ConnectionCommon.php';
|
||||
include_once 'creole/drivers/mysqli/MySQLiResultSet.php';
|
||||
|
||||
/**
|
||||
* MySQLi implementation of Connection.
|
||||
*
|
||||
*
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @version $Revision: 1.7 $
|
||||
* @package creole.drivers.mysqli
|
||||
*/
|
||||
class MySQLiConnection extends ConnectionCommon implements Connection {
|
||||
/** Current database (used in mysqli_select_db()). */
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* Connect to a database and log in as the specified user.
|
||||
*
|
||||
* @param $dsn the data source name (see DB::parseDSN for syntax)
|
||||
* @param $flags Any conneciton flags.
|
||||
* @access public
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
public function connect($dsninfo, $flags = 0)
|
||||
{
|
||||
if (!extension_loaded('mysqli')) {
|
||||
throw new SQLException('mysqli extension not loaded');
|
||||
}
|
||||
|
||||
$this->dsn = $dsninfo;
|
||||
$this->flags = $flags;
|
||||
|
||||
$dbhost = null;
|
||||
|
||||
|
||||
if (isset($dsninfo['protocol']) && $dsninfo['protocol'] == 'unix') {
|
||||
$dbhost = ':' . $dsninfo['socket'];
|
||||
} else {
|
||||
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
|
||||
|
||||
if (!empty($dsninfo['port'])) {
|
||||
$dbhost .= ':' . $dsninfo['port'];
|
||||
}
|
||||
}
|
||||
|
||||
$host = !empty($dsninfo['hostspec']) ? $dsninfo['hostspec'] : null;
|
||||
$user = !empty($dsninfo['username']) ? $dsninfo['username'] : null;
|
||||
$pw = !empty($dsninfo['password']) ? $dsninfo['password'] : null;
|
||||
$port = !empty($dsninfo['port']) ? $dsninfo['port'] : null;
|
||||
$socket = !empty($dsninfo['socket']) ? $dsninfo['socket'] : null;
|
||||
$database = !empty($dsninfo['database']) ? $dsninfo['database'] : null;
|
||||
|
||||
$encoding = !empty($dsninfo['encoding']) ? $dsninfo['encoding'] : null;
|
||||
|
||||
@ini_set('track_errors', true);
|
||||
|
||||
$conn = mysqli_connect($host, $user, $pw, $database, $port, $socket);
|
||||
|
||||
@ini_restore('track_errors');
|
||||
|
||||
if (empty($conn)) {
|
||||
if (($err = @mysqli_error()) != '') {
|
||||
throw new SQLException("connect failed", $err);
|
||||
} elseif (empty($php_errormsg)) {
|
||||
throw new SQLException("connect failed");
|
||||
} else {
|
||||
throw new SQLException("connect failed", $php_errormsg);
|
||||
}
|
||||
}
|
||||
|
||||
if ($dsninfo['database']) {
|
||||
if (!@mysqli_select_db($conn, $dsninfo['database'])) {
|
||||
switch(mysqli_errno($conn)) {
|
||||
case 1049:
|
||||
$exc = new SQLException("no such database", mysqli_error($conn));
|
||||
break;
|
||||
case 1044:
|
||||
$exc = new SQLException("access violation", mysqli_error($conn));
|
||||
break;
|
||||
default:
|
||||
$exc = new SQLException("cannot select database", mysqli_error($conn));
|
||||
}
|
||||
|
||||
throw $exc;
|
||||
|
||||
}
|
||||
|
||||
// fix to allow calls to different databases in the same script
|
||||
$this->database = $dsninfo['database'];
|
||||
}
|
||||
|
||||
$this->dblink = $conn;
|
||||
|
||||
if ($encoding) {
|
||||
$this->executeUpdate("SET NAMES " . $encoding);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getDatabaseInfo()
|
||||
*/
|
||||
public function getDatabaseInfo()
|
||||
{
|
||||
require_once 'creole/drivers/mysqli/metadata/MySQLiDatabaseInfo.php';
|
||||
return new MySQLiDatabaseInfo($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getIdGenerator()
|
||||
*/
|
||||
public function getIdGenerator()
|
||||
{
|
||||
require_once 'creole/drivers/mysqli/MySQLiIdGenerator.php';
|
||||
return new MySQLiIdGenerator($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::prepareStatement()
|
||||
*/
|
||||
public function prepareStatement($sql)
|
||||
{
|
||||
require_once 'creole/drivers/mysqli/MySQLiPreparedStatement.php';
|
||||
return new MySQLiPreparedStatement($this, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::prepareCall()
|
||||
*/
|
||||
public function prepareCall($sql) {
|
||||
throw new SQLException('MySQL does not support stored procedures.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::createStatement()
|
||||
*/
|
||||
public function createStatement()
|
||||
{
|
||||
require_once 'creole/drivers/mysqli/MySQLiStatement.php';
|
||||
return new MySQLiStatement($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::disconnect()
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$ret = mysqli_close($this->dblink);
|
||||
$this->dblink = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::applyLimit()
|
||||
*/
|
||||
public function applyLimit(&$sql, $offset, $limit)
|
||||
{
|
||||
if ( $limit > 0 ) {
|
||||
$sql .= " LIMIT " . ($offset > 0 ? $offset . ", " : "") . $limit;
|
||||
} else if ( $offset > 0 ) {
|
||||
$sql .= " LIMIT " . $offset . ", 18446744073709551615";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::executeQuery()
|
||||
*/
|
||||
public function executeQuery($sql, $fetchmode = null)
|
||||
{
|
||||
$this->lastQuery = $sql;
|
||||
|
||||
if ($this->database) {
|
||||
if (!@mysqli_select_db($this->dblink, $this->database)) {
|
||||
throw new SQLException('No database selected', mysqli_error($this->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
$result = @mysqli_query($this->dblink, $sql);
|
||||
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute query', mysqli_error($this->dblink), $sql);
|
||||
}
|
||||
|
||||
return new MySQLiResultSet($this, $result, $fetchmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::executeUpdate()
|
||||
*/
|
||||
public function executeUpdate($sql)
|
||||
{
|
||||
$this->lastQuery = $sql;
|
||||
|
||||
if ($this->database) {
|
||||
if (!@mysqli_select_db($this->dblink, $this->database)) {
|
||||
throw new SQLException('No database selected', mysqli_error($this->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
$result = @mysqli_query($this->dblink, $sql);
|
||||
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute update', mysqli_error($this->dblink), $sql);
|
||||
}
|
||||
|
||||
return (int) mysqli_affected_rows($this->dblink);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a database transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function beginTrans()
|
||||
{
|
||||
if (!mysqli_autocommit($this->dblink, FALSE)) {
|
||||
throw new SQLException('Could not begin transaction', mysqli_error($this->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function commitTrans()
|
||||
{
|
||||
if ($this->database) {
|
||||
if (!@mysqli_select_db($this->dblink, $this->database)) {
|
||||
throw new SQLException('No database selected', mysqli_error($this->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
if (!mysqli_commit($this->dblink)) {
|
||||
throw new SQLException('Can not commit transaction', mysqli_error($this->dblink));
|
||||
}
|
||||
|
||||
mysqli_autocommit($this->dblink, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll back (undo) the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function rollbackTrans()
|
||||
{
|
||||
if ($this->database) {
|
||||
if (!@mysqli_select_db($this->dblink, $this->database)) {
|
||||
throw new SQLException('No database selected', mysqli_error($this->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
if (!mysqli_rollback($this->dblink)) {
|
||||
throw new SQLException('Could not rollback transaction', mysqli_error($this->dblink));
|
||||
}
|
||||
|
||||
mysqli_autocommit($this->dblink, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by the data manipulation
|
||||
* query.
|
||||
*
|
||||
* @return int Number of rows affected by the last query.
|
||||
*/
|
||||
public function getUpdateCount()
|
||||
{
|
||||
return (int) @mysqli_affected_rows($this->dblink);
|
||||
}
|
||||
}
|
96
lib/symfony/vendor/creole/drivers/mysqli/MySQLiIdGenerator.php
vendored
Executable file
96
lib/symfony/vendor/creole/drivers/mysqli/MySQLiIdGenerator.php
vendored
Executable file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLiIdGenerator.php,v 1.4 2004/09/18 09:15:49 sb Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/IdGenerator.php';
|
||||
|
||||
/**
|
||||
* MySQLi implementation of IdGenerator.
|
||||
*
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @version $Revision: 1.4 $
|
||||
* @package creole.drivers.mysqli
|
||||
*/
|
||||
class MySQLiIdGenerator implements IdGenerator {
|
||||
/** Connection object that instantiated this class */
|
||||
private $conn;
|
||||
|
||||
/**
|
||||
* Creates a new IdGenerator class, saves passed connection for use
|
||||
* later by getId() method.
|
||||
* @param Connection $conn
|
||||
*/
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isBeforeInsert()
|
||||
*/
|
||||
public function isBeforeInsert()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isAfterInsert()
|
||||
*/
|
||||
public function isAfterInsert()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::getIdMethod()
|
||||
*/
|
||||
public function getIdMethod()
|
||||
{
|
||||
return self::AUTOINCREMENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last-generated auto-increment ID.
|
||||
*
|
||||
* Note that for very large values (2,147,483,648 to 9,223,372,036,854,775,807) a string
|
||||
* will be returned, because these numbers are larger than supported by PHP's native
|
||||
* numeric datatypes.
|
||||
*
|
||||
* @see IdGenerator::getId()
|
||||
*/
|
||||
public function getId($unused = null)
|
||||
{
|
||||
$resource = $this->conn->getResource();
|
||||
$insert_id = mysqli_insert_id($resource);
|
||||
|
||||
if ( $insert_id < 0 ) {
|
||||
$insert_id = null;
|
||||
|
||||
$result = mysqli_query($resource, 'SELECT LAST_INSERT_ID()');
|
||||
|
||||
if ( $result ) {
|
||||
$row = mysqli_fetch_row($result);
|
||||
$insert_id = $row ? $row[0] : null;
|
||||
}
|
||||
}
|
||||
|
||||
return $insert_id;
|
||||
}
|
||||
}
|
42
lib/symfony/vendor/creole/drivers/mysqli/MySQLiPreparedStatement.php
vendored
Executable file
42
lib/symfony/vendor/creole/drivers/mysqli/MySQLiPreparedStatement.php
vendored
Executable file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLiPreparedStatement.php,v 1.3 2004/09/18 09:15:49 sb Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/PreparedStatement.php';
|
||||
require_once 'creole/common/PreparedStatementCommon.php';
|
||||
|
||||
/**
|
||||
* MySQLi implementation of PreparedStatement.
|
||||
*
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @version $Revision: 1.3 $
|
||||
* @package creole.drivers.mysqli
|
||||
*/
|
||||
class MySQLiPreparedStatement extends PreparedStatementCommon implements PreparedStatement {
|
||||
/**
|
||||
* Quotes string using native MySQL function.
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
protected function escape($str)
|
||||
{
|
||||
return mysqli_real_escape_string($this->getConnection()->getResource(), $str);
|
||||
}
|
||||
}
|
173
lib/symfony/vendor/creole/drivers/mysqli/MySQLiResultSet.php
vendored
Executable file
173
lib/symfony/vendor/creole/drivers/mysqli/MySQLiResultSet.php
vendored
Executable file
@ -0,0 +1,173 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLiResultSet.php,v 1.5 2006/01/17 19:44:39 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/ResultSet.php';
|
||||
require_once 'creole/common/ResultSetCommon.php';
|
||||
|
||||
/**
|
||||
* MySQLi implementation of ResultSet.
|
||||
*
|
||||
* MySQL supports OFFSET / LIMIT natively; this means that no adjustments or checking
|
||||
* are performed. We will assume that if the lmitSQL() operation failed that an
|
||||
* exception was thrown, and that OFFSET/LIMIT will never be emulated for MySQL.
|
||||
*
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @version $Revision: 1.5 $
|
||||
* @package creole.drivers.mysqli
|
||||
*/
|
||||
class MySQLiResultSet extends ResultSetCommon implements ResultSet {
|
||||
/**
|
||||
* @see ResultSet::seek()
|
||||
*/
|
||||
public function seek($rownum)
|
||||
{
|
||||
// MySQL rows start w/ 0, but this works, because we are
|
||||
// looking to move the position _before_ the next desired position
|
||||
if (!@mysqli_data_seek($this->result, $rownum)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->cursorPos = $rownum;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::next()
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
$this->fields = mysqli_fetch_array($this->result, $this->fetchmode);
|
||||
$resource = $this->conn->getResource();
|
||||
|
||||
if (!$this->fields) {
|
||||
$errno = mysqli_errno($resource);
|
||||
|
||||
if (!$errno) {
|
||||
// We've advanced beyond end of recordset.
|
||||
$this->afterLast();
|
||||
return false;
|
||||
} else {
|
||||
throw new SQLException("Error fetching result", mysqli_error($resource));
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->fetchmode === ResultSet::FETCHMODE_ASSOC && $this->lowerAssocCase) {
|
||||
$this->fields = array_change_key_case($this->fields, CASE_LOWER);
|
||||
}
|
||||
|
||||
// Advance cursor position
|
||||
$this->cursorPos++;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::getRecordCount()
|
||||
*/
|
||||
public function getRecordCount()
|
||||
{
|
||||
$rows = @mysqli_num_rows($this->result);
|
||||
|
||||
if ($rows === null) {
|
||||
throw new SQLException("Error fetching num rows", mysqli_error($this->conn->getResource()));
|
||||
}
|
||||
|
||||
return (int) $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::close()
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
@mysqli_free_result($this->result);
|
||||
$this->fields = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string version of column.
|
||||
* No rtrim() necessary for MySQL, as this happens natively.
|
||||
* @see ResultSet::getString()
|
||||
*/
|
||||
public function getString($column)
|
||||
{
|
||||
$idx = (is_int($column) ? $column - 1 : $column);
|
||||
|
||||
if (!array_key_exists($idx, $this->fields)) {
|
||||
throw new SQLException("Invalid resultset column: " . $column);
|
||||
}
|
||||
|
||||
if ($this->fields[$idx] === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) $this->fields[$idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a unix epoch timestamp based on either a TIMESTAMP or DATETIME field.
|
||||
* @param mixed $column Column name (string) or index (int) starting with 1.
|
||||
* @return string
|
||||
* @throws SQLException - If the column specified is not a valid key in current field array.
|
||||
*/
|
||||
public function getTimestamp($column, $format='Y-m-d H:i:s')
|
||||
{
|
||||
if (is_int($column)) {
|
||||
// because Java convention is to start at 1
|
||||
$column--;
|
||||
}
|
||||
|
||||
if (!array_key_exists($column, $this->fields)) {
|
||||
throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column));
|
||||
}
|
||||
|
||||
if ($this->fields[$column] === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ts = strtotime($this->fields[$column]);
|
||||
|
||||
if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
|
||||
// otherwise it's an ugly MySQL timestamp!
|
||||
// YYYYMMDDHHMMSS
|
||||
if (preg_match('/([\d]{4})([\d]{2})([\d]{2})([\d]{2})([\d]{2})([\d]{2})/', $this->fields[$column], $matches)) {
|
||||
// YYYY MM DD HH MM SS
|
||||
// $1 $2 $3 $4 $5 $6
|
||||
$ts = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
|
||||
// if it's still -1, then there's nothing to be done; use a different method.
|
||||
throw new SQLException("Unable to convert value at column " . (is_int($column) ? $column + 1 : $column) . " to timestamp: " . $this->fields[$column]);
|
||||
}
|
||||
|
||||
if ($format === null) {
|
||||
return $ts;
|
||||
}
|
||||
|
||||
if (strpos($format, '%') !== false) {
|
||||
return strftime($format, $ts);
|
||||
} else {
|
||||
return date($format, $ts);
|
||||
}
|
||||
}
|
||||
}
|
33
lib/symfony/vendor/creole/drivers/mysqli/MySQLiStatement.php
vendored
Executable file
33
lib/symfony/vendor/creole/drivers/mysqli/MySQLiStatement.php
vendored
Executable file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLiStatement.php,v 1.2 2004/09/18 09:15:49 sb Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/Statement.php';
|
||||
require_once 'creole/common/StatementCommon.php';
|
||||
|
||||
/**
|
||||
* MySQLi implementation of Statement.
|
||||
*
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @version $Revision: 1.2 $
|
||||
* @package creole.drivers.mysqli
|
||||
*/
|
||||
class MySQLiStatement extends StatementCommon implements Statement {
|
||||
}
|
61
lib/symfony/vendor/creole/drivers/mysqli/metadata/MySQLiDatabaseInfo.php
vendored
Executable file
61
lib/symfony/vendor/creole/drivers/mysqli/metadata/MySQLiDatabaseInfo.php
vendored
Executable file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLiDatabaseInfo.php,v 1.3 2006/01/17 19:44:39 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/DatabaseInfo.php';
|
||||
|
||||
/**
|
||||
* MySQLi implementation of DatabaseInfo.
|
||||
*
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @version $Revision: 1.3 $
|
||||
* @package creole.drivers.mysqli.metadata
|
||||
*/
|
||||
class MySQLiDatabaseInfo extends DatabaseInfo {
|
||||
/**
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function initTables()
|
||||
{
|
||||
include_once 'creole/drivers/mysqli/metadata/MySQLiTableInfo.php';
|
||||
|
||||
$result = @mysqli_query($this->conn->getResource(), 'SHOW TABLES FROM ' . $this->dbname);
|
||||
|
||||
if (!$result) {
|
||||
throw new SQLException("Could not list tables", mysqli_error($this->conn->getResource()));
|
||||
}
|
||||
|
||||
while ($row = mysqli_fetch_row($result)) {
|
||||
$this->tables[strtoupper($row[0])] = new MySQLiTableInfo($this, $row[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL does not support sequences.
|
||||
*
|
||||
* @return void
|
||||
* @throws SQLException
|
||||
*/
|
||||
protected function initSequences()
|
||||
{
|
||||
// throw new SQLException("MySQL does not support sequences natively.");
|
||||
}
|
||||
}
|
155
lib/symfony/vendor/creole/drivers/mysqli/metadata/MySQLiTableInfo.php
vendored
Executable file
155
lib/symfony/vendor/creole/drivers/mysqli/metadata/MySQLiTableInfo.php
vendored
Executable file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLiTableInfo.php,v 1.3 2006/01/17 19:44:39 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/TableInfo.php';
|
||||
|
||||
/**
|
||||
* MySQLi implementation of TableInfo.
|
||||
*
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @version $Revision: 1.3 $
|
||||
* @package creole.drivers.mysqli.metadata
|
||||
*/
|
||||
class MySQLiTableInfo extends TableInfo {
|
||||
/** Loads the columns for this table. */
|
||||
protected function initColumns()
|
||||
{
|
||||
require_once 'creole/metadata/ColumnInfo.php';
|
||||
require_once 'creole/drivers/mysql/MySQLTypes.php';
|
||||
|
||||
if (!@mysqli_select_db($this->conn->getResource(), $this->dbname)) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
// To get all of the attributes we need, we use
|
||||
// the MySQL "SHOW COLUMNS FROM $tablename" SQL.
|
||||
$res = mysqli_query($this->conn->getResource(), "SHOW COLUMNS FROM " . $this->name);
|
||||
|
||||
$defaults = array();
|
||||
$nativeTypes = array();
|
||||
$precisions = array();
|
||||
|
||||
while($row = mysqli_fetch_assoc($res)) {
|
||||
$name = $row['Field'];
|
||||
$default = $row['Default'];
|
||||
$is_nullable = ($row['Null'] == 'YES');
|
||||
|
||||
$size = null;
|
||||
$precision = null;
|
||||
$scale = null;
|
||||
|
||||
if (preg_match('/^(\w+)[\(]?([\d,]*)[\)]?( |$)/', $row['Type'], $matches)) {
|
||||
// colname[1] size/precision[2]
|
||||
$nativeType = $matches[1];
|
||||
if ($matches[2]) {
|
||||
if ( ($cpos = strpos($matches[2], ',')) !== false) {
|
||||
$size = (int) substr($matches[2], 0, $cpos);
|
||||
$precision = $size;
|
||||
$scale = (int) substr($matches[2], $cpos + 1);
|
||||
} else {
|
||||
$size = (int) $matches[2];
|
||||
}
|
||||
}
|
||||
} elseif (preg_match('/^(\w+)\(/', $row['Type'], $matches)) {
|
||||
$nativeType = $matches[1];
|
||||
} else {
|
||||
$nativeType = $row['Type'];
|
||||
}
|
||||
|
||||
$this->columns[$name] = new ColumnInfo($this, $name, MySQLTypes::getType($nativeType), $nativeType, $size, $precision, $scale, $is_nullable, $default);
|
||||
}
|
||||
|
||||
$this->colsLoaded = true;
|
||||
}
|
||||
|
||||
/** Loads the primary key information for this table. */
|
||||
protected function initPrimaryKey()
|
||||
{
|
||||
require_once 'creole/metadata/PrimaryKeyInfo.php';
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) {
|
||||
$this->initColumns();
|
||||
}
|
||||
|
||||
if (!@mysqli_select_db($this->conn->getResource(), $this->dbname)) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
// Primary Keys
|
||||
$res = mysqli_query($this->conn->getResource(), "SHOW KEYS FROM " . $this->name);
|
||||
|
||||
// Loop through the returned results, grouping the same key_name together
|
||||
// adding each column for that key.
|
||||
while($row = mysqli_fetch_assoc($res)) {
|
||||
$name = $row["Column_name"];
|
||||
if (!isset($this->primaryKey)) {
|
||||
$this->primaryKey = new PrimaryKeyInfo($name);
|
||||
}
|
||||
|
||||
$this->primaryKey->addColumn($this->columns[ $name ]);
|
||||
}
|
||||
|
||||
$this->pkLoaded = true;
|
||||
}
|
||||
|
||||
/** Loads the indexes for this table. */
|
||||
protected function initIndexes() {
|
||||
require_once 'creole/metadata/IndexInfo.php';
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) {
|
||||
$this->initColumns();
|
||||
}
|
||||
|
||||
if (!@mysqli_select_db($this->conn->getResource(), $this->dbname)) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
// Indexes
|
||||
$res = mysqli_query($this->conn->getResource(), "SHOW INDEX FROM " . $this->name);
|
||||
|
||||
// Loop through the returned results, grouping the same key_name together
|
||||
// adding each column for that key.
|
||||
while($row = mysqli_fetch_assoc($res)) {
|
||||
$name = $row["Column_name"];
|
||||
|
||||
if (!isset($this->indexes[$name])) {
|
||||
$this->indexes[$name] = new IndexInfo($name);
|
||||
}
|
||||
|
||||
$this->indexes[$name]->addColumn($this->columns[ $name ]);
|
||||
}
|
||||
|
||||
$this->indexesLoaded = true;
|
||||
}
|
||||
|
||||
/** Load foreign keys (unsupported in MySQL). */
|
||||
protected function initForeignKeys() {
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) {
|
||||
$this->initColumns();
|
||||
}
|
||||
|
||||
// Foreign keys are not supported in mysql.
|
||||
$this->fksLoaded = true;
|
||||
}
|
||||
}
|
218
lib/symfony/vendor/creole/drivers/odbc/ODBCCachedResultSet.php
vendored
Executable file
218
lib/symfony/vendor/creole/drivers/odbc/ODBCCachedResultSet.php
vendored
Executable file
@ -0,0 +1,218 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: ODBCCachedResultSet.php,v 1.2 2005/04/01 17:04:00 dlawson_mi Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/drivers/odbc/ODBCResultSetCommon.php';
|
||||
require_once 'creole/drivers/odbc/ODBCTypes.php';
|
||||
|
||||
/**
|
||||
* ODBC implementation of a cached ResultSet.
|
||||
*
|
||||
* In addition to limit/offset emulation, this class implements a resultset
|
||||
* cache. This can be useful as a workaround for some ODBC drivers which lack
|
||||
* support for reverse/absolute cursor scrolling, etc.
|
||||
*
|
||||
* This class will cache rows _on-demand_. So if you only read the first couple
|
||||
* rows of a result, then only those rows will be cached. However, note that if
|
||||
* you call getRecordCount() or last(), the class must read and cache all
|
||||
* available records.
|
||||
*
|
||||
* The offset / limit variables are also taken into account when caching. Any
|
||||
* rows preceding the offset value will be skipped. Caching will stop once the
|
||||
* limit value is reached.
|
||||
*
|
||||
* To use this class, create a derived {@link ODBCAdapter} class which returns
|
||||
* an instance of ODBCCachedResultSet from the {@link ODBCAdapter::createResultSet()} method.
|
||||
* Specify the adapter via the query portion of the Connection URL:
|
||||
*
|
||||
* odbc://localhost/Driver=MySQL ODBC 3.51 Driver;Database=test?adapter=MySQL
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.2 $
|
||||
* @package creole.drivers.odbc
|
||||
*/
|
||||
class ODBCCachedResultSet extends ODBCResultSetCommon implements ResultSet
|
||||
{
|
||||
/**
|
||||
* Record cache
|
||||
* @var array
|
||||
*/
|
||||
protected $recs = array();
|
||||
|
||||
/**
|
||||
* Tracks the last cursor position of the recordset.
|
||||
* @var integer
|
||||
*/
|
||||
protected $lastPos = -1;
|
||||
|
||||
/**
|
||||
* True if blobs/clobs should also be cached.
|
||||
* @var boolean
|
||||
*/
|
||||
protected $cacheLobs = false;
|
||||
|
||||
/**
|
||||
* @see ResultSet::__construct()
|
||||
*/
|
||||
public function __construct(Connection $conn, $result, $fetchmode = null, $cacheLobs = false)
|
||||
{
|
||||
parent::__construct($conn, $result, $fetchmode);
|
||||
|
||||
$this->cacheLobs = $cacheLobs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ODBCResultSetCommon::close()
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
parent::close();
|
||||
$this->recs = null;
|
||||
$this->lastPos = -1;
|
||||
$this->cacheLobs = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches specified records up to and including the specified 1-based
|
||||
* record position. If -1 is specified, all records will be cached.
|
||||
* @param integer Maximum record position to cache.
|
||||
* @return void
|
||||
* @throws SQLException
|
||||
*/
|
||||
public function loadCache($recPos = -1)
|
||||
{
|
||||
$rid = $this->result->getHandle();
|
||||
|
||||
$curRecs = count($this->recs);
|
||||
$totRecs = ($curRecs ? $this->offset + $curRecs : 0);
|
||||
|
||||
while (1)
|
||||
{
|
||||
// Is record already cached?
|
||||
if ($this->lastPos != -1 || ($recPos > -1 && $recPos <= $curRecs))
|
||||
return;
|
||||
|
||||
// Fetch row (no buffers copied yet).
|
||||
$rowNum = ++$totRecs;
|
||||
$result = @odbc_fetch_row($rid, $rowNum);
|
||||
|
||||
// All records cached?
|
||||
if ($result === false || ($this->limit > 0 && $curRecs+1 > $this->limit))
|
||||
{
|
||||
$this->lastPos = $curRecs;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore offset records.
|
||||
if ($totRecs <= $this->offset)
|
||||
continue;
|
||||
|
||||
// Load row array.
|
||||
$row = array();
|
||||
for ($i = 0, $n = @odbc_num_fields($rid); $i < $n; $i++)
|
||||
{
|
||||
$fldNum = $i+1;
|
||||
$row[$i] = odbc_result($rid, $fldNum);
|
||||
|
||||
// Cache lobs if necessary
|
||||
if ($this->cacheLobs)
|
||||
{
|
||||
ODBCTypes::loadTypeMap($this->conn);
|
||||
|
||||
$nativeType = @odbc_field_type($rid, $fldNum);
|
||||
$creoleType = ODBCTypes::getType($nativeType);
|
||||
|
||||
$isBlob = ($creoleType == CreoleTypes::BLOB ||
|
||||
$creoleType == CreoleTypes::LONGVARBINARY);
|
||||
|
||||
$isClob = ($creoleType == CreoleTypes::CLOB ||
|
||||
$creoleType == CreoleTypes::LONGVARCHAR);
|
||||
|
||||
if (($isBlob || $isClob) && $row[$i] !== null)
|
||||
{
|
||||
$binmode = ($isBlob ? ODBC_BINMODE_RETURN : ODBC_BINMODE_CONVERT);
|
||||
$curdata = $row[$i];
|
||||
$row[$i] = $this->readLobData($fldNum, $binmode, $curdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add record to cache.
|
||||
$this->recs[++$curRecs] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::seek()
|
||||
*/
|
||||
public function seek($rownum)
|
||||
{
|
||||
$this->loadCache($rownum);
|
||||
|
||||
if ($rownum < 0 || $rownum > count($this->recs)+1)
|
||||
return false;
|
||||
|
||||
$this->cursorPos = $rownum;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::next()
|
||||
*/
|
||||
function next()
|
||||
{
|
||||
$this->loadCache(++$this->cursorPos);
|
||||
|
||||
if ($this->isAfterLast())
|
||||
{
|
||||
$this->afterLast();
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->fields =& $this->checkFetchMode($this->recs[$this->cursorPos]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::getRecordCount()
|
||||
*/
|
||||
function getRecordCount()
|
||||
{
|
||||
if ($this->lastPos == -1)
|
||||
$this->loadCache(-1);
|
||||
|
||||
return $this->lastPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::isAfterLast()
|
||||
*/
|
||||
public function isAfterLast()
|
||||
{
|
||||
// All records cached yet?
|
||||
if ($this->lastPos == -1)
|
||||
return false;
|
||||
|
||||
return ($this->cursorPos > $this->lastPos);
|
||||
}
|
||||
|
||||
}
|
362
lib/symfony/vendor/creole/drivers/odbc/ODBCConnection.php
vendored
Executable file
362
lib/symfony/vendor/creole/drivers/odbc/ODBCConnection.php
vendored
Executable file
@ -0,0 +1,362 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: ODBCConnection.php,v 1.6 2006/01/17 19:44:39 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/Connection.php';
|
||||
require_once 'creole/common/ConnectionCommon.php';
|
||||
require_once 'creole/drivers/odbc/adapters/ODBCAdapter.php';
|
||||
|
||||
/**
|
||||
* ODBC implementation of Connection.
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.6 $
|
||||
* @package creole.drivers.odbc
|
||||
*/
|
||||
class ODBCConnection extends ConnectionCommon implements Connection {
|
||||
|
||||
/**
|
||||
* Implements driver-specific behavior
|
||||
* @var ODBCAdapter
|
||||
*/
|
||||
protected $adapter = null;
|
||||
|
||||
/**
|
||||
* Last ODBC result resource from executeQuery/executeUpdate. Used in getUpdateCount()
|
||||
* @var ODBCResultResource
|
||||
*/
|
||||
protected $odbcresult = null;
|
||||
|
||||
/**
|
||||
* @see Connection::connect()
|
||||
*/
|
||||
public function connect($dsninfo, $flags = 0)
|
||||
{
|
||||
if (!function_exists('odbc_connect'))
|
||||
throw new SQLException('odbc extension not loaded');
|
||||
|
||||
$adapterclass = isset($dsninfo['adapter']) ? $dsninfo['adapter'] : null;
|
||||
|
||||
if (!$adapterclass)
|
||||
$adapterclass = 'ODBCAdapter';
|
||||
else
|
||||
$adapterclass .= 'Adapter';
|
||||
|
||||
Creole::import('creole.drivers.odbc.adapters.' . $adapterclass);
|
||||
$this->adapter = new $adapterclass();
|
||||
|
||||
$this->dsn = $dsninfo;
|
||||
$this->flags = $flags;
|
||||
|
||||
if ( !($this->flags & Creole::COMPAT_ASSOC_LOWER) && !$this->adapter->preservesColumnCase())
|
||||
{
|
||||
trigger_error('Connection created without Creole::COMPAT_ASSOC_LOWER, ' .
|
||||
'but driver does not support case preservation.',
|
||||
E_USER_WARNING);
|
||||
$this->flags != Creole::COMPAT_ASSOC_LOWER;
|
||||
}
|
||||
|
||||
$persistent = ($flags & Creole::PERSISTENT) === Creole::PERSISTENT;
|
||||
|
||||
if ($dsninfo['database'])
|
||||
$odbcdsn = $dsninfo['database'];
|
||||
elseif ($dsninfo['hostspec'])
|
||||
$odbcdsn = $dsninfo['hostspec'];
|
||||
else
|
||||
$odbcdsn = 'localhost';
|
||||
|
||||
$user = @$dsninfo['username'];
|
||||
$pw = @$dsninfo['password'];
|
||||
|
||||
$connect_function = $persistent ? 'odbc_pconnect' : 'odbc_connect';
|
||||
|
||||
$conn = @$connect_function($odbcdsn, $user, $pw, SQL_CUR_USE_IF_NEEDED);
|
||||
|
||||
if (!is_resource($conn))
|
||||
throw new SQLException('connect failed', $this->nativeError(), $odbcdsn);
|
||||
|
||||
$this->dblink = $conn;
|
||||
|
||||
/**
|
||||
* This prevents blob fields from being fetched when a row is loaded
|
||||
* from a recordset. Clob fields however are loaded with up to
|
||||
* 'odbc.defaultlrl' data. This should be the default anyway, but we'll
|
||||
* set it here just to keep things consistent.
|
||||
*/
|
||||
@odbc_binmode(0, ODBC_BINMODE_PASSTHRU);
|
||||
@odbc_longreadlen(0, ini_get('odbc.defaultlrl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::close()
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$ret = true;
|
||||
|
||||
$this->adapter = null;
|
||||
$this->odbcresult = null;
|
||||
|
||||
if ($this->dblink !== null)
|
||||
{
|
||||
$ret = @odbc_close($this->dblink);
|
||||
$this->dblink = null;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shouldn't this be in ConnectionCommon.php?
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted ODBC error string.
|
||||
* @return string
|
||||
*/
|
||||
public function nativeError()
|
||||
{
|
||||
if ($this->dblink && is_resource($this->dblink))
|
||||
$errstr = '[' . @odbc_error($this->dblink) . '] ' . @odbc_errormsg($this->dblink);
|
||||
else
|
||||
$errstr = '[' . @odbc_error() . '] ' . @odbc_errormsg();
|
||||
|
||||
return $errstr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns driver-specific ODBCAdapter.
|
||||
* @return ODBCAdapter
|
||||
*/
|
||||
public function getAdapter()
|
||||
{
|
||||
return $this->adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getDatabaseInfo()
|
||||
*/
|
||||
public function getDatabaseInfo()
|
||||
{
|
||||
require_once 'creole/drivers/odbc/metadata/ODBCDatabaseInfo.php';
|
||||
return new ODBCDatabaseInfo($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getIdGenerator()
|
||||
*/
|
||||
public function getIdGenerator()
|
||||
{
|
||||
return $this->adapter->getIdGenerator($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the appropriate ResultSet
|
||||
* @return ResultSet
|
||||
*/
|
||||
public function createResultSet($odbcresult, $fetchmode)
|
||||
{
|
||||
return $this->adapter->createResultSet($this, $odbcresult, $fetchmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::prepareStatement()
|
||||
*/
|
||||
public function prepareStatement($sql)
|
||||
{
|
||||
require_once 'creole/drivers/odbc/ODBCPreparedStatement.php';
|
||||
return new ODBCPreparedStatement($this, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::createStatement()
|
||||
*/
|
||||
public function createStatement()
|
||||
{
|
||||
require_once 'creole/drivers/odbc/ODBCStatement.php';
|
||||
return new ODBCStatement($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo To be implemented
|
||||
* @see Connection::prepareCall()
|
||||
*/
|
||||
public function prepareCall($sql)
|
||||
{
|
||||
throw new SQLException('Stored procedures not currently implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::applyLimit()
|
||||
*/
|
||||
public function applyLimit(&$sql, $offset, $limit)
|
||||
{
|
||||
if ($this->adapter->hasLimitOffset())
|
||||
$this->adapter->applyLimit($sql, $offset, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::executeQuery()
|
||||
*/
|
||||
public function executeQuery($sql, $fetchmode = null)
|
||||
{
|
||||
if ($this->odbcresult)
|
||||
$this->odbcresult = null;
|
||||
|
||||
$r = @odbc_exec($this->dblink, $sql);
|
||||
|
||||
if ($r === false)
|
||||
throw new SQLException('Could not execute query', $this->nativeError(), $sql);
|
||||
|
||||
$this->odbcresult = new ODBCResultResource($r);
|
||||
|
||||
return $this->createResultSet($this->odbcresult, $fetchmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::executeUpdate()
|
||||
*/
|
||||
public function executeUpdate($sql)
|
||||
{
|
||||
if ($this->odbcresult)
|
||||
$this->odbcresult = null;
|
||||
|
||||
$r = @odbc_exec($this->dblink, $sql);
|
||||
|
||||
if ($r === false)
|
||||
throw new SQLException('Could not execute update', $this->nativeError(), $sql);
|
||||
|
||||
$this->odbcresult = new ODBCResultResource($r);
|
||||
|
||||
return $this->getUpdateCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a database transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function beginTrans()
|
||||
{
|
||||
if ($this->adapter->supportsTransactions()) {
|
||||
@odbc_autocommit($this->dblink, false);
|
||||
if (odbc_error($this->dblink) == 'S1C00') {
|
||||
throw new SQLException('Could not begin transaction', $this->nativeError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function commitTrans()
|
||||
{
|
||||
if ($this->adapter->supportsTransactions()) {
|
||||
$result = @odbc_commit($this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not commit transaction', $this->nativeError());
|
||||
}
|
||||
@odbc_autocommit($this->dblink, true);
|
||||
if (odbc_error($this->dblink) == 'S1C00') {
|
||||
throw new SQLException('Could not commit transaction (autocommit failed)', $this->nativeError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll back (undo) the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function rollbackTrans()
|
||||
{
|
||||
if ($this->adapter->supportsTransactions()) {
|
||||
$result = @odbc_rollback($this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not rollback transaction', $this->nativeError());
|
||||
}
|
||||
@odbc_autocommit($this->dblink, true);
|
||||
if (odbc_error($this->dblink) == 'S1C00') {
|
||||
throw new SQLException('Could not rollback transaction (autocommit failed)', $this->nativeError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getUpdateCount()
|
||||
*/
|
||||
public function getUpdateCount()
|
||||
{
|
||||
if ($this->odbcresult === null)
|
||||
return 0;
|
||||
|
||||
$n = @odbc_num_rows($this->odbcresult->getHandle());
|
||||
|
||||
if ($n == -1)
|
||||
throw new SQLException('Could not retrieve update count', $this->nativeError());
|
||||
|
||||
return (int) $n;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a simple wrapper class to manage the lifetime of an ODBC result resource
|
||||
* (returned by odbc_exec(), odbc_execute(), etc.) We use a separate class because
|
||||
* the resource can be shared by both ODBCConnection and an ODBCResultSet at the
|
||||
* same time. ODBCConnection hangs on to the last result resource to be used in
|
||||
* its getUpdateCount() method. It also passes this resource to new instances of
|
||||
* ODBCResultSet. At some point the resource has to be cleaned up via
|
||||
* odbc_free_result(). Using this class as a wrapper, we can pass around multiple
|
||||
* references to the same resource. PHP's reference counting mechanism will clean
|
||||
* up the resource when its no longer used via ODBCResultResource::__destruct().
|
||||
* @package creole.drivers.odbc
|
||||
*/
|
||||
class ODBCResultResource
|
||||
{
|
||||
/**
|
||||
* @var resource ODBC result resource returned by {@link odbc_exec()}/{@link odbc_execute()}.
|
||||
*/
|
||||
protected $handle = null;
|
||||
|
||||
public function __construct($handle)
|
||||
{
|
||||
if (is_resource($handle))
|
||||
$this->handle = $handle;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->handle !== null)
|
||||
@odbc_free_result($this->handle);
|
||||
}
|
||||
|
||||
public function getHandle()
|
||||
{
|
||||
return $this->handle;
|
||||
}
|
||||
|
||||
}
|
118
lib/symfony/vendor/creole/drivers/odbc/ODBCIdGenerator.php
vendored
Executable file
118
lib/symfony/vendor/creole/drivers/odbc/ODBCIdGenerator.php
vendored
Executable file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
require_once 'creole/IdGenerator.php';
|
||||
|
||||
/**
|
||||
* ODBC IdGenerator implimenation.
|
||||
*
|
||||
* NOTE: I tried keeping the SQL as basic as possible in this class.
|
||||
* If you need something more optimized, derive your own IdGenerator
|
||||
* and use {@link ODBCAdapter::getIdGenerator()} to use it.
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.2 $
|
||||
* @package creole.drivers.odbc
|
||||
*/
|
||||
class ODBCIdGenerator implements IdGenerator {
|
||||
|
||||
/** Connection object that instantiated this class */
|
||||
private $conn;
|
||||
|
||||
/**
|
||||
* Creates a new IdGenerator class, saves passed connection for use
|
||||
* later by getId() method.
|
||||
* @param Connection $conn
|
||||
*/
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isBeforeInsert()
|
||||
*/
|
||||
public function isBeforeInsert()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isAfterInsert()
|
||||
*/
|
||||
public function isAfterInsert()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::getIdMethod()
|
||||
*/
|
||||
public function getIdMethod()
|
||||
{
|
||||
return self::SEQUENCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::getId()
|
||||
*/
|
||||
public function getId($seqname = null)
|
||||
{
|
||||
if ($seqname === null)
|
||||
throw new SQLException('You must specify the sequence name when calling getId() method.');
|
||||
|
||||
$triedcreate = false;
|
||||
|
||||
while (1)
|
||||
{
|
||||
try
|
||||
{
|
||||
$n = $this->conn->executeUpdate("UPDATE $seqname SET id = id + 1", ResultSet::FETCHMODE_NUM);
|
||||
|
||||
if ($n == 0)
|
||||
throw new SQLException('Failed to update IdGenerator id', $this->conn->nativeError());
|
||||
|
||||
$rs = $this->conn->executeQuery("SELECT id FROM $seqname", ResultSet::FETCHMODE_NUM);
|
||||
}
|
||||
catch (SQLException $e)
|
||||
{
|
||||
//$odbcerr = odbc_error($this->conn->getResource());
|
||||
|
||||
if ($triedcreate)// || ($odbcerr != 'S0000' && $odbcerr != 'S0002'))
|
||||
throw $e;
|
||||
|
||||
$this->drop($seqname, true);
|
||||
$this->create($seqname);
|
||||
$triedcreate = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$rs->first();
|
||||
|
||||
return $rs->getInt(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the sequence emulation table.
|
||||
*/
|
||||
public function create($seqname)
|
||||
{
|
||||
$this->conn->executeUpdate("CREATE TABLE $seqname ( id numeric(19,0) NOT NULL )");
|
||||
$this->conn->executeUpdate("INSERT INTO $seqname ( id ) VALUES ( 0 )");
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops the sequence emulation table.
|
||||
*/
|
||||
public function drop($seqname, $ignoreerrs = false)
|
||||
{
|
||||
try {
|
||||
$this->conn->executeUpdate("DROP TABLE $seqname");
|
||||
} catch (Exception $e) {
|
||||
if (!$ignoreerrs) throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
246
lib/symfony/vendor/creole/drivers/odbc/ODBCPreparedStatement.php
vendored
Executable file
246
lib/symfony/vendor/creole/drivers/odbc/ODBCPreparedStatement.php
vendored
Executable file
@ -0,0 +1,246 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: ODBCPreparedStatement.php,v 1.4 2005/11/13 01:29:01 gamr Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/PreparedStatement.php';
|
||||
require_once 'creole/common/PreparedStatementCommon.php';
|
||||
require_once 'creole/util/Lob.php';
|
||||
|
||||
/**
|
||||
* ODBC specific PreparedStatement functions.
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.4 $
|
||||
* @package creole.drivers.odbc
|
||||
*/
|
||||
class ODBCPreparedStatement extends PreparedStatementCommon implements PreparedStatement
|
||||
{
|
||||
/**
|
||||
* This does nothing since ODBC natively supports prepared statements.
|
||||
* @see PreparedStatementCommon::replaceParams()
|
||||
*/
|
||||
protected function replaceParams()
|
||||
{
|
||||
if ($this->conn->getAdapter()->emulatePrepareStmt())
|
||||
return parent::replaceParams();
|
||||
else
|
||||
return $this->sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function to call native ODBC prepare/execute functions.
|
||||
*/
|
||||
protected function _execute($sql, $params, $fetchmode, $isupdate)
|
||||
{
|
||||
if ($this->resultSet)
|
||||
{
|
||||
$this->resultSet->close();
|
||||
$this->resultSet = null;
|
||||
}
|
||||
|
||||
$this->updateCount = null;
|
||||
|
||||
if ($this->conn->getAdapter()->emulatePrepareStmt())
|
||||
{
|
||||
$stmt = @odbc_exec($this->conn->getResource(), $sql);
|
||||
$ret = ($stmt !== false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Trim surrounding quotes added from default set methods.
|
||||
// Exception: for LOB-based parameters, odbc_execute() will
|
||||
// accept a filename surrounded by single-quotes.
|
||||
foreach ($this->boundInVars as $idx => $var)
|
||||
{
|
||||
if ($var instanceof Lob)
|
||||
{
|
||||
$file = ($isupdate ? $var->getInputFile() : $var->getOutputFile());
|
||||
$this->boundInVars[$idx] = "'$file'";
|
||||
}
|
||||
else if (is_string($var))
|
||||
{
|
||||
$this->boundInVars[$idx] = trim($var, "\"\'");
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = @odbc_prepare($this->conn->getResource(), $sql);
|
||||
|
||||
if ($stmt === FALSE)
|
||||
throw new SQLException('Could not prepare query', $this->conn->nativeError(), $sql);
|
||||
|
||||
$ret = @odbc_execute($stmt, $this->boundInVars);
|
||||
}
|
||||
|
||||
if ($ret === FALSE)
|
||||
{
|
||||
@odbc_free_result($stmt);
|
||||
throw new SQLException('Could not execute query', $this->conn->nativeError(), $sql);
|
||||
}
|
||||
|
||||
return $this->conn->createResultSet(new ODBCResultResource($stmt), $fetchmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PreparedStatement::executeQuery()
|
||||
*/
|
||||
public function executeQuery()
|
||||
{
|
||||
switch (func_num_args()) {
|
||||
case 2:
|
||||
list($params, $fetchmode) = func_get_args();
|
||||
if (!is_array($params)) {
|
||||
unset($params);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
$params = null;
|
||||
list($fetchmode) = func_get_args();
|
||||
break;
|
||||
case 0:
|
||||
$params = null;
|
||||
$fetchmode = null;
|
||||
break;
|
||||
}
|
||||
|
||||
// Set any params passed directly
|
||||
if (isset($params)) {
|
||||
for($i=0,$cnt=count($params); $i < $cnt; $i++) {
|
||||
$this->set($i+1, $params[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = $this->replaceParams();
|
||||
|
||||
if ($this->conn->getAdapter()->hasLimitOffset())
|
||||
{
|
||||
if ($this->limit > 0 || $this->offset > 0)
|
||||
$this->conn->applyLimit($sql, $this->offset, $this->limit);
|
||||
}
|
||||
|
||||
$this->resultSet = $this->_execute($sql, $params, $fetchmode, false);
|
||||
|
||||
if (!$this->conn->getAdapter()->hasLimitOffset())
|
||||
{
|
||||
$this->resultSet->_setOffset($this->offset);
|
||||
$this->resultSet->_setLimit($this->limit);
|
||||
}
|
||||
|
||||
return $this->resultSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PreparedStatement::executeUpdate()
|
||||
*/
|
||||
public function executeUpdate($params = null)
|
||||
{
|
||||
// Set any params passed directly
|
||||
if ($params) {
|
||||
for($i=0,$cnt=count($params); $i < $cnt; $i++) {
|
||||
$this->set($i+1, $params[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = $this->replaceParams();
|
||||
$this->_execute($sql, $params, 0, true);
|
||||
$this->updateCount = $this->conn->getUpdateCount();
|
||||
|
||||
return $this->updateCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PreparedStatementCommon::escape()
|
||||
*/
|
||||
protected function escape($str)
|
||||
{
|
||||
if ($this->conn->getAdapter()->emulatePrepareStmt())
|
||||
return $this->conn->getAdapter()->escape($str);
|
||||
|
||||
// Nothing to do here. odbc_execute() takes care of escaping strings.
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PreparedStatement::setNull()
|
||||
*/
|
||||
function setNull($paramIndex)
|
||||
{
|
||||
$this->sql_cache_valid = false;
|
||||
$this->boundInVars[$paramIndex] = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PreparedStatement::setBlob()
|
||||
*/
|
||||
function setBlob($paramIndex, $blob)
|
||||
{
|
||||
if ($this->conn->getAdapter()->emulatePrepareStmt())
|
||||
return parent::setBlob($paramIndex, $blob);
|
||||
|
||||
$this->sql_cache_valid = false;
|
||||
if ($blob === null)
|
||||
{
|
||||
$this->setNull($paramIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($blob instanceof Blob)
|
||||
{
|
||||
if ($blob->isFromFile() && !$blob->isModified())
|
||||
{
|
||||
$this->boundInVars[$paramIndex] = $blob;
|
||||
return;
|
||||
}
|
||||
|
||||
$blob = $blob->__toString();
|
||||
}
|
||||
|
||||
$this->boundInVars[$paramIndex] = "'" . $this->escape($blob) . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PreparedStatement::setClob()
|
||||
*/
|
||||
function setClob($paramIndex, $clob)
|
||||
{
|
||||
if ($this->conn->getAdapter()->emulatePrepareStmt())
|
||||
return parent::setClob($paramIndex, $clob);
|
||||
|
||||
$this->sql_cache_valid = false;
|
||||
if ($clob === null)
|
||||
{
|
||||
$this->setNull($paramIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($clob instanceof Clob)
|
||||
{
|
||||
if ($clob->isFromFile() && !$clob->isModified())
|
||||
{
|
||||
$this->boundInVars[$paramIndex] = $clob;
|
||||
return;
|
||||
}
|
||||
|
||||
$clob = $clob->__toString();
|
||||
}
|
||||
|
||||
$this->boundInVars[$paramIndex] = "'" . $this->escape($clob) . "'";
|
||||
}
|
||||
|
||||
}
|
209
lib/symfony/vendor/creole/drivers/odbc/ODBCResultSet.php
vendored
Executable file
209
lib/symfony/vendor/creole/drivers/odbc/ODBCResultSet.php
vendored
Executable file
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: ODBCResultSet.php,v 1.2 2005/04/01 17:10:42 dlawson_mi Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/drivers/odbc/ODBCResultSetCommon.php';
|
||||
|
||||
/**
|
||||
* ODBC implementation of ResultSet.
|
||||
*
|
||||
* If the current ODBC driver does not support LIMIT or OFFSET natively,
|
||||
* the methods in here perform some adjustments and extra checking to make
|
||||
* sure that this behaves the same as RDBMS drivers using native OFFSET/LIMIT.
|
||||
*
|
||||
* This class also emulates a row count if the driver is not capable of
|
||||
* providing one natively.
|
||||
*
|
||||
* NOTE: This class only works with drivers that support absolute cursor
|
||||
* positioning (SQL_FETCH_DIRECTION = SQL_FD_FETCH_ABSOLUTE). If the
|
||||
* driver you are using does not support reverse/absolute cursor
|
||||
* scrolling, you should use the {@link ODBCCachedResultSet} class instead.
|
||||
* See the documentation for ODBCCachedResultSet for instructions on how
|
||||
* to use it.
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.2 $
|
||||
* @package creole.drivers.odbc
|
||||
*/
|
||||
class ODBCResultSet extends ODBCResultSetCommon implements ResultSet
|
||||
{
|
||||
/**
|
||||
* Number of rows in resultset.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $numRows = -1;
|
||||
|
||||
/**
|
||||
* True if ODBC driver supports odbc_num_rows().
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $hasRowCount = false;
|
||||
|
||||
/**
|
||||
* @see ResultSet::__construct()
|
||||
*/
|
||||
public function __construct(Connection $conn, $result, $fetchmode = null)
|
||||
{
|
||||
parent::__construct($conn, $result, $fetchmode);
|
||||
|
||||
/**
|
||||
* Some ODBC drivers appear not to handle odbc_num_rows() very well when
|
||||
* more than one result handle is active at once. For example, the MySQL
|
||||
* ODBC driver always returns the number of rows for the last executed
|
||||
* result. For this reason, we'll store the row count here.
|
||||
*
|
||||
* Note also that many ODBC drivers do not support this method. In this
|
||||
* case, getRecordCount() will perform a manual count.
|
||||
*/
|
||||
$this->numRows = @odbc_num_rows($result->getHandle());
|
||||
$this->hasRowCount = $this->numRows != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ODBCResultSetCommon::close()
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
parent::close();
|
||||
$numRows = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::seek()
|
||||
*/
|
||||
public function seek($rownum)
|
||||
{
|
||||
if ($rownum < 0 || $this->limit > 0 && $rownum > $this->limit)
|
||||
return false;
|
||||
|
||||
$this->cursorPos = $rownum;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::next()
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
$this->cursorPos++;
|
||||
|
||||
if ($this->limit > 0 && $this->cursorPos > $this->limit) {
|
||||
$this->cursorPos = $this->limit+1;
|
||||
return false;
|
||||
}
|
||||
|
||||
$rowNum = $this->offset + $this->cursorPos;
|
||||
$fields = null;
|
||||
|
||||
$cols = @odbc_fetch_into($this->result->getHandle(), $fields, $rowNum);
|
||||
|
||||
if ($cols === false) {
|
||||
$this->cursorPos = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->fields =& $this->checkFetchMode($fields);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::isAfterLast()
|
||||
*/
|
||||
public function isAfterLast()
|
||||
{
|
||||
// Force calculation of last record pos.
|
||||
if ($this->cursorPos == -1)
|
||||
$this->getRecordCount();
|
||||
|
||||
return parent::isAfterLast();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::getRecordCount()
|
||||
*/
|
||||
function getRecordCount()
|
||||
{
|
||||
if ($this->hasRowCount)
|
||||
{
|
||||
// Use driver row count if provided.
|
||||
$numRows = $this->numRows - $this->offset;
|
||||
|
||||
if ($this->limit > 0 && $numRows > $this->limit)
|
||||
$numRows = $this->limit;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do manual row count if driver doesn't provide one.
|
||||
if ($this->numRows == -1)
|
||||
{
|
||||
$this->numRows = 0;
|
||||
$this->beforeFirst();
|
||||
|
||||
while($this->next())
|
||||
$this->numRows++;
|
||||
}
|
||||
|
||||
$numRows = $this->numRows;
|
||||
}
|
||||
|
||||
// Cursor pos is -1 when an attempt to fetch past the last row was made
|
||||
// (or a fetch error occured).
|
||||
|
||||
if ($this->cursorPos == -1)
|
||||
$this->cursorPos = $numRows+1;
|
||||
|
||||
return $numRows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::getBlob()
|
||||
*/
|
||||
public function getBlob($column)
|
||||
{
|
||||
require_once 'creole/util/Blob.php';
|
||||
$idx = (is_int($column) ? $column - 1 : $column);
|
||||
if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
|
||||
$data = $this->readLobData($column, ODBC_BINMODE_RETURN, $this->fields[$idx]);
|
||||
if (!$data) { return null; }
|
||||
$b = new Blob();
|
||||
$b->setContents($data);
|
||||
return $b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::getClob()
|
||||
*/
|
||||
public function getClob($column)
|
||||
{
|
||||
require_once 'creole/util/Clob.php';
|
||||
$idx = (is_int($column) ? $column - 1 : $column);
|
||||
if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
|
||||
$data = $this->readLobData($column, ODBC_BINMODE_CONVERT, $this->fields[$idx]);
|
||||
if (!$data) { return null; }
|
||||
$c = new Clob();
|
||||
$c->setContents($data);
|
||||
return $c;
|
||||
}
|
||||
|
||||
}
|
188
lib/symfony/vendor/creole/drivers/odbc/ODBCResultSetCommon.php
vendored
Executable file
188
lib/symfony/vendor/creole/drivers/odbc/ODBCResultSetCommon.php
vendored
Executable file
@ -0,0 +1,188 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: ODBCResultSetCommon.php,v 1.3 2006/01/17 19:44:39 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/ResultSet.php';
|
||||
require_once 'creole/common/ResultSetCommon.php';
|
||||
|
||||
/**
|
||||
* Base class for ODBC implementation of ResultSet.
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.3 $
|
||||
* @package creole.drivers.odbc
|
||||
*/
|
||||
abstract class ODBCResultSetCommon extends ResultSetCommon
|
||||
{
|
||||
/**
|
||||
* Offset at which to start reading rows (for emulated offset).
|
||||
* @var int
|
||||
*/
|
||||
protected $offset = 0;
|
||||
|
||||
/**
|
||||
* Maximum rows to retrieve, or 0 if all (for emulated limit).
|
||||
* @var int
|
||||
*/
|
||||
protected $limit = 0;
|
||||
|
||||
/**
|
||||
* @see ResultSet::__construct()
|
||||
*/
|
||||
public function __construct(Connection $conn, $result, $fetchmode = null)
|
||||
{
|
||||
parent::__construct($conn, $result, $fetchmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::close()
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$this->result = null;
|
||||
$this->conn = null;
|
||||
$this->fetchmode = null;
|
||||
$this->cursorPos = 0;
|
||||
$this->fields = null;
|
||||
$this->lowerAssocCase = false;
|
||||
$this->limit = 0;
|
||||
$this->offset = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function exists to set offset after ResultSet is instantiated.
|
||||
* This function should be "protected" in Java sense: only available to classes in package.
|
||||
* THIS METHOD SHOULD NOT BE CALLED BY ANYTHING EXCEPTION DRIVER CLASSES.
|
||||
* @param int $offset New offset.
|
||||
* @access protected
|
||||
*/
|
||||
public function _setOffset($offset)
|
||||
{
|
||||
$this->offset = $offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function exists to set limit after ResultSet is instantiated.
|
||||
* This function should be "protected" in Java sense: only available to classes in package.
|
||||
* THIS METHOD SHOULD NOT BE CALLED BY ANYTHING EXCEPTION DRIVER CLASSES.
|
||||
* @param int $limit New limit.
|
||||
* @access protected
|
||||
*/
|
||||
public function _setLimit($limit)
|
||||
{
|
||||
$this->limit = $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* If fetchmode is FETCHMODE_ASSOC, returns the 1-based field index number
|
||||
* for the specified column name. Otherwise returns 0 (false).
|
||||
* @return int
|
||||
*/
|
||||
function getFieldNum($colname)
|
||||
{
|
||||
$fieldnum = 0;
|
||||
|
||||
if ($this->fetchmode == ResultSet::FETCHMODE_ASSOC)
|
||||
{
|
||||
$keys = array_keys($this->fields);
|
||||
$fieldnum = array_search($colname, $keys);
|
||||
}
|
||||
|
||||
return $fieldnum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads in any unread LOB data. For long char fields, we may already
|
||||
* have up to odbc_longreadlen() bytes in the buffer. These are passed
|
||||
* in via the $curdata parm. For long binary fields, no data is read
|
||||
* initially since odbc_binmode() is set to ODBC_BINMODE_PASSTHRU.
|
||||
* This method adjusts the binmode and longreadlen to finish reading
|
||||
* these datatypes into the buffer. Returns a string with the complete
|
||||
* contents.
|
||||
*
|
||||
* @param int|string $column Column index or name to read data from.
|
||||
* @param int $binmode ODBC_BINMODE_RETURN for binary data, ODBC_BINMODE_CONVERT for char data.
|
||||
* @param string $curdata Existing LOB data already in buffer.
|
||||
* @return string
|
||||
*/
|
||||
protected function readLobData($column, $binmode, $curdata = null)
|
||||
{
|
||||
// Retrieve field num
|
||||
$fldNum = (is_int($column) ? $column : getFieldNum($column));
|
||||
|
||||
$data = $curdata;
|
||||
$newdata = null;
|
||||
|
||||
// Adjust binmode and longreadlen
|
||||
odbc_binmode($this->result->getHandle(), $binmode);
|
||||
odbc_longreadlen($this->result->getHandle(), 4096);
|
||||
|
||||
while (1)
|
||||
{
|
||||
$newdata = odbc_result($this->result->getHandle(), $fldNum);
|
||||
|
||||
if ($newdata === false)
|
||||
break;
|
||||
else
|
||||
$data .= $newdata;
|
||||
}
|
||||
|
||||
// Restore the default binmode and longreadlen
|
||||
odbc_binmode($this->result->getHandle(), ODBC_BINMODE_PASSTHRU);
|
||||
odbc_longreadlen($this->result->getHandle(), ini_get('odbc.defaultlrl'));
|
||||
|
||||
// The ODBC driver I use seems to return a string with an escaped
|
||||
// null char at the end for clob data.
|
||||
$data = rtrim($data, "\x0");
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts row fields to names if FETCHMODE_ASSOC is set.
|
||||
*
|
||||
* @param array& Row to convert.
|
||||
*
|
||||
* @return array& Converted row.
|
||||
*/
|
||||
protected function checkFetchMode(&$row)
|
||||
{
|
||||
if ($this->fetchmode == ResultSet::FETCHMODE_ASSOC)
|
||||
{
|
||||
$newrow = array();
|
||||
|
||||
for ($i = 0, $n = count($row); $i < $n; $i++)
|
||||
{
|
||||
$colname = @odbc_field_name($this->result->getHandle(), $i+1);
|
||||
|
||||
if ($this->lowerAssocCase) {
|
||||
$colname = strtolower($colname);
|
||||
}
|
||||
|
||||
$newrow[$colname] = $row[$i];
|
||||
}
|
||||
|
||||
$row =& $newrow;
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
}
|
64
lib/symfony/vendor/creole/drivers/odbc/ODBCStatement.php
vendored
Executable file
64
lib/symfony/vendor/creole/drivers/odbc/ODBCStatement.php
vendored
Executable file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: ODBCStatement.php,v 1.1 2004/07/27 23:08:30 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/Statement.php';
|
||||
require_once 'creole/common/StatementCommon.php';
|
||||
|
||||
/**
|
||||
* ODBC Statement
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.1 $
|
||||
* @package creole.drivers.odbc
|
||||
*/
|
||||
class ODBCStatement extends StatementCommon implements Statement
|
||||
{
|
||||
/**
|
||||
* @see Statement::executeQuery()
|
||||
*/
|
||||
public function executeQuery($sql, $fetchmode = null)
|
||||
{
|
||||
if ($this->resultSet)
|
||||
{
|
||||
$this->resultSet->close();
|
||||
$this->resultSet = null;
|
||||
}
|
||||
|
||||
$this->updateCount = null;
|
||||
|
||||
if ($this->conn->getAdapter()->hasLimitOffset())
|
||||
{
|
||||
if ($this->limit > 0 || $this->offset > 0)
|
||||
$this->conn->applyLimit($sql, $this->offset, $this->limit);
|
||||
}
|
||||
|
||||
$this->resultSet = $this->conn->executeQuery($sql, $fetchmode);
|
||||
|
||||
if (!$this->conn->getAdapter()->hasLimitOffset())
|
||||
{
|
||||
$this->resultSet->_setOffset($this->offset);
|
||||
$this->resultSet->_setLimit($this->limit);
|
||||
}
|
||||
|
||||
return $this->resultSet;
|
||||
}
|
||||
|
||||
}
|
189
lib/symfony/vendor/creole/drivers/odbc/ODBCTypes.php
vendored
Executable file
189
lib/symfony/vendor/creole/drivers/odbc/ODBCTypes.php
vendored
Executable file
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* $Id: ODBCTypes.php,v 1.1 2004/07/27 23:08:30 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/CreoleTypes.php';
|
||||
|
||||
/**
|
||||
* ODBC types / type map.
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.1 $
|
||||
* @package creole.drivers.odbc
|
||||
*/
|
||||
class ODBCTypes extends CreoleTypes {
|
||||
|
||||
/**
|
||||
* Map ODBC native types to Creole (JDBC) types.
|
||||
*/
|
||||
protected static $typeMap = null;
|
||||
|
||||
/**
|
||||
* Reverse mapping, created on demand.
|
||||
*/
|
||||
protected static $reverseMap = null;
|
||||
|
||||
/**
|
||||
* Loads the map of ODBC data types to Creole (JDBC) types.
|
||||
*
|
||||
* NOTE: This function cannot map DBMS-specific datatypes. If you use a
|
||||
* driver which implements DBMS-specific datatypes, you will need
|
||||
* to modify/extend this class to add the correct mapping.
|
||||
*/
|
||||
public static function loadTypeMap($conn = null)
|
||||
{
|
||||
if (self::$typeMap !== null && count(self::$typeMap) > 0)
|
||||
return;
|
||||
|
||||
if ($conn == null)
|
||||
throw new SQLException('No connection specified when loading ODBC type map.');
|
||||
|
||||
self::$typeMap = array();
|
||||
|
||||
$result = @odbc_gettypeinfo($conn->getResource());
|
||||
|
||||
if ($result === false)
|
||||
throw new SQLException('Failed to retrieve type info.', $conn->nativeError());
|
||||
|
||||
$rowNum = 1;
|
||||
|
||||
while (odbc_fetch_row($result, $rowNum++))
|
||||
{
|
||||
$odbctypeid = odbc_result($result, 'DATA_TYPE');
|
||||
$odbctypename = odbc_result($result, 'TYPE_NAME');
|
||||
|
||||
switch ($odbctypeid)
|
||||
{
|
||||
case SQL_CHAR:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::CHAR;
|
||||
break;
|
||||
case SQL_VARCHAR:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::VARCHAR;
|
||||
break;
|
||||
case SQL_LONGVARCHAR:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::LONGVARCHAR;
|
||||
break;
|
||||
case SQL_DECIMAL:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::DECIMAL;
|
||||
break;
|
||||
case SQL_NUMERIC:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::NUMERIC;
|
||||
break;
|
||||
case SQL_BIT:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::BOOLEAN;
|
||||
break;
|
||||
case SQL_TINYINT:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::TINYINT;
|
||||
break;
|
||||
case SQL_SMALLINT:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::SMALLINT;
|
||||
break;
|
||||
case SQL_INTEGER:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::INTEGER;
|
||||
break;
|
||||
case SQL_BIGINT:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::BIGINT;
|
||||
break;
|
||||
case SQL_REAL:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::REAL;
|
||||
break;
|
||||
case SQL_FLOAT:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::FLOAT;
|
||||
break;
|
||||
case SQL_DOUBLE:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::DOUBLE;
|
||||
break;
|
||||
case SQL_BINARY:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::BINARY;
|
||||
break;
|
||||
case SQL_VARBINARY:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::VARBINARY;
|
||||
break;
|
||||
case SQL_LONGVARBINARY:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::LONGVARBINARY;
|
||||
break;
|
||||
case SQL_DATE:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::DATE;
|
||||
break;
|
||||
case SQL_TIME:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::TIME;
|
||||
break;
|
||||
case SQL_TIMESTAMP:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::TIMESTAMP;
|
||||
break;
|
||||
case SQL_TYPE_DATE:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::DATE;
|
||||
break;
|
||||
case SQL_TYPE_TIME:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::TIME;
|
||||
break;
|
||||
case SQL_TYPE_TIMESTAMP:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::TIMESTAMP;
|
||||
break;
|
||||
default:
|
||||
self::$typeMap[$odbctypename] = CreoleTypes::OTHER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@odbc_free_result($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the generic Creole (JDBC-like) type
|
||||
* when given the native db type.
|
||||
* @param string $nativeType DB native type (e.g. 'TEXT', 'byetea', etc.).
|
||||
* @return int Creole native type (e.g. CreoleTypes::LONGVARCHAR, CreoleTypes::BINARY, etc.).
|
||||
*/
|
||||
public static function getType($nativeType)
|
||||
{
|
||||
if (!self::$typeMap)
|
||||
self::loadTypeMap();
|
||||
|
||||
$t = strtoupper($nativeType);
|
||||
|
||||
if (isset(self::$typeMap[$t])) {
|
||||
return self::$typeMap[$t];
|
||||
} else {
|
||||
return CreoleTypes::OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will return a native type that corresponds to the specified
|
||||
* Creole (JDBC-like) type.
|
||||
* If there is more than one matching native type, then the LAST defined
|
||||
* native type will be returned.
|
||||
* @param int $creoleType
|
||||
* @return string Native type string.
|
||||
*/
|
||||
public static function getNativeType($creoleType)
|
||||
{
|
||||
if (!self::$typeMap)
|
||||
self::loadTypeMap();
|
||||
|
||||
if (self::$reverseMap === null) {
|
||||
self::$reverseMap = array_flip(self::$typeMap);
|
||||
}
|
||||
return @self::$reverseMap[$creoleType];
|
||||
}
|
||||
|
||||
}
|
90
lib/symfony/vendor/creole/drivers/odbc/README
vendored
Executable file
90
lib/symfony/vendor/creole/drivers/odbc/README
vendored
Executable file
@ -0,0 +1,90 @@
|
||||
|
||||
|
||||
Creole ODBC Bridge Driver
|
||||
=========================
|
||||
|
||||
|
||||
I. Overview
|
||||
-----------
|
||||
|
||||
In the text below, the word "driver" can get somewhat muddled since there are
|
||||
two libraries concerned here (Creole & ODBC). So, we'll use the term "bridge
|
||||
driver" to refer to Creole's ODBC bridge driver, and "ODBC driver" to refer to
|
||||
an ODBC database driver.
|
||||
|
||||
The Creole ODBC Bridge driver provides a solution for databases which
|
||||
currently have no PHP-native interface. It is currently in an experimental
|
||||
stage of development. It has been tested with two ODBC drivers (Sequiter's
|
||||
CodeBase ODBC driver and the MySQL ODBC driver (as a baseline test)). To
|
||||
use any other ODBC drivers you may need to write your own ODBCAdapter-derived
|
||||
class (see below).
|
||||
|
||||
|
||||
II. ODBCAdapter
|
||||
---------------
|
||||
|
||||
Because ODBC itself is a database abstraction library, the bridge driver needed
|
||||
a way of hiding ODBC driver-specific behavior. The solution to this was to
|
||||
create an adapter layer (akin to how the Propel runtime engine works). Think of
|
||||
it as a sub-driver for the bridge driver. Any ODBC driver-specific behavior is
|
||||
handled by an ODBCAdapter-derived class. To use a specific adapter class, you
|
||||
specify its name via a parameter in the connection string:
|
||||
|
||||
odbc://localhost/DSN=CodeBase;?adapter=CodeBase
|
||||
|
||||
The string above will load the following file as the adapter to use with the
|
||||
bridge driver: creole/drivers/odbc/adapters/CodeBaseAdapter.php
|
||||
|
||||
Some ODBC drivers are limited in support for various Creole features. The
|
||||
ODBCAdapter also provides a method for emulation of some of these missing
|
||||
features:
|
||||
|
||||
-The emulatePrepareStmt() method provides a switch for enabling prepared
|
||||
statement emulation for drivers that do not support (or have trouble with)
|
||||
prepared statements. This emulation is disabled by default.
|
||||
|
||||
-The hasLimitOffset() method provides a switch for enabling LIMIT/OFFSET
|
||||
emulation for drivers that do not support this. This emulation is enabled
|
||||
by default. The LIMIT/OFFSET emulation was borrowed from the MSSQL Creole
|
||||
driver.
|
||||
|
||||
-The createResultSet() method provides a switch for enabling cached
|
||||
result sets. To enable this feature, return an instance of
|
||||
ODBCCachedResultSet in the createResultSet() method of your ODBCAdapter-
|
||||
derived class. This can be useful as a workaround for ODBC drivers which
|
||||
lack support for record count retrieval, reverse/absolute cursor
|
||||
scrolling, etc. In most cases, result rows are cached on-demand. So if
|
||||
you only read the first couple rows of a result, then only those rows will
|
||||
be cached.
|
||||
|
||||
-The getIdGenerator() method provides a switch for enabling sequence
|
||||
emulation. This feature is enabled by default in ODBCAdapter and is
|
||||
implemented in the ODBCIdGenerator class. The emulation code was inspired
|
||||
by the PEAR::DB nextID() method. If your database supports sequences or
|
||||
autoincrement natively, you can return your own IdGenerator-derived class
|
||||
instead. Check out some of the other Creole drivers for IdGenerator
|
||||
examples.
|
||||
|
||||
|
||||
III. Incomplete Features
|
||||
------------------------
|
||||
|
||||
-The database metadata classes are not fully tested/complete. Specifically,
|
||||
the ODBCDatabaseInfo class does not currently set the database name. There
|
||||
may be other problems as well.
|
||||
|
||||
-The Creole CallableStatement class (stored procedures) is not currently
|
||||
implemented. No immediate plans to do this in the future, but it looks
|
||||
feasible.
|
||||
|
||||
|
||||
IV. Known Issues
|
||||
----------------
|
||||
|
||||
This driver was developed using the PHP v5.0 final build. During the course
|
||||
of testing I uncovered several bugs in the php_odbc module. I submitted
|
||||
patches for these bugs, but have not yet received word that they were
|
||||
committed (they were just submitted this morning). If you want more details
|
||||
on the problems I encountered or would like a copy of the patches, please
|
||||
e-mail me (dlawson@masterytech.com).
|
||||
|
73
lib/symfony/vendor/creole/drivers/odbc/adapters/CodeBaseAdapter.php
vendored
Executable file
73
lib/symfony/vendor/creole/drivers/odbc/adapters/CodeBaseAdapter.php
vendored
Executable file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: CodeBaseAdapter.php,v 1.3 2005/10/17 19:03:51 dlawson_mi Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/drivers/odbc/adapters/ODBCAdapter.php';
|
||||
|
||||
/**
|
||||
* CodeBase driver-specific behavior.
|
||||
*
|
||||
* This adapter is for Sequiter's CodeBaseSQL product. It is a dBase ODBC
|
||||
* driver. The driver only supports forward-only cursor scrolling so this
|
||||
* adapter causes the ODBCCachedResultSet to be used.
|
||||
*
|
||||
* A couple other quirks exist:
|
||||
*
|
||||
* 1) Cannot get blobs to work correctly. If I try writing one to a
|
||||
* LONGVARBINARY typed field, only the first few bytes are written.
|
||||
* This will cause the ResultSetTest::testGetBlob() test case to fail
|
||||
* when running tests for the driver.
|
||||
*
|
||||
* 2) For some reason the character count is off for the
|
||||
* ResultSetTest::testSetClob() test case _only_ when running from the
|
||||
* command line. If I run the same test through a web server it works fine.
|
||||
* Looks like it has something to do with line endings in Windows. The
|
||||
* difference in file sizes is 9803 vs 10090.
|
||||
*
|
||||
* 3) Setting a clob field to null writes a space to the field in the table.
|
||||
* This causes the PreparedStatementTest::testSetNull() test case to fail
|
||||
* when running tests for the driver.
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.3 $
|
||||
* @package creole.drivers.odbc
|
||||
*/
|
||||
class CodeBaseAdapter extends ODBCAdapter
|
||||
{
|
||||
/**
|
||||
* @see ODBCAdapter::createResultSet()
|
||||
*/
|
||||
public function preservesColumnCase()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ODBCAdapter::createResultSet()
|
||||
*/
|
||||
public function createResultSet($conn, $odbcresult, $fetchmode)
|
||||
{
|
||||
require_once 'creole/drivers/odbc/ODBCResultSet.php';
|
||||
return new ODBCResultSet($conn, $odbcresult, $fetchmode, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
78
lib/symfony/vendor/creole/drivers/odbc/adapters/MySQLAdapter.php
vendored
Executable file
78
lib/symfony/vendor/creole/drivers/odbc/adapters/MySQLAdapter.php
vendored
Executable file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: MySQLAdapter.php,v 1.1 2004/07/27 23:08:30 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/drivers/odbc/ODBCCachedResultSet.php';
|
||||
require_once 'creole/drivers/odbc/ODBCResultSet.php';
|
||||
require_once 'creole/drivers/odbc/adapters/ODBCAdapter.php';
|
||||
|
||||
/**
|
||||
* Implements MySQL driver-specific behavior.
|
||||
*
|
||||
* Obviously it would be much more efficient to simply use the Creole
|
||||
* MySQL driver. This adapter was created for the sole purpose of testing
|
||||
* the ODBC driver.
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.1 $
|
||||
* @package creole.drivers.odbc
|
||||
*/
|
||||
class MySQLAdapter extends ODBCAdapter
|
||||
{
|
||||
/**
|
||||
* @see ODBCAdapter::hasLimitOffset()
|
||||
*/
|
||||
public function hasLimitOffset()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ODBCAdapter::applyLimit()
|
||||
*/
|
||||
public function applyLimit(&$sql, $offset, $limit)
|
||||
{
|
||||
if ( $limit > 0 ) {
|
||||
$sql .= " LIMIT " . ($offset > 0 ? $offset . ", " : "") . $limit;
|
||||
} else if ( $offset > 0 ) {
|
||||
$sql .= " LIMIT " . $offset . ", 18446744073709551615";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ODBCAdapter::escape()
|
||||
*/
|
||||
public function escape($str)
|
||||
{
|
||||
return addslashes($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ODBCAdapter::createResultSet()
|
||||
*/
|
||||
public function createResultSet($conn, $odbcresult, $fetchmode)
|
||||
{
|
||||
// return new ODBCCachedResultSet($conn, $odbcresult, $fetchmode, true);
|
||||
return new ODBCResultSet($conn, $odbcresult, $fetchmode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
115
lib/symfony/vendor/creole/drivers/odbc/adapters/ODBCAdapter.php
vendored
Executable file
115
lib/symfony/vendor/creole/drivers/odbc/adapters/ODBCAdapter.php
vendored
Executable file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: ODBCAdapter.php,v 1.3 2005/10/17 19:03:51 dlawson_mi Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default class for ODBC driver-specific behavior.
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.3 $
|
||||
* @package creole.drivers.odbc
|
||||
*/
|
||||
class ODBCAdapter
|
||||
{
|
||||
/**
|
||||
* Returns true if column case is preserved in the database when a table
|
||||
* is first created. Returns false if table does not preserve case (i.e.
|
||||
* ProductID => PRODUCTID).
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function preservesColumnCase()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if prepared statements should be emulated. This
|
||||
* might be useful if your driver does not support (or has trouble with)
|
||||
* prepared statements.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function emulatePrepareStmt()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if ODBC driver supports LIMIT/OFFSET via SQL.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasLimitOffset()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::applyLimit()
|
||||
*/
|
||||
public function applyLimit(&$sql, $offset, $limit)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PreparedStatementCommon::escape()
|
||||
*/
|
||||
public function escape($str)
|
||||
{
|
||||
// use this instead of magic_quotes_sybase + addslashes(),
|
||||
// just in case multiple RDBMS being used at the same time
|
||||
return str_replace("'", "''", $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the default resultset.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function createResultSet($conn, $odbcresult, $fetchmode)
|
||||
{
|
||||
require_once 'creole/drivers/odbc/ODBCResultSet.php';
|
||||
return new ODBCResultSet($conn, $odbcresult, $fetchmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default ODBCIdGenerator for emulating sequences.
|
||||
*
|
||||
* @return ODBCIdGenerator
|
||||
*/
|
||||
public function getIdGenerator($conn)
|
||||
{
|
||||
require_once 'creole/drivers/odbc/ODBCIdGenerator.php';
|
||||
return new ODBCIdGenerator($conn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if driver support transactions.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function supportsTransactions()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
66
lib/symfony/vendor/creole/drivers/odbc/metadata/ODBCDatabaseInfo.php
vendored
Executable file
66
lib/symfony/vendor/creole/drivers/odbc/metadata/ODBCDatabaseInfo.php
vendored
Executable file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: ODBCDatabaseInfo.php,v 1.2 2006/01/17 19:44:39 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/DatabaseInfo.php';
|
||||
|
||||
/**
|
||||
* ODBC implementation of DatabaseInfo.
|
||||
*
|
||||
* @todo Still need a way to obtain the database name. Not sure how to do this yet.
|
||||
* @todo This might need to be an {@link ODBCAdapter} method.
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.2 $
|
||||
* @package creole.drivers.odbc.metadata
|
||||
*/
|
||||
class ODBCDatabaseInfo extends DatabaseInfo {
|
||||
|
||||
/**
|
||||
* @see DatabaseInfo::initTables()
|
||||
*/
|
||||
protected function initTables()
|
||||
{
|
||||
include_once 'creole/drivers/odbc/metadata/ODBCTableInfo.php';
|
||||
|
||||
$result = @odbc_tables($this->conn->getResource());
|
||||
|
||||
if (!$result)
|
||||
throw new SQLException('Could not list tables', $this->conn->nativeError());
|
||||
|
||||
while (odbc_fetch_row($result))
|
||||
{
|
||||
$tablename = strtoupper(odbc_result($result, 'TABLE_NAME'));
|
||||
$this->tables[$tablename] = new ODBCTableInfo($this, $tablename);
|
||||
}
|
||||
|
||||
@odbc_free_result($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws SQLException
|
||||
*/
|
||||
protected function initSequences()
|
||||
{
|
||||
// Not sure how this is used yet.
|
||||
}
|
||||
|
||||
}
|
141
lib/symfony/vendor/creole/drivers/odbc/metadata/ODBCTableInfo.php
vendored
Executable file
141
lib/symfony/vendor/creole/drivers/odbc/metadata/ODBCTableInfo.php
vendored
Executable file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: ODBCTableInfo.php,v 1.2 2006/01/17 19:44:39 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/TableInfo.php';
|
||||
|
||||
/**
|
||||
* ODBC implementation of TableInfo.
|
||||
*
|
||||
* @author Dave Lawson <dlawson@masterytech.com>
|
||||
* @version $Revision: 1.2 $
|
||||
* @package creole.drivers.odbc.metadata
|
||||
*/
|
||||
class ODBCTableInfo extends TableInfo {
|
||||
|
||||
/**
|
||||
* @see TableInfo::initColumns()
|
||||
*/
|
||||
protected function initColumns()
|
||||
{
|
||||
include_once 'creole/metadata/ColumnInfo.php';
|
||||
include_once 'creole/drivers/odbc/ODBCTypes.php';
|
||||
|
||||
ODBCTypes::loadTypeMap($this->conn);
|
||||
|
||||
$result = @odbc_columns($this->conn->getResource(), $this->dbname, '', $this->name);
|
||||
|
||||
if (!$result)
|
||||
throw new SQLException('Could not get column names', $this->conn->nativeError());
|
||||
|
||||
while (odbc_fetch_row($result))
|
||||
{
|
||||
$name = odbc_result($result, 'COLUMN_NAME');
|
||||
$type = odbc_result($result, 'TYPE_NAME');
|
||||
$length = odbc_result($result, 'LENGTH');
|
||||
$is_nullable = odbc_result($result, 'NULLABLE');
|
||||
$default = '';
|
||||
$precision = odbc_result($result, 'PRECISION');
|
||||
$scale = odbc_result($result, 'SCALE');
|
||||
$this->columns[$name] = new ColumnInfo($this, $name, ODBCTypes::getType($type), $type, $length, $precision, $scale, $is_nullable, $default);
|
||||
}
|
||||
|
||||
@odbc_free_result($result);
|
||||
|
||||
$this->colsLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TableInfo::initPrimaryKey()
|
||||
*/
|
||||
protected function initPrimaryKey()
|
||||
{
|
||||
include_once 'creole/metadata/PrimaryKeyInfo.php';
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
|
||||
$result = @odbc_primarykeys($this->conn->getResource(), $this->dbname, '', $this->name);
|
||||
|
||||
while (odbc_fetch_row($result))
|
||||
{
|
||||
$name = odbc_result($result, 'COLUMN_NAME');
|
||||
|
||||
if (!isset($this->primaryKey))
|
||||
$this->primaryKey = new PrimaryKeyInfo($name);
|
||||
|
||||
$this->primaryKey->addColumn($this->columns[$name]);
|
||||
}
|
||||
|
||||
@odbc_free_result($result);
|
||||
|
||||
$this->pkLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TableInfo::initIndexes()
|
||||
*/
|
||||
protected function initIndexes()
|
||||
{
|
||||
// Not sure if this can be implemented in a driver-independent way.
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TableInfo::initForeignKeys()
|
||||
*/
|
||||
protected function initForeignKeys()
|
||||
{
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
|
||||
$result = @odbc_foreignkeys($this->conn->getResource(), '', '', '', $this->dbname, '', $this->name);
|
||||
|
||||
while (odbc_fetch_row($result))
|
||||
{
|
||||
$name = odbc_result($result, 'COLUMN_NAME');
|
||||
$ftbl = odbc_result($result, 'FKTABLE_NAME');
|
||||
$fcol = odbc_result($result, 'FKCOLUMN_NAME');
|
||||
|
||||
if (!isset($this->foreignKeys[$name]))
|
||||
{
|
||||
$this->foreignKeys[$name] = new ForeignKeyInfo($name);
|
||||
|
||||
if (($foreignTable = $this->database->getTable($ftbl)) === null)
|
||||
{
|
||||
$foreignTable = new TableInfo($ltbl);
|
||||
$this->database->addTable($foreignTable);
|
||||
}
|
||||
|
||||
if (($foreignCol = $foreignTable->getColumn($name)) === null)
|
||||
{
|
||||
$foreignCol = new ColumnInfo($foreignTable, $name);
|
||||
$foreignTable->addColumn($foreignCol);
|
||||
}
|
||||
|
||||
$this->foreignKeys[$name]->addReference($this->columns[$name], $foreignCol);
|
||||
}
|
||||
}
|
||||
|
||||
@odbc_free_result($result);
|
||||
|
||||
$this->fksLoaded = true;
|
||||
}
|
||||
|
||||
}
|
398
lib/symfony/vendor/creole/drivers/oracle/OCI8Connection.php
vendored
Executable file
398
lib/symfony/vendor/creole/drivers/oracle/OCI8Connection.php
vendored
Executable file
@ -0,0 +1,398 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* $Id: OCI8Connection.php,v 1.18 2005/10/17 19:03:51 dlawson_mi Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/Connection.php';
|
||||
require_once 'creole/common/ConnectionCommon.php';
|
||||
include_once 'creole/drivers/oracle/OCI8ResultSet.php';
|
||||
|
||||
/**
|
||||
* Oracle implementation of Connection.
|
||||
*
|
||||
* @author David Giffin <david@giffin.org>
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @author Stig Bakken <ssb@fast.no>
|
||||
* @author Lukas Smith
|
||||
* @version $Revision: 1.18 $
|
||||
* @package creole.drivers.oracle
|
||||
*/
|
||||
class OCI8Connection extends ConnectionCommon implements Connection
|
||||
{
|
||||
protected $lastStmt = null;
|
||||
|
||||
/**
|
||||
* Auto commit mode for oci_execute
|
||||
* @var int
|
||||
*/
|
||||
protected $execMode = OCI_COMMIT_ON_SUCCESS;
|
||||
|
||||
/**
|
||||
* Connect to a database and log in as the specified user.
|
||||
*
|
||||
* @param array $dsn The data source hash.
|
||||
* @param int $flags Any connection flags.
|
||||
* @access public
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
function connect( $dsninfo, $flags = 0 )
|
||||
{
|
||||
if ( !extension_loaded( 'oci8' ) )
|
||||
{
|
||||
throw new SQLException( 'oci8 extension not loaded' );
|
||||
}
|
||||
|
||||
$this->dsn = $dsninfo;
|
||||
$this->flags = $flags;
|
||||
|
||||
$persistent =
|
||||
( $flags & Creole::PERSISTENT === Creole::PERSISTENT );
|
||||
|
||||
$user = $dsninfo[ 'username' ];
|
||||
$pw = $dsninfo[ 'password' ];
|
||||
$hostspec = $dsninfo[ 'hostspec' ];
|
||||
$port = $dsninfo[ 'port' ];
|
||||
$db = $dsninfo[ 'database' ];
|
||||
|
||||
$connect_function = ( $persistent )
|
||||
? 'oci_pconnect'
|
||||
: 'oci_connect';
|
||||
$encoding = !empty($dsninfo['encoding']) ? $dsninfo['encoding'] : null;
|
||||
|
||||
@ini_set( 'track_errors', true );
|
||||
|
||||
if ( $hostspec && $port )
|
||||
{
|
||||
$hostspec .= ':' . $port;
|
||||
}
|
||||
|
||||
if ( $db && $hostspec && $user && $pw )
|
||||
{
|
||||
$conn = @$connect_function( $user, $pw, "//$hostspec/$db", $encoding);
|
||||
}
|
||||
elseif ( $hostspec && $user && $pw )
|
||||
{
|
||||
$conn = @$connect_function( $user, $pw, $hostspec, $encoding );
|
||||
}
|
||||
|
||||
elseif ( $user || $pw )
|
||||
{
|
||||
$conn = @$connect_function( $user, $pw, null, $encoding );
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$conn = false;
|
||||
}
|
||||
|
||||
@ini_restore( 'track_errors' );
|
||||
|
||||
if ( $conn == false )
|
||||
{
|
||||
$error = oci_error();
|
||||
$error = ( is_array( $error ) )
|
||||
? $error[ 'message' ]
|
||||
: null;
|
||||
|
||||
throw new SQLException( 'connect failed', $error );
|
||||
}
|
||||
|
||||
$this->dblink = $conn;
|
||||
|
||||
//connected ok, need to set a few environment settings
|
||||
//please note, if this is changed, the function setTimestamp and setDate in OCI8PreparedStatement.php
|
||||
//must be changed to match
|
||||
$sql = "ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'";
|
||||
$this->executeQuery($sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see Connection::disconnect()
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
$ret = @oci_close( $this->dblink );
|
||||
$this->dblink = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::executeQuery()
|
||||
*/
|
||||
function executeQuery( $sql, $fetchmode = null )
|
||||
{
|
||||
$this->lastQuery = $sql;
|
||||
|
||||
// $result = @oci_parse( $this->dblink, $sql );
|
||||
$result = oci_parse( $this->dblink, $sql );
|
||||
|
||||
if ( ! $result )
|
||||
{
|
||||
throw new SQLException( 'Unable to prepare query'
|
||||
, $this->nativeError()
|
||||
, $sql
|
||||
);
|
||||
}
|
||||
|
||||
$success = oci_execute( $result, $this->execMode );
|
||||
|
||||
if ( ! $success )
|
||||
{
|
||||
throw new SQLException( 'Unable to execute query'
|
||||
, $this->nativeError( $result )
|
||||
, $sql
|
||||
);
|
||||
}
|
||||
|
||||
return new OCI8ResultSet( $this, $result, $fetchmode );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see Connection::simpleUpdate()
|
||||
*/
|
||||
|
||||
function executeUpdate( $sql )
|
||||
{
|
||||
$this->lastQuery = $sql;
|
||||
|
||||
$statement = oci_parse( $this->dblink, $sql );
|
||||
|
||||
if ( ! $statement )
|
||||
{
|
||||
throw new SQLException( 'Unable to prepare update'
|
||||
, $this->nativeError()
|
||||
, $sql
|
||||
);
|
||||
}
|
||||
|
||||
$success = oci_execute( $statement, $this->execMode );
|
||||
|
||||
if ( ! $success )
|
||||
{
|
||||
throw new SQLException( 'Unable to execute update'
|
||||
, $this->nativeError( $statement )
|
||||
, $sql
|
||||
);
|
||||
}
|
||||
|
||||
$this->lastStmt = $statement;
|
||||
|
||||
return oci_num_rows( $statement );
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a database transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function beginTrans()
|
||||
{
|
||||
$this->execMode = OCI_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function commitTrans()
|
||||
{
|
||||
$result = oci_commit( $this->dblink );
|
||||
|
||||
if ( ! $result )
|
||||
{
|
||||
throw new SQLException( 'Unable to commit transaction'
|
||||
, $this->nativeError()
|
||||
);
|
||||
}
|
||||
|
||||
$this->execMode = OCI_COMMIT_ON_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Roll back ( undo ) the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function rollbackTrans()
|
||||
{
|
||||
$result = oci_rollback( $this->dblink );
|
||||
|
||||
if ( ! $result )
|
||||
{
|
||||
throw new SQLException( 'Unable to rollback transaction'
|
||||
, $this->nativeError()
|
||||
);
|
||||
}
|
||||
|
||||
$this->execMode = OCI_COMMIT_ON_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by the data manipulation
|
||||
* query.
|
||||
*
|
||||
* @return int Number of rows affected by the last query.
|
||||
* @todo -cOCI8Connection Figure out whether getUpdateCount() should throw exception on error or just return 0.
|
||||
*/
|
||||
function getUpdateCount()
|
||||
{
|
||||
if ( ! $this->lastStmt )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
$result = oci_num_rows( $this->lastStmt );
|
||||
|
||||
if ( $result === false )
|
||||
{
|
||||
throw new SQLException( 'Update count failed'
|
||||
, $this->nativeError( $this->lastStmt )
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build Oracle-style query with limit or offset.
|
||||
* If the original SQL is in variable: query then the requlting
|
||||
* SQL looks like this:
|
||||
* <pre>
|
||||
* SELECT B.* FROM (
|
||||
* SELECT A.*, rownum as TORQUE$ROWNUM FROM (
|
||||
* query
|
||||
* ) A
|
||||
* ) B WHERE B.TORQUE$ROWNUM > offset AND B.TORQUE$ROWNUM
|
||||
* <= offset + limit
|
||||
* </pre>
|
||||
*
|
||||
* @param string &$sql the query
|
||||
* @param int $offset
|
||||
* @param int $limit
|
||||
* @return void ( $sql parameter is currently manipulated directly )
|
||||
*/
|
||||
public function applyLimit( &$sql, $offset, $limit )
|
||||
{
|
||||
$sql =
|
||||
'SELECT B.* FROM ( '
|
||||
. 'SELECT A.*, rownum AS CREOLE$ROWNUM FROM ( '
|
||||
. $sql
|
||||
. ' ) A '
|
||||
. ' ) B WHERE ';
|
||||
|
||||
if ( $offset > 0 )
|
||||
{
|
||||
$sql .= ' B.CREOLE$ROWNUM > ' . $offset;
|
||||
|
||||
if ( $limit > 0 )
|
||||
{
|
||||
$sql .= ' AND B.CREOLE$ROWNUM <= '
|
||||
. ( $offset + $limit );
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$sql .= ' B.CREOLE$ROWNUM <= ' . $limit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the native Oracle Error Message as a string.
|
||||
*
|
||||
* @param string $msg The Internal Error Message
|
||||
* @param mixed $errno The Oracle Error resource
|
||||
*/
|
||||
public function nativeError( $result = null )
|
||||
{
|
||||
if ( $result !== null )
|
||||
{
|
||||
$error = oci_error( $result );
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$error = oci_error( $this->dblink );
|
||||
}
|
||||
|
||||
return $error[ 'code' ] . ': ' . $error[ 'message' ];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see Connection::getDatabaseInfo()
|
||||
*/
|
||||
public function getDatabaseInfo()
|
||||
{
|
||||
require_once 'creole/drivers/oracle/metadata/OCI8DatabaseInfo.php';
|
||||
|
||||
return new OCI8DatabaseInfo( $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getIdGenerator()
|
||||
*/
|
||||
public function getIdGenerator()
|
||||
{
|
||||
require_once 'creole/drivers/oracle/OCI8IdGenerator.php';
|
||||
|
||||
return new OCI8IdGenerator( $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Oracle supports native prepared statements, but the oci_parse call
|
||||
* is actually called by the OCI8PreparedStatement class because
|
||||
* some additional SQL processing may be necessary ( e.g. to apply limit ).
|
||||
* @see OCI8PreparedStatement::executeQuery()
|
||||
* @see OCI8PreparedStatement::executeUpdate()
|
||||
* @see Connection::prepareStatement()
|
||||
*/
|
||||
public function prepareStatement( $sql )
|
||||
{
|
||||
require_once 'creole/drivers/oracle/OCI8PreparedStatement.php';
|
||||
|
||||
return new OCI8PreparedStatement( $this, $sql );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::prepareCall()
|
||||
*/
|
||||
public function prepareCall( $sql )
|
||||
{
|
||||
throw new SQLException( 'Oracle driver does not yet support stored procedures using CallableStatement.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::createStatement()
|
||||
*/
|
||||
public function createStatement()
|
||||
{
|
||||
require_once 'creole/drivers/oracle/OCI8Statement.php';
|
||||
|
||||
return new OCI8Statement( $this );
|
||||
}
|
||||
}
|
65
lib/symfony/vendor/creole/drivers/oracle/OCI8IdGenerator.php
vendored
Executable file
65
lib/symfony/vendor/creole/drivers/oracle/OCI8IdGenerator.php
vendored
Executable file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
require_once 'creole/IdGenerator.php';
|
||||
|
||||
/**
|
||||
* Oracle (OCI8) IdGenerator implimenation.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.5 $
|
||||
* @package creole.drivers.oracle
|
||||
*/
|
||||
class OCI8IdGenerator implements IdGenerator {
|
||||
|
||||
/** Connection object that instantiated this class */
|
||||
private $conn;
|
||||
|
||||
/**
|
||||
* Creates a new IdGenerator class, saves passed connection for use
|
||||
* later by getId() method.
|
||||
* @param Connection $conn
|
||||
*/
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isBeforeInsert()
|
||||
*/
|
||||
public function isBeforeInsert()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isAfterInsert()
|
||||
*/
|
||||
public function isAfterInsert()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::getIdMethod()
|
||||
*/
|
||||
public function getIdMethod()
|
||||
{
|
||||
return self::SEQUENCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::getId()
|
||||
*/
|
||||
public function getId($name = null)
|
||||
{
|
||||
if ($name === null) {
|
||||
throw new SQLException("You must specify the sequence name when calling getId() method.");
|
||||
}
|
||||
$rs = $this->conn->executeQuery("select " . $name . ".nextval from dual", ResultSet::FETCHMODE_NUM);
|
||||
$rs->next();
|
||||
return $rs->getInt(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
424
lib/symfony/vendor/creole/drivers/oracle/OCI8PreparedStatement.php
vendored
Executable file
424
lib/symfony/vendor/creole/drivers/oracle/OCI8PreparedStatement.php
vendored
Executable file
@ -0,0 +1,424 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: OCI8PreparedStatement.php,v 1.26 2006/01/30 21:32:05 sethr Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/PreparedStatement.php';
|
||||
require_once 'creole/common/PreparedStatementCommon.php';
|
||||
|
||||
/**
|
||||
* Oracle (OCI8) implementation of PreparedStatement.
|
||||
*
|
||||
* @author David Giffin <david@giffin.org>
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.26 $
|
||||
* @package creole.drivers.oracle
|
||||
*/
|
||||
class OCI8PreparedStatement extends PreparedStatementCommon implements PreparedStatement {
|
||||
|
||||
/**
|
||||
* Descriptor holders for LOB values.
|
||||
* There are other types of descriptors, but we need to keep
|
||||
* them separate, because we need to execute the save()/savefile() method
|
||||
* on lob descriptors.
|
||||
* @var array object from oci_new_descriptor
|
||||
*/
|
||||
private $lobDescriptors = array();
|
||||
|
||||
/**
|
||||
* Hold any Blob/Clob data.
|
||||
* These can be matched (by key) to descriptors in $lobDescriptors.
|
||||
* @var array Lob[]
|
||||
*/
|
||||
private $lobs = array();
|
||||
|
||||
/**
|
||||
* Array to store the columns in an insert or update statement.
|
||||
* This is necessary for the proper handling of lob variables
|
||||
* @var arrary columns[]
|
||||
*/
|
||||
private $columns = array();
|
||||
|
||||
/**
|
||||
* If the statement is set, free it.
|
||||
* @see PreparedStatement::close()
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
if (isset($this->stmt))
|
||||
@oci_free_statement($this->stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nothing to do - since oci_bind is used to insert data, no escaping is needed
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
protected function escape($str)
|
||||
{
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the SQL query in this PreparedStatement object and returns the resultset generated by the query.
|
||||
* @param mixed $p1 Either (array) Parameters that will be set using PreparedStatement::set() before query is executed or (int) fetchmode.
|
||||
* @param int $fetchmode The mode to use when fetching the results (e.g. ResultSet::FETCHMODE_NUM, ResultSet::FETCHMODE_ASSOC).
|
||||
* @return ResultSet
|
||||
* @throws SQLException if a database access error occurs.
|
||||
*/
|
||||
public function executeQuery($p1 = null, $fetchmode = null)
|
||||
{
|
||||
$params = null;
|
||||
if ($fetchmode !== null) {
|
||||
$params = $p1;
|
||||
} elseif ($p1 !== null) {
|
||||
if (is_array($p1)) $params = $p1;
|
||||
else $fetchmode = $p1;
|
||||
}
|
||||
|
||||
if ($params) {
|
||||
for($i=0,$cnt=count($params); $i < $cnt; $i++) {
|
||||
$this->set($i+1, $params[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->updateCount = null; // reset
|
||||
|
||||
$sql = $this->sqlToOracleBindVars($this->sql);
|
||||
|
||||
if ($this->limit > 0 || $this->offset > 0) {
|
||||
$this->conn->applyLimit($sql, $this->offset, $this->limit);
|
||||
}
|
||||
|
||||
$result = oci_parse($this->conn->getResource(), $sql);
|
||||
if (!$result) {
|
||||
throw new SQLException("Unable to prepare query", $this->conn->nativeError(), $this->sqlToOracleBindVars($this->sql));
|
||||
}
|
||||
|
||||
// bind all variables
|
||||
$this->bindVars($result);
|
||||
|
||||
$success = oci_execute($result, OCI_DEFAULT);
|
||||
if (!$success) {
|
||||
throw new SQLException("Unable to execute query", $this->conn->nativeError($result), $this->sqlToOracleBindVars($this->sql));
|
||||
}
|
||||
|
||||
$this->resultSet = new OCI8ResultSet($this->conn, $result, $fetchmode);
|
||||
|
||||
return $this->resultSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the SQL INSERT, UPDATE, or DELETE statement in this PreparedStatement object.
|
||||
*
|
||||
* @param array $params Parameters that will be set using PreparedStatement::set() before query is executed.
|
||||
* @return int Number of affected rows (or 0 for drivers that return nothing).
|
||||
* @throws SQLException if a database access error occurs.
|
||||
*/
|
||||
public function executeUpdate($params = null)
|
||||
{
|
||||
if ($params) {
|
||||
for($i=0,$cnt=count($params); $i < $cnt; $i++) {
|
||||
$this->set($i+1, $params[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
if($this->resultSet) $this->resultSet->close();
|
||||
$this->resultSet = null; // reset
|
||||
|
||||
$stmt = oci_parse($this->conn->getResource(), $this->sqlToOracleBindVars($this->sql));
|
||||
|
||||
if (!$stmt) {
|
||||
throw new SQLException("Unable to prepare update", $this->conn->nativeError(), $this->sqlToOracleBindVars($this->sql));
|
||||
}
|
||||
|
||||
// bind all variables
|
||||
$this->bindVars($stmt);
|
||||
|
||||
// Even if autocommit is on, delay commit until after LOBS have been saved
|
||||
$success = oci_execute($stmt, OCI_DEFAULT);
|
||||
if (!$success) {
|
||||
throw new SQLException("Unable to execute update", $this->conn->nativeError($stmt), $this->sqlToOracleBindVars($this->sql));
|
||||
}
|
||||
|
||||
// save data in any LOB descriptors, then free them
|
||||
foreach($this->lobDescriptors as $paramIndex => $lobster) {
|
||||
$lob = $this->lobs[$paramIndex]; // corresponding Blob/Clob
|
||||
if ($lob->isFromFile()) {
|
||||
$success = $lobster->savefile($lob->getInputFile());
|
||||
} else {
|
||||
$success = $lobster->save($lob->getContents());
|
||||
}
|
||||
if (!$success) {
|
||||
$lobster->free();
|
||||
throw new SQLException("Error saving lob bound to " . $paramIndex);
|
||||
}
|
||||
$lobster->free();
|
||||
}
|
||||
|
||||
if ($this->conn->getAutoCommit()) {
|
||||
oci_commit($this->conn->getResource()); // perform deferred commit
|
||||
}
|
||||
|
||||
$this->updateCount = @oci_num_rows($stmt);
|
||||
|
||||
return $this->updateCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the actual binding of variables using oci_bind_by_name().
|
||||
*
|
||||
* This may seem like useless overhead, but the reason why calls to oci_bind_by_name()
|
||||
* are not performed in the set*() methods is that it is possible that the SQL will
|
||||
* need to be modified -- e.g. by a setLimit() call -- and re-prepared. We cannot assume
|
||||
* that the statement has been prepared when the set*() calls are invoked. This also means,
|
||||
* therefore, that the set*() calls will not throw exceptions; all exceptions will be thrown
|
||||
* when the statement is prepared.
|
||||
*
|
||||
* @param resource $stmt The statement result of oci_parse to use for binding.
|
||||
* @return void
|
||||
*/
|
||||
private function bindVars($stmt)
|
||||
{
|
||||
foreach ($this->boundInVars as $idx => $val) {
|
||||
$idxName = ":var" . $idx;
|
||||
if (!oci_bind_by_name($stmt, $idxName, $this->boundInVars[$idx], -1)) {
|
||||
throw new SQLException("Erorr binding value to placeholder " . $idx);
|
||||
}
|
||||
} // foreach
|
||||
|
||||
foreach ($this->lobs as $idx => $val) {
|
||||
$idxName = ":var" . $idx;
|
||||
if (class_exists('Blob') && $val instanceof Blob){
|
||||
if (!oci_bind_by_name($stmt, $idxName, $this->lobDescriptors[$idx], -1, OCI_B_BLOB))
|
||||
throw new SQLException("Erorr binding blob to placeholder " . $idx);
|
||||
} elseif (class_exists('Clob') && $val instanceof Clob){
|
||||
if (!oci_bind_by_name($stmt, $idxName, $this->lobDescriptors[$idx], -1, OCI_B_CLOB))
|
||||
throw new SQLException("Erorr binding clob to placeholder " . $idx);
|
||||
}
|
||||
} // foreach
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a Propel SQL into Oracle SQL
|
||||
*
|
||||
* Look for all of the '?' and replace with ":varX"
|
||||
*
|
||||
* @param string $sql SQL in Propel native format
|
||||
* @return string SQL in Oracle Bind Var format
|
||||
* @todo -cOCI8PreparedStatement Consider changing this implementation to use the fact that we
|
||||
* already know where all the '?' chars are (in $positions array).
|
||||
*/
|
||||
private function sqlToOracleBindVars($sql)
|
||||
{
|
||||
$out = "";
|
||||
$in_literal = 0;
|
||||
$idxNum = 1;
|
||||
for ($i = 0; $i < strlen($sql); $i++) {
|
||||
$char = $sql[$i];
|
||||
if (strcmp($char,"'")==0) {
|
||||
$in_literal = ~$in_literal;
|
||||
}
|
||||
if (strcmp($char,"?")==0 && !$in_literal) {
|
||||
if (array_key_exists($idxNum, $this->lobs)){
|
||||
if (class_exists('Blob') && ($this->lobs[$idxNum] instanceof Blob))
|
||||
$out .= "empty_blob()";
|
||||
if (class_exists('Clob') && ($this->lobs[$idxNum] instanceof Clob))
|
||||
$out .= "empty_clob()";
|
||||
} else
|
||||
$out .= ":var" . $idxNum;
|
||||
$idxNum++;
|
||||
} else {
|
||||
$out .= $char;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->lobs) && !empty($this->lobs)) {
|
||||
$this->setColumnArray();
|
||||
|
||||
$retstmt = " Returning ";
|
||||
$collist = "";
|
||||
$bindlist = "";
|
||||
foreach ($this->lobs as $idx=>$val) {
|
||||
$idxName = ":var" . $idx;
|
||||
if ((class_exists('Blob') && $val instanceof Blob) || (class_exists('Clob') && $val instanceof Clob)) {
|
||||
//the columns array starts at zero instead of 1 like the lobs array
|
||||
$collist .= $this->columns[$idx-1] . ",";
|
||||
$bindlist .= $idxName . ",";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($collist))
|
||||
$out .= $retstmt . rtrim($collist, ",") . " into " . rtrim($bindlist, ",");
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $paramIndex
|
||||
* @param mixed $blob Blob object or string containing data.
|
||||
* @return void
|
||||
*/
|
||||
function setBlob($paramIndex, $blob)
|
||||
{
|
||||
require_once 'creole/util/Blob.php';
|
||||
if (!($blob instanceof Blob)) {
|
||||
$b = new Blob();
|
||||
$b->setContents($blob);
|
||||
$blob = $b;
|
||||
}
|
||||
$this->lobDescriptors[$paramIndex] = oci_new_descriptor($this->conn->getResource(), OCI_D_LOB);
|
||||
$this->lobs[$paramIndex] = $blob;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $paramIndex
|
||||
* @param mixed $clob Clob object or string containing data.
|
||||
* @return void
|
||||
*/
|
||||
function setClob($paramIndex, $clob)
|
||||
{
|
||||
require_once 'creole/util/Clob.php';
|
||||
if (!($clob instanceof Clob)) {
|
||||
$c = new Clob();
|
||||
$c->setContents($clob);
|
||||
$clob = $c;
|
||||
}
|
||||
$this->lobDescriptors[$paramIndex] = oci_new_descriptor($this->conn->getResource(), OCI_D_LOB);
|
||||
$this->lobs[$paramIndex] = $clob;
|
||||
}
|
||||
|
||||
/**
|
||||
* Since bind variables in oracle have no special characters, this setString method differs from the
|
||||
* common one in that it does not single quote strings.
|
||||
*
|
||||
* @param int $paramIndex
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
function setString($paramIndex, $value)
|
||||
{
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
// it's ok to have a fatal error here, IMO, if object doesn't have
|
||||
// __toString() and is being passed to this method.
|
||||
if ( is_object ( $value ) ) {
|
||||
$this->boundInVars[$paramIndex] = $value->__toString();
|
||||
} else {
|
||||
$this->boundInVars[$paramIndex] = (string)$value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied this function from common/PreparedStatement.php and modified to work with Oracle
|
||||
* Please note the format used with date() matches that of NLS_DATE_FORMAT set in
|
||||
* OCI8Connection.php
|
||||
*
|
||||
* @param int $paramIndex
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
function setTimestamp($paramIndex, $value)
|
||||
{
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
if (is_numeric($value)) $value = date('Y-m-d H:i:s', $value);
|
||||
elseif (is_object($value)) $value = date('Y-m-d H:i:s', $value->getTime());
|
||||
$this->boundInVars[$paramIndex] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Please note the format used with date() matches that of NLS_DATE_FORMAT set in
|
||||
* OCI8Connection.php
|
||||
*
|
||||
* @param int $paramIndex
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
function setDate($paramIndex, $value)
|
||||
{
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
if (is_numeric($value)) $value = date("Y-m-d", $value);
|
||||
elseif (is_object($value)) $value = date("Y-m-d", $value->getTime());
|
||||
$this->boundInVars[$paramIndex] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In order to send lob data (clob/blob) to the Oracle data base, the
|
||||
* sqlToOracleBindVars function needs to have an ordered list of the
|
||||
* columns being addressed in the sql statement.
|
||||
* Since only insert and update statements require special handling,
|
||||
* there are two ways to find the columns:
|
||||
* 1) find the first set of () and parse out the columns names based on
|
||||
* the token ','
|
||||
* 2) find all the text strings to the left of the equal signs.
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
private function setColumnArray()
|
||||
{
|
||||
$this->columns = array();
|
||||
|
||||
//handle the simple insert case first
|
||||
if(strtoupper(substr($this->sql, 0, 6)) == 'INSERT') {
|
||||
$firstPos = strpos($this->sql, '(');
|
||||
$secPos = strpos($this->sql, ')');
|
||||
$collist = substr($this->sql, $firstPos + 1, $secPos - $firstPos - 1);
|
||||
$this->columns = explode(',', $collist);
|
||||
}
|
||||
if (strtoupper(substr($this->sql, 0, 6)) == 'UPDATE') {
|
||||
//handle more complex update case
|
||||
//first get the string setup so we can explode based on '=?'
|
||||
//second split results from previous action based on ' '
|
||||
// the last token from this should be a column name
|
||||
$tmp = $this->sql;
|
||||
$tmp = str_replace(" =", "=", $this->sql);
|
||||
$tmp = str_replace("= ", "=", $tmp);
|
||||
$tmp = str_replace(",", " ", $tmp);
|
||||
$stage1 = explode("=?",$tmp);
|
||||
|
||||
foreach($stage1 as $chunk) {
|
||||
$stage2 = explode(' ', $chunk);
|
||||
$this->columns[count($this->columns)] = $stage2[count($stage2) - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $paramIndex
|
||||
* @return void
|
||||
*/
|
||||
function setNull($paramIndex)
|
||||
{
|
||||
$this->boundInVars[$paramIndex] = '';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
131
lib/symfony/vendor/creole/drivers/oracle/OCI8ResultSet.php
vendored
Executable file
131
lib/symfony/vendor/creole/drivers/oracle/OCI8ResultSet.php
vendored
Executable file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: OCI8ResultSet.php,v 1.13 2006/01/17 19:44:40 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/ResultSet.php';
|
||||
require_once 'creole/common/ResultSetCommon.php';
|
||||
|
||||
/**
|
||||
* Oracle (OCI8) implementation of ResultSet class.
|
||||
*
|
||||
* @author David Giffin <david@giffin.org>
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.13 $
|
||||
* @package creole.drivers.oracle
|
||||
*/
|
||||
class OCI8ResultSet extends ResultSetCommon implements ResultSet
|
||||
{
|
||||
/**
|
||||
* @see ResultSet::seek()
|
||||
*/
|
||||
function seek($rownum)
|
||||
{
|
||||
if ( $rownum < $this->cursorPos )
|
||||
{
|
||||
// this will effectively disable previous(), first() and some calls to relative() or absolute()
|
||||
throw new SQLException( 'Oracle ResultSet is FORWARD-ONLY' );
|
||||
}
|
||||
|
||||
// Oracle has no seek function imulate it here
|
||||
while ( $this->cursorPos < $rownum )
|
||||
{
|
||||
$this->next();
|
||||
}
|
||||
|
||||
$this->cursorPos = $rownum;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::next()
|
||||
*/
|
||||
function next()
|
||||
{
|
||||
// no specific result position available
|
||||
|
||||
// Returns an array, which corresponds to the next result row or FALSE
|
||||
// in case of error or there is no more rows in the result.
|
||||
$this->fields = oci_fetch_array( $this->result
|
||||
, $this->fetchmode
|
||||
+ OCI_RETURN_NULLS
|
||||
+ OCI_RETURN_LOBS
|
||||
);
|
||||
|
||||
if ( ! $this->fields )
|
||||
{
|
||||
// grab error via array
|
||||
$error = oci_error( $this->result );
|
||||
|
||||
if ( ! $error )
|
||||
{
|
||||
// end of recordset
|
||||
$this->afterLast();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
throw new SQLException( 'Error fetching result'
|
||||
, $error[ 'code' ] . ': ' . $error[ 'message' ]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Oracle returns all field names in uppercase and associative indices
|
||||
// in the result array will be uppercased too.
|
||||
if ($this->fetchmode === ResultSet::FETCHMODE_ASSOC && $this->lowerAssocCase)
|
||||
{
|
||||
$this->fields = array_change_key_case($this->fields, CASE_LOWER);
|
||||
}
|
||||
|
||||
// Advance cursor position
|
||||
$this->cursorPos++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::getRecordCount()
|
||||
*/
|
||||
function getRecordCount()
|
||||
{
|
||||
$rows = oci_num_rows( $this->result );
|
||||
|
||||
if ( $rows === false )
|
||||
{
|
||||
throw new SQLException( 'Error fetching num rows'
|
||||
, $this->conn->nativeError( $this->result )
|
||||
);
|
||||
}
|
||||
|
||||
return ( int ) $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::close()
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
$this->fields = array();
|
||||
@oci_free_statement( $this->result );
|
||||
}
|
||||
}
|
34
lib/symfony/vendor/creole/drivers/oracle/OCI8Statement.php
vendored
Executable file
34
lib/symfony/vendor/creole/drivers/oracle/OCI8Statement.php
vendored
Executable file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: OCI8Statement.php,v 1.2 2004/03/05 15:46:12 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/Statement.php';
|
||||
require_once 'creole/common/StatementCommon.php';
|
||||
|
||||
/**
|
||||
* Oracle (OCI8) Statement implementation.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.2 $
|
||||
* @package creole.drivers.oracle
|
||||
*/
|
||||
class OCI8Statement extends StatementCommon implements Statement {
|
||||
|
||||
}
|
90
lib/symfony/vendor/creole/drivers/oracle/OCI8Types.php
vendored
Executable file
90
lib/symfony/vendor/creole/drivers/oracle/OCI8Types.php
vendored
Executable file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* $Id: OCI8Types.php,v 1.8 2004/03/20 04:16:50 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/CreoleTypes.php';
|
||||
|
||||
/**
|
||||
* Oracle types / type map.
|
||||
*
|
||||
* @author David Giffin <david@giffin.org>
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.8 $
|
||||
* @package creole.drivers.oracle
|
||||
*/
|
||||
class OCI8Types extends CreoleTypes {
|
||||
|
||||
/** Map Oracle native types to Creole (JDBC) types. */
|
||||
private static $typeMap = array(
|
||||
'char' => CreoleTypes::CHAR,
|
||||
'varchar2' => CreoleTypes::VARCHAR,
|
||||
'long' => CreoleTypes::LONGVARCHAR,
|
||||
'number' => CreoleTypes::NUMERIC,
|
||||
'float' => CreoleTypes::FLOAT,
|
||||
'integer' => CreoleTypes::INTEGER,
|
||||
'smallint' => CreoleTypes::SMALLINT,
|
||||
'double' => CreoleTypes::DOUBLE,
|
||||
'raw' => CreoleTypes::VARBINARY,
|
||||
'longraw' => CreoleTypes::LONGVARBINARY,
|
||||
'date' => CreoleTypes::DATE,
|
||||
'timestamp' => CreoleTypes::TIMESTAMP,
|
||||
'blob' => CreoleTypes::BLOB,
|
||||
'clob' => CreoleTypes::CLOB,
|
||||
'varray' => CreoleTypes::ARR,
|
||||
);
|
||||
|
||||
/** Reverse mapping, created on demand. */
|
||||
private static $reverseMap = null;
|
||||
|
||||
/**
|
||||
* This method returns the generic Creole (JDBC-like) type
|
||||
* when given the native db type.
|
||||
* @param string $nativeType DB native type (e.g. 'TEXT', 'byetea', etc.).
|
||||
* @return int Creole native type (e.g. CreoleTypes::LONGVARCHAR, CreoleTypes::BINARY, etc.).
|
||||
*/
|
||||
public static function getType($nativeType)
|
||||
{
|
||||
$t = str_replace(' ', '', strtolower($nativeType));
|
||||
if ( substr($t, 0, 9) == 'timestamp' ) return CreoleTypes::TIMESTAMP;
|
||||
if (isset(self::$typeMap[$t])) {
|
||||
return self::$typeMap[$t];
|
||||
} else {
|
||||
return CreoleTypes::OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will return a native type that corresponds to the specified
|
||||
* Creole (JDBC-like) type.
|
||||
* If there is more than one matching native type, then the LAST defined
|
||||
* native type will be returned.
|
||||
* @param int $creoleType
|
||||
* @return string Native type string.
|
||||
*/
|
||||
public static function getNativeType($creoleType)
|
||||
{
|
||||
if (self::$reverseMap === null) {
|
||||
self::$reverseMap = array_flip(self::$typeMap);
|
||||
}
|
||||
return @self::$reverseMap[$creoleType];
|
||||
}
|
||||
|
||||
}
|
90
lib/symfony/vendor/creole/drivers/oracle/metadata/OCI8DatabaseInfo.php
vendored
Executable file
90
lib/symfony/vendor/creole/drivers/oracle/metadata/OCI8DatabaseInfo.php
vendored
Executable file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: OCI8DatabaseInfo.php,v 1.11 2006/01/17 19:44:40 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/DatabaseInfo.php';
|
||||
|
||||
/**
|
||||
* Oracle (OCI8) implementation of DatabaseInfo.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.11 $
|
||||
* @package creole.drivers.oracle.metadata
|
||||
*/
|
||||
class OCI8DatabaseInfo extends DatabaseInfo {
|
||||
|
||||
private $schema;
|
||||
|
||||
public function __construct(Connection $conn) {
|
||||
parent::__construct($conn);
|
||||
|
||||
$dsn = $conn->getDSN();
|
||||
|
||||
if (isset($dsn['schema'])) {
|
||||
$this->schema = $dsn['schema'];
|
||||
} else {
|
||||
// For Changing DB/Schema in Meta Data Interface
|
||||
$this->schema = $dsn['username'];
|
||||
}
|
||||
|
||||
$this->schema = strtoupper( $this->schema );
|
||||
}
|
||||
|
||||
public function getSchema() {
|
||||
return $this->schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function initTables()
|
||||
{
|
||||
include_once 'creole/drivers/oracle/metadata/OCI8TableInfo.php';
|
||||
|
||||
$sql = "SELECT table_name
|
||||
FROM all_tables
|
||||
WHERE owner = '{$this->schema}'";
|
||||
|
||||
$statement = @oci_parse($this->conn->getResource(),$sql);
|
||||
|
||||
$success = @oci_execute($statement,OCI_DEFAULT);
|
||||
if (!$success) {
|
||||
throw new SQLException("Could not get tables", $this->conn->getResource()->nativeError($statement));
|
||||
}
|
||||
while ( $statement && $row = oci_fetch_assoc( $statement ) )
|
||||
{
|
||||
$row = array_change_key_case($row,CASE_LOWER);
|
||||
$this->tables[strtoupper($row['table_name'])] = new OCI8TableInfo($this,$row['table_name']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Oracle supports sequences.
|
||||
*
|
||||
* @return void
|
||||
* @throws SQLException
|
||||
*/
|
||||
protected function initSequences()
|
||||
{
|
||||
// throw new SQLException("MySQL does not support sequences natively.");
|
||||
}
|
||||
|
||||
}
|
273
lib/symfony/vendor/creole/drivers/oracle/metadata/OCI8TableInfo.php
vendored
Executable file
273
lib/symfony/vendor/creole/drivers/oracle/metadata/OCI8TableInfo.php
vendored
Executable file
@ -0,0 +1,273 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: OCI8TableInfo.php,v 1.13 2006/01/06 00:02:38 sethr Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/TableInfo.php';
|
||||
|
||||
/**
|
||||
* Oracle (OCI8) implementation of TableInfo.
|
||||
*
|
||||
* @author David Giffin <david@giffin.org>
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision$
|
||||
* @package creole.drivers.oracle.metadata
|
||||
*/
|
||||
class OCI8TableInfo extends TableInfo {
|
||||
|
||||
private $schema;
|
||||
|
||||
public function __construct(OCI8DatabaseInfo $database, $name)
|
||||
{
|
||||
$this->schema = strtoupper( $database->getSchema() );
|
||||
parent::__construct($database, $name);
|
||||
$this->name = strtoupper( $this->name );
|
||||
}
|
||||
|
||||
/** Loads the columns for this table. */
|
||||
protected function initColumns()
|
||||
{
|
||||
|
||||
include_once 'creole/metadata/ColumnInfo.php';
|
||||
include_once 'creole/drivers/oracle/OCI8Types.php';
|
||||
|
||||
|
||||
// To get all of the attributes we need, we'll actually do
|
||||
// two separate queries. The first gets names and default values
|
||||
// the second will fill in some more details.
|
||||
|
||||
$sql = "
|
||||
SELECT column_name
|
||||
, data_type
|
||||
, data_precision
|
||||
, data_length
|
||||
, data_default
|
||||
, nullable
|
||||
, data_scale
|
||||
FROM all_tab_columns
|
||||
WHERE table_name = '{$this->name}'
|
||||
AND OWNER = '{$this->schema}'";
|
||||
|
||||
$statement = @oci_parse($this->conn->getResource(),$sql);
|
||||
$success = @oci_execute($statement,OCI_DEFAULT);
|
||||
if (!$success) {
|
||||
throw new SQLException("Could Not Get Columns");
|
||||
}
|
||||
|
||||
while ( $statement && $row = oci_fetch_array( $statement
|
||||
, OCI_ASSOC + OCI_RETURN_NULLS ) ) {
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
$this->columns[$row['column_name']] = new ColumnInfo( $this
|
||||
, $row['column_name']
|
||||
, OCI8Types::getType($row['data_type'])
|
||||
, $row['data_type']
|
||||
, $row['data_length']
|
||||
, $row['data_precision']
|
||||
, $row['data_scale']
|
||||
, $row['nullable']
|
||||
, $row['data_default']
|
||||
);
|
||||
}
|
||||
|
||||
$this->colsLoaded = true;
|
||||
}
|
||||
|
||||
/** Loads the primary key information for this table. */
|
||||
protected function initPrimaryKey()
|
||||
{
|
||||
include_once 'creole/metadata/PrimaryKeyInfo.php';
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
|
||||
|
||||
// Primary Keys Query
|
||||
$sql = "SELECT a.owner, a.table_name,
|
||||
a.constraint_name, a.column_name
|
||||
FROM all_cons_columns a, all_constraints b
|
||||
WHERE b.constraint_type = 'P'
|
||||
AND a.constraint_name = b.constraint_name
|
||||
AND b.table_name = '{$this->name}'
|
||||
AND b.owner = '{$this->schema}'
|
||||
";
|
||||
|
||||
|
||||
$statement = @oci_parse($this->conn->getResource(),$sql);
|
||||
$success = @oci_execute($statement,OCI_DEFAULT);
|
||||
if (!$success) {
|
||||
throw new SQLException("Could Not Get Primary Keys");
|
||||
}
|
||||
|
||||
while ( $statement && $row = oci_fetch_assoc( $statement )) {
|
||||
$row = array_change_key_case($row,CASE_LOWER);
|
||||
|
||||
$name = $row['column_name'];
|
||||
|
||||
if (!isset($this->primaryKey)) {
|
||||
$this->primaryKey = new PrimaryKeyInfo($name);
|
||||
}
|
||||
|
||||
$this->primaryKey->addColumn($this->columns[$name]);
|
||||
}
|
||||
|
||||
$this->pkLoaded = true;
|
||||
}
|
||||
|
||||
/** Loads the indexes for this table. */
|
||||
protected function initIndexes() {
|
||||
|
||||
include_once 'creole/metadata/IndexInfo.php';
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
|
||||
// Indexes
|
||||
$sql = "SELECT
|
||||
allind.index_name,
|
||||
allind.table_name,
|
||||
allind.index_type,
|
||||
allind.uniqueness,
|
||||
indcol.column_name
|
||||
FROM all_indexes allind INNER JOIN all_ind_columns indcol
|
||||
ON allind.owner = indcol.index_owner
|
||||
AND allind.index_name = indcol.index_name
|
||||
WHERE allind.table_owner = '{$this->schema}'
|
||||
AND allind.table_name = '{$this->name}'
|
||||
AND allind.index_name NOT IN (SELECT
|
||||
constraint_name
|
||||
FROM all_constraints
|
||||
WHERE constraint_type = 'P')
|
||||
ORDER BY allind.index_name,
|
||||
indcol.column_position";
|
||||
|
||||
$statement = @oci_parse($this->conn->getResource(),$sql);
|
||||
$success = @oci_execute($statement,OCI_DEFAULT);
|
||||
if (!$success) {
|
||||
throw new SQLException("Could Not Get Primary Keys");
|
||||
}
|
||||
|
||||
|
||||
// Loop through the returned results, grouping the same key_name together
|
||||
// adding each column for that key.
|
||||
|
||||
while ( $statement && $row = oci_fetch_assoc( $statement )) {
|
||||
$row = array_change_key_case($row,CASE_LOWER);
|
||||
|
||||
$name = $row['index_name'];
|
||||
$index_col_name = $row['column_name'];
|
||||
|
||||
if (!isset($this->indexes[$name])) {
|
||||
$this->indexes[$name] = new IndexInfo($name);
|
||||
}
|
||||
|
||||
$this->indexes[$name]->addColumn($this->columns[ $index_col_name ]);
|
||||
}
|
||||
|
||||
|
||||
$this->indexesLoaded = true;
|
||||
}
|
||||
|
||||
/** Load foreign keys */
|
||||
protected function initForeignKeys() {
|
||||
|
||||
include_once 'creole/metadata/ForeignKeyInfo.php';
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
|
||||
// Foreign keys
|
||||
// TODO resolve cross schema references
|
||||
// use all_cons... to do so, however, very slow queries then
|
||||
// optimizations are very ugly
|
||||
$sql = "
|
||||
SELECT a.owner AS local_owner
|
||||
, a.table_name AS local_table
|
||||
, c.column_name AS local_column
|
||||
, a.constraint_name AS foreign_key_name
|
||||
, b.owner AS foreign_owner
|
||||
, b.table_name AS foreign_table
|
||||
, d.column_name AS foreign_column
|
||||
, b.constraint_name AS foreign_constraint_name
|
||||
, a.delete_rule AS on_delete
|
||||
FROM user_constraints a
|
||||
, user_constraints b
|
||||
, user_cons_columns c
|
||||
, user_cons_columns d
|
||||
WHERE a.r_constraint_name = b.constraint_name
|
||||
AND c.constraint_name = a.constraint_name
|
||||
AND d.constraint_name = b.constraint_name
|
||||
AND a.r_owner = b.owner
|
||||
AND a.constraint_type='R'
|
||||
AND a.table_name = '{$this->name}'
|
||||
AND a.owner = '{$this->schema}'
|
||||
";
|
||||
|
||||
$statement = @oci_parse($this->conn->getResource(),$sql);
|
||||
$success = @oci_execute($statement,OCI_DEFAULT);
|
||||
if (!$success) {
|
||||
throw new SQLException("Could Not Get Primary Keys");
|
||||
}
|
||||
|
||||
// Loop through the returned results, grouping the same key_name
|
||||
// together adding each column for that key.
|
||||
|
||||
while ( $statement && $row = oci_fetch_assoc( $statement )) {
|
||||
$row = array_change_key_case($row,CASE_LOWER);
|
||||
|
||||
$name = $row['foreign_key_name'];
|
||||
|
||||
$foreignTable = $this->database->getTable($row['foreign_table']);
|
||||
$foreignColumn = $foreignTable->getColumn($row['foreign_column']);
|
||||
|
||||
$localTable = $this->database->getTable($row['local_table']);
|
||||
$localColumn = $localTable->getColumn($row['local_column']);
|
||||
|
||||
if (!isset($this->foreignKeys[$name])) {
|
||||
$this->foreignKeys[$name] = new ForeignKeyInfo($name);
|
||||
}
|
||||
|
||||
switch ( $row[ 'on_delete' ] )
|
||||
{
|
||||
case 'CASCADE':
|
||||
$onDelete = ForeignKeyInfo::CASCADE;
|
||||
break;
|
||||
|
||||
case 'SET NULL':
|
||||
$onDelete = ForeignKeyInfo::SETNULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
case 'NO ACTION':
|
||||
$onDelete = ForeignKeyInfo::NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
// addReference( local, foreign, onDelete, onUpdate )
|
||||
// Oracle doesn't support 'on update'
|
||||
$this->foreignKeys[ $name ]->addReference(
|
||||
$localColumn
|
||||
, $foreignColumn
|
||||
, $onDelete
|
||||
);
|
||||
}
|
||||
|
||||
$this->fksLoaded = true;
|
||||
}
|
||||
|
||||
}
|
260
lib/symfony/vendor/creole/drivers/pgsql/PgSQLConnection.php
vendored
Executable file
260
lib/symfony/vendor/creole/drivers/pgsql/PgSQLConnection.php
vendored
Executable file
@ -0,0 +1,260 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: PgSQLConnection.php,v 1.21 2005/08/03 17:56:22 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/Connection.php';
|
||||
require_once 'creole/common/ConnectionCommon.php';
|
||||
include_once 'creole/drivers/pgsql/PgSQLResultSet.php';
|
||||
|
||||
/**
|
||||
* PgSQL implementation of Connection.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org> (Creole)
|
||||
* @author Stig Bakken <ssb@fast.no> (PEAR::DB)
|
||||
* @author Lukas Smith (PEAR::MDB)
|
||||
* @version $Revision: 1.21 $
|
||||
* @package creole.drivers.pgsql
|
||||
*/
|
||||
class PgSQLConnection extends ConnectionCommon implements Connection {
|
||||
|
||||
/**
|
||||
* Affected Rows of last executed query.
|
||||
* Postgres needs this for getUpdateCount()
|
||||
* We used to store the entire result set
|
||||
* instead but that can be a large dataset.
|
||||
* @var int
|
||||
*/
|
||||
private $result_affected_rows;
|
||||
|
||||
/**
|
||||
* Connect to a database and log in as the specified user.
|
||||
*
|
||||
* @param array $dsn The datasource hash.
|
||||
* @param $flags Any connection flags.
|
||||
* @access public
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
function connect($dsninfo, $flags = 0)
|
||||
{
|
||||
global $php_errormsg;
|
||||
|
||||
if (!extension_loaded('pgsql')) {
|
||||
throw new SQLException('pgsql extension not loaded');
|
||||
}
|
||||
|
||||
$this->dsn = $dsninfo;
|
||||
$this->flags = $flags;
|
||||
|
||||
$persistent = ($flags & Creole::PERSISTENT === Creole::PERSISTENT);
|
||||
|
||||
$protocol = (isset($dsninfo['protocol'])) ? $dsninfo['protocol'] : 'tcp';
|
||||
$connstr = '';
|
||||
|
||||
if ($protocol == 'tcp') {
|
||||
if (!empty($dsninfo['hostspec'])) {
|
||||
$connstr = 'host=' . $dsninfo['hostspec'];
|
||||
}
|
||||
if (!empty($dsninfo['port'])) {
|
||||
$connstr .= ' port=' . $dsninfo['port'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($dsninfo['database'])) {
|
||||
$connstr .= ' dbname=\'' . addslashes($dsninfo['database']) . '\'';
|
||||
}
|
||||
if (!empty($dsninfo['username'])) {
|
||||
$connstr .= ' user=\'' . addslashes($dsninfo['username']) . '\'';
|
||||
}
|
||||
if (!empty($dsninfo['password'])) {
|
||||
$connstr .= ' password=\'' . addslashes($dsninfo['password']) . '\'';
|
||||
}
|
||||
if (!empty($dsninfo['options'])) {
|
||||
$connstr .= ' options=' . $dsninfo['options'];
|
||||
}
|
||||
if (!empty($dsninfo['tty'])) {
|
||||
$connstr .= ' tty=' . $dsninfo['tty'];
|
||||
}
|
||||
|
||||
if ($persistent) {
|
||||
$conn = @pg_pconnect($connstr);
|
||||
} else {
|
||||
$conn = @pg_connect($connstr);
|
||||
}
|
||||
|
||||
if (!$conn) {
|
||||
// hide the password from connstr
|
||||
$cleanconnstr = preg_replace('/password=\'.*?\'($|\s)/', 'password=\'*********\'', $connstr);
|
||||
throw new SQLException('Could not connect', $php_errormsg, $cleanconnstr);
|
||||
}
|
||||
|
||||
$this->dblink = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::applyLimit()
|
||||
*/
|
||||
public function applyLimit(&$sql, $offset, $limit)
|
||||
{
|
||||
if ( $limit > 0 ) {
|
||||
$sql .= " LIMIT ".$limit;
|
||||
}
|
||||
if ( $offset > 0 ) {
|
||||
$sql .= " OFFSET ".$offset;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::disconnect()
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
$ret = @pg_close($this->dblink);
|
||||
$this->result_affected_rows = null;
|
||||
$this->dblink = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::simpleQuery()
|
||||
*/
|
||||
function executeQuery($sql, $fetchmode = null)
|
||||
{
|
||||
$result = @pg_query($this->dblink, $sql);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute query', pg_last_error($this->dblink), $sql);
|
||||
}
|
||||
$this->result_affected_rows = (int) @pg_affected_rows($result);
|
||||
|
||||
return new PgSQLResultSet($this, $result, $fetchmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::simpleUpdate()
|
||||
*/
|
||||
function executeUpdate($sql)
|
||||
{
|
||||
$result = @pg_query($this->dblink, $sql);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute update', pg_last_error($this->dblink), $sql);
|
||||
}
|
||||
$this->result_affected_rows = (int) @pg_affected_rows($result);
|
||||
|
||||
return $this->result_affected_rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a database transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function beginTrans()
|
||||
{
|
||||
$result = @pg_query($this->dblink, "BEGIN");
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not begin transaction', pg_last_error($this->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function commitTrans()
|
||||
{
|
||||
$result = @pg_query($this->dblink, "COMMIT");
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not commit transaction', pg_last_error($this->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll back (undo) the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function rollbackTrans()
|
||||
{
|
||||
$result = @pg_query($this->dblink, "ROLLBACK");
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not rollback transaction', pg_last_error($this->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by the data manipulation
|
||||
* query.
|
||||
* @see Statement::getUpdateCount()
|
||||
* @return int Number of rows affected by the last query.
|
||||
*/
|
||||
function getUpdateCount()
|
||||
{
|
||||
if ( $this->result_affected_rows === null ) {
|
||||
throw new SQLException('getUpdateCount called before any sql queries were executed');
|
||||
}
|
||||
return $this->result_affected_rows;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see Connection::getDatabaseInfo()
|
||||
*/
|
||||
public function getDatabaseInfo()
|
||||
{
|
||||
require_once 'creole/drivers/pgsql/metadata/PgSQLDatabaseInfo.php';
|
||||
return new PgSQLDatabaseInfo($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getIdGenerator()
|
||||
*/
|
||||
public function getIdGenerator()
|
||||
{
|
||||
require_once 'creole/drivers/pgsql/PgSQLIdGenerator.php';
|
||||
return new PgSQLIdGenerator($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::prepareStatement()
|
||||
*/
|
||||
public function prepareStatement($sql)
|
||||
{
|
||||
require_once 'creole/drivers/pgsql/PgSQLPreparedStatement.php';
|
||||
return new PgSQLPreparedStatement($this, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::prepareCall()
|
||||
*/
|
||||
public function prepareCall($sql) {
|
||||
throw new SQLException('PostgreSQL does not support stored procedures.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::createStatement()
|
||||
*/
|
||||
public function createStatement()
|
||||
{
|
||||
require_once 'creole/drivers/pgsql/PgSQLStatement.php';
|
||||
return new PgSQLStatement($this);
|
||||
}
|
||||
|
||||
}
|
84
lib/symfony/vendor/creole/drivers/pgsql/PgSQLIdGenerator.php
vendored
Executable file
84
lib/symfony/vendor/creole/drivers/pgsql/PgSQLIdGenerator.php
vendored
Executable file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: PgSQLIdGenerator.php,v 1.5 2004/03/19 14:19:50 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/IdGenerator.php';
|
||||
|
||||
/**
|
||||
* PostgreSQL IdGenerator implemenation.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.5 $
|
||||
* @package creole.drivers.pgsql
|
||||
*/
|
||||
class PgSQLIdGenerator implements IdGenerator {
|
||||
|
||||
/** Connection object that instantiated this class */
|
||||
private $conn;
|
||||
|
||||
/**
|
||||
* Creates a new IdGenerator class, saves passed connection for use
|
||||
* later by getId() method.
|
||||
* @param Connection $conn
|
||||
*/
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isBeforeInsert()
|
||||
*/
|
||||
public function isBeforeInsert()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isAfterInsert()
|
||||
*/
|
||||
public function isAfterInsert()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::getIdMethod()
|
||||
*/
|
||||
public function getIdMethod()
|
||||
{
|
||||
return self::SEQUENCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::getId()
|
||||
*/
|
||||
public function getId($name = null)
|
||||
{
|
||||
if ($name === null) {
|
||||
throw new SQLException("You must specify the sequence name when calling getId() method.");
|
||||
}
|
||||
$rs = $this->conn->executeQuery("SELECT nextval('" . pg_escape_string ( $name ) . "')", ResultSet::FETCHMODE_NUM);
|
||||
$rs->next();
|
||||
return $rs->getInt(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
157
lib/symfony/vendor/creole/drivers/pgsql/PgSQLPreparedStatement.php
vendored
Executable file
157
lib/symfony/vendor/creole/drivers/pgsql/PgSQLPreparedStatement.php
vendored
Executable file
@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: PgSQLPreparedStatement.php,v 1.14 2005/04/16 18:55:28 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/PreparedStatement.php';
|
||||
require_once 'creole/common/PreparedStatementCommon.php';
|
||||
|
||||
/**
|
||||
* PgSQL subclass for prepared statements.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.14 $
|
||||
* @package creole.drivers.pgsql
|
||||
*/
|
||||
class PgSQLPreparedStatement extends PreparedStatementCommon implements PreparedStatement {
|
||||
|
||||
/**
|
||||
* Quotes string using native pgsql function (pg_escape_string).
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
protected function escape($str)
|
||||
{
|
||||
return pg_escape_string($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive function to turn multi-dim array into str representation.
|
||||
* @param array $arr
|
||||
* @return string Array in pgsql-friendly string notation: {val1, val2} or {{sub1,sub2}, {sub3, sub4}}
|
||||
*/
|
||||
private function arrayToStr($arr)
|
||||
{
|
||||
$parts = array();
|
||||
foreach((array)$arr as $el) {
|
||||
if (is_array($el)) {
|
||||
$parts[] = $this->arrayToStr($el);
|
||||
} else {
|
||||
if (is_string($el)) {
|
||||
$parts[] = '"' . $this->escape($el) . '"';
|
||||
} else {
|
||||
$parts[] = $el;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '{' . implode(',', $parts) . '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an array.
|
||||
* Unless a driver-specific method is used, this means simply serializing
|
||||
* the passed parameter and storing it as a string.
|
||||
* @param int $paramIndex
|
||||
* @param array $value
|
||||
* @return void
|
||||
* @see PreparedStatement::setArray()
|
||||
*/
|
||||
function setArray($paramIndex, $value)
|
||||
{
|
||||
if( $paramIndex > $this->positionsCount || $paramIndex < 1) {
|
||||
throw new SQLException('Cannot bind to invalid param index: '.$paramIndex);
|
||||
}
|
||||
if ($value === null)
|
||||
$this->setNull($paramIndex);
|
||||
else
|
||||
$this->boundInVars[$paramIndex] = "'" . $this->arrayToStr($value) . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* For setting value of Postgres BOOLEAN column.
|
||||
* @param int $paramIndex
|
||||
* @param boolean $value
|
||||
* @return void
|
||||
*/
|
||||
function setBoolean($paramIndex, $value)
|
||||
{
|
||||
if( $paramIndex > $this->positionsCount || $paramIndex < 1) {
|
||||
throw new SQLException('Cannot bind to invalid param index: '.$paramIndex);
|
||||
}
|
||||
if ($value === null)
|
||||
$this->setNull($paramIndex);
|
||||
else
|
||||
$this->boundInVars[$paramIndex] = ($value ? "'t'" : "'f'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies sqlite_udf_encode_binary() to ensure that binary contents will be handled correctly by sqlite.
|
||||
* @param int $paramIndex
|
||||
* @param mixed $blob Blob object or string containing data.
|
||||
* @return void
|
||||
*/
|
||||
function setBlob($paramIndex, $blob)
|
||||
{
|
||||
if ($blob === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
// they took magic __toString() out of PHP5.0.0; this sucks
|
||||
if (is_object($blob)) {
|
||||
$blob = $blob->__toString();
|
||||
}
|
||||
$this->boundInVars[$paramIndex] = "'" . pg_escape_bytea( $blob ) . "'";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $paramIndex
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
function setTime($paramIndex, $value)
|
||||
{
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
if ( is_numeric ( $value ) ) {
|
||||
$value = date ( "H:i:s O", $value );
|
||||
} elseif ( is_object ( $value ) ) {
|
||||
$value = date ( "H:i:s O", $value->getTime ( ) );
|
||||
}
|
||||
$this->boundInVars [ $paramIndex ] = "'" . $this->escape ( $value ) . "'";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $paramIndex
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
function setTimestamp($paramIndex, $value)
|
||||
{
|
||||
if ($value === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
if (is_numeric($value)) $value = date('Y-m-d H:i:s O', $value);
|
||||
elseif (is_object($value)) $value = date("Y-m-d H:i:s O", $value->getTime());
|
||||
$this->boundInVars[$paramIndex] = "'".$this->escape($value)."'";
|
||||
}
|
||||
}
|
||||
}
|
205
lib/symfony/vendor/creole/drivers/pgsql/PgSQLResultSet.php
vendored
Executable file
205
lib/symfony/vendor/creole/drivers/pgsql/PgSQLResultSet.php
vendored
Executable file
@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: PgSQLResultSet.php,v 1.31 2006/01/17 19:44:40 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/ResultSet.php';
|
||||
require_once 'creole/common/ResultSetCommon.php';
|
||||
|
||||
/**
|
||||
* PostgreSQL implementation of ResultSet.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.31 $
|
||||
* @package creole.drivers.pgsql
|
||||
*/
|
||||
class PgSQLResultSet extends ResultSetCommon implements ResultSet {
|
||||
|
||||
|
||||
/**
|
||||
* Gets optimized PgSQLResultSetIterator.
|
||||
* @return PgSQLResultSetIterator
|
||||
*/
|
||||
/*
|
||||
public function getIterator()
|
||||
{
|
||||
require_once 'creole/drivers/pgsql/PgSQLResultSetIterator.php';
|
||||
return new PgSQLResultSetIterator($this);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Postgres doesn't actually move the db pointer. The specific row
|
||||
* is fetched by call to pg_fetch_array() rather than by a seek and
|
||||
* then an unspecified pg_fetch_array() call.
|
||||
*
|
||||
* The only side-effect of this situation is that we don't really know
|
||||
* if the seek will fail or succeed until we have called next(). This
|
||||
* behavior is acceptible - and explicitly documented in
|
||||
* ResultSet::seek() phpdoc.
|
||||
*
|
||||
* @see ResultSet::seek()
|
||||
*/
|
||||
public function seek($rownum)
|
||||
{
|
||||
if ($rownum < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// PostgreSQL rows start w/ 0, but this works, because we are
|
||||
// looking to move the position _before_ the next desired position
|
||||
$this->cursorPos = $rownum;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::next()
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
|
||||
$this->fields = @pg_fetch_array($this->result, $this->cursorPos, $this->fetchmode);
|
||||
|
||||
if (!$this->fields) {
|
||||
$err = @pg_result_error($this->result);
|
||||
if (!$err) {
|
||||
// We've advanced beyond end of recordset.
|
||||
$this->afterLast();
|
||||
return false;
|
||||
} else {
|
||||
throw new SQLException("Error fetching result", $err);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->fetchmode === ResultSet::FETCHMODE_ASSOC && $this->lowerAssocCase) {
|
||||
$this->fields = array_change_key_case($this->fields, CASE_LOWER);
|
||||
}
|
||||
// Advance cursor position
|
||||
$this->cursorPos++;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::getRecordCount()
|
||||
*/
|
||||
public function getRecordCount()
|
||||
{
|
||||
$rows = @pg_num_rows($this->result);
|
||||
if ($rows === null) {
|
||||
throw new SQLException("Error fetching num rows", pg_result_error($this->result));
|
||||
}
|
||||
return (int) $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::close()
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$this->fields = array();
|
||||
@pg_free_result($this->result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Postgres string representation of array into native PHP array.
|
||||
* @param string $str Postgres string array rep: {1223, 2343} or {{"welcome", "home"}, {"test2", ""}}
|
||||
* @return array
|
||||
*/
|
||||
private function strToArray($str)
|
||||
{
|
||||
$str = substr($str, 1, -1); // remove { }
|
||||
$res = array();
|
||||
|
||||
$subarr = array();
|
||||
$in_subarr = 0;
|
||||
|
||||
$toks = explode(',', $str);
|
||||
foreach($toks as $tok) {
|
||||
if ($in_subarr > 0) { // already in sub-array?
|
||||
$subarr[$in_subarr][] = $tok;
|
||||
if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component
|
||||
$res[] = $this->strToArray(implode(',', $subarr[$in_subarr]));
|
||||
$in_subarr--;
|
||||
}
|
||||
} elseif ($tok{0} === '{') { // we're inside a new sub-array
|
||||
if ('}' !== substr($tok, -1, 1)) {
|
||||
$in_subarr++;
|
||||
// if sub-array has more than one element
|
||||
$subarr[$in_subarr] = array();
|
||||
$subarr[$in_subarr][] = $tok;
|
||||
} else {
|
||||
$res[] = $this->strToArray($tok);
|
||||
}
|
||||
} else { // not sub-array
|
||||
$val = trim($tok, '"'); // remove " (surrounding strings)
|
||||
// perform type castng here?
|
||||
$res[] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a column as an array.
|
||||
* The value of the column is unserialized & returned as an array.
|
||||
* @param mixed $column Column name (string) or index (int) starting with 1.
|
||||
* @return array
|
||||
* @throws SQLException - If the column specified is not a valid key in current field array.
|
||||
*/
|
||||
public function getArray($column)
|
||||
{
|
||||
if (is_int($column)) { $column--; } // because Java convention is to start at 1
|
||||
if (!array_key_exists($column, $this->fields)) { throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column)); }
|
||||
if ($this->fields[$column] === null) { return null; }
|
||||
return $this->strToArray($this->fields[$column]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Blob with contents of column value.
|
||||
*
|
||||
* @param mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used).
|
||||
* @return Blob New Blob with data from column.
|
||||
* @throws SQLException - If the column specified is not a valid key in current field array.
|
||||
*/
|
||||
public function getBlob($column)
|
||||
{
|
||||
if (is_int($column)) { $column--; } // because Java convention is to start at 1
|
||||
if (!array_key_exists($column, $this->fields)) { throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column)); }
|
||||
if ($this->fields[$column] === null) { return null; }
|
||||
require_once 'creole/util/Blob.php';
|
||||
$b = new Blob();
|
||||
$b->setContents(pg_unescape_bytea($this->fields[$column]));
|
||||
return $b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $column Column name (string) or index (int) starting with 1.
|
||||
* @return boolean
|
||||
* @throws SQLException - If the column specified is not a valid key in current field array.
|
||||
*/
|
||||
public function getBoolean($column)
|
||||
{
|
||||
if (is_int($column)) { $column--; } // because Java convention is to start at 1
|
||||
if (!array_key_exists($column, $this->fields)) { throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column)); }
|
||||
if ($this->fields[$column] === null) { return null; }
|
||||
return ($this->fields[$column] === 't');
|
||||
}
|
||||
|
||||
}
|
109
lib/symfony/vendor/creole/drivers/pgsql/PgSQLResultSetIterator.php
vendored
Executable file
109
lib/symfony/vendor/creole/drivers/pgsql/PgSQLResultSetIterator.php
vendored
Executable file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: PgSQLResultSetIterator.php,v 1.1 2004/12/04 05:58:53 gamr Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Optimized iterator for PostgreSQL, based off of SQLite iterator.
|
||||
* Testing with SeekableIterator, no idea if it will keep this
|
||||
* functionality or what uses it or even how to use it as yet.
|
||||
*
|
||||
* @author Cameron Brunner <webmaster@animetorrents.com>
|
||||
* @version $Revision: 1.1 $
|
||||
* @package creole.drivers.pgsql
|
||||
*/
|
||||
class PgSQLResultSetIterator implements SeekableIterator, Countable {
|
||||
|
||||
private $result;
|
||||
private $pos = 0;
|
||||
private $fetchmode;
|
||||
private $row_count;
|
||||
private $rs;
|
||||
|
||||
/**
|
||||
* Construct the iterator.
|
||||
* @param PgSQLResultSet $rs
|
||||
*/
|
||||
public function __construct(PgSQLResultSet $rs)
|
||||
{
|
||||
$this->result = $rs->getResource();
|
||||
$this->fetchmode = $rs->getFetchmode();
|
||||
$this->row_count = $rs->getRecordCount();
|
||||
$this->rs = $rs; // This is to address reference count bug: http://creole.phpdb.org/trac/ticket/6
|
||||
}
|
||||
|
||||
/**
|
||||
* This method actually has no effect, since we do not rewind ResultSet for iteration.
|
||||
*/
|
||||
function rewind()
|
||||
{
|
||||
$this->pos = 0;
|
||||
}
|
||||
|
||||
function valid()
|
||||
{
|
||||
return ( $this->pos < $this->row_count );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cursor position. Note that this will not necessarily
|
||||
* be 1 for the first row, since no rewind is performed at beginning
|
||||
* of iteration.
|
||||
* @return int
|
||||
*/
|
||||
function key()
|
||||
{
|
||||
return $this->pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the row (assoc array) at current cursor pos.
|
||||
* @return array
|
||||
*/
|
||||
function current()
|
||||
{
|
||||
return pg_fetch_array($this->result, $this->pos, $this->fetchmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances internal cursor pos.
|
||||
*/
|
||||
function next()
|
||||
{
|
||||
$this->pos++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets cursor to specific value.
|
||||
*/
|
||||
function seek ( $index )
|
||||
{
|
||||
if ( ! is_int ( $index ) ) {
|
||||
throw new InvalidArgumentException ( 'Invalid arguement to seek' );
|
||||
}
|
||||
if ( $index < 0 || $index > $this->row_count ) {
|
||||
throw new OutOfBoundsException ( 'Invalid seek position' );
|
||||
}
|
||||
$this->pos = $index;
|
||||
}
|
||||
|
||||
function count ( ) {
|
||||
return $this->row_count;
|
||||
}
|
||||
}
|
34
lib/symfony/vendor/creole/drivers/pgsql/PgSQLStatement.php
vendored
Executable file
34
lib/symfony/vendor/creole/drivers/pgsql/PgSQLStatement.php
vendored
Executable file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: PgSQLStatement.php,v 1.1 2004/02/19 02:49:42 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/Statement.php';
|
||||
require_once 'creole/common/StatementCommon.php';
|
||||
|
||||
/**
|
||||
* PostgreSQL Statement implementation.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.1 $
|
||||
* @package creole.drivers.pgsql
|
||||
*/
|
||||
class PgSQLStatement extends StatementCommon implements Statement {
|
||||
|
||||
}
|
101
lib/symfony/vendor/creole/drivers/pgsql/PgSQLTypes.php
vendored
Executable file
101
lib/symfony/vendor/creole/drivers/pgsql/PgSQLTypes.php
vendored
Executable file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* $Id: PgSQLTypes.php,v 1.8 2004/04/09 19:16:05 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/CreoleTypes.php';
|
||||
|
||||
/**
|
||||
* PostgreSQL types / type map.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.8 $
|
||||
* @package creole.drivers.pgsql
|
||||
*/
|
||||
class PgSQLTypes extends CreoleTypes {
|
||||
|
||||
/** Map PostgreSQL native types to Creole (JDBC) types. */
|
||||
private static $typeMap = array (
|
||||
"int2" => CreoleTypes::SMALLINT,
|
||||
"int4" => CreoleTypes::INTEGER,
|
||||
"oid" => CreoleTypes::INTEGER,
|
||||
"int8" => CreoleTypes::BIGINT,
|
||||
"cash" => CreoleTypes::DOUBLE,
|
||||
"money" => CreoleTypes::DOUBLE,
|
||||
"numeric" => CreoleTypes::NUMERIC,
|
||||
"float4" => CreoleTypes::REAL,
|
||||
"float8" => CreoleTypes::DOUBLE,
|
||||
"bpchar" => CreoleTypes::CHAR,
|
||||
"char" => CreoleTypes::CHAR,
|
||||
"char2" => CreoleTypes::CHAR,
|
||||
"char4" => CreoleTypes::CHAR,
|
||||
"char8" => CreoleTypes::CHAR,
|
||||
"char16" => CreoleTypes::CHAR,
|
||||
"varchar" => CreoleTypes::VARCHAR,
|
||||
"text" => CreoleTypes::VARCHAR,
|
||||
"name" => CreoleTypes::VARCHAR,
|
||||
"filename" => CreoleTypes::VARCHAR,
|
||||
"bytea" => CreoleTypes::BINARY,
|
||||
"bool" => CreoleTypes::BOOLEAN,
|
||||
"date" => CreoleTypes::DATE,
|
||||
"time" => CreoleTypes::TIME,
|
||||
"abstime" => CreoleTypes::TIMESTAMP,
|
||||
"timestamp" => CreoleTypes::TIMESTAMP,
|
||||
"timestamptz" => CreoleTypes::TIMESTAMP,
|
||||
"_bool" => CreoleTypes::ARR,
|
||||
"_char" => CreoleTypes::ARR,
|
||||
"_int2" => CreoleTypes::ARR,
|
||||
"_int4" => CreoleTypes::ARR,
|
||||
"_text" => CreoleTypes::ARR,
|
||||
"_oid" => CreoleTypes::ARR,
|
||||
"_varchar" => CreoleTypes::ARR,
|
||||
"_int8" => CreoleTypes::ARR,
|
||||
"_float4" => CreoleTypes::ARR,
|
||||
"_float8" => CreoleTypes::ARR,
|
||||
"_abstime" => CreoleTypes::ARR,
|
||||
"_date" => CreoleTypes::ARR,
|
||||
"_time" => CreoleTypes::ARR,
|
||||
"_timestamp" => CreoleTypes::ARR,
|
||||
"_numeric" => CreoleTypes::ARR,
|
||||
"_bytea" => CreoleTypes::ARR,
|
||||
);
|
||||
|
||||
/** Reverse lookup map, created on demand. */
|
||||
private static $reverseMap = null;
|
||||
|
||||
public static function getType($pgsqlType)
|
||||
{
|
||||
$t = strtolower($pgsqlType);
|
||||
if (isset(self::$typeMap[$t])) {
|
||||
return self::$typeMap[$t];
|
||||
} else {
|
||||
return CreoleTypes::OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getNativeType($creoleType)
|
||||
{
|
||||
if (self::$reverseMap === null) {
|
||||
self::$reverseMap = array_flip(self::$typeMap);
|
||||
}
|
||||
return @self::$reverseMap[$creoleType];
|
||||
}
|
||||
|
||||
}
|
115
lib/symfony/vendor/creole/drivers/pgsql/metadata/PgSQLDatabaseInfo.php
vendored
Executable file
115
lib/symfony/vendor/creole/drivers/pgsql/metadata/PgSQLDatabaseInfo.php
vendored
Executable file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: PgSQLDatabaseInfo.php,v 1.11 2006/01/17 19:44:40 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/DatabaseInfo.php';
|
||||
|
||||
/**
|
||||
* MySQL implementation of DatabaseInfo.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.11 $
|
||||
* @package creole.drivers.pgsql.metadata
|
||||
*/
|
||||
class PgSQLDatabaseInfo extends DatabaseInfo {
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function initTables()
|
||||
{
|
||||
include_once 'creole/drivers/pgsql/metadata/PgSQLTableInfo.php';
|
||||
|
||||
// Get Database Version
|
||||
// TODO: www.php.net/pg_version
|
||||
$result = pg_query ($this->conn->getResource(), "SELECT version() as ver");
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
throw new SQLException ("Failed to select database version");
|
||||
} // if (!$result)
|
||||
$row = pg_fetch_assoc ($result, 0);
|
||||
$arrVersion = sscanf ($row['ver'], '%*s %d.%d');
|
||||
$version = sprintf ("%d.%d", $arrVersion[0], $arrVersion[1]);
|
||||
// Clean up
|
||||
$arrVersion = null;
|
||||
$row = null;
|
||||
pg_free_result ($result);
|
||||
$result = null;
|
||||
|
||||
$result = pg_query($this->conn->getResource(), "SELECT oid, relname FROM pg_class
|
||||
WHERE relkind = 'r' AND relnamespace = (SELECT oid
|
||||
FROM pg_namespace
|
||||
WHERE
|
||||
nspname NOT IN ('information_schema','pg_catalog')
|
||||
AND nspname NOT LIKE 'pg_temp%'
|
||||
AND nspname NOT LIKE 'pg_toast%'
|
||||
LIMIT 1)
|
||||
ORDER BY relname");
|
||||
|
||||
if (!$result) {
|
||||
throw new SQLException("Could not list tables", pg_last_error($this->dblink));
|
||||
}
|
||||
|
||||
while ($row = pg_fetch_assoc($result)) {
|
||||
$this->tables[strtoupper($row['relname'])] = new PgSQLTableInfo($this, $row['relname'], $version, $row['oid']);
|
||||
}
|
||||
|
||||
$this->tablesLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* PgSQL sequences.
|
||||
*
|
||||
* @return void
|
||||
* @throws SQLException
|
||||
*/
|
||||
protected function initSequences()
|
||||
{
|
||||
|
||||
$this->sequences = array();
|
||||
|
||||
$result = pg_query($this->conn->getResource(), "SELECT oid, relname FROM pg_class
|
||||
WHERE relkind = 'S' AND relnamespace = (SELECT oid
|
||||
FROM pg_namespace
|
||||
WHERE
|
||||
nspname NOT IN ('information_schema','pg_catalog')
|
||||
AND nspname NOT LIKE 'pg_temp%'
|
||||
AND nspname NOT LIKE 'pg_toast%'
|
||||
LIMIT 1)
|
||||
ORDER BY relname");
|
||||
|
||||
if (!$result) {
|
||||
throw new SQLException("Could not list sequences", pg_last_error($this->dblink));
|
||||
}
|
||||
|
||||
while ($row = pg_fetch_assoc($result)) {
|
||||
// FIXME -- decide what info we need for sequences & then create a SequenceInfo object (if needed)
|
||||
$obj = new stdClass;
|
||||
$obj->name = $row['relname'];
|
||||
$obj->oid = $row['oid'];
|
||||
$this->sequences[strtoupper($row['relname'])] = $obj;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
423
lib/symfony/vendor/creole/drivers/pgsql/metadata/PgSQLTableInfo.php
vendored
Executable file
423
lib/symfony/vendor/creole/drivers/pgsql/metadata/PgSQLTableInfo.php
vendored
Executable file
@ -0,0 +1,423 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: PgSQLTableInfo.php,v 1.31 2006/01/17 19:44:40 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/TableInfo.php';
|
||||
|
||||
/**
|
||||
* PgSQL implementation of TableInfo.
|
||||
*
|
||||
* See this Python code by David M. Cook for some good reference on Pgsql metadata
|
||||
* functions:
|
||||
* @link http://www.sandpyt.org/pipermail/sandpyt/2003-March/000008.html
|
||||
*
|
||||
* Here's some more information from postgresql:
|
||||
* @link http://developer.postgresql.org/docs/pgsql/src/backend/catalog/information_schema.sql
|
||||
*
|
||||
* @todo -c Eventually move to supporting only Postgres >= 7.4, which has the information_schema
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.31 $
|
||||
* @package creole.drivers.pgsql.metadata
|
||||
*/
|
||||
class PgSQLTableInfo extends TableInfo {
|
||||
|
||||
/**
|
||||
* Database Version.
|
||||
* @var String
|
||||
*/
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* Table OID
|
||||
* @var Integer
|
||||
*/
|
||||
private $oid;
|
||||
|
||||
/**
|
||||
* @param string $table The table name.
|
||||
* @param string $database The database name.
|
||||
* @param resource $dblink The db connection resource.
|
||||
*/
|
||||
function __construct(DatabaseInfo $database, $name, $version, $intOID) {
|
||||
parent::__construct ($database, $name);
|
||||
$this->version = $version;
|
||||
$this->oid = $intOID;
|
||||
} // function __construct(DatabaseInfo $database, $name) {
|
||||
|
||||
/** Load the columns for this table */
|
||||
protected function initColumns () {
|
||||
// Include dependencies
|
||||
include_once ('creole/metadata/ColumnInfo.php');
|
||||
include_once ('creole/drivers/pgsql/PgSQLTypes.php');
|
||||
|
||||
// Get the columns, types, etc.
|
||||
// Based on code from pgAdmin3 (http://www.pgadmin.org/)
|
||||
$result = pg_query ($this->conn->getResource(), sprintf ("SELECT
|
||||
att.attname,
|
||||
att.atttypmod,
|
||||
att.atthasdef,
|
||||
att.attnotnull,
|
||||
def.adsrc,
|
||||
CASE WHEN att.attndims > 0 THEN 1 ELSE 0 END AS isarray,
|
||||
CASE
|
||||
WHEN ty.typname = 'bpchar'
|
||||
THEN 'char'
|
||||
WHEN ty.typname = '_bpchar'
|
||||
THEN '_char'
|
||||
ELSE
|
||||
ty.typname
|
||||
END AS typname,
|
||||
ty.typtype
|
||||
FROM pg_attribute att
|
||||
JOIN pg_type ty ON ty.oid=att.atttypid
|
||||
LEFT OUTER JOIN pg_attrdef def ON adrelid=att.attrelid AND adnum=att.attnum
|
||||
WHERE att.attrelid = %d AND att.attnum > 0
|
||||
AND att.attisdropped IS FALSE
|
||||
ORDER BY att.attnum", $this->oid));
|
||||
|
||||
if (!$result) {
|
||||
throw new SQLException("Could not list fields for table: " . $this->name, pg_last_error($this->conn->getResource()));
|
||||
}
|
||||
while($row = pg_fetch_assoc($result)) {
|
||||
|
||||
$size = null;
|
||||
$precision = null;
|
||||
$scale = null;
|
||||
|
||||
// Check to ensure that this column isn't an array data type
|
||||
if (((int) $row['isarray']) === 1)
|
||||
{
|
||||
throw new SQLException (sprintf ("Array datatypes are not currently supported [%s.%s]", $this->name, $row['attname']));
|
||||
} // if (((int) $row['isarray']) === 1)
|
||||
$name = $row['attname'];
|
||||
// If they type is a domain, Process it
|
||||
if (strtolower ($row['typtype']) == 'd')
|
||||
{
|
||||
$arrDomain = $this->processDomain ($row['typname']);
|
||||
$type = $arrDomain['type'];
|
||||
$size = $arrDomain['length'];
|
||||
$precision = $size;
|
||||
$scale = $arrDomain['scale'];
|
||||
$boolHasDefault = (strlen (trim ($row['atthasdef'])) > 0) ? $row['atthasdef'] : $arrDomain['hasdefault'];
|
||||
$default = (strlen (trim ($row['adsrc'])) > 0) ? $row['adsrc'] : $arrDomain['default'];
|
||||
$is_nullable = (strlen (trim ($row['attnotnull'])) > 0) ? $row['attnotnull'] : $arrDomain['notnull'];
|
||||
$is_nullable = (($is_nullable == 't') ? false : true);
|
||||
} // if (strtolower ($row['typtype']) == 'd')
|
||||
else
|
||||
{
|
||||
$type = $row['typname'];
|
||||
$arrLengthPrecision = $this->processLengthScale ($row['atttypmod'], $type);
|
||||
$size = $arrLengthPrecision['length'];
|
||||
$precision = $size;
|
||||
$scale = $arrLengthPrecision['scale'];
|
||||
$boolHasDefault = $row['atthasdef'];
|
||||
$default = $row['adsrc'];
|
||||
$is_nullable = (($row['attnotnull'] == 't') ? false : true);
|
||||
} // else (strtolower ($row['typtype']) == 'd')
|
||||
|
||||
$autoincrement = null;
|
||||
|
||||
// if column has a default
|
||||
if (($boolHasDefault == 't') && (strlen (trim ($default)) > 0))
|
||||
{
|
||||
if (!preg_match('/^nextval\(/', $default))
|
||||
{
|
||||
$strDefault= preg_replace ('/::[\W\D]*/', '', $default);
|
||||
$default = str_replace ("'", '', $strDefault);
|
||||
} // if (!preg_match('/^nextval\(/', $row['atthasdef']))
|
||||
else
|
||||
{
|
||||
$autoincrement = true;
|
||||
$default = null;
|
||||
} // else
|
||||
} // if (($boolHasDefault == 't') && (strlen (trim ($default)) > 0))
|
||||
else
|
||||
{
|
||||
$default = null;
|
||||
} // else (($boolHasDefault == 't') && (strlen (trim ($default)) > 0))
|
||||
|
||||
$this->columns[$name] = new ColumnInfo($this, $name, PgSQLTypes::getType($type), $type, $size, $precision, $scale, $is_nullable, $default, $autoincrement);
|
||||
}
|
||||
|
||||
$this->colsLoaded = true;
|
||||
} // protected function initColumns ()
|
||||
|
||||
private function processLengthScale ($intTypmod, $strName)
|
||||
{
|
||||
// Define the return array
|
||||
$arrRetVal = array ('length'=>null, 'scale'=>null);
|
||||
|
||||
// Some datatypes don't have a Typmod
|
||||
if ($intTypmod == -1)
|
||||
{
|
||||
return $arrRetVal;
|
||||
} // if ($intTypmod == -1)
|
||||
|
||||
// Numeric Datatype?
|
||||
if ($strName == PgSQLTypes::getNativeType (CreoleTypes::NUMERIC))
|
||||
{
|
||||
$intLen = ($intTypmod - 4) >> 16;
|
||||
$intPrec = ($intTypmod - 4) & 0xffff;
|
||||
$intLen = sprintf ("%ld", $intLen);
|
||||
if ($intPrec)
|
||||
{
|
||||
$intPrec = sprintf ("%ld", $intPrec);
|
||||
} // if ($intPrec)
|
||||
$arrRetVal['length'] = $intLen;
|
||||
$arrRetVal['scale'] = $intPrec;
|
||||
} // if ($strName == PgSQLTypes::getNativeType (CreoleTypes::NUMERIC))
|
||||
elseif ($strName == PgSQLTypes::getNativeType (CreoleTypes::TIME) || $strName == 'timetz'
|
||||
|| $strName == PgSQLTypes::getNativeType (CreoleTypes::TIMESTAMP) || $strName == 'timestamptz'
|
||||
|| $strName == 'interval' || $strName == 'bit')
|
||||
{
|
||||
$arrRetVal['length'] = sprintf ("%ld", $intTypmod);
|
||||
} // elseif (TIME, TIMESTAMP, INTERVAL, BIT)
|
||||
else
|
||||
{
|
||||
$arrRetVal['length'] = sprintf ("%ld", ($intTypmod - 4));
|
||||
} // else
|
||||
return $arrRetVal;
|
||||
} // private function processLengthScale ($intTypmod, $strName)
|
||||
|
||||
private function processDomain ($strDomain)
|
||||
{
|
||||
if (strlen (trim ($strDomain)) < 1)
|
||||
{
|
||||
throw new SQLException ("Invalid domain name [" . $strDomain . "]");
|
||||
} // if (strlen (trim ($strDomain)) < 1)
|
||||
$result = pg_query ($this->conn->getResource(), sprintf ("SELECT
|
||||
d.typname as domname,
|
||||
b.typname as basetype,
|
||||
d.typlen,
|
||||
d.typtypmod,
|
||||
d.typnotnull,
|
||||
d.typdefault
|
||||
FROM pg_type d
|
||||
INNER JOIN pg_type b ON b.oid = CASE WHEN d.typndims > 0 then d.typelem ELSE d.typbasetype END
|
||||
WHERE
|
||||
d.typtype = 'd'
|
||||
AND d.typname = '%s'
|
||||
ORDER BY d.typname", $strDomain));
|
||||
|
||||
if (!$result) {
|
||||
throw new SQLException("Query for domain [" . $strDomain . "] failed.", pg_last_error($this->conn->getResource()));
|
||||
}
|
||||
|
||||
$row = pg_fetch_assoc ($result);
|
||||
if (!$row)
|
||||
{
|
||||
throw new SQLException ("Domain [" . $strDomain . "] not found.");
|
||||
} // if (!$row)
|
||||
$arrDomain = array ();
|
||||
$arrDomain['type'] = $row['basetype'];
|
||||
$arrLengthPrecision = $this->processLengthScale ($row['typtypmod'], $row['basetype']);
|
||||
$arrDomain['length'] = $arrLengthPrecision['length'];
|
||||
$arrDomain['scale'] = $arrLengthPrecision['scale'];
|
||||
$arrDomain['notnull'] = $row['typnotnull'];
|
||||
$arrDomain['default'] = $row['typdefault'];
|
||||
$arrDomain['hasdefault'] = (strlen (trim ($row['typdefault'])) > 0) ? 't' : 'f';
|
||||
|
||||
pg_free_result ($result);
|
||||
return $arrDomain;
|
||||
} // private function processDomain ($strDomain)
|
||||
|
||||
/** Load foreign keys for this table. */
|
||||
protected function initForeignKeys()
|
||||
{
|
||||
include_once 'creole/metadata/ForeignKeyInfo.php';
|
||||
|
||||
$result = pg_query ($this->conn->getResource(), sprintf ("SELECT
|
||||
conname,
|
||||
confupdtype,
|
||||
confdeltype,
|
||||
cl.relname as fktab,
|
||||
a2.attname as fkcol,
|
||||
cr.relname as reftab,
|
||||
a1.attname as refcol
|
||||
FROM pg_constraint ct
|
||||
JOIN pg_class cl ON cl.oid=conrelid
|
||||
JOIN pg_class cr ON cr.oid=confrelid
|
||||
LEFT JOIN pg_catalog.pg_attribute a1 ON a1.attrelid = ct.confrelid
|
||||
LEFT JOIN pg_catalog.pg_attribute a2 ON a2.attrelid = ct.conrelid
|
||||
WHERE
|
||||
contype='f'
|
||||
AND conrelid = %d
|
||||
AND a2.attnum = ct.conkey[1]
|
||||
AND a1.attnum = ct.confkey[1]
|
||||
ORDER BY conname", $this->oid));
|
||||
if (!$result) {
|
||||
throw new SQLException("Could not list foreign keys for table: " . $this->name, pg_last_error($this->conn->getResource()));
|
||||
}
|
||||
|
||||
while($row = pg_fetch_assoc($result)) {
|
||||
$name = $row['conname'];
|
||||
$local_table = $row['fktab'];
|
||||
$local_column = $row['fkcol'];
|
||||
$foreign_table = $row['reftab'];
|
||||
$foreign_column = $row['refcol'];
|
||||
|
||||
// On Update
|
||||
switch ($row['confupdtype']) {
|
||||
case 'c':
|
||||
$onupdate = ForeignKeyInfo::CASCADE; break;
|
||||
case 'd':
|
||||
$onupdate = ForeignKeyInfo::SETDEFAULT; break;
|
||||
case 'n':
|
||||
$onupdate = ForeignKeyInfo::SETNULL; break;
|
||||
case 'r':
|
||||
$onupdate = ForeignKeyInfo::RESTRICT; break;
|
||||
default:
|
||||
case 'a':
|
||||
//NOACTION is the postgresql default
|
||||
$onupdate = ForeignKeyInfo::NONE; break;
|
||||
}
|
||||
// On Delete
|
||||
switch ($row['confdeltype']) {
|
||||
case 'c':
|
||||
$ondelete = ForeignKeyInfo::CASCADE; break;
|
||||
case 'd':
|
||||
$ondelete = ForeignKeyInfo::SETDEFAULT; break;
|
||||
case 'n':
|
||||
$ondelete = ForeignKeyInfo::SETNULL; break;
|
||||
case 'r':
|
||||
$ondelete = ForeignKeyInfo::RESTRICT; break;
|
||||
default:
|
||||
case 'a':
|
||||
//NOACTION is the postgresql default
|
||||
$ondelete = ForeignKeyInfo::NONE; break;
|
||||
}
|
||||
|
||||
|
||||
$foreignTable = $this->database->getTable($foreign_table);
|
||||
$foreignColumn = $foreignTable->getColumn($foreign_column);
|
||||
|
||||
$localTable = $this->database->getTable($local_table);
|
||||
$localColumn = $localTable->getColumn($local_column);
|
||||
|
||||
if (!isset($this->foreignKeys[$name])) {
|
||||
$this->foreignKeys[$name] = new ForeignKeyInfo($name);
|
||||
}
|
||||
$this->foreignKeys[$name]->addReference($localColumn, $foreignColumn, $ondelete, $onupdate);
|
||||
}
|
||||
|
||||
$this->fksLoaded = true;
|
||||
}
|
||||
|
||||
/** Load indexes for this table */
|
||||
protected function initIndexes()
|
||||
{
|
||||
include_once 'creole/metadata/IndexInfo.php';
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
|
||||
$result = pg_query ($this->conn->getResource(), sprintf ("SELECT
|
||||
DISTINCT ON(cls.relname)
|
||||
cls.relname as idxname,
|
||||
indkey,
|
||||
indisunique
|
||||
FROM pg_index idx
|
||||
JOIN pg_class cls ON cls.oid=indexrelid
|
||||
WHERE indrelid = %d AND NOT indisprimary
|
||||
ORDER BY cls.relname", $this->oid));
|
||||
|
||||
|
||||
if (!$result) {
|
||||
throw new SQLException("Could not list indexes keys for table: " . $this->name, pg_last_error($this->conn->getResource()));
|
||||
}
|
||||
|
||||
while($row = pg_fetch_assoc($result)) {
|
||||
$name = $row["idxname"];
|
||||
$unique = ($row["indisunique"] == 't') ? true : false;
|
||||
if (!isset($this->indexes[$name])) {
|
||||
$this->indexes[$name] = new IndexInfo($name, $unique);
|
||||
}
|
||||
$arrColumns = explode (' ', $row['indkey']);
|
||||
foreach ($arrColumns as $intColNum)
|
||||
{
|
||||
$result2 = pg_query ($this->conn->getResource(), sprintf ("SELECT a.attname
|
||||
FROM pg_catalog.pg_class c JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid
|
||||
WHERE c.oid = '%s' AND a.attnum = %d AND NOT a.attisdropped
|
||||
ORDER BY a.attnum", $this->oid, $intColNum));
|
||||
if (!$result2)
|
||||
{
|
||||
throw new SQLException("Could not list indexes keys for table: " . $this->name, pg_last_error($this->conn->getResource()));
|
||||
}
|
||||
$row2 = pg_fetch_assoc($result2);
|
||||
$this->indexes[$name]->addColumn($this->columns[ $row2['attname'] ]);
|
||||
} // foreach ($arrColumns as $intColNum)
|
||||
}
|
||||
|
||||
$this->indexesLoaded = true;
|
||||
}
|
||||
|
||||
/** Loads the primary keys for this table. */
|
||||
protected function initPrimaryKey() {
|
||||
|
||||
include_once 'creole/metadata/PrimaryKeyInfo.php';
|
||||
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
|
||||
// Primary Keys
|
||||
|
||||
$result = pg_query($this->conn->getResource(), sprintf ("SELECT
|
||||
DISTINCT ON(cls.relname)
|
||||
cls.relname as idxname,
|
||||
indkey,
|
||||
indisunique
|
||||
FROM pg_index idx
|
||||
JOIN pg_class cls ON cls.oid=indexrelid
|
||||
WHERE indrelid = %s AND indisprimary
|
||||
ORDER BY cls.relname", $this->oid));
|
||||
if (!$result) {
|
||||
throw new SQLException("Could not list primary keys for table: " . $this->name, pg_last_error($this->conn->getResource()));
|
||||
}
|
||||
|
||||
// Loop through the returned results, grouping the same key_name together
|
||||
// adding each column for that key.
|
||||
|
||||
while($row = pg_fetch_assoc($result)) {
|
||||
$arrColumns = explode (' ', $row['indkey']);
|
||||
foreach ($arrColumns as $intColNum)
|
||||
{
|
||||
$result2 = pg_query ($this->conn->getResource(), sprintf ("SELECT a.attname
|
||||
FROM pg_catalog.pg_class c JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid
|
||||
WHERE c.oid = '%s' AND a.attnum = %d AND NOT a.attisdropped
|
||||
ORDER BY a.attnum", $this->oid, $intColNum));
|
||||
if (!$result2)
|
||||
{
|
||||
throw new SQLException("Could not list indexes keys for table: " . $this->name, pg_last_error($this->conn->getResource()));
|
||||
}
|
||||
$row2 = pg_fetch_assoc($result2);
|
||||
if (!isset($this->primaryKey)) {
|
||||
$this->primaryKey = new PrimaryKeyInfo($row2['attname']);
|
||||
}
|
||||
$this->primaryKey->addColumn($this->columns[ $row2['attname'] ]);
|
||||
} // foreach ($arrColumns as $intColNum)
|
||||
}
|
||||
$this->pkLoaded = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
245
lib/symfony/vendor/creole/drivers/sqlite/SQLiteConnection.php
vendored
Executable file
245
lib/symfony/vendor/creole/drivers/sqlite/SQLiteConnection.php
vendored
Executable file
@ -0,0 +1,245 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: SQLiteConnection.php,v 1.15 2006/01/17 19:44:41 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/Connection.php';
|
||||
require_once 'creole/common/ConnectionCommon.php';
|
||||
|
||||
/**
|
||||
* SQLite implementation of Connection.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @author Stig Bakken <ssb@fast.no>
|
||||
* @author Lukas Smith
|
||||
* @version $Revision: 1.15 $
|
||||
* @package creole.drivers.sqlite
|
||||
*/
|
||||
class SQLiteConnection extends ConnectionCommon implements Connection {
|
||||
|
||||
/**
|
||||
* The case to use for SQLite results.
|
||||
* (0=nochange, 1=upper, 2=lower)
|
||||
* This is set in each call to executeQuery() in order to ensure that different
|
||||
* Connections do not overwrite each other's settings
|
||||
*/
|
||||
private $sqliteAssocCase;
|
||||
|
||||
/**
|
||||
* @see Connection::connect()
|
||||
*/
|
||||
function connect($dsninfo, $flags = 0)
|
||||
{
|
||||
if (!extension_loaded('sqlite')) {
|
||||
throw new SQLException('sqlite extension not loaded');
|
||||
}
|
||||
|
||||
$file = $dsninfo['database'];
|
||||
|
||||
$this->dsn = $dsninfo;
|
||||
$this->flags = $flags;
|
||||
|
||||
$persistent = ($flags & Creole::PERSISTENT === Creole::PERSISTENT);
|
||||
|
||||
if (PHP_VERSION == '5.0.4' || PHP_VERSION == '5.0.5') {
|
||||
$nochange = TRUE;
|
||||
} else {
|
||||
$nochange = !(($flags & Creole::COMPAT_ASSOC_LOWER) === Creole::COMPAT_ASSOC_LOWER);
|
||||
}
|
||||
|
||||
if ($nochange) {
|
||||
$this->sqliteAssocCase = 0;
|
||||
} else {
|
||||
$this->sqliteAssocCase = 2;
|
||||
}
|
||||
|
||||
if ($file === null) {
|
||||
throw new SQLException("No SQLite database specified.");
|
||||
}
|
||||
|
||||
$mode = (isset($dsninfo['mode']) && is_numeric($dsninfo['mode'])) ? $dsninfo['mode'] : 0644;
|
||||
|
||||
if ($file != ':memory:') {
|
||||
if (!file_exists($file)) {
|
||||
touch($file);
|
||||
chmod($file, $mode);
|
||||
if (!file_exists($file)) {
|
||||
throw new SQLException("Unable to create SQLite database.");
|
||||
}
|
||||
}
|
||||
if (!is_file($file)) {
|
||||
throw new SQLException("Unable to open SQLite database: not a valid file.");
|
||||
}
|
||||
if (!is_readable($file)) {
|
||||
throw new SQLException("Unable to read SQLite database.");
|
||||
}
|
||||
}
|
||||
|
||||
$connect_function = $persistent ? 'sqlite_popen' : 'sqlite_open';
|
||||
if (!($conn = @$connect_function($file, $mode, $errmsg) )) {
|
||||
throw new SQLException("Unable to connect to SQLite database", $errmsg);
|
||||
}
|
||||
|
||||
$this->dblink = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getDatabaseInfo()
|
||||
*/
|
||||
public function getDatabaseInfo()
|
||||
{
|
||||
require_once 'creole/drivers/sqlite/metadata/SQLiteDatabaseInfo.php';
|
||||
return new SQLiteDatabaseInfo($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::getIdGenerator()
|
||||
*/
|
||||
public function getIdGenerator()
|
||||
{
|
||||
require_once 'creole/drivers/sqlite/SQLiteIdGenerator.php';
|
||||
return new SQLiteIdGenerator($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::prepareStatement()
|
||||
*/
|
||||
public function prepareStatement($sql)
|
||||
{
|
||||
require_once 'creole/drivers/sqlite/SQLitePreparedStatement.php';
|
||||
return new SQLitePreparedStatement($this, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::prepareCall()
|
||||
*/
|
||||
public function prepareCall($sql) {
|
||||
throw new SQLException('SQLite does not support stored procedures using CallableStatement.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::createStatement()
|
||||
*/
|
||||
public function createStatement()
|
||||
{
|
||||
require_once 'creole/drivers/sqlite/SQLiteStatement.php';
|
||||
return new SQLiteStatement($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::close()
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
$ret = @sqlite_close($this->dblink);
|
||||
$this->dblink = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::applyLimit()
|
||||
*/
|
||||
public function applyLimit(&$sql, $offset, $limit)
|
||||
{
|
||||
if ( $limit > 0 ) {
|
||||
$sql .= " LIMIT " . $limit . ($offset > 0 ? " OFFSET " . $offset : "");
|
||||
} elseif ( $offset > 0 ) {
|
||||
$sql .= " LIMIT -1 OFFSET " . $offset;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::executeQuery()
|
||||
*/
|
||||
public function executeQuery($sql, $fetchmode = null)
|
||||
{
|
||||
ini_set('sqlite.assoc_case', $this->sqliteAssocCase);
|
||||
$this->lastQuery = $sql;
|
||||
$result = @sqlite_query($this->dblink, $this->lastQuery);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute query', $php_errormsg, $this->lastQuery); //sqlite_error_string(sqlite_last_error($this->dblink))
|
||||
}
|
||||
require_once 'creole/drivers/sqlite/SQLiteResultSet.php';
|
||||
return new SQLiteResultSet($this, $result, $fetchmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Connection::executeUpdate()
|
||||
*/
|
||||
function executeUpdate($sql)
|
||||
{
|
||||
$this->lastQuery = $sql;
|
||||
$result = @sqlite_query($this->dblink, $this->lastQuery);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute update', $php_errormsg, $this->lastQuery); //sqlite_error_string(sqlite_last_error($this->dblink))
|
||||
}
|
||||
return (int) @sqlite_changes($this->dblink);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a database transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function beginTrans()
|
||||
{
|
||||
$result = @sqlite_query($this->dblink, 'BEGIN');
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not begin transaction', $php_errormsg); //sqlite_error_string(sqlite_last_error($this->dblink))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function commitTrans()
|
||||
{
|
||||
$result = @sqlite_query($this->dblink, 'COMMIT');
|
||||
if (!$result) {
|
||||
throw new SQLException('Can not commit transaction', $php_errormsg); // sqlite_error_string(sqlite_last_error($this->dblink))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll back (undo) the current transaction.
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function rollbackTrans()
|
||||
{
|
||||
$result = @sqlite_query($this->dblink, 'ROLLBACK');
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not rollback transaction', $php_errormsg); // sqlite_error_string(sqlite_last_error($this->dblink))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by the data manipulation
|
||||
* query.
|
||||
*
|
||||
* @return int Number of rows affected by the last query.
|
||||
*/
|
||||
function getUpdateCount()
|
||||
{
|
||||
return (int) @sqlite_changes($this->dblink);
|
||||
}
|
||||
|
||||
}
|
60
lib/symfony/vendor/creole/drivers/sqlite/SQLiteIdGenerator.php
vendored
Executable file
60
lib/symfony/vendor/creole/drivers/sqlite/SQLiteIdGenerator.php
vendored
Executable file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
require_once 'creole/IdGenerator.php';
|
||||
|
||||
/**
|
||||
* SQLite IdGenerator implimenation.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.4 $
|
||||
* @package creole.drivers.sqlite
|
||||
*/
|
||||
class SQLiteIdGenerator implements IdGenerator {
|
||||
|
||||
/** Connection object that instantiated this class */
|
||||
private $conn;
|
||||
|
||||
/**
|
||||
* Creates a new IdGenerator class, saves passed connection for use
|
||||
* later by getId() method.
|
||||
* @param Connection $conn
|
||||
*/
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isBeforeInsert()
|
||||
*/
|
||||
public function isBeforeInsert()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::isAfterInsert()
|
||||
*/
|
||||
public function isAfterInsert()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::getIdMethod()
|
||||
*/
|
||||
public function getIdMethod()
|
||||
{
|
||||
return self::AUTOINCREMENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdGenerator::getId()
|
||||
*/
|
||||
public function getId($unused = null)
|
||||
{
|
||||
return sqlite_last_insert_rowid($this->conn->getResource());
|
||||
}
|
||||
|
||||
}
|
||||
|
61
lib/symfony/vendor/creole/drivers/sqlite/SQLitePreparedStatement.php
vendored
Executable file
61
lib/symfony/vendor/creole/drivers/sqlite/SQLitePreparedStatement.php
vendored
Executable file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: SQLitePreparedStatement.php,v 1.7 2004/03/20 04:16:50 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/PreparedStatement.php';
|
||||
require_once 'creole/common/PreparedStatementCommon.php';
|
||||
|
||||
/**
|
||||
* MySQL subclass for prepared statements.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.7 $
|
||||
* @package creole.drivers.sqlite
|
||||
*/
|
||||
class SQLitePreparedStatement extends PreparedStatementCommon implements PreparedStatement {
|
||||
|
||||
/**
|
||||
* Quotes string using native sqlite_escape_string() function.
|
||||
* @see ResultSetCommon::escape()
|
||||
*/
|
||||
protected function escape($str)
|
||||
{
|
||||
return sqlite_escape_string($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies sqlite_udf_encode_binary() to ensure that binary contents will be handled correctly by sqlite.
|
||||
* @see PreparedStatement::setBlob()
|
||||
* @see ResultSet::getBlob()
|
||||
*/
|
||||
function setBlob($paramIndex, $blob)
|
||||
{
|
||||
if ($blob === null) {
|
||||
$this->setNull($paramIndex);
|
||||
} else {
|
||||
// they took magic __toString() out of PHP5.0.0; this sucks
|
||||
if (is_object($blob)) {
|
||||
$blob = $blob->__toString();
|
||||
}
|
||||
$this->boundInVars[$paramIndex] = "'" . sqlite_udf_encode_binary( $blob ) . "'";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
120
lib/symfony/vendor/creole/drivers/sqlite/SQLiteResultSet.php
vendored
Executable file
120
lib/symfony/vendor/creole/drivers/sqlite/SQLiteResultSet.php
vendored
Executable file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: SQLiteResultSet.php,v 1.9 2004/11/29 13:41:24 micha Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/ResultSet.php';
|
||||
require_once 'creole/common/ResultSetCommon.php';
|
||||
|
||||
/**
|
||||
* SQLite implementation of ResultSet class.
|
||||
*
|
||||
* SQLite supports OFFSET / LIMIT natively; this means that no adjustments or checking
|
||||
* are performed. We will assume that if the lmitSQL() operation failed that an
|
||||
* exception was thrown, and that OFFSET/LIMIT will never be emulated for SQLite.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.9 $
|
||||
* @package creole.drivers.sqlite
|
||||
*/
|
||||
class SQLiteResultSet extends ResultSetCommon implements ResultSet {
|
||||
|
||||
/**
|
||||
* Gets optimized SQLiteResultSetIterator.
|
||||
* @return SQLiteResultSetIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
require_once 'creole/drivers/sqlite/SQLiteResultSetIterator.php';
|
||||
return new SQLiteResultSetIterator($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::seek()
|
||||
*/
|
||||
public function seek($rownum)
|
||||
{
|
||||
// MySQL rows start w/ 0, but this works, because we are
|
||||
// looking to move the position _before_ the next desired position
|
||||
if (!@sqlite_seek($this->result, $rownum)) {
|
||||
return false;
|
||||
}
|
||||
$this->cursorPos = $rownum;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::next()
|
||||
*/
|
||||
function next()
|
||||
{
|
||||
$this->fields = sqlite_fetch_array($this->result, $this->fetchmode); // (ResultSet::FETCHMODE_NUM = SQLITE_NUM, etc.)
|
||||
if (!$this->fields) {
|
||||
$errno = sqlite_last_error($this->conn->getResource());
|
||||
if (!$errno) {
|
||||
// We've advanced beyond end of recordset.
|
||||
$this->afterLast();
|
||||
return false;
|
||||
} else {
|
||||
throw new SQLException("Error fetching result", sqlite_error_string($errno));
|
||||
}
|
||||
}
|
||||
|
||||
// Advance cursor position
|
||||
$this->cursorPos++;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResultSet::getRecordCount()
|
||||
*/
|
||||
public function getRecordCount()
|
||||
{
|
||||
$rows = @sqlite_num_rows($this->result);
|
||||
if ($rows === null) {
|
||||
throw new SQLException("Error fetching num rows", sqlite_error_string(sqlite_last_error($this->conn->getResource())));
|
||||
}
|
||||
return (int) $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs sqlite_udf_decode_binary on binary data.
|
||||
* @see ResultSet::getBlob()
|
||||
*/
|
||||
public function getBlob($column)
|
||||
{
|
||||
$idx = (is_int($column) ? $column - 1 : $column);
|
||||
if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
|
||||
if ($this->fields[$idx] === null) { return null; }
|
||||
require_once 'creole/util/Blob.php';
|
||||
$b = new Blob();
|
||||
$b->setContents(sqlite_udf_decode_binary($this->fields[$idx]));
|
||||
return $b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply empties array as there is no result free method for sqlite.
|
||||
* @see ResultSet::close()
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$this->fields = array();
|
||||
$this->result = null;
|
||||
}
|
||||
}
|
88
lib/symfony/vendor/creole/drivers/sqlite/SQLiteResultSetIterator.php
vendored
Executable file
88
lib/symfony/vendor/creole/drivers/sqlite/SQLiteResultSetIterator.php
vendored
Executable file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: SQLiteResultSetIterator.php,v 1.6 2004/12/03 16:57:54 gamr Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Optimized iterator for SQLite.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.6 $
|
||||
* @package creole.drivers.sqlite
|
||||
*/
|
||||
class SQLiteResultSetIterator implements Iterator {
|
||||
|
||||
private $result;
|
||||
private $pos = 0;
|
||||
private $fetchmode;
|
||||
private $row_count;
|
||||
|
||||
/**
|
||||
* Construct the iterator.
|
||||
* @param SQLiteResultSet $rs
|
||||
*/
|
||||
public function __construct(SQLiteResultSet $rs)
|
||||
{
|
||||
$this->result = $rs->getResource();
|
||||
$this->fetchmode = $rs->getFetchmode();
|
||||
$this->row_count = $rs->getRecordCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method actually has no effect, since we do not rewind ResultSet for iteration.
|
||||
*/
|
||||
function rewind()
|
||||
{
|
||||
sqlite_rewind($this->result);
|
||||
}
|
||||
|
||||
function valid()
|
||||
{
|
||||
return ( $this->pos < $this->row_count );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cursor position. Note that this will not necessarily
|
||||
* be 1 for the first row, since no rewind is performed at beginning
|
||||
* of iteration.
|
||||
* @return int
|
||||
*/
|
||||
function key()
|
||||
{
|
||||
return $this->pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the row (assoc array) at current cursor pos.
|
||||
* @return array
|
||||
*/
|
||||
function current()
|
||||
{
|
||||
return sqlite_fetch_array($this->result, $this->fetchmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances internal cursor pos.
|
||||
*/
|
||||
function next()
|
||||
{
|
||||
$this->pos++;
|
||||
}
|
||||
|
||||
}
|
34
lib/symfony/vendor/creole/drivers/sqlite/SQLiteStatement.php
vendored
Executable file
34
lib/symfony/vendor/creole/drivers/sqlite/SQLiteStatement.php
vendored
Executable file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: SQLiteStatement.php,v 1.1 2004/02/19 02:49:43 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/Statement.php';
|
||||
require_once 'creole/common/StatementCommon.php';
|
||||
|
||||
/**
|
||||
* SQLite Statement
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.1 $
|
||||
* @package creole.drivers.sqlite
|
||||
*/
|
||||
class SQLiteStatement extends StatementCommon implements Statement {
|
||||
|
||||
}
|
108
lib/symfony/vendor/creole/drivers/sqlite/SQLiteTypes.php
vendored
Executable file
108
lib/symfony/vendor/creole/drivers/sqlite/SQLiteTypes.php
vendored
Executable file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* $Id: SQLiteTypes.php,v 1.3 2004/03/20 04:16:50 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/CreoleTypes.php';
|
||||
|
||||
/**
|
||||
* MySQL types / type map.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.3 $
|
||||
* @package creole.drivers.sqlite
|
||||
*/
|
||||
class SQLiteTypes extends CreoleTypes {
|
||||
|
||||
/**
|
||||
* Map some fake SQLite types CreoleTypes.
|
||||
* SQLite is typeless so this is really only for "hint" / readability
|
||||
* purposes.
|
||||
* @var array
|
||||
*/
|
||||
private static $typeMap = array(
|
||||
'tinyint' => CreoleTypes::TINYINT,
|
||||
'smallint' => CreoleTypes::SMALLINT,
|
||||
'mediumint' => CreoleTypes::SMALLINT,
|
||||
'int' => CreoleTypes::INTEGER,
|
||||
'integer' => CreoleTypes::INTEGER,
|
||||
'bigint' => CreoleTypes::BIGINT,
|
||||
'int24' => CreoleTypes::BIGINT,
|
||||
'real' => CreoleTypes::REAL,
|
||||
'float' => CreoleTypes::FLOAT,
|
||||
'decimal' => CreoleTypes::DECIMAL,
|
||||
'numeric' => CreoleTypes::NUMERIC,
|
||||
'double' => CreoleTypes::DOUBLE,
|
||||
'char' => CreoleTypes::CHAR,
|
||||
'varchar' => CreoleTypes::VARCHAR,
|
||||
'date' => CreoleTypes::DATE,
|
||||
'time' => CreoleTypes::TIME,
|
||||
'year' => CreoleTypes::YEAR,
|
||||
'datetime' => CreoleTypes::TIMESTAMP,
|
||||
'timestamp' => CreoleTypes::TIMESTAMP,
|
||||
'tinyblob' => CreoleTypes::BINARY,
|
||||
'blob' => CreoleTypes::VARBINARY,
|
||||
'mediumblob' => CreoleTypes::VARBINARY,
|
||||
'longblob' => CreoleTypes::VARBINARY,
|
||||
'tinytext' => CreoleTypes::VARCHAR,
|
||||
'mediumtext' => CreoleTypes::LONGVARCHAR,
|
||||
'text' => CreoleTypes::LONGVARCHAR,
|
||||
);
|
||||
|
||||
/** Reverse mapping, created on demand. */
|
||||
private static $reverseMap = null;
|
||||
|
||||
/**
|
||||
* This method returns the generic Creole (JDBC-like) type
|
||||
* when given the native db type. If no match is found then we just
|
||||
* return CreoleTypes::TEXT because SQLite is typeless.
|
||||
* @param string $nativeType DB native type (e.g. 'TEXT', 'byetea', etc.).
|
||||
* @return int Creole native type (e.g. CreoleTypes::LONGVARCHAR, CreoleTypes::BINARY, etc.).
|
||||
*/
|
||||
public static function getType($nativeType)
|
||||
{
|
||||
$t = strtolower($nativeType);
|
||||
if (isset(self::$typeMap[$t])) {
|
||||
return self::$typeMap[$t];
|
||||
} else {
|
||||
return CreoleTypes::TEXT; // because SQLite is typeless
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will return a native type that corresponds to the specified
|
||||
* Creole (JDBC-like) type. Remember that this is really only for "hint" purposes
|
||||
* as SQLite is typeless.
|
||||
*
|
||||
* If there is more than one matching native type, then the LAST defined
|
||||
* native type will be returned.
|
||||
*
|
||||
* @param int $creoleType
|
||||
* @return string Native type string.
|
||||
*/
|
||||
public static function getNativeType($creoleType)
|
||||
{
|
||||
if (self::$reverseMap === null) {
|
||||
self::$reverseMap = array_flip(self::$typeMap);
|
||||
}
|
||||
return @self::$reverseMap[$creoleType];
|
||||
}
|
||||
|
||||
}
|
64
lib/symfony/vendor/creole/drivers/sqlite/metadata/SQLiteDatabaseInfo.php
vendored
Executable file
64
lib/symfony/vendor/creole/drivers/sqlite/metadata/SQLiteDatabaseInfo.php
vendored
Executable file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: SQLiteDatabaseInfo.php,v 1.3 2004/03/20 04:16:50 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/DatabaseInfo.php';
|
||||
|
||||
/**
|
||||
* SQLite implementation of DatabaseInfo.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.3 $
|
||||
* @package creole.drivers.sqlite.metadata
|
||||
*/
|
||||
class SQLiteDatabaseInfo extends DatabaseInfo {
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
* @return void
|
||||
*/
|
||||
protected function initTables()
|
||||
{
|
||||
include_once 'creole/drivers/sqlite/metadata/SQLiteTableInfo.php';
|
||||
|
||||
$sql = "SELECT name FROM sqlite_master WHERE type='table' UNION ALL SELECT name FROM sqlite_temp_master WHERE type='table' ORDER BY name;";
|
||||
$result = sqlite_query($this->dblink, $sql);
|
||||
|
||||
if (!$result) {
|
||||
throw new SQLException("Could not list tables", sqlite_last_error($this->dblink));
|
||||
}
|
||||
|
||||
while ($row = sqlite_fetch_array($result)) {
|
||||
$this->tables[strtoupper($row[0])] = new SQLiteTableInfo($this, $row[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SQLite does not support sequences.
|
||||
*
|
||||
* @return void
|
||||
* @throws SQLException
|
||||
*/
|
||||
protected function initSequences()
|
||||
{
|
||||
// throw new SQLException("MySQL does not support sequences natively.");
|
||||
}
|
||||
|
||||
}
|
137
lib/symfony/vendor/creole/drivers/sqlite/metadata/SQLiteTableInfo.php
vendored
Executable file
137
lib/symfony/vendor/creole/drivers/sqlite/metadata/SQLiteTableInfo.php
vendored
Executable file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id: SQLiteTableInfo.php,v 1.8 2005/10/18 02:27:50 hlellelid Exp $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
require_once 'creole/metadata/TableInfo.php';
|
||||
|
||||
/**
|
||||
* MySQL implementation of TableInfo.
|
||||
*
|
||||
* @author Hans Lellelid <hans@xmpl.org>
|
||||
* @version $Revision: 1.8 $
|
||||
* @package creole.drivers.sqlite.metadata
|
||||
*/
|
||||
class SQLiteTableInfo extends TableInfo {
|
||||
|
||||
/** Loads the columns for this table. */
|
||||
protected function initColumns()
|
||||
{
|
||||
|
||||
include_once 'creole/metadata/ColumnInfo.php';
|
||||
include_once 'creole/metadata/PrimaryKeyInfo.php';
|
||||
include_once 'creole/drivers/sqlite/SQLiteTypes.php';
|
||||
|
||||
// To get all of the attributes we need, we'll actually do
|
||||
// two separate queries. The first gets names and default values
|
||||
// the second will fill in some more details.
|
||||
|
||||
$sql = "PRAGMA table_info('".$this->name."')";
|
||||
|
||||
$res = sqlite_query($this->conn->getResource(), $sql);
|
||||
|
||||
|
||||
while($row = sqlite_fetch_array($res, SQLITE_ASSOC)) {
|
||||
|
||||
$name = $row['name'];
|
||||
|
||||
$fulltype = $row['type'];
|
||||
$size = null;
|
||||
$precision = null;
|
||||
$scale = null;
|
||||
|
||||
if (preg_match('/^([^\(]+)\(\s*(\d+)\s*,\s*(\d+)\s*\)$/', $fulltype, $matches)) {
|
||||
$type = $matches[1];
|
||||
$precision = $matches[2];
|
||||
$scale = $matches[3]; // aka precision
|
||||
} elseif (preg_match('/^([^\(]+)\(\s*(\d+)\s*\)$/', $fulltype, $matches)) {
|
||||
$type = $matches[1];
|
||||
$size = $matches[2];
|
||||
} else {
|
||||
$type = $fulltype;
|
||||
}
|
||||
// If column is primary key and of type INTEGER, it is auto increment
|
||||
// See: http://sqlite.org/faq.html#q1
|
||||
$is_auto_increment = ($row['pk'] == 1 && $fulltype == 'INTEGER');
|
||||
$not_null = $row['notnull'];
|
||||
$is_nullable = !$not_null;
|
||||
|
||||
$default_val = $row['dflt_value'];
|
||||
|
||||
$this->columns[$name] = new ColumnInfo($this, $name, SQLiteTypes::getType($type), $type, $size, $precision, $scale, $is_nullable, $default_val);
|
||||
|
||||
if (($row['pk'] == 1) || (strtolower($type) == 'integer primary key')) {
|
||||
if ($this->primaryKey === null) {
|
||||
$this->primaryKey = new PrimaryKeyInfo($name);
|
||||
}
|
||||
$this->primaryKey->addColumn($this->columns[ $name ]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->colsLoaded = true;
|
||||
}
|
||||
|
||||
/** Loads the primary key information for this table. */
|
||||
protected function initPrimaryKey()
|
||||
{
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
// keys are loaded by initColumns() in this class.
|
||||
$this->pkLoaded = true;
|
||||
}
|
||||
|
||||
/** Loads the indexes for this table. */
|
||||
protected function initIndexes() {
|
||||
|
||||
include_once 'creole/metadata/IndexInfo.php';
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
|
||||
$sql = "PRAGMA index_list('".$this->name."')";
|
||||
$res = sqlite_query($this->conn->getResource(), $sql);
|
||||
|
||||
while($row = sqlite_fetch_array($res, SQLITE_ASSOC)) {
|
||||
$name = $row['name'];
|
||||
$this->indexes[$name] = new IndexInfo($name);
|
||||
|
||||
// get columns for that index
|
||||
$res2 = sqlite_query($this->conn->getResource(), "PRAGMA index_info('$name')");
|
||||
while($row2 = sqlite_fetch_array($res2, SQLITE_ASSOC)) {
|
||||
$colname = $row2['name'];
|
||||
$this->indexes[$name]->addColumn($this->columns[ $colname ]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->indexesLoaded = true;
|
||||
}
|
||||
|
||||
/** Load foreign keys (unsupported in SQLite). */
|
||||
protected function initForeignKeys() {
|
||||
|
||||
// columns have to be loaded first
|
||||
if (!$this->colsLoaded) $this->initColumns();
|
||||
|
||||
// No fkeys in SQLite
|
||||
|
||||
$this->fksLoaded = true;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user