diff --git a/lib/Doctrine/Import/Mssql.php b/lib/Doctrine/Import/Mssql.php index fe040682c..57638fd57 100644 --- a/lib/Doctrine/Import/Mssql.php +++ b/lib/Doctrine/Import/Mssql.php @@ -105,7 +105,7 @@ class Doctrine_Import_Mssql extends Doctrine_Import public function listTableColumns($table) { $sql = 'EXEC sp_columns @table_name = ' . $this->quoteIdentifier($table); - $result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); + $result = $this->conn->fetchAssoc($sql); $columns = array(); foreach ($result as $key => $val) { @@ -127,7 +127,7 @@ class Doctrine_Import_Mssql extends Doctrine_Import 'default' => $val['column_def'], 'primary' => (strtolower($identity) == 'identity'), ); - $columns[$val['column_name']] = new Doctrine_Schema_Column($description); + $columns[$val['column_name']] = $description; } return $columns; diff --git a/lib/Doctrine/Import/Mysql.php b/lib/Doctrine/Import/Mysql.php index 992b9b16e..849e46968 100644 --- a/lib/Doctrine/Import/Mysql.php +++ b/lib/Doctrine/Import/Mysql.php @@ -31,17 +31,15 @@ Doctrine::autoload('Doctrine_Import'); */ class Doctrine_Import_Mysql extends Doctrine_Import { - /** - * lists all databases - * - * @return array - */ - public function listDatabases() - { - $sql = 'SHOW DATABASES'; + protected $sql = array( + 'showDatabases' => 'SHOW DATABASES', + 'listTableFields' => 'DESCRIBE %s', + 'listSequences' => 'SHOW TABLES', + 'listTables' => 'SHOW TABLES', + 'listUsers' => 'SELECT DISTINCT USER FROM USER', + 'listViews' => "SHOW FULL TABLES %sWHERE Table_type = 'VIEW'", - return $this->dbh->query($sql)->fetchAll(PDO::FETCH_COLUMN); - } + ); /** * lists all availible database functions * @@ -73,7 +71,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import if (!is_null($database)) { $query .= " FROM $database"; } - $tableNames = $db->queryCol($query); + $tableNames = $this->conn->fetchColumn($query); $result = array(); foreach ($tableNames as $tableName) { @@ -81,9 +79,6 @@ class Doctrine_Import_Mysql extends Doctrine_Import $result[] = $sqn; } } - if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { - $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result); - } return $result; } /** @@ -94,11 +89,6 @@ class Doctrine_Import_Mysql extends Doctrine_Import */ public function listTableConstraints($table) { - $db =& $this->getDBInstance(); - if (PEAR::isError($db)) { - return $db; - } - $key_name = 'Key_name'; $non_unique = 'Non_unique'; if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { @@ -114,9 +104,6 @@ class Doctrine_Import_Mysql extends Doctrine_Import $table = $db->quoteIdentifier($table, true); $query = "SHOW INDEX FROM $table"; $indexes = $db->queryAll($query, null, MDB2_FETCHMODE_ASSOC); - if (PEAR::isError($indexes)) { - return $indexes; - } $result = array(); foreach ($indexes as $index_data) { @@ -132,7 +119,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import } } - if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) { $result = array_change_key_case($result, $db->options['field_case']); } return array_keys($result); @@ -145,23 +132,22 @@ class Doctrine_Import_Mysql extends Doctrine_Import */ public function listTableColumns($table) { - $sql = "DESCRIBE $table"; - $result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); + $sql = 'DESCRIBE ' . $table; + $result = $this->conn->fetchAssoc($sql); $description = array(); - foreach ($result as $key => $val2) { - $val = array(); - foreach (array_keys($val2) as $valKey){ // lowercase the key names - $val[strtolower($valKey)] = $val2[$valKey]; - } + foreach ($result as $key => $val) { + + array_change_key_case($val, CASE_LOWER); + $description = array( 'name' => $val['field'], 'type' => $val['type'], 'primary' => (strtolower($val['key']) == 'pri'), 'default' => $val['default'], 'notnull' => (bool) ($val['null'] != 'YES'), - 'autoinc' => (bool) (strpos($val['extra'], 'auto_increment') > -1), + 'autoinc' => (bool) (strpos($val['extra'], 'auto_increment') !== false), ); - $columns[$val['field']] = new Doctrine_Schema_Column($description); + $columns[$val['field']] = $description; } @@ -212,9 +198,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import */ public function listTables($database = null) { - $sql = 'SHOW TABLES'; - - return $this->dbh->query($sql)->fetchAll(PDO::FETCH_COLUMN); + return $this->conn->fetchColumn($this->sql['listTables']); } /** * lists table triggers @@ -235,15 +219,6 @@ class Doctrine_Import_Mysql extends Doctrine_Import public function listTableViews($table) { - } - /** - * lists database users - * - * @return array - */ - public function listUsers() - { - return $db->queryCol('SELECT DISTINCT USER FROM USER'); } /** * lists database views @@ -253,17 +228,10 @@ class Doctrine_Import_Mysql extends Doctrine_Import */ public function listViews($database = null) { - $query = 'SHOW FULL TABLES'; if (!is_null($database)) { - $query.= ' FROM ' . $database; - } - $query.= " WHERE Table_type = 'VIEW'"; + $query = sprintf($this->sql['listViews'], ' FROM ' . $database); + } - $result = $db->queryCol($query); - - if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { - $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result); - } - return $result; + return $this->conn->fetchColumn($query); } } diff --git a/lib/Doctrine/Import/Oracle.php b/lib/Doctrine/Import/Oracle.php index 708b3239e..48910af6f 100644 --- a/lib/Doctrine/Import/Oracle.php +++ b/lib/Doctrine/Import/Oracle.php @@ -145,16 +145,18 @@ class Doctrine_Import_Oracle extends Doctrine_Import */ public function listTableColumns($table) { + $table = strtoupper($table); + $sql = "SELECT column_name, data_type, data_length, nullable, data_default from all_tab_columns WHERE table_name='$table' ORDER BY column_name"; + $result = $this->conn->fetchAssoc($sql); - $table = $this->conn->quote($table, 'text'); - $query = 'SELECT column_name FROM user_tab_columns'; - $query.= ' WHERE table_name='.$table.' OR table_name='.strtoupper($table).' ORDER BY column_id'; - $result = $this->conn->queryCol($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); + foreach($result as $val) { + $descr[$val['column_name']] = array( + 'name' => $val['column_name'], + 'notnull' => (bool) ($val['nullable'] === 'N'), // nullable is N when mandatory + 'type' => $val['data_type'], + 'default' => $val['data_default'], + 'length' => $val['data_length'] + ); } return $result; } diff --git a/lib/Doctrine/Import/Pgsql.php b/lib/Doctrine/Import/Pgsql.php index aaff53a7c..df40cfa5e 100644 --- a/lib/Doctrine/Import/Pgsql.php +++ b/lib/Doctrine/Import/Pgsql.php @@ -165,7 +165,7 @@ class Doctrine_Import_Pgsql extends Doctrine_Import 'default' => $val['default'], 'primary' => ($val['pri'] == 't'), ); - $columns[$val['field']] = new Doctrine_Schema_Column($description); + $columns[$val['field']] = $description; } return $columns; } diff --git a/lib/Doctrine/Import/Sqlite.php b/lib/Doctrine/Import/Sqlite.php index dcb708b3e..c2c5a93e6 100644 --- a/lib/Doctrine/Import/Sqlite.php +++ b/lib/Doctrine/Import/Sqlite.php @@ -129,7 +129,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import { $sql = 'PRAGMA table_info(' . $table . ')'; - $result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); + $result = $this->conn->fetchAll($sql); $description = array(); $columns = array(); @@ -141,7 +141,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import 'default' => $val['dflt_value'], 'primary' => (bool) $val['pk'], ); - $columns[$val['name']] = new Doctrine_Schema_Column($description); + $columns[$val['name']] = $description; } return $columns; }