diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index b02e234fd..948b99ac2 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -67,6 +67,15 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun $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 * @@ -145,7 +154,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * READ COMMITTED (prevents dirty reads) * REPEATABLE READ (prevents nonrepeatable reads) * SERIALIZABLE (prevents phantom reads) - * @throws Doctrine_Connection_Mysql_Exception if using unknown isolation level + * * @throws PDOException if something fails at the PDO level * @return void */ @@ -162,6 +171,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun public function getRegexpOperator() { 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 * queries the database with Doctrine Query Language diff --git a/lib/Doctrine/Connection/Mysql.php b/lib/Doctrine/Connection/Mysql.php index ba4e4c6aa..fe2d04f29 100644 --- a/lib/Doctrine/Connection/Mysql.php +++ b/lib/Doctrine/Connection/Mysql.php @@ -46,6 +46,15 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { public function getRegexpOperator() { 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. * diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index 05bb0d020..77c54e902 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -27,14 +27,79 @@ * @license LGPL */ class Doctrine_Export { + /** + * @var Doctrine_Connection $conn Doctrine_Connection object + */ private $conn; - + /** + * @var mixed $dbh the database handler (either PDO or Doctrine_DB object) + */ private $dbh; public function __construct($conn) { $this->conn = $conn; $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() { $parent = new ReflectionClass('Doctrine_Record'); $conn = Doctrine_Manager::getInstance()->getCurrentConnection(); diff --git a/lib/Doctrine/Expression/Firebird.php b/lib/Doctrine/Expression/Firebird.php new file mode 100644 index 000000000..e9473b846 --- /dev/null +++ b/lib/Doctrine/Expression/Firebird.php @@ -0,0 +1,39 @@ +. + */ +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'; + } +} diff --git a/lib/Doctrine/Expression/Mssql.php b/lib/Doctrine/Expression/Mssql.php new file mode 100644 index 000000000..3509c758d --- /dev/null +++ b/lib/Doctrine/Expression/Mssql.php @@ -0,0 +1,73 @@ +. + */ +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) . ')'; + } +} diff --git a/lib/Doctrine/Expression/Mysql.php b/lib/Doctrine/Expression/Mysql.php new file mode 100644 index 000000000..13d7de005 --- /dev/null +++ b/lib/Doctrine/Expression/Mysql.php @@ -0,0 +1,29 @@ +. + */ +Doctrine::autoload('Doctrine_Expression'); +/** + * Doctrine_Expression_Mysql + * + * @package Doctrine ORM + * @url www.phpdoctrine.com + * @license LGPL + */ +class Doctrine_Expression_Mysql extends Doctrine_Expression { }