This commit is contained in:
parent
faa5e603f0
commit
4a1bff1428
@ -43,7 +43,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
|
|||||||
* @param PDO|Doctrine_Adapter $adapter database handler
|
* @param PDO|Doctrine_Adapter $adapter database handler
|
||||||
*/
|
*/
|
||||||
public function __construct(Doctrine_Manager $manager, $adapter) {
|
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');
|
$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' => "'",
|
$this->properties['string_quoting'] = array('start' => "'",
|
||||||
'end' => "'",
|
'end' => "'",
|
||||||
'escape' => '\\',
|
'escape' => '\\',
|
||||||
'escape_pattern' => '\\');
|
'escape_pattern' => '\\');
|
||||||
|
|
||||||
$this->properties['identifier_quoting'] = array('start' => '`',
|
$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++) {
|
for(reset($fields); $colnum < $count; next($fields), $colnum++) {
|
||||||
$name = key($fields);
|
$name = key($fields);
|
||||||
|
|
||||||
if ($colnum > 0) {
|
if($colnum > 0) {
|
||||||
$query .= ',';
|
$query .= ',';
|
||||||
$values.= ',';
|
$values.= ',';
|
||||||
}
|
}
|
||||||
|
|
||||||
$query .= $name;
|
$query .= $name;
|
||||||
|
|
||||||
if (isset($fields[$name]['null']) && $fields[$name]['null']) {
|
if(isset($fields[$name]['null']) && $fields[$name]['null']) {
|
||||||
$value = 'NULL';
|
$value = 'NULL';
|
||||||
} else {
|
} else {
|
||||||
$type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
|
$type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
|
||||||
@ -213,15 +213,15 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
|
|||||||
|
|
||||||
$values .= $value;
|
$values .= $value;
|
||||||
|
|
||||||
if (isset($fields[$name]['key']) && $fields[$name]['key']) {
|
if(isset($fields[$name]['key']) && $fields[$name]['key']) {
|
||||||
if ($value === 'NULL')
|
if($value === 'NULL')
|
||||||
throw new Doctrine_Connection_Mysql_Exception('key value '.$name.' may not be NULL');
|
throw new Doctrine_Connection_Mysql_Exception('key value '.$name.' may not be NULL');
|
||||||
|
|
||||||
$keys++;
|
$keys++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($keys == 0)
|
if($keys == 0)
|
||||||
throw new Doctrine_Connection_Mysql_Exception('not specified which fields are keys');
|
throw new Doctrine_Connection_Mysql_Exception('not specified which fields are keys');
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,11 +134,11 @@ class Doctrine_DataDict_Mysql extends Doctrine_Connection_Module {
|
|||||||
* @param array $field native field description
|
* @param array $field native field description
|
||||||
* @return array containing the various possible types, length, sign, fixed
|
* @return array containing the various possible types, length, sign, fixed
|
||||||
*/
|
*/
|
||||||
public function getPortableDeclaration($field) {
|
public function getPortableDeclaration(array $field) {
|
||||||
$db_type = strtolower($field['type']);
|
$dbType = strtolower($field['type']);
|
||||||
$db_type = strtok($db_type, '(), ');
|
$dbType = strtok($dbType, '(), ');
|
||||||
if ($db_type == 'national') {
|
if ($dbType == 'national') {
|
||||||
$db_type = strtok('(), ');
|
$dbType = strtok('(), ');
|
||||||
}
|
}
|
||||||
if (!empty($field['length'])) {
|
if (!empty($field['length'])) {
|
||||||
$length = $field['length'];
|
$length = $field['length'];
|
||||||
@ -149,7 +149,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_Connection_Module {
|
|||||||
}
|
}
|
||||||
$type = array();
|
$type = array();
|
||||||
$unsigned = $fixed = null;
|
$unsigned = $fixed = null;
|
||||||
switch ($db_type) {
|
switch ($dbType) {
|
||||||
case 'tinyint':
|
case 'tinyint':
|
||||||
$type[] = 'integer';
|
$type[] = 'integer';
|
||||||
$type[] = 'boolean';
|
$type[] = 'boolean';
|
||||||
@ -195,7 +195,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_Connection_Module {
|
|||||||
if (preg_match('/^(is|has)/', $field['name'])) {
|
if (preg_match('/^(is|has)/', $field['name'])) {
|
||||||
$type = array_reverse($type);
|
$type = array_reverse($type);
|
||||||
}
|
}
|
||||||
} elseif (strstr($db_type, 'text')) {
|
} elseif (strstr($dbType, 'text')) {
|
||||||
$type[] = 'clob';
|
$type[] = 'clob';
|
||||||
if ($decimal == 'binary') {
|
if ($decimal == 'binary') {
|
||||||
$type[] = 'blob';
|
$type[] = 'blob';
|
||||||
@ -265,7 +265,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_Connection_Module {
|
|||||||
$length = null;
|
$length = null;
|
||||||
break;
|
break;
|
||||||
default:
|
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);
|
return array($type, $length, $unsigned, $fixed);
|
||||||
|
@ -120,13 +120,13 @@ class Doctrine_DataDict_Sqlite extends Doctrine_Connection_Module {
|
|||||||
* @param array $field native field description
|
* @param array $field native field description
|
||||||
* @return array containing the various possible types, length, sign, fixed
|
* @return array containing the various possible types, length, sign, fixed
|
||||||
*/
|
*/
|
||||||
public function getPortableDeclaration($field) {
|
public function getPortableDeclaration(array $field) {
|
||||||
$db_type = strtolower($field['type']);
|
$dbType = strtolower($field['type']);
|
||||||
$length = !empty($field['length']) ? $field['length'] : null;
|
$length = ( ! empty($field['length'])) ? $field['length'] : null;
|
||||||
$unsigned = !empty($field['unsigned']) ? $field['unsigned'] : null;
|
$unsigned = ( ! empty($field['unsigned'])) ? $field['unsigned'] : null;
|
||||||
$fixed = null;
|
$fixed = null;
|
||||||
$type = array();
|
$type = array();
|
||||||
switch ($db_type) {
|
switch ($dbType) {
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
$type[] = 'boolean';
|
$type[] = 'boolean';
|
||||||
break;
|
break;
|
||||||
@ -177,7 +177,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_Connection_Module {
|
|||||||
if (preg_match('/^(is|has)/', $field['name'])) {
|
if (preg_match('/^(is|has)/', $field['name'])) {
|
||||||
$type = array_reverse($type);
|
$type = array_reverse($type);
|
||||||
}
|
}
|
||||||
} elseif (strstr($db_type, 'text')) {
|
} elseif (strstr($dbType, 'text')) {
|
||||||
$type[] = 'clob';
|
$type[] = 'clob';
|
||||||
}
|
}
|
||||||
if ($fixed !== false) {
|
if ($fixed !== false) {
|
||||||
@ -221,7 +221,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_Connection_Module {
|
|||||||
$length = null;
|
$length = null;
|
||||||
break;
|
break;
|
||||||
default:
|
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);
|
return array($type, $length, $unsigned, $fixed);
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
class Doctrine_DataDict_Mysql_TestCase extends Doctrine_Driver_UnitTestCase {
|
class Doctrine_DataDict_Mysql_TestCase extends Doctrine_Driver_UnitTestCase {
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct('mysql');
|
parent::__construct('mysql');
|
||||||
|
}
|
||||||
|
public function testGetPortableDefinitionSupportsIntegers() {
|
||||||
|
$field = array('INT UNSIGNED');
|
||||||
|
|
||||||
}
|
}
|
||||||
public function testGetNativeDefinitionSupportsIntegerType() {
|
public function testGetNativeDefinitionSupportsIntegerType() {
|
||||||
$a = array('type' => 'integer', 'length' => 20, 'fixed' => false);
|
$a = array('type' => 'integer', 'length' => 20, 'fixed' => false);
|
||||||
@ -10,76 +14,76 @@ class Doctrine_DataDict_Mysql_TestCase extends Doctrine_Driver_UnitTestCase {
|
|||||||
|
|
||||||
$a['length'] = 4;
|
$a['length'] = 4;
|
||||||
|
|
||||||
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INT');
|
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'INT');
|
||||||
|
|
||||||
$a['length'] = 2;
|
$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);
|
$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);
|
$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);
|
$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);
|
$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);
|
$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');
|
$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');
|
$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);
|
$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);
|
$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);
|
$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');
|
$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');
|
$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');
|
$a = array('type' => 'object');
|
||||||
|
|
||||||
$this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
|
$this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TEXT');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class Doctrine_DataDict_Sqlite_TestCase extends Doctrine_Driver_UnitTestCase {
|
|||||||
$this->assertDeclarationType('real', 'float');
|
$this->assertDeclarationType('real', 'float');
|
||||||
}
|
}
|
||||||
public function testYearMapsToIntegerAndDate() {
|
public function testYearMapsToIntegerAndDate() {
|
||||||
$this->assertDeclarationType('year', array('integer','date'));
|
$this->assertDeclarationType('year', array('integer','date'));
|
||||||
}
|
}
|
||||||
public function testGetNativeDefinitionSupportsIntegerType() {
|
public function testGetNativeDefinitionSupportsIntegerType() {
|
||||||
$a = array('type' => 'integer', 'length' => 20, 'fixed' => false);
|
$a = array('type' => 'integer', 'length' => 20, 'fixed' => false);
|
||||||
|
Loading…
Reference in New Issue
Block a user