Commit 4ff559ce authored by zYne's avatar zYne

Refactored import drivers

parent 7e8310ce
...@@ -33,34 +33,6 @@ Doctrine::autoload('Doctrine_Import'); ...@@ -33,34 +33,6 @@ Doctrine::autoload('Doctrine_Import');
*/ */
class Doctrine_Import_Mssql extends Doctrine_Import class Doctrine_Import_Mssql extends Doctrine_Import
{ {
/**
* lists all databases
*
* @return array
*/
public function listDatabases()
{
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions()
{
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null)
{
}
/** /**
* lists all database sequences * lists all database sequences
* *
...@@ -70,29 +42,9 @@ class Doctrine_Import_Mssql extends Doctrine_Import ...@@ -70,29 +42,9 @@ class Doctrine_Import_Mssql extends Doctrine_Import
public function listSequences($database = null) public function listSequences($database = null)
{ {
$query = "SELECT name FROM sysobjects WHERE xtype = 'U'"; $query = "SELECT name FROM sysobjects WHERE xtype = 'U'";
$table_names = $this->conn->fetchColumn($query); $tableNames = $this->conn->fetchColumn($query);
$result = array();
foreach ($table_names as $table_name) {
if ($sqn = $this->_fixSequenceName($table_name, true)) {
$result[] = $sqn;
}
}
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
$result = array_map(($this->conn->options['field_case'] == CASE_LOWER ?
'strtolower' : 'strtoupper'), $result);
}
return $result;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table)
{
return array_map(array($this->conn, 'fixSequenceName'), $tableNames);
} }
/** /**
* lists table constraints * lists table constraints
...@@ -168,12 +120,6 @@ class Doctrine_Import_Mssql extends Doctrine_Import ...@@ -168,12 +120,6 @@ class Doctrine_Import_Mssql extends Doctrine_Import
$result = $this->conn->fetchColumn($query); $result = $this->conn->fetchColumn($query);
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE &&
$this->conn->options['field_case'] == CASE_LOWER)
{
$result = array_map(($this->conn->options['field_case'] == CASE_LOWER ?
'strtolower' : 'strtoupper'), $result);
}
return $result; return $result;
} }
/** /**
...@@ -204,23 +150,11 @@ class Doctrine_Import_Mssql extends Doctrine_Import ...@@ -204,23 +150,11 @@ class Doctrine_Import_Mssql extends Doctrine_Import
$result = array(); $result = array();
foreach ($indexes as $index) { foreach ($indexes as $index) {
if (!in_array($index, $pkAll) && $index != null) { if (!in_array($index, $pkAll) && $index != null) {
$result[$this->_fixIndexName($index)] = true; $result[] = $this->_fixIndexName($index);
} }
} }
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) { return $result;
$result = array_change_key_case($result, $this->conn->options['field_case']);
}
return array_keys($result);
}
/**
* lists database users
*
* @return array
*/
public function listUsers()
{
} }
/** /**
* lists database views * lists database views
...@@ -232,14 +166,6 @@ class Doctrine_Import_Mssql extends Doctrine_Import ...@@ -232,14 +166,6 @@ class Doctrine_Import_Mssql extends Doctrine_Import
{ {
$query = "SELECT name FROM sysobjects WHERE xtype = 'V'"; $query = "SELECT name FROM sysobjects WHERE xtype = 'V'";
$result = $this->conn->fetchColumn($query); return $this->conn->fetchColumn($query);
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE &&
$this->conn->options['field_case'] == CASE_LOWER)
{
$result = array_map(($this->conn->options['field_case'] == CASE_LOWER ?
'strtolower' : 'strtoupper'), $result);
}
return $result;
} }
} }
...@@ -38,27 +38,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import ...@@ -38,27 +38,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import
'listTables' => 'SHOW TABLES', 'listTables' => 'SHOW TABLES',
'listUsers' => 'SELECT DISTINCT USER FROM USER', 'listUsers' => 'SELECT DISTINCT USER FROM USER',
'listViews' => "SHOW FULL TABLES %sWHERE Table_type = 'VIEW'", 'listViews' => "SHOW FULL TABLES %sWHERE Table_type = 'VIEW'",
); );
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions()
{
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null)
{
}
/** /**
* lists all database sequences * lists all database sequences
* *
...@@ -73,13 +53,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import ...@@ -73,13 +53,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import
} }
$tableNames = $this->conn->fetchColumn($query); $tableNames = $this->conn->fetchColumn($query);
$result = array(); return array_map(array($this->conn, 'fixSequenceName'), $tableNames);
foreach ($tableNames as $tableName) {
if ($sqn = $this->_fixSequenceName($tableName, true)) {
$result[] = $sqn;
}
}
return $result;
} }
/** /**
* lists table constraints * lists table constraints
...@@ -89,40 +63,36 @@ class Doctrine_Import_Mysql extends Doctrine_Import ...@@ -89,40 +63,36 @@ class Doctrine_Import_Mysql extends Doctrine_Import
*/ */
public function listTableConstraints($table) public function listTableConstraints($table)
{ {
$key_name = 'Key_name'; $keyName = 'Key_name';
$non_unique = 'Non_unique'; $nonUnique = 'Non_unique';
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) { if ($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_FIX_CASE) {
if ($this->conn->options['field_case'] == CASE_LOWER) { if ($this->conn->options['field_case'] == CASE_LOWER) {
$key_name = strtolower($key_name); $keyName = strtolower($keyName);
$non_unique = strtolower($non_unique); $nonUnique = strtolower($nonUnique);
} else { } else {
$key_name = strtoupper($key_name); $keyName = strtoupper($keyName);
$non_unique = strtoupper($non_unique); $nonUnique = strtoupper($nonUnique);
} }
} }
$table = $this->conn->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$query = "SHOW INDEX FROM $table"; $query = 'SHOW INDEX FROM ' . $table;
$indexes = $this->conn->fetchAssoc($query); $indexes = $this->conn->fetchAssoc($query);
$result = array(); $result = array();
foreach ($indexes as $index_data) { foreach ($indexes as $indexData) {
if (!$index_data[$non_unique]) { if (!$indexData[$nonUnique]) {
if ($index_data[$key_name] !== 'PRIMARY') { if ($indexData[$keyName] !== 'PRIMARY') {
$index = $this->_fixIndexName($index_data[$key_name]); $index = $this->conn->fixIndexName($indexData[$keyName]);
} else { } else {
$index = 'PRIMARY'; $index = 'PRIMARY';
} }
if (!empty($index)) { if ( ! empty($index)) {
$result[$index] = true; $result[] = $index;
}
} }
} }
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
$result = array_change_key_case($result, $this->conn->options['field_case']);
} }
return array_keys($result); return $result;
} }
/** /**
* lists table constraints * lists table constraints
...@@ -161,15 +131,15 @@ class Doctrine_Import_Mysql extends Doctrine_Import ...@@ -161,15 +131,15 @@ class Doctrine_Import_Mysql extends Doctrine_Import
*/ */
public function listTableIndexes($table) public function listTableIndexes($table)
{ {
$key_name = 'Key_name'; $keyName = 'Key_name';
$non_unique = 'Non_unique'; $nonUnique = 'Non_unique';
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) { if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
if ($this->conn->options['field_case'] == CASE_LOWER) { if ($this->conn->options['field_case'] == CASE_LOWER) {
$key_name = strtolower($key_name); $keyName = strtolower($keyName);
$non_unique = strtolower($non_unique); $nonUnique = strtolower($nonUnique);
} else { } else {
$key_name = strtoupper($key_name); $keyName = strtoupper($key_name);
$non_unique = strtoupper($non_unique); $nonUnique = strtoupper($nonUnique);
} }
} }
...@@ -179,16 +149,12 @@ class Doctrine_Import_Mysql extends Doctrine_Import ...@@ -179,16 +149,12 @@ class Doctrine_Import_Mysql extends Doctrine_Import
$result = array(); $result = array();
foreach ($indexes as $index_data) { foreach ($indexes as $indexData) {
if ($index_data[$non_unique] && ($index = $this->_fixIndexName($index_data[$key_name]))) { if ($indexData[$nonUnique] && ($index = $this->conn->fixIndexName($indexData[$keyName]))) {
$result[$index] = true; $result[] = $index;
} }
} }
return $result;
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
$result = array_change_key_case($result, $this->conn->options['field_case']);
}
return array_keys($result);
} }
/** /**
* lists tables * lists tables
...@@ -199,26 +165,6 @@ class Doctrine_Import_Mysql extends Doctrine_Import ...@@ -199,26 +165,6 @@ class Doctrine_Import_Mysql extends Doctrine_Import
public function listTables($database = null) public function listTables($database = null)
{ {
return $this->conn->fetchColumn($this->sql['listTables']); return $this->conn->fetchColumn($this->sql['listTables']);
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table)
{
}
/**
* lists table views
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table)
{
} }
/** /**
* lists database views * lists database views
......
...@@ -64,6 +64,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import ...@@ -64,6 +64,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import
public function listFunctions() public function listFunctions()
{ {
$query = "SELECT name FROM sys.user_source WHERE line = 1 AND type = 'FUNCTION'"; $query = "SELECT name FROM sys.user_source WHERE line = 1 AND type = 'FUNCTION'";
return $this->conn->fetchColumn($query); return $this->conn->fetchColumn($query);
} }
/** /**
...@@ -87,7 +88,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import ...@@ -87,7 +88,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import
$query = "SELECT sequence_name FROM sys.user_sequences"; $query = "SELECT sequence_name FROM sys.user_sequences";
$tableNames = $this->conn->fetchColumn($query); $tableNames = $this->conn->fetchColumn($query);
return array_map(array($this->conn, 'fixSequenceName'), $result); return array_map(array($this->conn, 'fixSequenceName'), $tableNames);
} }
/** /**
* lists table constraints * lists table constraints
......
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