1
0
mirror of synced 2024-12-14 15:16:04 +03:00
This commit is contained in:
zYne 2006-11-30 14:40:50 +00:00
parent faa5e603f0
commit 4a1bff1428
5 changed files with 55 additions and 51 deletions

View File

@ -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');

View File

@ -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);

View File

@ -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);

View File

@ -3,6 +3,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');
}
}