1
0
mirror of synced 2024-12-13 22:56:04 +03:00

Added Mysql, Mssql and Firebird expression drivers, fixes #199, #200, #201

Ticket: 199
This commit is contained in:
zYne 2006-10-26 15:32:09 +00:00
parent 0d75147c70
commit 79034ea74d
6 changed files with 234 additions and 2 deletions

View File

@ -67,6 +67,15 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this->getAttribute(Doctrine::ATTR_LISTENER)->onOpen($this); $this->getAttribute(Doctrine::ATTR_LISTENER)->onOpen($this);
} }
/**
* quoteIdentifier
*
* @param string $identifier identifier to be quoted
* @return string modified identifier
*/
public function quoteIdentifier($identifier) {
return $identifier;
}
/** /**
* getUnitOfWork * getUnitOfWork
* *
@ -145,7 +154,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* READ COMMITTED (prevents dirty reads) * READ COMMITTED (prevents dirty reads)
* REPEATABLE READ (prevents nonrepeatable reads) * REPEATABLE READ (prevents nonrepeatable reads)
* SERIALIZABLE (prevents phantom reads) * SERIALIZABLE (prevents phantom reads)
* @throws Doctrine_Connection_Mysql_Exception if using unknown isolation level *
* @throws PDOException if something fails at the PDO level * @throws PDOException if something fails at the PDO level
* @return void * @return void
*/ */
@ -162,6 +171,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function getRegexpOperator() { public function getRegexpOperator() {
throw new Doctrine_Connection_Exception('Regular expression operator is not supported by this database driver.'); throw new Doctrine_Connection_Exception('Regular expression operator is not supported by this database driver.');
} }
/**
* getTransactionIsolation
*
* @return string returns the current session transaction isolation level
*/
public function getTransactionIsolation() {
throw new Doctrine_Connection_Exception('Fetching transaction isolation level not supported by this database driver.');
}
/** /**
* query * query
* queries the database with Doctrine Query Language * queries the database with Doctrine Query Language

View File

@ -46,6 +46,15 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
public function getRegexpOperator() { public function getRegexpOperator() {
return 'RLIKE'; return 'RLIKE';
} }
/**
* getTransactionIsolation
*
* @return string returns the current session transaction isolation level
*/
public function getTransactionIsolation() {
$ret = $this->dbh->query('SELECT @@tx_isolation')->fetch(PDO::FETCH_NUM);
return $ret[0];
}
/** /**
* Set the transacton isolation level. * Set the transacton isolation level.
* *

View File

@ -27,14 +27,79 @@
* @license LGPL * @license LGPL
*/ */
class Doctrine_Export { class Doctrine_Export {
/**
* @var Doctrine_Connection $conn Doctrine_Connection object
*/
private $conn; private $conn;
/**
* @var mixed $dbh the database handler (either PDO or Doctrine_DB object)
*/
private $dbh; private $dbh;
public function __construct($conn) { public function __construct($conn) {
$this->conn = $conn; $this->conn = $conn;
$this->dbh = $conn->getDBH(); $this->dbh = $conn->getDBH();
} }
/**
* dropTable
*
* @param string $table name of table that should be dropped from the database
* @throws PDOException
* @return void
*/
public function dropTable($table) {
$this->dbh->query('DROP TABLE '.$table);
}
/**
* [[ borrowed from PEAR MDB2 ]]
*
* Get the stucture of a field into an array
*
*
* @param string $table name of the table on which the index is to be created
* @param string $name name of the index to be created
* @param array $definition associative array that defines properties of the index to be created.
* Currently, only one property named FIELDS is supported. This property
* is also an associative with the names of the index fields as array
* indexes. Each entry of this array is set to another type of associative
* array that specifies properties of the index that are specific to
* each field.
*
* Currently, only the sorting property is supported. It should be used
* to define the sorting direction of the index. It may be set to either
* ascending or descending.
*
* Not all DBMS support index sorting direction configuration. The DBMS
* drivers of those that do not support it ignore this property. Use the
* function supports() to determine whether the DBMS driver can manage indexes.
*
* Example
* array(
* 'fields' => array(
* 'user_name' => array(
* 'sorting' => 'ascending'
* ),
* 'last_login' => array()
* )
* )
* @throws PDOException
* @return void
*/
function createIndex($table, $name, array $definition) {
$table = $this->conn->quoteIdentifier($table);
$name = $this->conn->quoteIdentifier($name);
$query = "CREATE INDEX $name ON $table";
$fields = array();
foreach (array_keys($definition['fields']) as $field) {
$fields[] = $this->conn->quoteIdentifier($field);
}
$query .= ' ('. implode(', ', $fields) . ')';
return $this->dbh->query($query);
}
/**
* export
*/
public function export() { public function export() {
$parent = new ReflectionClass('Doctrine_Record'); $parent = new ReflectionClass('Doctrine_Record');
$conn = Doctrine_Manager::getInstance()->getCurrentConnection(); $conn = Doctrine_Manager::getInstance()->getCurrentConnection();

View File

@ -0,0 +1,39 @@
<?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.com>.
*/
Doctrine::autoload('Doctrine_Expression');
/**
* Doctrine_Expression_Firebird
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*/
class Doctrine_Expression_Firebird extends Doctrine_Expression {
/**
* return string for internal table used when calling only a function
*
* @return string for internal table used when calling only a function
* @access public
*/
public function functionTable() {
return ' FROM RDB$DATABASE';
}
}

View File

@ -0,0 +1,73 @@
<?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.com>.
*/
Doctrine::autoload('Doctrine_Expression');
/**
* Doctrine_Expression_Mssql
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*/
class Doctrine_Expression_Mssql extends Doctrine_Expression {
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time:
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
* - CURRENT_DATE (date, DATE type)
* - CURRENT_TIME (time, TIME type)
*
* @return string to call a variable with the current timestamp
* @access public
*/
public function now($type = 'timestamp') {
switch ($type) {
case 'time':
case 'date':
case 'timestamp':
default:
return 'GETDATE()';
}
}
/**
* return string to call a function to get a substring inside an SQL statement
*
* @return string to call a function to get a substring
*/
public function substring($value, $position = 1, $length = null) {
if (!is_null($length))
return "SUBSTRING($value, $position, $length)";
return "SUBSTRING($value, $position, LEN($value) - $position + 1)";
}
/**
* Returns string to concatenate two or more string parameters
*
* @param string $arg1
* @param string $arg2
* @param string $values...
* @return string to concatenate two strings
* @access public
**/
function concat($arg1, $arg2) {
$args = func_get_args();
return '(' . implode(' + ', $args) . ')';
}
}

View File

@ -0,0 +1,29 @@
<?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.com>.
*/
Doctrine::autoload('Doctrine_Expression');
/**
* Doctrine_Expression_Mysql
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*/
class Doctrine_Expression_Mysql extends Doctrine_Expression { }