From 4a1bff142873272cc3659793bd70ef57fa1674db Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 30 Nov 2006 14:40:50 +0000 Subject: [PATCH] --- lib/Doctrine/Connection/Mysql.php | 14 ++++---- lib/Doctrine/DataDict/Mysql.php | 16 ++++----- lib/Doctrine/DataDict/Sqlite.php | 14 ++++---- tests/DataDict/MysqlTestCase.php | 60 ++++++++++++++++--------------- tests/DataDict/SqliteTestCase.php | 2 +- 5 files changed, 55 insertions(+), 51 deletions(-) diff --git a/lib/Doctrine/Connection/Mysql.php b/lib/Doctrine/Connection/Mysql.php index 5b1e75f23..fc3ac3ff8 100644 --- a/lib/Doctrine/Connection/Mysql.php +++ b/lib/Doctrine/Connection/Mysql.php @@ -43,7 +43,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { * @param PDO|Doctrine_Adapter $adapter database handler */ public function __construct(Doctrine_Manager $manager, $adapter) { - $adapter->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + $adapter->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $this->setAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE, 'INNODB'); @@ -70,7 +70,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { $this->properties['string_quoting'] = array('start' => "'", 'end' => "'", - 'escape' => '\\', + 'escape' => '\\', 'escape_pattern' => '\\'); $this->properties['identifier_quoting'] = array('start' => '`', @@ -197,14 +197,14 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { for(reset($fields); $colnum < $count; next($fields), $colnum++) { $name = key($fields); - if ($colnum > 0) { + if($colnum > 0) { $query .= ','; $values.= ','; } $query .= $name; - if (isset($fields[$name]['null']) && $fields[$name]['null']) { + if(isset($fields[$name]['null']) && $fields[$name]['null']) { $value = 'NULL'; } else { $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null; @@ -213,15 +213,15 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { $values .= $value; - if (isset($fields[$name]['key']) && $fields[$name]['key']) { - if ($value === 'NULL') + if(isset($fields[$name]['key']) && $fields[$name]['key']) { + if($value === 'NULL') throw new Doctrine_Connection_Mysql_Exception('key value '.$name.' may not be NULL'); $keys++; } } - if ($keys == 0) + if($keys == 0) throw new Doctrine_Connection_Mysql_Exception('not specified which fields are keys'); diff --git a/lib/Doctrine/DataDict/Mysql.php b/lib/Doctrine/DataDict/Mysql.php index 794a3fabc..67b64c04d 100644 --- a/lib/Doctrine/DataDict/Mysql.php +++ b/lib/Doctrine/DataDict/Mysql.php @@ -134,11 +134,11 @@ class Doctrine_DataDict_Mysql extends Doctrine_Connection_Module { * @param array $field native field description * @return array containing the various possible types, length, sign, fixed */ - public function getPortableDeclaration($field) { - $db_type = strtolower($field['type']); - $db_type = strtok($db_type, '(), '); - if ($db_type == 'national') { - $db_type = strtok('(), '); + public function getPortableDeclaration(array $field) { + $dbType = strtolower($field['type']); + $dbType = strtok($dbType, '(), '); + if ($dbType == 'national') { + $dbType = strtok('(), '); } if (!empty($field['length'])) { $length = $field['length']; @@ -149,7 +149,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_Connection_Module { } $type = array(); $unsigned = $fixed = null; - switch ($db_type) { + switch ($dbType) { case 'tinyint': $type[] = 'integer'; $type[] = 'boolean'; @@ -195,7 +195,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_Connection_Module { if (preg_match('/^(is|has)/', $field['name'])) { $type = array_reverse($type); } - } elseif (strstr($db_type, 'text')) { + } elseif (strstr($dbType, 'text')) { $type[] = 'clob'; if ($decimal == 'binary') { $type[] = 'blob'; @@ -265,7 +265,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_Connection_Module { $length = null; break; default: - throw new Doctrine_DataDict_Mysql_Exception('unknown database attribute type: '.$db_type); + throw new Doctrine_DataDict_Mysql_Exception('unknown database attribute type: '.$dbType); } return array($type, $length, $unsigned, $fixed); diff --git a/lib/Doctrine/DataDict/Sqlite.php b/lib/Doctrine/DataDict/Sqlite.php index ca19ce671..2d5339973 100644 --- a/lib/Doctrine/DataDict/Sqlite.php +++ b/lib/Doctrine/DataDict/Sqlite.php @@ -120,13 +120,13 @@ class Doctrine_DataDict_Sqlite extends Doctrine_Connection_Module { * @param array $field native field description * @return array containing the various possible types, length, sign, fixed */ - public function getPortableDeclaration($field) { - $db_type = strtolower($field['type']); - $length = !empty($field['length']) ? $field['length'] : null; - $unsigned = !empty($field['unsigned']) ? $field['unsigned'] : null; + public function getPortableDeclaration(array $field) { + $dbType = strtolower($field['type']); + $length = ( ! empty($field['length'])) ? $field['length'] : null; + $unsigned = ( ! empty($field['unsigned'])) ? $field['unsigned'] : null; $fixed = null; $type = array(); - switch ($db_type) { + switch ($dbType) { case 'boolean': $type[] = 'boolean'; break; @@ -177,7 +177,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_Connection_Module { if (preg_match('/^(is|has)/', $field['name'])) { $type = array_reverse($type); } - } elseif (strstr($db_type, 'text')) { + } elseif (strstr($dbType, 'text')) { $type[] = 'clob'; } if ($fixed !== false) { @@ -221,7 +221,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_Connection_Module { $length = null; break; default: - throw new Doctrine_DataDict_Sqlite_Exception('unknown database attribute type: '.$db_type); + throw new Doctrine_DataDict_Sqlite_Exception('unknown database attribute type: '.$dbType); } return array($type, $length, $unsigned, $fixed); diff --git a/tests/DataDict/MysqlTestCase.php b/tests/DataDict/MysqlTestCase.php index e217b8c07..1701ac4de 100644 --- a/tests/DataDict/MysqlTestCase.php +++ b/tests/DataDict/MysqlTestCase.php @@ -2,6 +2,10 @@ class Doctrine_DataDict_Mysql_TestCase extends Doctrine_Driver_UnitTestCase { public function __construct() { parent::__construct('mysql'); + } + public function testGetPortableDefinitionSupportsIntegers() { + $field = array('INT UNSIGNED'); + } public function testGetNativeDefinitionSupportsIntegerType() { $a = array('type' => 'integer', 'length' => 20, 'fixed' => false); @@ -10,76 +14,76 @@ class Doctrine_DataDict_Mysql_TestCase extends Doctrine_Driver_UnitTestCase { $a['length'] = 4; - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INT'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'INT'); $a['length'] = 2; - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'SMALLINT'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'SMALLINT'); } - public function testGetNativeDefinitionSupportsFloatType() { + public function testGetNativeDeclarationSupportsFloatType() { $a = array('type' => 'float', 'length' => 20, 'fixed' => false); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'DOUBLE'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'DOUBLE'); } - public function testGetNativeDefinitionSupportsBooleanType() { + public function testGetNativeDeclarationSupportsBooleanType() { $a = array('type' => 'boolean', 'fixed' => false); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TINYINT(1)'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TINYINT(1)'); } - public function testGetNativeDefinitionSupportsDateType() { + public function testGetNativeDeclarationSupportsDateType() { $a = array('type' => 'date', 'fixed' => false); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'DATE'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'DATE'); } - public function testGetNativeDefinitionSupportsTimestampType() { + public function testGetNativeDeclarationSupportsTimestampType() { $a = array('type' => 'timestamp', 'fixed' => false); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'DATETIME'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'DATETIME'); } - public function testGetNativeDefinitionSupportsTimeType() { + public function testGetNativeDeclarationSupportsTimeType() { $a = array('type' => 'time', 'fixed' => false); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TIME'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TIME'); } - public function testGetNativeDefinitionSupportsClobType() { + public function testGetNativeDeclarationSupportsClobType() { $a = array('type' => 'clob'); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'LONGTEXT'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'LONGTEXT'); } - public function testGetNativeDefinitionSupportsBlobType() { + public function testGetNativeDeclarationSupportsBlobType() { $a = array('type' => 'blob'); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'LONGBLOB'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'LONGBLOB'); } - public function testGetNativeDefinitionSupportsCharType() { + public function testGetNativeDeclarationSupportsCharType() { $a = array('type' => 'char', 'length' => 10); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(10)'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'CHAR(10)'); } - public function testGetNativeDefinitionSupportsVarcharType() { + public function testGetNativeDeclarationSupportsVarcharType() { $a = array('type' => 'varchar', 'length' => 10); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(10)'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'VARCHAR(10)'); } - public function testGetNativeDefinitionSupportsArrayType() { + public function testGetNativeDeclarationSupportsArrayType() { $a = array('type' => 'array', 'length' => 40); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(40)'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'VARCHAR(40)'); } - public function testGetNativeDefinitionSupportsStringType() { + public function testGetNativeDeclarationSupportsStringType() { $a = array('type' => 'string'); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TEXT'); } - public function testGetNativeDefinitionSupportsArrayType2() { + public function testGetNativeDeclarationSupportsArrayType2() { $a = array('type' => 'array'); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TEXT'); } - public function testGetNativeDefinitionSupportsObjectType() { + public function testGetNativeDeclarationSupportsObjectType() { $a = array('type' => 'object'); - $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT'); + $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TEXT'); } } diff --git a/tests/DataDict/SqliteTestCase.php b/tests/DataDict/SqliteTestCase.php index ec3702fa0..0e5ef1a3b 100644 --- a/tests/DataDict/SqliteTestCase.php +++ b/tests/DataDict/SqliteTestCase.php @@ -33,7 +33,7 @@ class Doctrine_DataDict_Sqlite_TestCase extends Doctrine_Driver_UnitTestCase { $this->assertDeclarationType('real', 'float'); } public function testYearMapsToIntegerAndDate() { - $this->assertDeclarationType('year', array('integer','date')); + $this->assertDeclarationType('year', array('integer','date')); } public function testGetNativeDefinitionSupportsIntegerType() { $a = array('type' => 'integer', 'length' => 20, 'fixed' => false);