From 4ff559cec4577325c20c79f03488a7a2c640d442 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 15 Jan 2007 22:44:24 +0000 Subject: [PATCH] Refactored import drivers --- lib/Doctrine/Import/Mssql.php | 84 ++------------------------ lib/Doctrine/Import/Mysql.php | 106 ++++++++------------------------- lib/Doctrine/Import/Oracle.php | 3 +- 3 files changed, 33 insertions(+), 160 deletions(-) diff --git a/lib/Doctrine/Import/Mssql.php b/lib/Doctrine/Import/Mssql.php index 10ea09d90..c3db03023 100644 --- a/lib/Doctrine/Import/Mssql.php +++ b/lib/Doctrine/Import/Mssql.php @@ -33,34 +33,6 @@ Doctrine::autoload('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 * @@ -70,29 +42,9 @@ class Doctrine_Import_Mssql extends Doctrine_Import public function listSequences($database = null) { $query = "SELECT name FROM sysobjects WHERE xtype = 'U'"; - $table_names = $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) - { + $tableNames = $this->conn->fetchColumn($query); + return array_map(array($this->conn, 'fixSequenceName'), $tableNames); } /** * lists table constraints @@ -168,12 +120,6 @@ class Doctrine_Import_Mssql extends Doctrine_Import $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; } /** @@ -204,23 +150,11 @@ class Doctrine_Import_Mssql extends Doctrine_Import $result = array(); foreach ($indexes as $index) { 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) { - $result = array_change_key_case($result, $this->conn->options['field_case']); - } - return array_keys($result); - } - /** - * lists database users - * - * @return array - */ - public function listUsers() - { - + return $result; } /** * lists database views @@ -232,14 +166,6 @@ class Doctrine_Import_Mssql extends Doctrine_Import { $query = "SELECT name FROM sysobjects WHERE xtype = 'V'"; - $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 $this->conn->fetchColumn($query); } } diff --git a/lib/Doctrine/Import/Mysql.php b/lib/Doctrine/Import/Mysql.php index a61d014d6..3990570d9 100644 --- a/lib/Doctrine/Import/Mysql.php +++ b/lib/Doctrine/Import/Mysql.php @@ -38,27 +38,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import 'listTables' => 'SHOW TABLES', 'listUsers' => 'SELECT DISTINCT USER FROM USER', '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 * @@ -73,13 +53,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import } $tableNames = $this->conn->fetchColumn($query); - $result = array(); - foreach ($tableNames as $tableName) { - if ($sqn = $this->_fixSequenceName($tableName, true)) { - $result[] = $sqn; - } - } - return $result; + return array_map(array($this->conn, 'fixSequenceName'), $tableNames); } /** * lists table constraints @@ -89,40 +63,36 @@ class Doctrine_Import_Mysql extends Doctrine_Import */ public function listTableConstraints($table) { - $key_name = 'Key_name'; - $non_unique = 'Non_unique'; - if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) { + $keyName = 'Key_name'; + $nonUnique = 'Non_unique'; + if ($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_FIX_CASE) { if ($this->conn->options['field_case'] == CASE_LOWER) { - $key_name = strtolower($key_name); - $non_unique = strtolower($non_unique); + $keyName = strtolower($keyName); + $nonUnique = strtolower($nonUnique); } else { - $key_name = strtoupper($key_name); - $non_unique = strtoupper($non_unique); + $keyName = strtoupper($keyName); + $nonUnique = strtoupper($nonUnique); } } $table = $this->conn->quoteIdentifier($table, true); - $query = "SHOW INDEX FROM $table"; + $query = 'SHOW INDEX FROM ' . $table; $indexes = $this->conn->fetchAssoc($query); $result = array(); - foreach ($indexes as $index_data) { - if (!$index_data[$non_unique]) { - if ($index_data[$key_name] !== 'PRIMARY') { - $index = $this->_fixIndexName($index_data[$key_name]); + foreach ($indexes as $indexData) { + if (!$indexData[$nonUnique]) { + if ($indexData[$keyName] !== 'PRIMARY') { + $index = $this->conn->fixIndexName($indexData[$keyName]); } else { $index = 'PRIMARY'; } - if (!empty($index)) { - $result[$index] = true; + if ( ! empty($index)) { + $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 @@ -161,15 +131,15 @@ class Doctrine_Import_Mysql extends Doctrine_Import */ public function listTableIndexes($table) { - $key_name = 'Key_name'; - $non_unique = 'Non_unique'; + $keyName = 'Key_name'; + $nonUnique = 'Non_unique'; if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) { if ($this->conn->options['field_case'] == CASE_LOWER) { - $key_name = strtolower($key_name); - $non_unique = strtolower($non_unique); + $keyName = strtolower($keyName); + $nonUnique = strtolower($nonUnique); } else { - $key_name = strtoupper($key_name); - $non_unique = strtoupper($non_unique); + $keyName = strtoupper($key_name); + $nonUnique = strtoupper($nonUnique); } } @@ -179,16 +149,12 @@ class Doctrine_Import_Mysql extends Doctrine_Import $result = array(); - foreach ($indexes as $index_data) { - if ($index_data[$non_unique] && ($index = $this->_fixIndexName($index_data[$key_name]))) { - $result[$index] = true; + foreach ($indexes as $indexData) { + if ($indexData[$nonUnique] && ($index = $this->conn->fixIndexName($indexData[$keyName]))) { + $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 tables @@ -199,26 +165,6 @@ class Doctrine_Import_Mysql extends Doctrine_Import public function listTables($database = null) { 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 diff --git a/lib/Doctrine/Import/Oracle.php b/lib/Doctrine/Import/Oracle.php index 3221bf046..0c25c5d85 100644 --- a/lib/Doctrine/Import/Oracle.php +++ b/lib/Doctrine/Import/Oracle.php @@ -64,6 +64,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import public function listFunctions() { $query = "SELECT name FROM sys.user_source WHERE line = 1 AND type = 'FUNCTION'"; + return $this->conn->fetchColumn($query); } /** @@ -87,7 +88,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import $query = "SELECT sequence_name FROM sys.user_sequences"; $tableNames = $this->conn->fetchColumn($query); - return array_map(array($this->conn, 'fixSequenceName'), $result); + return array_map(array($this->conn, 'fixSequenceName'), $tableNames); } /** * lists table constraints