Commit fcce6bd2 authored by zYne's avatar zYne

Updated transaction drivers, ORM core now uses the new Export API

parent 33fbb4f3
......@@ -34,7 +34,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
/**
* @var $dbh the database handler
*/
private $dbh;
protected $dbh;
/**
* @var array $tables an array containing all the initialized Doctrine_Table objects
* keys representing Doctrine_Table component names and values as Doctrine_Table objects
......@@ -76,7 +76,20 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
/**
* @var array $properties an array of connection properties
*/
protected $properties = array();
protected $properties = array('sql_comments' => array(array('start' => '--', 'end' => "\n", 'escape' => false),
array('start' => '/*', 'end' => '*/', 'escape' => false)
),
'identifier_quoting' => array('start' => '"',
'end' => '"',
'escape' => '"'
),
'string_quoting' => array('start' => "'",
'end' => "'",
'escape' => false,
'escape_pattern' => false
),
'wildcards' => array('%', '_')
);
/**
* @var array $availibleDrivers an array containing all availible drivers
*/
......@@ -254,15 +267,24 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
/**
* quote
* quotes given input parameter
*
* @param mixed $input
* @param mixed $input parameter to be quoted
* @param string $type
* @return mixed
*/
public function quote($input, $type = null) {
if($type == null) {
$type = gettype($input);
}
switch($type) {
case 'integer':
case 'enum':
case 'boolean':
return $input;
case 'array':
case 'object':
$input = serialize($input);
case 'string':
case 'char':
case 'varchar':
......@@ -270,8 +292,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
case 'gzip':
case 'blob':
case 'clob':
case 'array':
case 'object':
return $this->dbh->quote($input);
}
}
......
......@@ -44,7 +44,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
*/
public function __construct(Doctrine_Manager $manager, $adapter) {
$adapter->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$this->setAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE, 'INNODB');
$this->supported = array(
......
......@@ -65,6 +65,14 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
'pattern_escaping' => true,
);
$this->properties['string_quoting'] = array('start' => "'",
'end' => "'",
'escape' => "'",
'escape_pattern' => '\\');
$this->properties['identifier_quoting'] = array('start' => '"',
'end' => '"',
'escape' => '"');
parent::__construct($manager, $adapter);
}
/**
......@@ -92,10 +100,9 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
* Returns the current id of a sequence
*
* @param string $seq_name name of the sequence
* @return mixed MDB2 Error Object or id
* @access public
* @return integer
*/
function currId($sequence) {
public function currId($sequence) {
$stmt = $this->dbh->query('SELECT last_value FROM '.$sequence);
$data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0];
......
......@@ -60,6 +60,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_Connection_Module {
case 'array':
case 'string':
case 'char':
case 'gzip':
case 'varchar':
$length = (isset($field['length']) && $field['length']) ? $field['length'] : null;
......@@ -93,19 +94,8 @@ class Doctrine_DataDict_Sqlite extends Doctrine_Connection_Module {
return 'LONGBLOB';
case 'enum':
case 'integer':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 2) {
return 'SMALLINT';
} elseif ($length == 3 || $length == 4) {
return 'INTEGER';
} elseif ($length > 4) {
return 'BIGINT';
}
}
return 'INTEGER';
case 'boolean':
return 'BOOLEAN';
return 'INTEGER';
case 'date':
return 'DATE';
case 'time':
......@@ -120,7 +110,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_Connection_Module {
$length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
}
return '';
throw new Doctrine_DataDict_Sqlite_Exception('Unknown datatype ' . $field['type']);
}
/**
* Maps a native array description of a field to Doctrine datatype and length
......@@ -262,13 +252,16 @@ class Doctrine_DataDict_Sqlite extends Doctrine_Connection_Module {
*/
public function getIntegerDeclaration($name, array $field) {
$default = $autoinc = '';
$type = $this->getNativeDeclaration($field);
if(isset($field['autoincrement']) && $field['autoincrement']) {
$autoinc = ' PRIMARY KEY AUTOINCREMENT';
} elseif (array_key_exists('default', $field)) {
$type = 'INTEGER';
} elseif(array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0;
}
$default = ' DEFAULT '.$this->conn->quote($field['default'], $field['type']);
$default = ' DEFAULT ' . $this->conn->quote($field['default'], $field['type']);
}/**
elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL';
......@@ -279,7 +272,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_Connection_Module {
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : '';
$name = $this->conn->quoteIdentifier($name, true);
return $name . ' ' . $this->getNativeDeclaration($field) . $unsigned . $default . $notnull . $autoinc;
return $name . ' ' . $type . $unsigned . $default . $notnull . $autoinc;
}
/**
* lists all databases
......
......@@ -140,6 +140,7 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$name = $this->conn->quoteIdentifier($name, true);
$query = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')';
return $this->conn->getDbh()->exec($query);
}
/**
......@@ -235,6 +236,7 @@ class Doctrine_Export extends Doctrine_Connection_Module {
}
$query .= ' ('. implode(', ', $fields) . ')';
return $this->conn->getDbh()->query($query);
}
......@@ -400,7 +402,7 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$field['default'] = empty($field['notnull'])
? null : $this->valid_default_values[$field['type']];
if ($field['default'] === ''
&& ($db->options['portability'] & Doctrine::PORTABILITY_EMPTY_TO_NULL)
&& ($conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EMPTY_TO_NULL)
) {
$field['default'] = ' ';
}
......
......@@ -84,6 +84,6 @@ class Doctrine_Export_Sqlite extends Doctrine_Export {
$fields[] = $fieldString;
}
$query .= ' ('.implode(', ', $fields) . ')';
return $this->dbh->exec($query);
return $this->conn->getDbh()->exec($query);
}
}
......@@ -139,9 +139,12 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
* connection
* a short cut for Doctrine_Manager::getInstance()->openConnection($dbh);
*
* @param PDO|Doctrine_Adapter_Interface $adapter database driver
* @param string $name name of the connection, if empty numeric key is used
* @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name
* @return Doctrine_Connection
*/
public static function connection(PDO $dbh) {
public static function connection($adapter, $name = null) {
return Doctrine_Manager::getInstance()->openConnection($dbh);
}
/**
......
......@@ -457,7 +457,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
public function getQueryBase() {
switch($this->type) {
case self::DELETE:
if($this->conn->getName() == 'mysql')
if($this->connection->getName() == 'mysql')
$q = 'DELETE '.end($this->tableAliases).' FROM ';
else
$q = 'DELETE FROM ';
......
......@@ -247,12 +247,20 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$columns = array();
foreach($this->columns as $name => $column) {
$definition = $column[2];
$definition['type'] = $column[1];
$definition['type'] = $column[0];
$definition['length'] = $column[1];
if($definition['type'] == 'enum' && isset($definition['default']))
$definition['default'] = $this->enumIndex($name, $definition['default']);
if($definition['type'] == 'boolean' && isset($definition['default']))
$definition['default'] = (int) $definition['default'];
$columns[$name] = $definition;
}
$this->conn->export->createTable($this->options['tableName'], $columns);
} catch(Exception $e) {
}
}
}
......
......@@ -200,16 +200,12 @@ class Doctrine_Transaction extends Doctrine_Connection_Module {
if($this->transactionLevel == 0)
return false;
$this->transactionLevel--;
if ( ! is_null($savepoint)) {
$this->transactionLevel = $this->removeSavePoints($savepoint);
$this->releaseSavePoint($savepoint);
} else {
if($this->transactionLevel == 0) {
} else {
if($this->transactionLevel == 1) {
$this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onPreTransactionCommit($this->conn);
......@@ -237,6 +233,9 @@ class Doctrine_Transaction extends Doctrine_Connection_Module {
$this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionCommit($this->conn);
}
}
$this->transactionLevel--;
return true;
}
/**
......
......@@ -38,7 +38,7 @@ class Doctrine_DataDict_Sqlite_TestCase extends Doctrine_Driver_UnitTestCase {
public function testGetNativeDefinitionSupportsIntegerType() {
$a = array('type' => 'integer', 'length' => 20, 'fixed' => false);
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BIGINT');
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INTEGER');
$a['length'] = 4;
......@@ -46,7 +46,7 @@ class Doctrine_DataDict_Sqlite_TestCase extends Doctrine_Driver_UnitTestCase {
$a['length'] = 2;
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'SMALLINT');
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INTEGER');
}
public function testGetNativeDefinitionSupportsFloatType() {
......@@ -57,7 +57,7 @@ class Doctrine_DataDict_Sqlite_TestCase extends Doctrine_Driver_UnitTestCase {
public function testGetNativeDefinitionSupportsBooleanType() {
$a = array('type' => 'boolean', 'fixed' => false);
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BOOLEAN');
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INTEGER');
}
public function testGetNativeDefinitionSupportsDateType() {
$a = array('type' => 'date', 'fixed' => false);
......
......@@ -23,6 +23,9 @@ class AdapterMock implements Doctrine_Adapter_Interface {
return new AdapterStatementMock;
}
public function getAll() {
return $this->queries;
}
public function quote($input) {
return "'" . addslashes($input) . "'";
}
......
......@@ -14,6 +14,7 @@ class Doctrine_Transaction_Firebird_TestCase extends Doctrine_Driver_UnitTestCas
$this->assertEqual($this->adapter->pop(), 'RELEASE SAVEPOINT mypoint');
}
public function testRollbackSavePointExecutesSql() {
$this->transaction->beginTransaction('mypoint');
$this->transaction->rollback('mypoint');
$this->assertEqual($this->adapter->pop(), 'ROLLBACK TO SAVEPOINT mypoint');
......
......@@ -14,6 +14,7 @@ class Doctrine_Transaction_Mysql_TestCase extends Doctrine_Driver_UnitTestCase {
$this->assertEqual($this->adapter->pop(), 'RELEASE SAVEPOINT mypoint');
}
public function testRollbackSavePointExecutesSql() {
$this->transaction->beginTransaction('mypoint');
$this->transaction->rollback('mypoint');
$this->assertEqual($this->adapter->pop(), 'ROLLBACK TO SAVEPOINT mypoint');
......
......@@ -12,6 +12,7 @@ class Doctrine_Transaction_Oracle_TestCase extends Doctrine_Driver_UnitTestCase
$this->assertEqual($this->transaction->commit('mypoint'), true);
}
public function testRollbackSavePointExecutesSql() {
$this->transaction->beginTransaction('mypoint');
$this->transaction->rollback('mypoint');
$this->assertEqual($this->adapter->pop(), 'ROLLBACK TO SAVEPOINT mypoint');
......
......@@ -14,6 +14,7 @@ class Doctrine_Transaction_Pgsql_TestCase extends Doctrine_Driver_UnitTestCase {
$this->assertEqual($this->adapter->pop(), 'RELEASE SAVEPOINT mypoint');
}
public function testRollbackSavePointExecutesSql() {
$this->transaction->beginTransaction('mypoint');
$this->transaction->rollback('mypoint');
$this->assertEqual($this->adapter->pop(), 'ROLLBACK TO SAVEPOINT mypoint');
......
......@@ -63,19 +63,19 @@ class Doctrine_UnitTestCase extends UnitTestCase {
if($this->manager->count() > 0) {
$this->connection = $this->manager->getConnection(0);
try {
$this->connection = $this->manager->getConnection('main');
$this->connection->evictTables();
$this->dbh = $this->connection->getDBH();
$this->listener = $this->manager->getAttribute(Doctrine::ATTR_LISTENER);
$this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener);
} else {
} catch(Doctrine_Manager_Exception $e) {
//$this->dbh = Doctrine_Db::getConnection();
$this->dbh = Doctrine_Db::getConnection("sqlite::memory:");
//$this->dbh = new PDO("sqlite::memory:");
$this->connection = $this->manager->openConnection($this->dbh);
$this->connection = $this->manager->openConnection($this->dbh, 'main');
$this->listener = new Doctrine_EventListener_Debugger();
$this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener);
......@@ -87,6 +87,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this->prepareData();
$this->valueHolder = new Doctrine_ValueHolder($this->connection->getTable('User'));
}
public function prepareTables() {
foreach($this->tables as $name) {
......
......@@ -104,6 +104,7 @@ require_once('ExportMysqlTestCase.php');
require_once('ExportFirebirdTestCase.php');
require_once('ExportPgsqlTestCase.php');
require_once('ExportOracleTestCase.php');
require_once('ExportSqliteTestCase.php');
require_once('TransactionTestCase.php');
require_once('TransactionMysqlTestCase.php');
......@@ -122,7 +123,16 @@ print '<pre>';
$test = new GroupTest('Doctrine Framework Unit Tests');
/**
/**
$test->addTestCase(new Doctrine_Export_Sqlite_TestCase());
foreach($drivers as $driver) {
$class = 'Doctrine_DataDict_' . $driver . '_TestCase';
$test->addTestCase(new $class());
}
$test->addTestCase(new Doctrine_Connection_Mysql_TestCase());
$test->addTestCase(new Doctrine_Export_Mysql_TestCase());
......@@ -133,16 +143,9 @@ $test->addTestCase(new Doctrine_Export_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Export_Firebird_TestCase());
foreach($drivers as $driver) {
$class = 'Doctrine_DataDict_' . $driver . '_TestCase';
$test->addTestCase(new $class());
}
$test->addTestCase(new Doctrine_Configurable_TestCase());
*/
......@@ -159,9 +162,16 @@ $test->addTestCase(new Doctrine_Transaction_Firebird_TestCase());
$test->addTestCase(new Doctrine_Transaction_Sqlite_TestCase());
$test->addTestCase(new Doctrine_Transaction_Mssql_TestCase()); */
$test->addTestCase(new Doctrine_Transaction_Mssql_TestCase());
//$test->addTestCase(new Doctrine_Relation_ManyToMany_TestCase());
$test->addTestCase(new Doctrine_Relation_ManyToMany_TestCase());
$test->addTestCase(new Doctrine_BooleanTestCase());
$test->addTestCase(new Doctrine_TableTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_UnitOfWork_TestCase());
......@@ -185,7 +195,6 @@ $test->addTestCase(new Doctrine_Record_State_TestCase());
$test->addTestCase(new Doctrine_SchemaTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_EventListenerTestCase());
......@@ -193,8 +202,6 @@ $test->addTestCase(new Doctrine_Connection_Transaction_TestCase());
$test->addTestCase(new Doctrine_AccessTestCase());
$test->addTestCase(new Doctrine_TableTestCase());
$test->addTestCase(new Doctrine_ManagerTestCase());
$test->addTestCase(new Doctrine_BatchIteratorTestCase());
......@@ -224,7 +231,6 @@ $test->addTestCase(new Doctrine_RelationAccessTestCase());
$test->addTestCase(new Doctrine_CustomResultSetOrderTestCase());
$test->addTestCase(new Doctrine_BooleanTestCase());
//$test->addTestCase(new Doctrine_Record_Filter_TestCase());
......
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