From 1c92c3a9fb320ec35949634e53b28ee4ab79f138 Mon Sep 17 00:00:00 2001 From: wei <> Date: Tue, 23 Jan 2007 12:55:49 +0000 Subject: fix pgsql schema table problems. --- .../ActiveRecord/Vendor/TPgsqlColumnMetaData.php | 2 +- .../Vendor/TPgsqlMetaDataInspector.php | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'framework/Data/ActiveRecord/Vendor') diff --git a/framework/Data/ActiveRecord/Vendor/TPgsqlColumnMetaData.php b/framework/Data/ActiveRecord/Vendor/TPgsqlColumnMetaData.php index 59a2d43e..1e799aac 100644 --- a/framework/Data/ActiveRecord/Vendor/TPgsqlColumnMetaData.php +++ b/framework/Data/ActiveRecord/Vendor/TPgsqlColumnMetaData.php @@ -61,7 +61,7 @@ class TPgsqlColumnMetaData extends TComponent { switch(strtolower($this->_type)) { - case 'bit': case 'bit varying': case 'real': case 'serial': + case 'bit': case 'bit varying': case 'real': case 'serial': case 'int': case 'integer': return 'integer'; case 'boolean': return 'boolean'; diff --git a/framework/Data/ActiveRecord/Vendor/TPgsqlMetaDataInspector.php b/framework/Data/ActiveRecord/Vendor/TPgsqlMetaDataInspector.php index 9d474f14..910b826e 100644 --- a/framework/Data/ActiveRecord/Vendor/TPgsqlMetaDataInspector.php +++ b/framework/Data/ActiveRecord/Vendor/TPgsqlMetaDataInspector.php @@ -130,16 +130,17 @@ EOD; $command->bindValue(':schema', $schema); $cols = array(); foreach($command->query() as $col) - $cols[$col['attname']] = $this->getColumnMetaData($col); + $cols[$col['attname']] = $this->getColumnMetaData($schema,$col); return $cols; } /** * Returns the column details. + * @param string schema name. * @param array column details. * @return TPgsqlColumnMetaData column meta data. */ - protected function getColumnMetaData($col) + protected function getColumnMetaData($schema, $col) { $name = '"'.$col['attname'].'"'; //quote the column names! $type = $col['type']; @@ -147,7 +148,7 @@ EOD; // A specific constant in the 7.0 source, the length is offset by 4. $length = $col['atttypmod'] > 0 ? $col['atttypmod'] - 4 : -1; $notNull = $col['attnotnull']; - $serial = $col['attisserial'] ? $this->getSerialName($col['adsrc']) : null; + $serial = $col['attisserial'] ? $schema.'.'.$this->getSerialName($col['adsrc']) : null; $default = $serial === null && $col['atthasdef'] ? $col['adsrc'] : null; return new TPgsqlColumnMetaData($name,$type,$length,$notNull,$serial,$default); } @@ -169,6 +170,17 @@ EOD; */ protected function getConstraintKeys($table) { + if(count($parts= explode('.', $table)) > 1) + { + $tablename = $parts[1]; + $schema = $parts[0]; + } + else + { + $tablename = $parts[0]; + $schema = $this->getDefaultSchema(); + } + $sql = 'SELECT pg_catalog.pg_get_constraintdef(pc.oid, true) AS consrc, pc.contype @@ -181,8 +193,8 @@ EOD; '; $this->getDbConnection()->setActive(true); $command = $this->getDbConnection()->createCommand($sql); - $command->bindValue(':table', $table); - $command->bindValue(':schema', $this->getDefaultSchema()); + $command->bindValue(':table', $tablename); + $command->bindValue(':schema', $schema); $keys['primary'] = array(); $keys['foreign'] = array(); foreach($command->query() as $row) -- cgit v1.2.3