Permalink
Browse files

Implement some of the remaining functions in Platform and Schema mana…

…ger.
  • Loading branch information...
1 parent 2044afb commit a0cea52ce76ca143bdc8e6e395c3a699d8354913 @posulliv committed Aug 23, 2012
@@ -254,23 +254,29 @@ public function getListTableConstraintsSQL($table)
*/
public function getListTableIndexesSQL($table, $currentDatabase = null)
{
- // TODO - should $currentDatabase be used?
- return "SELECT table_name, index_name, is_unique " .
- "FROM information_schema.indexes " .
- "WHERE table_name = '" . $table . "'";
+ if (! is_null($currentDatabase)) {
+ $schemaPredicate = "c.schema_name = '" . $currentDatabase . "' and ";
+ } else {
+ $schemaPredicate = "";
+ }
+ return "SELECT i.table_name as table_name, i.index_name as index_name, i.is_unique as is_unique, i.index_type as index_type, c.column_name as column_name " .
+ "FROM information_schema.indexes i left outer join information_schema.columns c on i.table_name = c.table_name " .
+ "WHERE c.schema_name != 'information_schema' and " . $schemaPredicate . "c.table_name = '" . $table . "'";
}
public function getListTableColumnsSQL($table, $database = null)
{
if (! is_null($database)) {
- $schemaPredicate = "schema_name = '" . $database . "' and ";
+ $schemaPredicate = "c.schema_name = '" . $database . "' and ";
} else {
- $schemePredicate = "";
+ $schemaPredicate = "";
}
- return "SELECT column_name, type, nullable, character_set_name, collation_name " .
- "FROM information_schema.columns " .
- "WHERE schema_name != 'information_schema' and " . $schemaPredicate .
- "table_name = '" . $table . "'";
+ return "SELECT c.column_name as column_name, c.length as length, c.type as type, c.nullable as nullable, " .
+ "c.character_set_name as character_set_name, c.collation_name as collation_name, " .
+ "i.index_type as index_type " .
+ "FROM information_schema.columns c left outer join information_schema.indexes i on c.table_name = i.table_name " .
+ "WHERE c.schema_name != 'information_schema' and " . $schemaPredicate .
+ "c.table_name = '" . $table . "'";
}
/**
@@ -629,6 +635,7 @@ protected function initializeDoctrineTypeMappings()
'numeric' => 'decimal',
'year' => 'date',
'blob' => 'blob',
+ 'longblob' => 'blob',
);
}
@@ -105,12 +105,28 @@ protected function _getPortableTableDefinition($table)
*/
protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
{
- // TODO
+ $indexBuffer = array();
+ if (! empty($tableIndexes)) {
+ foreach ($tableIndexes as $tableIndex) {
+ if ($tableIndex['index_type'] == "PRIMARY") {
+ $keyName = 'primary';
+ $buffer['primary'] = true;
+ $buffer['non_unique'] = false;
+ } else {
+ $buffer['primary'] = false;
+ $buffer['non_unique'] = ($tableIndex['is_unique'] == 0) ? true : false;
+ }
+ $buffer['key_name'] = $tableIndex['index_name'];
+ $buffer['column_name'] = $tableIndex['column_name'];
+ $indexBuffer[] = $buffer;
+ }
+ }
+ return parent::_getPortableTableIndexesList($indexBuffer, $tableName);
}
protected function _getPortableDatabaseDefinition($database)
{
- return $database['datname'];
+ return $database['schema_name'];
}
protected function _getPortableSequenceDefinition($sequence)
@@ -120,7 +136,89 @@ protected function _getPortableSequenceDefinition($sequence)
protected function _getPortableTableColumnDefinition($tableColumn)
{
- // TODO
+ $tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
+
+ if (strtolower($tableColumn['type']) === 'varchar') {
+ // get length from varchar definition
+ $length = $tableColumn['length'];
+ }
+
+ $matches = array();
+
+ $autoincrement = false;
+ $tableColumn['default'] = null;
+
+ $length = (isset($tableColumn['length'])) ? $tableColumn['length'] : null;
+ if ((int) $length <= 0) {
+ $length = null;
+ }
+ $fixed = null;
+
+ if (!isset($tableColumn['column_name'])) {
+ $tableColumn['name'] = '';
+ }
+
+ $precision = null;
+ $scale = null;
+
+ $dbType = strtolower($tableColumn['type']);
+ $type = $this->_platform->getDoctrineTypeMapping($dbType);
+
+ switch ($dbType) {
+ case 'smallint':
+ $length = null;
+ break;
+ case 'int':
+ case 'integer':
+ $length = null;
+ break;
+ case 'bigint':
+ $length = null;
+ break;
+ case 'boolean':
+ $length = null;
+ break;
+ case 'varchar':
+ case 'interval':
+ $fixed = false;
+ break;
+ case 'char':
+ $fixed = true;
+ break;
+ case 'float':
+ case 'double':
+ case 'double precision':
+ case 'real':
+ case 'decimal':
+ case 'numeric':
+ // TODO
+ break;
+ case 'year':
+ $length = null;
+ break;
+ }
+
+ if ($tableColumn['default'] && preg_match("('([^']+)'::)", $tableColumn['default'], $match)) {
+ $tableColumn['default'] = $match[1];
+ }
+
+ $tableColumn['nullable'] == 'NO' ? $notnull = true : $notnull = false;
+ $tableColumn['index_type'] == 'PRIMARY' ? $primaryKey = true : $primaryKey = false;
+
+ $options = array(
+ 'length' => $length,
+ 'notnull' => $notnull,
+ 'default' => $tableColumn['default'],
+ 'primary' => $primaryKey,
+ 'precision' => $precision,
+ 'scale' => $scale,
+ 'fixed' => $fixed,
+ 'unsigned' => false,
+ 'autoincrement' => $autoincrement,
+ 'comment' => NULL,
+ );
+
+ return new Column($tableColumn['column_name'], \Doctrine\DBAL\Types\Type::getType($type), $options);
}
}

0 comments on commit a0cea52

Please sign in to comment.