- s/\$db/\$this->conn
- turned raiseError() calls into throw Exception - MDB2 style query*() conversion to Doctrine style fetch*()
This commit is contained in:
parent
1a21a43e52
commit
67514f4c6a
@ -52,7 +52,7 @@ class Doctrine_Import_Firebird extends Doctrine_Import
|
||||
*/
|
||||
public function listTableFields($table)
|
||||
{
|
||||
$table = $db->quote(strtoupper($table), 'text');
|
||||
$table = $this->conn->quote(strtoupper($table), 'text');
|
||||
$query = 'SELECT RDB\$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
|
||||
|
||||
return $this->conn->fetchColumn($query);
|
||||
@ -73,9 +73,7 @@ class Doctrine_Import_Firebird extends Doctrine_Import
|
||||
*/
|
||||
public function listViews()
|
||||
{
|
||||
$result = $db->queryCol('SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS');
|
||||
|
||||
return $this->conn->fetchColumn($query);
|
||||
return $this->conn->fetchColumn('SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS');
|
||||
}
|
||||
/**
|
||||
* list the views in the database that reference a given table
|
||||
@ -86,7 +84,7 @@ class Doctrine_Import_Firebird extends Doctrine_Import
|
||||
public function listTableViews($table)
|
||||
{
|
||||
$query = 'SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS';
|
||||
$table = $db->quote(strtoupper($table), 'text');
|
||||
$table = $this->conn->quote(strtoupper($table), 'text');
|
||||
$query .= 'WHERE UPPER(RDB\$RELATION_NAME) = ' . $table;
|
||||
|
||||
return $this->conn->fetchColumn($query);
|
||||
@ -104,7 +102,7 @@ class Doctrine_Import_Firebird extends Doctrine_Import
|
||||
}
|
||||
/**
|
||||
* This function will be called to get all triggers of the
|
||||
* current database ($db->getDatabase())
|
||||
* current database ($this->conn->getDatabase())
|
||||
*
|
||||
* @param string $table The name of the table from the
|
||||
* previous database to query against.
|
||||
@ -118,7 +116,7 @@ class Doctrine_Import_Firebird extends Doctrine_Import
|
||||
OR RDB$SYSTEM_FLAG = 0';
|
||||
|
||||
if ( ! is_null($table)) {
|
||||
$table = $db->quote(strtoupper($table), 'text');
|
||||
$table = $this->conn->quote(strtoupper($table), 'text');
|
||||
$query .= 'WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
|
||||
}
|
||||
|
||||
|
@ -70,18 +70,16 @@ class Doctrine_Import_Mssql extends Doctrine_Import
|
||||
public function listSequences($database = null)
|
||||
{
|
||||
$query = "SELECT name FROM sysobjects WHERE xtype = 'U'";
|
||||
$table_names = $db->queryCol($query);
|
||||
if (PEAR::isError($table_names)) {
|
||||
return $table_names;
|
||||
}
|
||||
$table_names = $this->conn->fetchColumn($query);
|
||||
|
||||
$result = array();
|
||||
foreach ($table_names as $table_name) {
|
||||
if ($sqn = $this->_fixSequenceName($table_name, true)) {
|
||||
$result[] = $sqn;
|
||||
}
|
||||
}
|
||||
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
|
||||
$result = array_map(($db->options['field_case'] == CASE_LOWER ?
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
|
||||
$result = array_map(($this->conn->options['field_case'] == CASE_LOWER ?
|
||||
'strtolower' : 'strtoupper'), $result);
|
||||
}
|
||||
return $result;
|
||||
@ -152,7 +150,7 @@ class Doctrine_Import_Mssql extends Doctrine_Import
|
||||
{
|
||||
$sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
|
||||
|
||||
return $this->dbh->fetchCol($sql);
|
||||
return $this->dbh->fetchColumn($sql);
|
||||
}
|
||||
/**
|
||||
* lists table triggers
|
||||
@ -162,21 +160,18 @@ class Doctrine_Import_Mssql extends Doctrine_Import
|
||||
*/
|
||||
public function listTableTriggers($table)
|
||||
{
|
||||
$table = $db->quote($table, 'text');
|
||||
$table = $this->conn->quote($table, 'text');
|
||||
$query = "SELECT name FROM sysobjects WHERE xtype = 'TR'";
|
||||
if (!is_null($table)) {
|
||||
$query .= "AND object_name(parent_obj) = $table";
|
||||
}
|
||||
|
||||
$result = $db->queryCol($query);
|
||||
if (PEAR::isError($results)) {
|
||||
return $result;
|
||||
}
|
||||
$result = $this->conn->fetchColumn($query);
|
||||
|
||||
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE &&
|
||||
$db->options['field_case'] == CASE_LOWER)
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE &&
|
||||
$this->conn->options['field_case'] == CASE_LOWER)
|
||||
{
|
||||
$result = array_map(($db->options['field_case'] == CASE_LOWER ?
|
||||
$result = array_map(($this->conn->options['field_case'] == CASE_LOWER ?
|
||||
'strtolower' : 'strtoupper'), $result);
|
||||
}
|
||||
return $result;
|
||||
@ -191,8 +186,8 @@ class Doctrine_Import_Mssql extends Doctrine_Import
|
||||
{
|
||||
$keyName = 'INDEX_NAME';
|
||||
$pkName = 'PK_NAME';
|
||||
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
|
||||
if ($db->options['field_case'] == CASE_LOWER) {
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
|
||||
if ($this->conn->options['field_case'] == CASE_LOWER) {
|
||||
$keyName = strtolower($keyName);
|
||||
$pkName = strtolower($pkName);
|
||||
} else {
|
||||
@ -200,12 +195,12 @@ class Doctrine_Import_Mssql extends Doctrine_Import
|
||||
$pkName = strtoupper($pkName);
|
||||
}
|
||||
}
|
||||
$table = $db->quote($table, 'text');
|
||||
$table = $this->conn->quote($table, 'text');
|
||||
$query = 'EXEC sp_statistics @table_name = ' . $table;
|
||||
$indexes = $db->queryCol($query, 'text', $keyName);
|
||||
$indexes = $this->conn->queryCol($query, 'text', $keyName);
|
||||
|
||||
$query = 'EXEC sp_pkeys @table_name = ' . $table;
|
||||
$pkAll = $db->queryCol($query, 'text', $pkName);
|
||||
$pkAll = $this->conn->queryCol($query, 'text', $pkName);
|
||||
$result = array();
|
||||
foreach ($indexes as $index) {
|
||||
if (!in_array($index, $pkAll) && $index != null) {
|
||||
@ -213,8 +208,8 @@ class Doctrine_Import_Mssql extends Doctrine_Import
|
||||
}
|
||||
}
|
||||
|
||||
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
|
||||
$result = array_change_key_case($result, $db->options['field_case']);
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
|
||||
$result = array_change_key_case($result, $this->conn->options['field_case']);
|
||||
}
|
||||
return array_keys($result);
|
||||
}
|
||||
@ -237,12 +232,12 @@ class Doctrine_Import_Mssql extends Doctrine_Import
|
||||
{
|
||||
$query = "SELECT name FROM sysobjects WHERE xtype = 'V'";
|
||||
|
||||
$result = $db->queryCol($query);
|
||||
$result = $this->conn->fetchColumn($query);
|
||||
|
||||
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE &&
|
||||
$db->options['field_case'] == CASE_LOWER)
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE &&
|
||||
$this->conn->options['field_case'] == CASE_LOWER)
|
||||
{
|
||||
$result = array_map(($db->options['field_case'] == CASE_LOWER ?
|
||||
$result = array_map(($this->conn->options['field_case'] == CASE_LOWER ?
|
||||
'strtolower' : 'strtoupper'), $result);
|
||||
}
|
||||
return $result;
|
||||
|
@ -91,8 +91,8 @@ class Doctrine_Import_Mysql extends Doctrine_Import
|
||||
{
|
||||
$key_name = 'Key_name';
|
||||
$non_unique = 'Non_unique';
|
||||
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
|
||||
if ($db->options['field_case'] == CASE_LOWER) {
|
||||
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);
|
||||
} else {
|
||||
@ -101,9 +101,9 @@ class Doctrine_Import_Mysql extends Doctrine_Import
|
||||
}
|
||||
}
|
||||
|
||||
$table = $db->quoteIdentifier($table, true);
|
||||
$table = $this->conn->quoteIdentifier($table, true);
|
||||
$query = "SHOW INDEX FROM $table";
|
||||
$indexes = $db->queryAll($query, null, MDB2_FETCHMODE_ASSOC);
|
||||
$indexes = $this->conn->fetchAssoc($query);
|
||||
|
||||
$result = array();
|
||||
foreach ($indexes as $index_data) {
|
||||
@ -119,8 +119,8 @@ class Doctrine_Import_Mysql extends Doctrine_Import
|
||||
}
|
||||
}
|
||||
|
||||
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
|
||||
$result = array_change_key_case($result, $db->options['field_case']);
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
|
||||
$result = array_change_key_case($result, $this->conn->options['field_case']);
|
||||
}
|
||||
return array_keys($result);
|
||||
}
|
||||
@ -163,8 +163,8 @@ class Doctrine_Import_Mysql extends Doctrine_Import
|
||||
{
|
||||
$key_name = 'Key_name';
|
||||
$non_unique = 'Non_unique';
|
||||
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
|
||||
if ($db->options['field_case'] == CASE_LOWER) {
|
||||
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);
|
||||
} else {
|
||||
@ -173,9 +173,9 @@ class Doctrine_Import_Mysql extends Doctrine_Import
|
||||
}
|
||||
}
|
||||
|
||||
$table = $db->quoteIdentifier($table, true);
|
||||
$table = $this->conn->quoteIdentifier($table, true);
|
||||
$query = "SHOW INDEX FROM $table";
|
||||
$indexes = $db->queryAll($query, null, MDB2_FETCHMODE_ASSOC);
|
||||
$indexes = $this->conn->fetchAssoc($query);
|
||||
|
||||
|
||||
$result = array();
|
||||
@ -185,8 +185,8 @@ class Doctrine_Import_Mysql extends Doctrine_Import
|
||||
}
|
||||
}
|
||||
|
||||
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
|
||||
$result = array_change_key_case($result, $db->options['field_case']);
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
|
||||
$result = array_change_key_case($result, $this->conn->options['field_case']);
|
||||
}
|
||||
return array_keys($result);
|
||||
}
|
||||
@ -230,7 +230,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import
|
||||
{
|
||||
if (!is_null($database)) {
|
||||
$query = sprintf($this->sql['listViews'], ' FROM ' . $database);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->conn->fetchColumn($query);
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import
|
||||
public function listFunctions()
|
||||
{
|
||||
$query = "SELECT name FROM sys.user_source WHERE line = 1 AND type = 'FUNCTION'";
|
||||
$result = $this->conn->queryCol($query);
|
||||
$result = $this->conn->fetchColumn($query);
|
||||
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE
|
||||
&& $this->conn->options['field_case'] == CASE_LOWER
|
||||
@ -97,7 +97,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import
|
||||
public function listSequences($database = null)
|
||||
{
|
||||
$query = "SELECT sequence_name FROM sys.user_sequences";
|
||||
$tableNames = $this->conn->queryCol($query);
|
||||
$tableNames = $this->conn->fetchColumn($query);
|
||||
|
||||
$result = array();
|
||||
foreach ($tableNames as $tableName) {
|
||||
@ -120,7 +120,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import
|
||||
$table = $this->conn->quote($table, 'text');
|
||||
$query = 'SELECT index_name name FROM user_constraints';
|
||||
$query.= ' WHERE table_name='.$table.' OR table_name='.strtoupper($table);
|
||||
$constraints = $this->conn->queryCol($query);
|
||||
$constraints = $this->conn->fetchColumn($query);
|
||||
|
||||
$result = array();
|
||||
foreach ($constraints as $constraint) {
|
||||
@ -150,7 +150,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import
|
||||
$result = $this->conn->fetchAssoc($sql);
|
||||
|
||||
foreach($result as $val) {
|
||||
$descr[$val['column_name']] = array(
|
||||
$descr[$val['column_name']] = array(
|
||||
'name' => $val['column_name'],
|
||||
'notnull' => (bool) ($val['nullable'] === 'N'), // nullable is N when mandatory
|
||||
'type' => $val['data_type'],
|
||||
@ -168,12 +168,11 @@ class Doctrine_Import_Oracle extends Doctrine_Import
|
||||
*/
|
||||
public function listTableIndexes($table)
|
||||
{
|
||||
|
||||
$table = $this->conn->quote($table, 'text');
|
||||
$query = 'SELECT index_name name FROM user_indexes';
|
||||
$query.= ' WHERE table_name='.$table.' OR table_name='.strtoupper($table);
|
||||
$query.= ' AND generated=' .$this->conn->quote('N', 'text');
|
||||
$indexes = $this->conn->queryCol($query, 'text');
|
||||
$indexes = $this->conn->fetchColumn($query);
|
||||
|
||||
$result = array();
|
||||
foreach ($indexes as $index) {
|
||||
@ -198,9 +197,8 @@ class Doctrine_Import_Oracle extends Doctrine_Import
|
||||
*/
|
||||
public function listTables($database = null)
|
||||
{
|
||||
|
||||
$query = 'SELECT table_name FROM sys.user_tables';
|
||||
$result = $this->conn->queryCol($query);
|
||||
$result = $this->conn->fetchColumn($query);
|
||||
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE
|
||||
&& $this->conn->options['field_case'] == CASE_LOWER
|
||||
@ -236,7 +234,6 @@ class Doctrine_Import_Oracle extends Doctrine_Import
|
||||
*/
|
||||
public function listUsers()
|
||||
{
|
||||
|
||||
if ($this->conn->options['emulate_database'] && $this->conn->options['database_name_prefix']) {
|
||||
$query = 'SELECT SUBSTR(username, ';
|
||||
$query.= (strlen($this->conn->options['database_name_prefix'])+1);
|
||||
@ -245,7 +242,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import
|
||||
} else {
|
||||
$query = 'SELECT username FROM sys.dba_users';
|
||||
}
|
||||
return $this->conn->queryCol($query);
|
||||
return $this->conn->fetchColumn($query);
|
||||
}
|
||||
/**
|
||||
* lists database views
|
||||
@ -256,7 +253,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import
|
||||
public function listViews($database = null)
|
||||
{
|
||||
$query = 'SELECT view_name FROM sys.user_views';
|
||||
$result = $this->conn->queryCol($query);
|
||||
$result = $this->conn->fetchColumn($query);
|
||||
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE
|
||||
&& $this->conn->options['field_case'] == CASE_LOWER
|
||||
|
@ -77,7 +77,7 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
|
||||
|
||||
$dbName = 'XXtest'; // @todo FIXME where should we get
|
||||
|
||||
$db->set("name",$dbName);
|
||||
$this->conn->set("name",$dbName);
|
||||
$tableNames = $dataDict->listTables();
|
||||
foreach ($tableNames as $tableName){
|
||||
$table = new Doctrine_Schema_Table();
|
||||
@ -86,7 +86,7 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
|
||||
foreach ($tableColumns as $tableColumn){
|
||||
$table->addColumn($tableColumn);
|
||||
}
|
||||
$db->addTable($table);
|
||||
$this->conn->addTable($table);
|
||||
if ($fks = $dataDict->listTableConstraints($tableName)){
|
||||
foreach ($fks as $fk){
|
||||
$relation = new Doctrine_Schema_Relation();
|
||||
|
@ -68,18 +68,16 @@ class Doctrine_Import_Sqlite extends Doctrine_Import
|
||||
public function listSequences($database = null)
|
||||
{
|
||||
$query = "SELECT name FROM sqlite_master WHERE type='table' AND sql NOT NULL ORDER BY name";
|
||||
$table_names = $db->queryCol($query);
|
||||
if (PEAR::isError($table_names)) {
|
||||
return $table_names;
|
||||
}
|
||||
$table_names = $this->conn->fetchColumn($query);
|
||||
|
||||
$result = array();
|
||||
foreach ($table_names as $table_name) {
|
||||
if ($sqn = $this->_fixSequenceName($table_name, true)) {
|
||||
$result[] = $sqn;
|
||||
}
|
||||
}
|
||||
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
|
||||
$result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
|
||||
$result = array_map(($this->conn->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@ -91,18 +89,15 @@ class Doctrine_Import_Sqlite extends Doctrine_Import
|
||||
*/
|
||||
public function listTableConstraints($table)
|
||||
{
|
||||
$table = $db->quote($table, 'text');
|
||||
$table = $this->conn->quote($table, 'text');
|
||||
$query = "SELECT sql FROM sqlite_master WHERE type='index' AND ";
|
||||
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
|
||||
$query.= 'LOWER(tbl_name)='.strtolower($table);
|
||||
} else {
|
||||
$query.= "tbl_name=$table";
|
||||
}
|
||||
$query.= " AND sql NOT NULL ORDER BY name";
|
||||
$indexes = $db->queryCol($query, 'text');
|
||||
if (PEAR::isError($indexes)) {
|
||||
return $indexes;
|
||||
}
|
||||
$indexes = $this->conn->fetchColumn($query);
|
||||
|
||||
$result = array();
|
||||
foreach ($indexes as $sql) {
|
||||
@ -114,8 +109,8 @@ class Doctrine_Import_Sqlite extends Doctrine_Import
|
||||
}
|
||||
}
|
||||
|
||||
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
|
||||
$result = array_change_key_case($result, $db->options['field_case']);
|
||||
if ($this->conn->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
|
||||
$result = array_change_key_case($result, $this->conn->options['field_case']);
|
||||
}
|
||||
return array_keys($result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user