1
0
mirror of synced 2024-12-13 22:56:04 +03:00

import drivers updated

This commit is contained in:
zYne 2006-12-30 10:58:58 +00:00
parent 611c65e759
commit 5bfd47cd42
5 changed files with 38 additions and 68 deletions

View File

@ -105,7 +105,7 @@ class Doctrine_Import_Mssql extends Doctrine_Import
public function listTableColumns($table) public function listTableColumns($table)
{ {
$sql = 'EXEC sp_columns @table_name = ' . $this->quoteIdentifier($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(); $columns = array();
foreach ($result as $key => $val) { foreach ($result as $key => $val) {
@ -127,7 +127,7 @@ class Doctrine_Import_Mssql extends Doctrine_Import
'default' => $val['column_def'], 'default' => $val['column_def'],
'primary' => (strtolower($identity) == 'identity'), 'primary' => (strtolower($identity) == 'identity'),
); );
$columns[$val['column_name']] = new Doctrine_Schema_Column($description); $columns[$val['column_name']] = $description;
} }
return $columns; return $columns;

View File

@ -31,17 +31,15 @@ Doctrine::autoload('Doctrine_Import');
*/ */
class Doctrine_Import_Mysql extends Doctrine_Import class Doctrine_Import_Mysql extends Doctrine_Import
{ {
/** protected $sql = array(
* lists all databases 'showDatabases' => 'SHOW DATABASES',
* 'listTableFields' => 'DESCRIBE %s',
* @return array 'listSequences' => 'SHOW TABLES',
*/ 'listTables' => 'SHOW TABLES',
public function listDatabases() 'listUsers' => 'SELECT DISTINCT USER FROM USER',
{ 'listViews' => "SHOW FULL TABLES %sWHERE Table_type = 'VIEW'",
$sql = 'SHOW DATABASES';
return $this->dbh->query($sql)->fetchAll(PDO::FETCH_COLUMN); );
}
/** /**
* lists all availible database functions * lists all availible database functions
* *
@ -73,7 +71,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import
if (!is_null($database)) { if (!is_null($database)) {
$query .= " FROM $database"; $query .= " FROM $database";
} }
$tableNames = $db->queryCol($query); $tableNames = $this->conn->fetchColumn($query);
$result = array(); $result = array();
foreach ($tableNames as $tableName) { foreach ($tableNames as $tableName) {
@ -81,9 +79,6 @@ class Doctrine_Import_Mysql extends Doctrine_Import
$result[] = $sqn; $result[] = $sqn;
} }
} }
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
}
return $result; return $result;
} }
/** /**
@ -94,11 +89,6 @@ class Doctrine_Import_Mysql extends Doctrine_Import
*/ */
public function listTableConstraints($table) public function listTableConstraints($table)
{ {
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$key_name = 'Key_name'; $key_name = 'Key_name';
$non_unique = 'Non_unique'; $non_unique = 'Non_unique';
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
@ -114,9 +104,6 @@ class Doctrine_Import_Mysql extends Doctrine_Import
$table = $db->quoteIdentifier($table, true); $table = $db->quoteIdentifier($table, true);
$query = "SHOW INDEX FROM $table"; $query = "SHOW INDEX FROM $table";
$indexes = $db->queryAll($query, null, MDB2_FETCHMODE_ASSOC); $indexes = $db->queryAll($query, null, MDB2_FETCHMODE_ASSOC);
if (PEAR::isError($indexes)) {
return $indexes;
}
$result = array(); $result = array();
foreach ($indexes as $index_data) { 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']); $result = array_change_key_case($result, $db->options['field_case']);
} }
return array_keys($result); return array_keys($result);
@ -145,23 +132,22 @@ class Doctrine_Import_Mysql extends Doctrine_Import
*/ */
public function listTableColumns($table) public function listTableColumns($table)
{ {
$sql = "DESCRIBE $table"; $sql = 'DESCRIBE ' . $table;
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); $result = $this->conn->fetchAssoc($sql);
$description = array(); $description = array();
foreach ($result as $key => $val2) { foreach ($result as $key => $val) {
$val = array();
foreach (array_keys($val2) as $valKey){ // lowercase the key names array_change_key_case($val, CASE_LOWER);
$val[strtolower($valKey)] = $val2[$valKey];
}
$description = array( $description = array(
'name' => $val['field'], 'name' => $val['field'],
'type' => $val['type'], 'type' => $val['type'],
'primary' => (strtolower($val['key']) == 'pri'), 'primary' => (strtolower($val['key']) == 'pri'),
'default' => $val['default'], 'default' => $val['default'],
'notnull' => (bool) ($val['null'] != 'YES'), '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) public function listTables($database = null)
{ {
$sql = 'SHOW TABLES'; return $this->conn->fetchColumn($this->sql['listTables']);
return $this->dbh->query($sql)->fetchAll(PDO::FETCH_COLUMN);
} }
/** /**
* lists table triggers * lists table triggers
@ -235,15 +219,6 @@ class Doctrine_Import_Mysql extends Doctrine_Import
public function listTableViews($table) public function listTableViews($table)
{ {
}
/**
* lists database users
*
* @return array
*/
public function listUsers()
{
return $db->queryCol('SELECT DISTINCT USER FROM USER');
} }
/** /**
* lists database views * lists database views
@ -253,17 +228,10 @@ class Doctrine_Import_Mysql extends Doctrine_Import
*/ */
public function listViews($database = null) public function listViews($database = null)
{ {
$query = 'SHOW FULL TABLES';
if (!is_null($database)) { if (!is_null($database)) {
$query.= ' FROM ' . $database; $query = sprintf($this->sql['listViews'], ' FROM ' . $database);
} }
$query.= " WHERE Table_type = 'VIEW'";
$result = $db->queryCol($query); return $this->conn->fetchColumn($query);
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
}
return $result;
} }
} }

View File

@ -145,16 +145,18 @@ class Doctrine_Import_Oracle extends Doctrine_Import
*/ */
public function listTableColumns($table) 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'); foreach($result as $val) {
$query = 'SELECT column_name FROM user_tab_columns'; $descr[$val['column_name']] = array(
$query.= ' WHERE table_name='.$table.' OR table_name='.strtoupper($table).' ORDER BY column_id'; 'name' => $val['column_name'],
$result = $this->conn->queryCol($query); 'notnull' => (bool) ($val['nullable'] === 'N'), // nullable is N when mandatory
'type' => $val['data_type'],
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE 'default' => $val['data_default'],
&& $this->conn->options['field_case'] == CASE_LOWER 'length' => $val['data_length']
) { );
$result = array_map(($this->conn->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
} }
return $result; return $result;
} }

View File

@ -165,7 +165,7 @@ class Doctrine_Import_Pgsql extends Doctrine_Import
'default' => $val['default'], 'default' => $val['default'],
'primary' => ($val['pri'] == 't'), 'primary' => ($val['pri'] == 't'),
); );
$columns[$val['field']] = new Doctrine_Schema_Column($description); $columns[$val['field']] = $description;
} }
return $columns; return $columns;
} }

View File

@ -129,7 +129,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import
{ {
$sql = 'PRAGMA table_info(' . $table . ')'; $sql = 'PRAGMA table_info(' . $table . ')';
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); $result = $this->conn->fetchAll($sql);
$description = array(); $description = array();
$columns = array(); $columns = array();
@ -141,7 +141,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import
'default' => $val['dflt_value'], 'default' => $val['dflt_value'],
'primary' => (bool) $val['pk'], 'primary' => (bool) $val['pk'],
); );
$columns[$val['name']] = new Doctrine_Schema_Column($description); $columns[$val['name']] = $description;
} }
return $columns; return $columns;
} }