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)
{
$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;

View File

@ -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 = sprintf($this->sql['listViews'], ' FROM ' . $database);
}
$query.= " WHERE Table_type = 'VIEW'";
$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);
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}