From 4ac32e78aa84a582b334b2ac8ad910b249504d62 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 10 Aug 2014 22:22:29 +0900 Subject: [PATCH] Implement getColumnInfo() for MS SQL --- classes/db/DBMssql.class.php | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/classes/db/DBMssql.class.php b/classes/db/DBMssql.class.php index f53b32ac4..784f3a03c 100644 --- a/classes/db/DBMssql.class.php +++ b/classes/db/DBMssql.class.php @@ -449,6 +449,66 @@ class DBMssql extends DB return true; } + /** + * Get information about a column + * @param string $table_name table name + * @param string $column_name column name + * @return object + */ + function getColumnInfo($table_name, $column_name) + { + $query = sprintf("select syscolumns.name as name, systypes.name as type_name, syscolumns.length as length, " . + "syscolumns.isnullable as isnullable, syscomments.text as default_value from syscolumns " . + "inner join sysobjects on sysobjects.id = syscolumns.id " . + "inner join systypes on systypes.xtype = syscolumns.xtype " . + "left join syscomments on syscolumns.cdefault = syscomments.id " . + "where sysobjects.name = '%s%s' and syscolumns.name = '%s'", $this->prefix, $table_name, $column_name); + $result = $this->_query($query); + if($this->isError()) + { + return; + } + $output = $this->_fetch($result); + if($output) + { + $dbtype = $output->type_name; + $size = ($output->length > 0) ? $output->length : null; + if($xetype = array_search("$dbtype($size)", $this->column_type)) + { + $dbtype = "$dbtype($size)"; + $size = null; + } + elseif($size !== null) + { + if($xetype = array_search($dbtype, $this->column_type)) + { + // no-op + } + else + { + $xetype = $dbtype; + } + } + else + { + $xetype = $dbtype; + $size = null; + } + return (object)array( + 'name' => $output->name, + 'dbtype' => $dbtype, + 'xetype' => $xetype, + 'size' => $size, + 'default_value' => $output->default_value, + 'notnull' => !$output->isnullable, + ); + } + else + { + return false; + } + } + /** * Add an index to the table * $target_columns = array(col1, col2)