From 32b73a0b1dfcd33e07e7fd2b2cf2fd7d42cf48a0 Mon Sep 17 00:00:00 2001 From: wei <> Date: Thu, 12 Apr 2007 12:43:49 +0000 Subject: Add Sqlite driver. --- framework/Data/Common/Mysql/TMysqlMetaData.php | 17 ++++----- framework/Data/Common/Mysql/TMysqlTableColumn.php | 42 +++++++++++++---------- 2 files changed, 29 insertions(+), 30 deletions(-) (limited to 'framework/Data/Common/Mysql') diff --git a/framework/Data/Common/Mysql/TMysqlMetaData.php b/framework/Data/Common/Mysql/TMysqlMetaData.php index ee3bd2e0..2a6d80bd 100644 --- a/framework/Data/Common/Mysql/TMysqlMetaData.php +++ b/framework/Data/Common/Mysql/TMysqlMetaData.php @@ -49,8 +49,6 @@ class TMysqlMetaData extends TDbMetaData $info['IsPrimaryKey'] = true; if($this->isForeignKeyColumn($columnId, $tableInfo)) $info['IsForeignKey'] = true; - if(in_array($columnId, $tableInfo->getUniqueKeys())) - $info['IsUnique'] = true; $info['DbType'] = $col['Type']; $match=array(); @@ -142,8 +140,8 @@ class TMysqlMetaData extends TDbMetaData $info['SchemaName'] = $schemaName; $info['TableName'] = $tableName; $info['IsView'] = $this->getIsView($schemaName,$tableName); - list($primary, $foreign, $unique) = $this->getConstraintKeys($schemaName, $tableName); - return new TMysqlTableInfo($info,$primary,$foreign, $unique); + list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName); + return new TMysqlTableInfo($info,$primary,$foreign); } /** @@ -173,10 +171,10 @@ class TMysqlMetaData extends TDbMetaData } /** - * Gets the primary, foreign key, and unique column details for the given table. + * Gets the primary and foreign key column details for the given table. * @param string schema name * @param string table name. - * @return array tuple ($primary, $foreign, $unique) + * @return array tuple ($primary, $foreign) */ protected function getConstraintKeys($schemaName, $tableName) { @@ -185,15 +183,12 @@ class TMysqlMetaData extends TDbMetaData $command = $this->getDbConnection()->createCommand($sql); $primary = array(); $foreign = $this->getForeignConstraints($schemaName,$tableName); - $unique = array(); foreach($command->query() as $row) { if($row['Key_name']==='PRIMARY') $primary[] = $row['Column_name']; - else if(intval($row['Non_unique'])===0) - $unique[] = $row['Column_name']; } - return array($primary,$foreign,$unique); + return array($primary,$foreign); } /** @@ -229,7 +224,7 @@ EOD; $fkeys[$col['con']]['keys'][$col['col']] = $col['fkcol']; $fkeys[$col['con']]['table'] = "`{$col['fkschema']}`.`{$col['fktable']}`"; } - return array_values($fkeys); + return count($fkeys) > 0 ? array_values($fkeys) : $fkeys; } /** diff --git a/framework/Data/Common/Mysql/TMysqlTableColumn.php b/framework/Data/Common/Mysql/TMysqlTableColumn.php index 0f013acd..4f0f7da2 100644 --- a/framework/Data/Common/Mysql/TMysqlTableColumn.php +++ b/framework/Data/Common/Mysql/TMysqlTableColumn.php @@ -25,6 +25,29 @@ Prado::using('System.Data.Common.TDbTableColumn'); */ class TMysqlTableColumn extends TDbTableColumn { + private static $types = array( + 'integer' => array('bit', 'tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint'), + 'boolean' => array('boolean', 'bool'), + 'float' => array('float', 'double', 'double precision', 'decimal', 'dec', 'numeric', 'fixed') + ); + + /** + * Overrides parent implementation, returns PHP type from the db type. + * @return boolean derived PHP primitive type from the column db type. + */ + public function getPHPType() + { + $dbtype = trim(str_replace(array('unsigned', 'zerofill'),array('','',),strtolower($this->getDbType()))); + if($dbtype==='tinyint' && $this->getColumnSize()===1) + return 'boolean'; + foreach(self::$types as $type => $dbtypes) + { + if(in_array($dbtype, $dbtypes)) + return $type; + } + return 'string'; + } + /** * @return boolean true if column will auto-increment when the column value is inserted as null. */ @@ -45,25 +68,6 @@ class TMysqlTableColumn extends TDbTableColumn { return $this->getInfo('DbTypeValues'); } - - /** - * Overrides parent implementation, returns PHP type from the db type. - * @return boolean derived PHP primitive type from the column db type. - */ - public function getPHPType() - { - switch(strtolower($this->getDbType())) - { - case 'bit': case 'bit varying': case 'real': case 'serial': case 'int': case 'integer': - return 'integer'; - case 'boolean': - return 'boolean'; - case 'bigint': case 'bigserial': case 'double precision': case 'money': case 'numeric': - return 'float'; - default: - return 'string'; - } - } } ?> \ No newline at end of file -- cgit v1.2.3