Commit c3ad9559 authored by romanb's avatar romanb

further cleanups

parent 70c96548
This diff is collapsed.
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* standard connection, the parent of pgsql, mysql and sqlite
*
* @package Doctrine
* @subpackage Connection
* @link www.phpdoctrine.org
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @TODO Remove this class and move the modifyLimitQuery implementation to Connection.
* @deprecated
*/
class Doctrine_Connection_Common extends Doctrine_Connection
{
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query
* @param mixed $limit
* @param mixed $offset
* @todo 4th parameter not used? Remove?
*/
public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false)
{
$limit = (int) $limit;
$offset = (int) $offset;
if ($limit && $offset) {
$query .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} elseif ($limit && ! $offset) {
$query .= ' LIMIT ' . $limit;
} elseif ( ! $limit && $offset) {
$query .= ' LIMIT 999999999999 OFFSET ' . $offset;
}
return $query;
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Connection_Db2
*
* @package Doctrine
* @subpackage Connection
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @deprecated
*/
class Doctrine_Connection_Db2 extends Doctrine_Connection
{
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query query to modify
* @param integer $limit limit the number of rows
* @param integer $offset start reading from given offset
* @return string the modified query
*/
public function modifyLimitQuery($query, $limit, $offset)
{
if ($limit <= 0)
return $query;
if ($offset == 0) {
return $query . ' FETCH FIRST '. $limit .' ROWS ONLY';
} else {
$sqlPieces = explode('from', $query);
$select = $sqlPieces[0];
$table = $sqlPieces[1];
$col = explode('select', $select);
$sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' .
'OVER(ORDER BY ' . $col[1] . ') AS doctrine_rownum FROM ' . $table . ')' .
$select . 'FROM OFFSET WHERE doctrine_rownum BETWEEN ' . $offset .
'AND ' . ($offset + $limit - 1);
return $sql;
}
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Exception
*
* @package Doctrine
* @subpackage Connection
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @deprecated
*/
class Doctrine_Connection_Exception extends Doctrine_Exception
{
/**
* @var array $errorMessages an array containing messages for portable error codes
*/
static protected $errorMessages = array(
Doctrine::ERR => 'unknown error',
Doctrine::ERR_ALREADY_EXISTS => 'already exists',
Doctrine::ERR_CANNOT_CREATE => 'can not create',
Doctrine::ERR_CANNOT_ALTER => 'can not alter',
Doctrine::ERR_CANNOT_REPLACE => 'can not replace',
Doctrine::ERR_CANNOT_DELETE => 'can not delete',
Doctrine::ERR_CANNOT_DROP => 'can not drop',
Doctrine::ERR_CONSTRAINT => 'constraint violation',
Doctrine::ERR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
Doctrine::ERR_DIVZERO => 'division by zero',
Doctrine::ERR_INVALID => 'invalid',
Doctrine::ERR_INVALID_DATE => 'invalid date or time',
Doctrine::ERR_INVALID_NUMBER => 'invalid number',
Doctrine::ERR_MISMATCH => 'mismatch',
Doctrine::ERR_NODBSELECTED => 'no database selected',
Doctrine::ERR_NOSUCHFIELD => 'no such field',
Doctrine::ERR_NOSUCHTABLE => 'no such table',
Doctrine::ERR_NOT_CAPABLE => 'Doctrine backend not capable',
Doctrine::ERR_NOT_FOUND => 'not found',
Doctrine::ERR_NOT_LOCKED => 'not locked',
Doctrine::ERR_SYNTAX => 'syntax error',
Doctrine::ERR_UNSUPPORTED => 'not supported',
Doctrine::ERR_VALUE_COUNT_ON_ROW => 'value count on row',
Doctrine::ERR_INVALID_DSN => 'invalid DSN',
Doctrine::ERR_CONNECT_FAILED => 'connect failed',
Doctrine::ERR_NEED_MORE_DATA => 'insufficient data supplied',
Doctrine::ERR_EXTENSION_NOT_FOUND=> 'extension not found',
Doctrine::ERR_NOSUCHDB => 'no such database',
Doctrine::ERR_ACCESS_VIOLATION => 'insufficient permissions',
Doctrine::ERR_LOADMODULE => 'error while including on demand module',
Doctrine::ERR_TRUNCATED => 'truncated',
Doctrine::ERR_DEADLOCK => 'deadlock detected',
);
/**
* @see Doctrine::ERR_* constants
* @since 1.0
* @var integer $portableCode portable error code
*/
protected $portableCode;
/**
* getPortableCode
* returns portable error code
*
* @return integer portable error code
*/
public function getPortableCode()
{
return $this->portableCode;
}
/**
* getPortableMessage
* returns portable error message
*
* @return string portable error message
*/
public function getPortableMessage()
{
return self::errorMessage($this->portableCode);
}
/**
* Return a textual error message for a Doctrine error code
*
* @param int|array integer error code,
* null to get the current error code-message map,
* or an array with a new error code-message map
*
* @return string error message, or false if the error code was
* not recognized
*/
public function errorMessage($value = null)
{
return isset(self::$errorMessages[$value]) ?
self::$errorMessages[$value] : self::$errorMessages[Doctrine::ERR];
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Connection_Firebird
*
* @package Doctrine
* @subpackage Connection
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @deprecated
*/
class Doctrine_Connection_Firebird extends Doctrine_Connection
{
/**
* @var string $driverName the name of this connection driver
*/
protected $driverName = 'Firebird';
/**
* the constructor
*
* @param Doctrine_Manager $manager
* @param PDO $pdo database handle
*/
public function __construct(array $params)
{
parent::__construct($params);
}
/**
* Set the charset on the current connection
*
* @param string charset
*
* @return void
*/
public function setCharset($charset)
{
$query = 'SET NAMES '.$this->dbh->quote($charset);
$this->exec($query);
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Connection_Mysql
*
* @package Doctrine
* @subpackage Connection
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @deprecated
*/
class Doctrine_Connection_Informix extends Doctrine_Connection
{
/**
* @var string $driverName the name of this connection driver
*/
protected $driverName = 'Informix';
/**
* the constructor
*
* @param Doctrine_Manager $manager
* @param PDO $pdo database handle
*/
public function __construct(Doctrine_Manager $manager, $adapter)
{
// initialize all driver options
parent::__construct($manager, $adapter);
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Connection_Module
*
* @package Doctrine
* @subpackage Connection
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @deprecated
*/
class Doctrine_Connection_Module
{
/**
* @var Doctrine_Connection $conn Doctrine_Connection object, every connection
* module holds an instance of Doctrine_Connection
*/
protected $conn;
/**
* @var string $moduleName the name of this module
*/
protected $moduleName;
/**
* @param Doctrine_Connection $conn Doctrine_Connection object, every connection
* module holds an instance of Doctrine_Connection
*/
public function __construct($conn = null)
{
if ( ! ($conn instanceof Doctrine_Connection)) {
$conn = Doctrine_Manager::getInstance()->getCurrentConnection();
}
$this->conn = $conn;
$e = explode('_', get_class($this));
$this->moduleName = $e[1];
}
/**
* getConnection
* returns the connection object this module uses
*
* @return Doctrine_Connection
*/
public function getConnection()
{
return $this->conn;
}
/**
* getModuleName
* returns the name of this module
*
* @return string the name of this module
*/
public function getModuleName()
{
return $this->moduleName;
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Connection_Mssql
*
* @package Doctrine
* @subpackage Connection
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @deprecated
*/
class Doctrine_Connection_Mssql extends Doctrine_Connection
{
/**
* @var string $driverName the name of this connection driver
*/
protected $driverName = 'Mssql';
/**
* the constructor
*
* @param Doctrine_Manager $manager
* @param PDO $pdo database handle
*/
public function __construct(array $params)
{
parent::__construct($params);
}
/**
* Quote a string so it can be safely used as a table / column name
*
* Quoting style depends on which database driver is being used.
*
* @param string $identifier identifier name to be quoted
* @param bool $checkOption check the 'quote_identifier' option
*
* @return string quoted identifier string
*/
public function quoteIdentifier($identifier, $checkOption = false)
{
if ($checkOption && ! $this->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER)) {
return $identifier;
}
if (strpos($identifier, '.') !== false) {
$parts = explode('.', $identifier);
$quotedParts = array();
foreach ($parts as $p) {
$quotedParts[] = $this->quoteIdentifier($p);
}
return implode('.', $quotedParts);
}
return '[' . str_replace(']', ']]', $identifier) . ']';
}
/**
* return version information about the server
*
* @param bool $native determines if the raw version string should be returned
* @return mixed array/string with version information or MDB2 error object
*/
public function getServerVersion($native = false)
{
if ($this->serverInfo) {
$serverInfo = $this->serverInfo;
} else {
$query = 'SELECT @@VERSION';
$serverInfo = $this->fetchOne($query);
}
// cache server_info
$this->serverInfo = $serverInfo;
if ( ! $native) {
if (preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $serverInfo, $tmp)) {
$serverInfo = array(
'major' => $tmp[1],
'minor' => $tmp[2],
'patch' => $tmp[3],
'extra' => null,
'native' => $serverInfo,
);
} else {
$serverInfo = array(
'major' => null,
'minor' => null,
'patch' => null,
'extra' => null,
'native' => $serverInfo,
);
}
}
return $serverInfo;
}
/**
* Checks if there's a sequence that exists.
*
* @param string $seq_name The sequence name to verify.
* @return boolean The value if the table exists or not
*/
public function checkSequence($seqName)
{
$query = 'SELECT * FROM ' . $seqName;
try {
$this->exec($query);
} catch(Doctrine_Connection_Exception $e) {
if ($e->getPortableCode() == Doctrine::ERR_NOSUCHTABLE) {
return false;
}
throw $e;
}
return true;
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine::DBAL::Connections;
/**
* Doctrine_Connection_Mysql
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @deprecated
*/
class Doctrine_Connection_Mysql extends Doctrine_Connection_Common
{
/**
* Driver name.
*
* @var string
*/
protected $_driverName = 'Mysql';
/**
* the constructor
*
* @param Doctrine_Manager $manager
* @param PDO|Doctrine_Adapter $adapter database handler
*/
public function __construct(array $params)
{
parent::__construct($params);
}
/**
* Set the charset on the current connection
*
* @param string charset
*/
public function setCharset($charset)
{
$this->exec('SET NAMES ' . $this->quote($charset));
}
/**
* Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT
* query, except that if there is already a row in the table with the same
* key field values, the REPLACE query just updates its values instead of
* inserting a new row.
*
* The REPLACE type of query does not make part of the SQL standards. Since
* practically only MySQL implements it natively, this type of query is
* emulated through this method for other DBMS using standard types of
* queries inside a transaction to assure the atomicity of the operation.
*
* @access public
*
* @param string $table name of the table on which the REPLACE query will
* be executed.
* @param array $fields associative array that describes the fields and the
* values that will be inserted or updated in the specified table. The
* indexes of the array are the names of all the fields of the table. The
* values of the array are also associative arrays that describe the
* values and other properties of the table fields.
*
* Here follows a list of field properties that need to be specified:
*
* value:
* Value to be assigned to the specified field. This value may be
* of specified in database independent type format as this
* function can perform the necessary datatype conversions.
*
* Default:
* this property is required unless the Null property
* is set to 1.
*
* type
* Name of the type of the field. Currently, all types Metabase
* are supported except for clob and blob.
*
* Default: no type conversion
*
* null
* Boolean property that indicates that the value for this field
* should be set to null.
*
* The default value for fields missing in INSERT queries may be
* specified the definition of a table. Often, the default value
* is already null, but since the REPLACE may be emulated using
* an UPDATE query, make sure that all fields of the table are
* listed in this function argument array.
*
* Default: 0
*
* key
* Boolean property that indicates that this field should be
* handled as a primary key or at least as part of the compound
* unique index of the table that will determine the row that will
* updated if it exists or inserted a new row otherwise.
*
* This function will fail if no key field is specified or if the
* value of a key field is set to null because fields that are
* part of unique index they may not be null.
*
* Default: 0
*
* @return integer the number of affected rows
*/
public function replace($tableName, array $data, array $keys)
{
$count = count($data);
$query = $values = '';
$keys = $colnum = 0;
for (reset($data); $colnum < $count; next($data), $colnum++) {
$name = key($data);
if ($colnum > 0) {
$query .= ',';
$values.= ',';
}
$query .= $name;
if (isset($data[$name]['null']) && $data[$name]['null']) {
$value = 'NULL';
} else {
$type = isset($data[$name]['type']) ? $data[$name]['type'] : null;
$value = $this->quote($data[$name]['value'], $type);
}
$values .= $value;
if (isset($data[$name]['key']) && $data[$name]['key']) {
if ($value === 'NULL') {
throw new Doctrine_Connection_Mysql_Exception('key value '.$name.' may not be NULL.');
}
$keys++;
}
}
if ($keys == 0) {
throw new Doctrine_Connection_Mysql_Exception('Not specified which fields are keys.');
}
$query = 'REPLACE INTO ' . $tableName . ' (' . $query . ') VALUES (' . $values . ')';
return $this->exec($query);
}
/**
* Constructs the MySql PDO DSN.
*
* Overrides Connection#_constructPdoDsn().
*
* @return string The DSN.
*/
protected function _constructPdoDsn()
{
$dsn = 'mysql:';
if (isset($this->_params['host'])) {
$dsn .= 'host=' . $this->_params['host'] . ';';
}
if (isset($this->_params['port'])) {
$dsn .= 'port=' . $this->_params['port'] . ';';
}
if (isset($this->_params['dbname'])) {
$dsn .= 'dbname=' . $this->_params['dbname'] . ';';
}
if (isset($this->_params['unix_socket'])) {
$dsn .= 'unix_socket=' . $this->_params['unix_socket'] . ';';
}
return $dsn;
}
}
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Connection_Oracle
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @deprecated
*/
class Doctrine_Connection_Oracle extends Doctrine_Connection
{
/**
* @var string $driverName the name of this connection driver
*/
protected $driverName = 'Oracle';
public function __construct(array $params)
{
parent::__construct($params);
}
/**
* Sets up the date/time format
*
*/
public function setDateFormat($format = 'YYYY-MM-DD HH24:MI:SS')
{
$this->exec('ALTER SESSION SET NLS_DATE_FORMAT = "' . $format . '"');
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine::DBAL::Connections;
/**
* PgsqlConnection
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @deprecated
*/
class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common
{
/**
* @var string $driverName the name of this connection driver
*/
protected $driverName = 'Pgsql';
/**
* the constructor
*
* @param Doctrine_Manager $manager
* @param PDO $pdo database handle
*/
public function __construct(array $params)
{
parent::__construct($params);
}
/**
* Set the charset on the current connection
*
* @param string charset
*
* @return void
*/
public function setCharset($charset)
{
$query = 'SET NAMES '.$this->dbh->quote($charset);
$this->exec($query);
}
/**
* convertBoolean
* some drivers need the boolean values to be converted into integers
* when using DQL API
*
* This method takes care of that conversion
*
* @param array $item
* @return void
* @deprecated Moved to PostgreSqlPlatform
*/
public function convertBooleans($item)
{
if (is_array($item)) {
foreach ($item as $key => $value) {
if (is_bool($value) || is_numeric($item)) {
$item[$key] = ($value) ? 'true' : 'false';
}
}
} else {
if (is_bool($item) || is_numeric($item)) {
$item = ($item) ? 'true' : 'false';
}
}
return $item;
}
/**
* return version information about the server
*
* @param string $native determines if the raw version string should be returned
* @return array|string an array or string with version information
*/
/*public function getServerVersion($native = false)
{
$query = 'SHOW SERVER_VERSION';
$serverInfo = $this->fetchOne($query);
if ( ! $native) {
$tmp = explode('.', $serverInfo, 3);
if (empty($tmp[2]) && isset($tmp[1])
&& preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)
) {
$serverInfo = array(
'major' => $tmp[0],
'minor' => $tmp2[1],
'patch' => null,
'extra' => $tmp2[2],
'native' => $serverInfo,
);
} else {
$serverInfo = array(
'major' => isset($tmp[0]) ? $tmp[0] : null,
'minor' => isset($tmp[1]) ? $tmp[1] : null,
'patch' => isset($tmp[2]) ? $tmp[2] : null,
'extra' => null,
'native' => $serverInfo,
);
}
}
return $serverInfo;
}*/
}
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Connection_Profiler
*
* @package Doctrine
* @subpackage Connection
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @deprecated
* @todo remove
*/
class Doctrine_Connection_Profiler implements Doctrine_Overloadable, IteratorAggregate, Countable
{
/**
* @param array $listeners an array containing all availible listeners
*/
private $listeners = array('query',
'prepare',
'commit',
'rollback',
'connect',
'begintransaction',
'exec',
'execute',
);
/**
* @param array $events an array containing all listened events
*/
private $events = array();
/**
* constructor
*/
public function __construct() {
}
/**
* setFilterQueryType
*
* @param integer $filter
* @return boolean
*/
public function setFilterQueryType() {
}
/**
* method overloader
* this method is used for invoking different listeners, for the full
* list of availible listeners, see Doctrine_EventListener
*
* @param string $m the name of the method
* @param array $a method arguments
* @see Doctrine_EventListener
* @return boolean
*/
public function __call($m, $a)
{
// first argument should be an instance of Doctrine_Event
if ( ! ($a[0] instanceof Doctrine_Event)) {
throw new Doctrine_Connection_Profiler_Exception("Couldn't listen event. Event should be an instance of Doctrine_Event.");
}
if (substr($m, 0, 3) === 'pre') {
// pre-event listener found
$a[0]->start();
if ( ! in_array($a[0], $this->events, true)) {
$this->events[] = $a[0];
}
} else {
// after-event listener found
$a[0]->end();
}
/**
* If filtering by query type is enabled, only keep the query if
* it was one of the allowed types.
*/
/**
if ( ! is_null($this->filterTypes)) {
if ( ! ($a[0]->getQueryType() & $this->_filterTypes)) {
}
}
*/
}
/**
* get
*
* @param mixed $key
* @return Doctrine_Event
*/
public function get($key)
{
if (isset($this->events[$key])) {
return $this->events[$key];
}
return null;
}
/**
* getAll
* returns all profiled events as an array
*
* @return array all events in an array
*/
public function getAll()
{
return $this->events;
}
/**
* getIterator
* returns an iterator that iterates through the logged events
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->events);
}
/**
* count
*
* @return integer
*/
public function count()
{
return count($this->events);
}
/**
* pop the last event from the event stack
*
* @return Doctrine_Event
*/
public function pop()
{
return array_pop($this->events);
}
/**
* Get the Doctrine_Event object for the last query that was run, regardless if it has
* ended or not. If the event has not ended, it's end time will be Null.
*
* @return Doctrine_Event
*/
public function lastEvent()
{
if (empty($this->events)) {
return false;
}
end($this->events);
return current($this->events);
}
}
\ No newline at end of file
<?php
/*
* $Id: Exception.php 1345 2007-05-14 13:00:14Z meus $
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Connection_Profiler_Exception
*
* @package Doctrine
* @subpackage Connection
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision: 1345 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @deprecated
*/
class Doctrine_Connection_Profiler_Exception extends Doctrine_Exception
{
}
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine::DBAL::Connections;
/**
* Doctrine_Connection_Sqlite
*
* @package Doctrine
* @subpackage Connection
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @deprecated
*/
class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common
{
/**
* @var string $driverName the name of this connection driver
*/
protected $_driverName = 'Sqlite';
/**
* the constructor
*
* @param Doctrine_Manager $manager
* @param PDO $pdo database handle
*/
public function __construct(array $params)
{
parent::__construct($params);
if ($this->_isConnected) {
$this->_pdo->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
$this->_pdo->sqliteCreateFunction('md5', 'md5', 1);
$this->_pdo->sqliteCreateFunction('now', 'time', 0);
}
}
/**
* initializes database functions missing in sqlite
*
* @see Doctrine_Expression
* @return void
*/
public function connect()
{
if ($this->_isConnected) {
return false;
}
parent::connect();
$this->_pdo->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
$this->_pdo->sqliteCreateFunction('md5', 'md5', 1);
$this->_pdo->sqliteCreateFunction('now', 'time', 0);
}
/**
* createDatabase
*
* @return void
*/
public function createDatabase()
{
try {
if ( ! $dsn = $this->getOption('dsn')) {
throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality');
}
$info = $this->getManager()->parseDsn($dsn);
$this->export->createDatabase($info['database']);
return 'Successfully created database for connection "' . $this->getName() . '" at path "' . $info['database'] . '"';
} catch (Exception $e) {
return $e;
}
}
/**
* dropDatabase
*
* @return void
*/
public function dropDatabase()
{
try {
if ( ! $dsn = $this->getOption('dsn')) {
throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality');
}
$info = $this->getManager()->parseDsn($dsn);
$this->export->dropDatabase($info['database']);
return 'Successfully dropped database for connection "' . $this->getName() . '" at path "' . $info['database'] . '"';
} catch (Exception $e) {
return $e;
}
}
/**
* Constructs the Sqlite PDO DSN.
*
* Overrides Connection#_constructPdoDsn().
*
* @return string The DSN.
*/
protected function _constructPdoDsn()
{
$dsn = 'sqlite:';
if (isset($this->_params['path'])) {
$dsn .= $this->_params['path'];
} else if (isset($this->_params['memory'])) {
$dsn .= ':memory:';
}
return $dsn;
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
...@@ -32,7 +32,7 @@ interface Doctrine_DBAL_Driver ...@@ -32,7 +32,7 @@ interface Doctrine_DBAL_Driver
* *
* @return Doctrine::DBAL::SchemaManager * @return Doctrine::DBAL::SchemaManager
*/ */
public function getSchemaManager(); public function getSchemaManager(Doctrine_DBAL_Connection $conn);
} }
?> ?>
\ No newline at end of file
<?php
/**
* Connection interface.
* Drivers must implement this interface.
*
* This resembles the PDO interface.
*
* @since 2.0
*/
interface Doctrine_DBAL_Driver_Connection
{
public function prepare($prepareString);
public function query($queryString);
public function quote($input);
public function exec($statement);
public function lastInsertId();
public function beginTransaction();
public function commit();
public function rollBack();
public function errorCode();
public function errorInfo();
}
?>
\ No newline at end of file
<?php
class Doctrine_DBAL_Driver_PDOConnection extends PDO implements Doctrine_DBAL_Driver_Connection
{
public function __construct($dsn, $user = null, $password = null, array $options = null)
{
parent::__construct($dsn, $user, $password, $options);
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine_DBAL_Driver_PDOStatement', array()));
}
}
?>
\ No newline at end of file
...@@ -7,54 +7,8 @@ ...@@ -7,54 +7,8 @@
* *
* @since 2.0 * @since 2.0
*/ */
class Doctrine_DBAL_Driver_PDOMsSql_Connection extends PDO implements Doctrine_DBAL_Connection class Doctrine_DBAL_Driver_PDOMsSql_Connection extends PDO implements Doctrine_DBAL_Driver_Connection
{ {
private $_isolationLevel = Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED;
/**
* Set the transacton isolation level.
*
* @param string standard isolation level (SQL-92)
* portable modes:
* READ UNCOMMITTED (allows dirty reads)
* READ COMMITTED (prevents dirty reads)
* REPEATABLE READ (prevents nonrepeatable reads)
* SERIALIZABLE (prevents phantom reads)
*
* @link http://msdn2.microsoft.com/en-us/library/ms173763.aspx
* @throws PDOException if something fails at the PDO level
* @throws Doctrine_Transaction_Exception if using unknown isolation level or unknown wait option
* @return void
* @override
*/
public function setTransactionIsolation($level, $options = array()) {
$sql = "";
switch ($level) {
case Doctrine_DBAL_Connection::TRANSACTION_READ_UNCOMMITTED:
$sql = 'READ UNCOMMITTED';
break;
case Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED:
$sql = 'READ COMMITTED';
break;
case Doctrine_DBAL_Connection::TRANSACTION_REPEATABLE_READ:
$sql = 'REPEATABLE READ';
break;
case Doctrine_DBAL_Connection::TRANSACTION_SERIALIZABLE:
$sql = 'SERIALIZABLE';
break;
default:
throw new Doctrine_Transaction_Exception('isolation level is not supported: ' . $isolation);
}
$this->_isolationLevel = $level;
$this->exec('SET TRANSACTION ISOLATION LEVEL ' . $sql);
}
public function getTransactionIsolation()
{
return $this->_isolationLevel;
}
/** /**
* Performs the rollback. * Performs the rollback.
* *
......
...@@ -9,7 +9,11 @@ class Doctrine_DBAL_Driver_PDOMsSql_Driver implements Doctrine_DBAL_Driver ...@@ -9,7 +9,11 @@ class Doctrine_DBAL_Driver_PDOMsSql_Driver implements Doctrine_DBAL_Driver
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{ {
return new PDO($this->_constructPdoDsn($params), $username, $password, $driverOptions); return new Doctrine_DBAL_Driver_MsSql_Connection(
$this->_constructPdoDsn($params),
$username,
$password,
$driverOptions);
} }
/** /**
......
<?php
class Doctrine_DBAL_Driver_PDOMySql_Connection extends PDO implements Doctrine_DBAL_Connection
{
private $_isolationLevel = Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED;
/**
* Set the transacton isolation level.
*
* @param string standard isolation level
* READ UNCOMMITTED (allows dirty reads)
* READ COMMITTED (prevents dirty reads)
* REPEATABLE READ (prevents nonrepeatable reads)
* SERIALIZABLE (prevents phantom reads)
*
* @throws Doctrine_Transaction_Exception if using unknown isolation level
* @throws PDOException if something fails at the PDO level
* @return void
*/
public function setTransactionIsolation($level)
{
$sql = "";
switch ($level) {
case Doctrine_DBAL_Connection::TRANSACTION_READ_UNCOMMITTED:
$sql = 'READ UNCOMMITTED';
break;
case Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED:
$sql = 'READ COMMITTED';
break;
case Doctrine_DBAL_Connection::TRANSACTION_REPEATABLE_READ:
$sql = 'REPEATABLE READ';
break;
case Doctrine_DBAL_Connection::TRANSACTION_SERIALIZABLE:
$sql = 'SERIALIZABLE';
break;
default:
throw new Doctrine_Transaction_Exception('isolation level is not supported: ' . $isolation);
}
$this->_isolationLevel = $level;
return $this->exec('SET SESSION TRANSACTION ISOLATION LEVEL ' . $sql);
}
/**
* getTransactionIsolation
*
* @return string returns the current session transaction isolation level
*/
public function getTransactionIsolation()
{
return $this->_isolationLevel;
}
}
?>
\ No newline at end of file
...@@ -9,7 +9,11 @@ class Doctrine_DBAL_Driver_PDOMySql_Driver implements Doctrine_DBAL_Driver ...@@ -9,7 +9,11 @@ class Doctrine_DBAL_Driver_PDOMySql_Driver implements Doctrine_DBAL_Driver
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{ {
return new PDO($this->_constructPdoDsn($params), $username, $password, $driverOptions); return new Doctrine_DBAL_Driver_PDOConnection(
$this->_constructPdoDsn($params),
$username,
$password,
$driverOptions);
} }
/** /**
......
...@@ -9,7 +9,11 @@ class Doctrine_DBAL_Driver_PDOOracle_Driver implements Doctrine_DBAL_Driver ...@@ -9,7 +9,11 @@ class Doctrine_DBAL_Driver_PDOOracle_Driver implements Doctrine_DBAL_Driver
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{ {
return new PDO($this->_constructPdoDsn($params), $username, $password, $driverOptions); return new Doctrine_DBAL_Driver_PDOConnection(
$this->_constructPdoDsn($params),
$username,
$password,
$driverOptions);
} }
/** /**
......
...@@ -12,7 +12,11 @@ class Doctrine_DBAL_Driver_PDOPgSql_Driver implements Doctrine_DBAL_Driver ...@@ -12,7 +12,11 @@ class Doctrine_DBAL_Driver_PDOPgSql_Driver implements Doctrine_DBAL_Driver
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{ {
return new PDO($this->_constructPdoDsn($params), $username, $password, $driverOptions); return new Doctrine_DBAL_Driver_PDOConnection(
$this->_constructPdoDsn($params),
$username,
$password,
$driverOptions);
} }
/** /**
......
...@@ -9,7 +9,11 @@ class Doctrine_DBAL_Driver_PDOSqlite_Driver implements Doctrine_DBAL_Driver ...@@ -9,7 +9,11 @@ class Doctrine_DBAL_Driver_PDOSqlite_Driver implements Doctrine_DBAL_Driver
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{ {
return new PDO($this->_constructPdoDsn($params), $username, $password, $driverOptions); return new Doctrine_DBAL_Driver_PDOConnection(
$this->_constructPdoDsn($params),
$username,
$password,
$driverOptions);
} }
/** /**
...@@ -32,12 +36,12 @@ class Doctrine_DBAL_Driver_PDOSqlite_Driver implements Doctrine_DBAL_Driver ...@@ -32,12 +36,12 @@ class Doctrine_DBAL_Driver_PDOSqlite_Driver implements Doctrine_DBAL_Driver
public function getDatabasePlatform() public function getDatabasePlatform()
{ {
return new Doctrine_DatabasePlatform_SqlitePlatform(); return new Doctrine_DBAL_Platforms_SqlitePlatform();
} }
public function getSchemaManager(Doctrine_Connection $conn) public function getSchemaManager(Doctrine_DBAL_Connection $conn)
{ {
return new Doctrine_Schema_SqliteSchemaManager($conn); return new Doctrine_DBAL_Schema_SqliteSchemaManager($conn);
} }
} }
......
<?php
class Doctrine_DBAL_Driver_PDOStatement extends PDOStatement implements Doctrine_DBAL_Driver_Statement
{}
?>
\ No newline at end of file
...@@ -19,14 +19,13 @@ ...@@ -19,14 +19,13 @@
* <http://www.phpdoctrine.org>. * <http://www.phpdoctrine.org>.
*/ */
#namespace Doctrine::DBAL; #namespace Doctrine::DBAL::Driver;
/** /**
* Statement interface. * Statement interface.
* Drivers must implement this interface. * Drivers must implement this interface.
* *
* This includes the full PDOStatement interface as well as custom extensions of * This resembles the PDOStatement interface.
* Doctrine's DBAL.
* *
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
...@@ -35,7 +34,7 @@ ...@@ -35,7 +34,7 @@
* @since 2.0 * @since 2.0
* @version $Revision$ * @version $Revision$
*/ */
interface Doctrine_DBAL_Statement interface Doctrine_DBAL_Driver_Statement
{ {
/** /**
* Bind a column to a PHP variable * Bind a column to a PHP variable
......
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine::DBAL;
/**
* Factory for creating dbms-specific Connection instances.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class Doctrine_DBAL_DriverManager
{
/**
* List of supported drivers and their mappings to the driver class.
*
* @var array
*/
private $_drivers = array(
'pdo_mysql' => 'Doctrine_DBAL_Driver_PDOMySql_Driver',
'pdo_sqlite' => 'Doctrine_DBAL_Driver_PDOSqlite_Driver',
'pdo_pgsql' => 'Doctrine_DBAL_Driver_PDOPgSql_Driver',
'pdo_oracle' => 'Doctrine_DBAL_Driver_PDOOracle_Driver',
'pdo_mssql' => 'Doctrine_DBAL_Driver_PDOMsSql_Driver',
'pdo_firebird' => 'Doctrine_DBAL_Driver_PDOFirebird_Driver',
'pdo_informix' => 'Doctrine_DBAL_Driver_PDOInformix_Driver',
);
public function __construct()
{
}
/**
* Creates a connection object with the specified parameters.
*
* @param array $params
* @return Connection
*/
public function getConnection(array $params, Doctrine_Common_Configuration $config = null,
Doctrine_Common_EventManager $eventManager = null)
{
// create default config and event manager, if not set
if ( ! $config) {
$config = new Doctrine_Common_Configuration();
}
if ( ! $eventManager) {
$eventManager = new Doctrine_Common_EventManager();
}
// check for existing pdo object
if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) {
throw Doctrine_DBAL_Exceptions_DBALException::invalidPDOInstance();
} else if (isset($params['pdo'])) {
$params['driver'] = $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME);
} else {
$this->_checkParams($params);
}
if (isset($params['driverClass'])) {
$className = $params['driverClass'];
} else {
$className = $this->_drivers[$params['driver']];
}
$driver = new $className();
$wrapperClass = 'Doctrine_DBAL_Connection';
if (isset($params['wrapperClass'])) {
$wrapperClass = $params['wrapperClass'];
}
return new $wrapperClass($params, $driver, $config, $eventManager);
}
/**
* Checks the list of parameters.
*
* @param array $params
*/
private function _checkParams(array $params)
{
// check existance of mandatory parameters
// driver
if ( ! isset($params['driver']) && ! isset($params['driverClass'])) {
throw Doctrine_ConnectionFactory_Exception::driverRequired();
}
// check validity of parameters
// driver
if ( isset($params['driver']) && ! isset($this->_drivers[$params['driver']])) {
throw Doctrine_DBAL_Exceptions_DBALException::unknownDriver($params['driver']);
}
}
}
?>
\ No newline at end of file
<?php
/**
*
*
* @package Doctrine
* @subpackage Hydrate
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision: 1080 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_DBAL_Exceptions_DBALException extends Exception
{
public static function invalidPDOInstance()
{
return new self("Invalid PDO instance provided on connection creation.");
}
public static function driverRequired()
{
return new self("Please provide a driver or a driverClass to be able to start a Connection.");
}
public static function unknownDriver($driver)
{
return new self("Unknown Connection driver '$driver'.");
}
}
\ No newline at end of file
...@@ -1774,6 +1774,48 @@ abstract class Doctrine_DBAL_Platforms_AbstractPlatform ...@@ -1774,6 +1774,48 @@ abstract class Doctrine_DBAL_Platforms_AbstractPlatform
return 'SET NAMES ' . $this->quote($charset); return 'SET NAMES ' . $this->quote($charset);
} }
/**
* Enter description here...
*
* @param unknown_type $level
*/
protected function _getTransactionIsolationLevelSql($level)
{
switch ($level) {
case Doctrine_DBAL_Connection::TRANSACTION_READ_UNCOMMITTED:
return 'READ UNCOMMITTED';
case Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED:
return 'READ COMMITTED';
case Doctrine_DBAL_Connection::TRANSACTION_REPEATABLE_READ:
return 'REPEATABLE READ';
case Doctrine_DBAL_Connection::TRANSACTION_SERIALIZABLE:
return 'SERIALIZABLE';
default:
throw new Doctrine_Common_Exceptions_DoctrineException('isolation level is not supported: ' . $isolation);
}
}
/**
* Enter description here...
*
* @param unknown_type $level
*/
public function getSetTransactionIsolationSql($level)
{
throw new Doctrine_Export_Exception('Set transaction isolation not supported by this platform.');
}
/**
* Gets the default transaction isolation level of the platform.
*
* @return integer The default isolation level.
* @see Doctrine::DBAL::Connection::TRANSACTION_* constants.
*/
public function getDefaultTransactionIsolationLevel()
{
return Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED;
}
/* supports*() metods */ /* supports*() metods */
......
...@@ -257,6 +257,39 @@ class Doctrine_DBAL_Platforms_FirebirdPlatform extends Doctrine_DBAL_Platforms_A ...@@ -257,6 +257,39 @@ class Doctrine_DBAL_Platforms_FirebirdPlatform extends Doctrine_DBAL_Platforms_A
return 'SELECT GEN_ID(' . $this->quoteIdentifier($sequenceName) . ', 1) FROM RDB$DATABASE'; return 'SELECT GEN_ID(' . $this->quoteIdentifier($sequenceName) . ', 1) FROM RDB$DATABASE';
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
protected function _getTransactionIsolationLevelSql($level)
{
switch ($level) {
case Doctrine_DBAL_Connection::TRANSACTION_READ_UNCOMMITTED:
return 'READ COMMITTED RECORD_VERSION';
case Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED:
return 'READ COMMITTED NO RECORD_VERSION';
case Doctrine_DBAL_Connection::TRANSACTION_REPEATABLE_READ:
return 'SNAPSHOT';
case Doctrine_DBAL_Connection::TRANSACTION_SERIALIZABLE:
return 'SNAPSHOT TABLE STABILITY';
default:
return parent::_getTransactionIsolationLevelSql($level);
}
}
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
public function getSetTransactionIsolationSql($level)
{
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
}
} }
?> ?>
\ No newline at end of file
...@@ -311,6 +311,17 @@ class Doctrine_DBAL_Platforms_MsSqlPlatform extends Doctrine_DBAL_Platforms_Abst ...@@ -311,6 +311,17 @@ class Doctrine_DBAL_Platforms_MsSqlPlatform extends Doctrine_DBAL_Platforms_Abst
return '[' . str_replace(']', ']]', $identifier) . ']'; return '[' . str_replace(']', ']]', $identifier) . ']';
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
public function getSetTransactionIsolationSql($level)
{
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
}
} }
?> ?>
\ No newline at end of file
...@@ -1234,6 +1234,17 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst ...@@ -1234,6 +1234,17 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
$table = $this->quoteIdentifier($table, true); $table = $this->quoteIdentifier($table, true);
return 'DROP TABLE ' . $table; return 'DROP TABLE ' . $table;
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
public function getSetTransactionIsolationSql($level)
{
return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
}
} }
?> ?>
\ No newline at end of file
...@@ -344,6 +344,37 @@ class Doctrine_DBAL_Platforms_OraclePlatform extends Doctrine_DBAL_Platforms_Abs ...@@ -344,6 +344,37 @@ class Doctrine_DBAL_Platforms_OraclePlatform extends Doctrine_DBAL_Platforms_Abs
{ {
return 'SELECT ' . $this->quoteIdentifier($sequenceName) . '.nextval FROM DUAL'; return 'SELECT ' . $this->quoteIdentifier($sequenceName) . '.nextval FROM DUAL';
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
public function getSetTransactionIsolationSql($level)
{
return 'ALTER SESSION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
}
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
protected function _getTransactionIsolationLevelSql($level)
{
switch ($level) {
case Doctrine_DBAL_Connection::TRANSACTION_READ_UNCOMMITTED:
return 'READ COMMITTED';
case Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED:
case Doctrine_DBAL_Connection::TRANSACTION_REPEATABLE_READ:
case Doctrine_DBAL_Connection::TRANSACTION_SERIALIZABLE:
return 'SERIALIZABLE';
default:
return parent::_getTransactionIsolationLevelSql($level);
}
}
} }
?> ?>
\ No newline at end of file
...@@ -989,6 +989,18 @@ class Doctrine_DBAL_Platforms_PostgreSqlPlatform extends Doctrine_DBAL_Platforms ...@@ -989,6 +989,18 @@ class Doctrine_DBAL_Platforms_PostgreSqlPlatform extends Doctrine_DBAL_Platforms
{ {
return "SELECT NEXTVAL('" . $sequenceName . "')"; return "SELECT NEXTVAL('" . $sequenceName . "')";
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
public function getSetTransactionIsolationSql($level)
{
return 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL '
. $this->_getTransactionIsolationLevelSql($level);
}
} }
?> ?>
\ No newline at end of file
...@@ -360,6 +360,37 @@ class Doctrine_DBAL_Platforms_SqlitePlatform extends Doctrine_DBAL_Platforms_Abs ...@@ -360,6 +360,37 @@ class Doctrine_DBAL_Platforms_SqlitePlatform extends Doctrine_DBAL_Platforms_Abs
'unsigned' => $unsigned, 'unsigned' => $unsigned,
'fixed' => $fixed); 'fixed' => $fixed);
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
protected function _getTransactionIsolationLevelSql($level)
{
switch ($level) {
case Doctrine_DBAL_Connection::TRANSACTION_READ_UNCOMMITTED:
return 0;
case Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED:
case Doctrine_DBAL_Connection::TRANSACTION_REPEATABLE_READ:
case Doctrine_DBAL_Connection::TRANSACTION_SERIALIZABLE:
return 1;
default:
return parent::_getTransactionIsolationLevelSql($level);
}
}
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
public function getSetTransactionIsolationSql($level)
{
return 'PRAGMA read_uncommitted = ' . $this->_getTransactionIsolationLevelSql($level);
}
} }
?> ?>
\ No newline at end of file
...@@ -148,7 +148,7 @@ class Doctrine_ORM_EntityManager ...@@ -148,7 +148,7 @@ class Doctrine_ORM_EntityManager
* @param Doctrine_Connection $conn * @param Doctrine_Connection $conn
* @param string $name * @param string $name
*/ */
protected function __construct(Doctrine_Connection $conn, $name, Doctrine_Common_Configuration $config, protected function __construct(Doctrine_DBAL_Connection $conn, $name, Doctrine_Common_Configuration $config,
Doctrine_Common_EventManager $eventManager) Doctrine_Common_EventManager $eventManager)
{ {
$this->_conn = $conn; $this->_conn = $conn;
...@@ -157,7 +157,7 @@ class Doctrine_ORM_EntityManager ...@@ -157,7 +157,7 @@ class Doctrine_ORM_EntityManager
$this->_eventManager = $eventManager; $this->_eventManager = $eventManager;
$this->_metadataFactory = new Doctrine_ClassMetadata_Factory( $this->_metadataFactory = new Doctrine_ClassMetadata_Factory(
$this, new Doctrine_ClassMetadata_CodeDriver()); $this, new Doctrine_ClassMetadata_CodeDriver());
$this->_unitOfWork = new Doctrine_Connection_UnitOfWork($this); $this->_unitOfWork = new Doctrine_ORM_UnitOfWork($this);
$this->_nullObject = Doctrine_ORM_Internal_Null::$INSTANCE; $this->_nullObject = Doctrine_ORM_Internal_Null::$INSTANCE;
} }
......
<?php <?php
/* /*
* $Id$ * $Id: UnitOfWork.php 4947 2008-09-12 13:16:05Z romanb $
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
...@@ -33,13 +33,13 @@ ...@@ -33,13 +33,13 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org * @link www.phpdoctrine.org
* @since 2.0 * @since 2.0
* @version $Revision$ * @version $Revision: 4947 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @todo Rename: Doctrine::ORM::UnitOfWork. * @todo Rename: Doctrine::ORM::UnitOfWork.
* @todo Turn connection exceptions into UnitOfWorkExceptions. * @todo Turn connection exceptions into UnitOfWorkExceptions.
*/ */
class Doctrine_Connection_UnitOfWork class Doctrine_ORM_UnitOfWork
{ {
/** /**
* The identity map that holds references to all managed entities that have * The identity map that holds references to all managed entities that have
......
...@@ -130,7 +130,7 @@ class Doctrine_Query_Parser ...@@ -130,7 +130,7 @@ class Doctrine_Query_Parser
$this->_em = $query->getEntityManager(); $this->_em = $query->getEntityManager();
$this->_input = $query->getDql(); $this->_input = $query->getDql();
$this->_scanner = new Doctrine_Query_Scanner($this->_input); $this->_scanner = new Doctrine_Query_Scanner($this->_input);
$this->_sqlBuilder = Doctrine_Query_SqlBuilder::fromConnection($this->_em); $this->_sqlBuilder = new Doctrine_Query_SqlBuilder($this->_em);
$this->_keywordTable = new Doctrine_Query_Token(); $this->_keywordTable = new Doctrine_Query_Token();
$this->_parserResult = new Doctrine_Query_ParserResult( $this->_parserResult = new Doctrine_Query_ParserResult(
......
...@@ -21,7 +21,10 @@ ...@@ -21,7 +21,10 @@
*/ */
/** /**
* Base class of each Sql Builder object * The SqlBuilder. Creates SQL out of an AST.
*
* INTERNAL: For platform-specific SQL, the platform of the connection should be used.
* ($this->_connection->getDatabasePlatform())
* *
* @package Doctrine * @package Doctrine
* @subpackage Query * @subpackage Query
...@@ -32,28 +35,17 @@ ...@@ -32,28 +35,17 @@
* @since 2.0 * @since 2.0
* @version $Revision$ * @version $Revision$
*/ */
abstract class Doctrine_Query_SqlBuilder class Doctrine_Query_SqlBuilder
{ {
/** protected $_em;
* The Connection object. protected $_conn;
*
* @var Doctrine_Connection
*/
protected $_connection;
public function __construct(Doctrine_ORM_EntityManager $em)
public static function fromConnection(Doctrine_ORM_EntityManager $entityManager)
{ {
$connection = $entityManager->getConnection(); $this->_em = $em;
$this->_conn = $this->_em->getConnection();
$className = "Doctrine_Query_SqlBuilder_" . $connection->getDriverName();
$sqlBuilder = new $className();
$sqlBuilder->_connection = $connection;
return $sqlBuilder;
} }
/** /**
* Retrieves the assocated Doctrine_Connection to this object. * Retrieves the assocated Doctrine_Connection to this object.
* *
...@@ -64,23 +56,12 @@ abstract class Doctrine_Query_SqlBuilder ...@@ -64,23 +56,12 @@ abstract class Doctrine_Query_SqlBuilder
return $this->_connection; return $this->_connection;
} }
/** /**
* @nodoc * @nodoc
*/ */
public function quoteIdentifier($identifier) public function quoteIdentifier($identifier)
{ {
return $this->_connection->quoteIdentifier($identifier); return $this->_conn->quoteIdentifier($identifier);
} }
// Start Common SQL generations
// Here we follow the SQL-99 specifications available at:
// http://savage.net.au/SQL/sql-99.bnf
// End of Common SQL generations
} }
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Sequence_Db2
*
* @package Doctrine
* @subpackage Sequence
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @deprecated
*/
class Doctrine_Sequence_Db2 extends Doctrine_Sequence
{
/**
* Return the most recent value from the specified sequence in the database.
* This is supported only on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return integer
* @throws Doctrine_Adapter_Db2_Exception
*/
public function lastSequenceId($sequenceName)
{
$sql = 'SELECT PREVVAL FOR '
. $this->quoteIdentifier($this->conn->formatter->getSequenceName($sequenceName))
. ' AS VAL FROM SYSIBM.SYSDUMMY1';
$stmt = $this->query($sql);
$result = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
if ($result) {
return $result[0]['VAL'];
} else {
return null;
}
}
/**
* Generate a new value from the specified sequence in the database, and return it.
* This is supported only on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return integer
* @throws Doctrine_Adapter_Db2_Exception
*/
public function nextSequenceId($sequenceName)
{
$this->_connect();
$sql = 'SELECT NEXTVAL FOR '
. $this->quoteIdentifier($this->conn->formatter->getSequenceName($sequenceName))
. ' AS VAL FROM SYSIBM.SYSDUMMY1';
$stmt = $this->query($sql);
$result = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
if ($result) {
return $result[0]['VAL'];
} else {
return null;
}
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* As a convention, on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
* from the arguments and returns the last id generated by that sequence.
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
* returns the last value generated for such a column, and the table name
* argument is disregarded.
*
* The IDENTITY_VAL_LOCAL() function gives the last generated identity value
* in the current process, even if it was for a GENERATED column.
*
* @param string $tableName OPTIONAL
* @param string $primaryKey OPTIONAL
* @return integer
* @throws Doctrine_Adapter_Db2_Exception
*/
public function lastInsertId($tableName = null, $primaryKey = null)
{
$this->_connect();
if ($tableName !== null) {
$sequenceName = $tableName;
if ($primaryKey) {
$sequenceName .= "_$primaryKey";
}
$sequenceName .= '_seq';
return $this->lastSequenceId($sequenceName);
}
$sql = 'SELECT IDENTITY_VAL_LOCAL() AS VAL FROM SYSIBM.SYSDUMMY1';
$stmt = $this->query($sql);
$result = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
if ($result) {
return $result[0]['VAL'];
} else {
return null;
}
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Exception');
/**
* Doctrine_Sequence_Exception
*
* @package Doctrine
* @subpackage Sequence
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Sequence_Exception extends Doctrine_Exception
{ }
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Sequence_Firebird
*
* @package Doctrine
* @subpackage Sequence
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
*/
class Doctrine_Sequence_Firebird extends Doctrine_Sequence
{
/**
* Returns the next free id of a sequence.
*
* @param string $seqName name of the sequence
* @param bool when true missing sequences are automatic created
*
* @return integer next id in the given sequence
*/
public function nextID($seqName, $onDemand = true)
{
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
$query = 'SELECT GEN_ID(' . $sequenceName . ', 1) as the_value FROM RDB$DATABASE';
try {
$result = $this->conn->fetchOne($query);
} catch(Doctrine_Connection_Exception $e) {
if ($onDemand && $e->getPortableCode() == Doctrine::ERR_NOSUCHTABLE) {
// Since we are creating the sequence on demand
// we know the first id = 1 so initialize the
// sequence at 2
try {
$result = $this->conn->export->createSequence($seqName, 2);
} catch(Doctrine_Exception $e) {
throw new Doctrine_Sequence_Exception('on demand sequence ' . $seqName . ' could not be created');
}
// First ID of a newly created sequence is 1
// return 1;
// BUT generators are not always reset, so return the actual value
return $this->currID($seqName);
}
throw $e;
}
return $result;
}
/**
* Returns the autoincrement ID if supported or $id or fetches the current
* ID in a sequence called: $table.(empty($field) ? '' : '_'.$field)
*
* @param string name of the table into which a new row was inserted
* @param string name of the field into which a new row was inserted
*/
public function lastInsertId($table = null, $field = null)
{
return $this->conn->getDbh()->lastInsertId();
}
/**
* Returns the current id of a sequence
*
* @param string $seqName name of the sequence
*
* @return integer current id in the given sequence
*/
public function currId($seqName)
{
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
$query = 'SELECT GEN_ID(' . $sequenceName . ', 0) as the_value FROM RDB$DATABASE';
try {
$value = $this->conn->fetchOne($query);
} catch(Doctrine_Connection_Exception $e) {
throw new Doctrine_Sequence_Exception('Unable to select from ' . $seqName);
}
if ( ! is_numeric($value)) {
throw new Doctrine_Sequence_Exception('could not find value in sequence table');
}
return $value;
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Sequence_Informix
*
* @package Doctrine
* @subpackage Sequence
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @deprecated
*/
class Doctrine_Sequence_Informix extends Doctrine_Sequence
{ }
\ No newline at end of file
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Sequence_Mssql
*
* @package Doctrine
* @subpackage Sequence
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @deprecated
*/
class Doctrine_Sequence_Mssql extends Doctrine_Sequence
{
/**
* Returns the next free id of a sequence
*
* @param string $seqName name of the sequence
* @param bool when true missing sequences are automatic created
*
* @return integer next id in the given sequence
*/
public function nextId($seqName, $onDemand = true)
{
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
if ($this->checkSequence($sequenceName)) {
$query = 'SET IDENTITY_INSERT ' . $sequenceName . ' OFF '
. 'INSERT INTO ' . $sequenceName . ' DEFAULT VALUES';
} else {
$query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (0)';
}
try {
$this->conn->exec($query);
} catch(Doctrine_Connection_Exception $e) {
if ($onDemand && $e->getPortableCode() == Doctrine::ERR_NOSUCHTABLE) {
// Since we are creating the sequence on demand
// we know the first id = 1 so initialize the
// sequence at 2
try {
$result = $this->conn->export->createSequence($seqName, 2);
} catch(Doctrine_Exception $e) {
throw new Doctrine_Sequence_Exception('on demand sequence ' . $seqName . ' could not be created');
}
/**
* This could actually be a table that starts at 18.. oh well..
* we will keep the fallback to return 1 in case we skip this.. which
* should really not happen.. otherwise the returned values is biased.
*/
if ($this->checkSequence($seqName)) {
return $this->lastInsertId($seqName);
}
return 1;
}
throw $e;
}
$value = $this->lastInsertId($sequenceName);
if (is_numeric($value)) {
$query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value;
try {
$this->conn->exec($query);
} catch (Doctrine_Connection_Exception $e) {
throw new Doctrine_Sequence_Exception('Could not delete previous sequence from ' . $sequenceName .
' at ' . __FILE__ . ' in ' . __FUNCTION__ . ' with the message: ' .
$e->getMessage());
}
}
return $value;
}
/**
* Checks if there's a sequence that exists.
*
* @param string $seqName The sequence name to verify.
* @return bool $tableExists The value if the table exists or not
* @access private
*/
public function checkSequence($seqName)
{
$query = 'SELECT COUNT(1) FROM ' . $seqName;
try {
$this->conn->execute($query);
} catch (Doctrine_Connection_Exception $e) {
if ($e->getPortableCode() == Doctrine::ERR_NOSUCHTABLE) {
return false;
}
}
return true;
}
/**
* Returns the autoincrement ID if supported or $id or fetches the current
* ID in a sequence called: $table.(empty($field) ? '' : '_'.$field)
*
* @param string name of the table into which a new row was inserted
* @param string name of the field into which a new row was inserted
*/
public function lastInsertId($table = null, $field = null)
{
$serverInfo = $this->conn->getServerVersion();
if (is_array($serverInfo)
&& ! is_null($serverInfo['major'])
&& $serverInfo['major'] >= 8) {
$query = 'SELECT SCOPE_IDENTITY()';
} else {
$query = 'SELECT @@IDENTITY';
}
return (string) floor((float) $this->conn->fetchOne($query));
}
/**
* Returns the current id of a sequence
*
* @param string $seqName name of the sequence
*
* @return integer current id in the given sequence
*/
public function currId($seqName)
{
$this->warnings[] = 'database does not support getting current
sequence value, the sequence value was incremented';
return $this->nextId($seqName);
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
/*
* $Id$
*
* 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, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Exception');
/**
* Doctrine_Transaction_Exception
*
* @package Doctrine
* @subpackage Transaction
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @since 1.0
* @version $Revision$
* @link www.phpdoctrine.org
* @todo remove
*/
class Doctrine_Transaction_Exception extends Doctrine_Exception
{ }
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php <?php
require_once 'lib/mocks/Doctrine_ConnectionMock.php'; require_once 'lib/mocks/Doctrine_DriverMock.php';
/** /**
* Base testcase class for all orm testcases. * Base testcase class for all orm testcases.
...@@ -18,7 +18,8 @@ class Doctrine_OrmTestCase extends Doctrine_TestCase ...@@ -18,7 +18,8 @@ class Doctrine_OrmTestCase extends Doctrine_TestCase
$config = new Doctrine_Configuration(); $config = new Doctrine_Configuration();
$eventManager = new Doctrine_EventManager(); $eventManager = new Doctrine_EventManager();
$connectionOptions = array( $connectionOptions = array(
'driverClass' => 'Doctrine_ConnectionMock', 'driverClass' => 'Doctrine_DriverMock',
'wrapperClass' => 'Doctrine_ConnectionMock',
'user' => 'john', 'user' => 'john',
'password' => 'wayne' 'password' => 'wayne'
); );
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment