diff --git a/classes/db/DBMysql.class.php b/classes/db/DBMysql.class.php index 35a0d1ec1..d102385d1 100644 --- a/classes/db/DBMysql.class.php +++ b/classes/db/DBMysql.class.php @@ -370,6 +370,61 @@ class DBMysql extends DB return false; } + /** + * 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("show fields from `%s%s` where `Field` = '%s'", $this->prefix, $table_name, $column_name); + $result = $this->_query($query); + if($this->isError()) + { + return; + } + $output = $this->_fetch($result); + if($output) + { + $dbtype = $output->{'Type'}; + if($xetype = array_search($dbtype, $this->column_type)) + { + $size = null; + } + elseif(strpos($dbtype, '(') !== false) + { + list($dbtype, $size) = explode('(', $dbtype, 2); + $size = intval(rtrim($size, ')')); + if($xetype = array_search($dbtype, $this->column_type)) + { + // no-op + } + else + { + $xetype = $dbtype; + } + } + else + { + $xetype = $dbtype; + $size = null; + } + return (object)array( + 'name' => $output->{'Field'}, + 'dbtype' => $dbtype, + 'xetype' => $xetype, + 'size' => $size, + 'default_value' => $output->{'Default'}, + 'notnull' => strncmp($output->{'Null'}, 'NO', 2) == 0 ? true : false, + ); + } + else + { + return false; + } + } + /** * Add an index to the table * $target_columns = array(col1, col2)