summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorwei <>2007-01-23 12:55:49 +0000
committerwei <>2007-01-23 12:55:49 +0000
commit1c92c3a9fb320ec35949634e53b28ee4ab79f138 (patch)
tree4becb5ff4edca26ca283e5a11506f28e5f3d0f08 /framework
parent9e6fdda71cf70275fcf7e4b09230daa713c18b70 (diff)
fix pgsql schema table problems.
Diffstat (limited to 'framework')
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordCriteria.php12
-rw-r--r--framework/Data/ActiveRecord/Vendor/TPgsqlColumnMetaData.php2
-rw-r--r--framework/Data/ActiveRecord/Vendor/TPgsqlMetaDataInspector.php22
3 files changed, 30 insertions, 6 deletions
diff --git a/framework/Data/ActiveRecord/TActiveRecordCriteria.php b/framework/Data/ActiveRecord/TActiveRecordCriteria.php
index 457b5dc0..968a2691 100644
--- a/framework/Data/ActiveRecord/TActiveRecordCriteria.php
+++ b/framework/Data/ActiveRecord/TActiveRecordCriteria.php
@@ -40,9 +40,16 @@ class TActiveRecordCriteria extends TComponent
/**
* Creates a new criteria with given condition;
+ * @param string sql string after the WHERE stanza
+ * @param mixed named or indexed parameters, accepts as multiple arguments.
*/
public function __construct($condition=null,$parameters=array())
{
+ if(!is_array($parameters) && func_num_args() > 2)
+ {
+ $parameters = func_get_args();
+ array_shift($parameters);
+ }
$this->setCondition($condition);
$this->_parameters=new TAttributeCollection((array)$parameters);
$this->_ordersBy=new TAttributeCollection;
@@ -141,6 +148,11 @@ class TActiveRecordCriteria extends TComponent
{
$this->_offset=$value;
}
+
+ public function __toString()
+ {
+ return $this->getCondition();
+ }
}
?> \ No newline at end of file
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)