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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user