<?php
class Model_Column_Model extends Model {
	function __construct(){
		parent::__construct();
	}
	function analyseSql($table_name=false,$column_name=false){
		
		$columns	=	$this->db->query("SHOW FULL COLUMNS FROM ".DBFIX."$table_name")->result()->result_array(false);
		foreach($columns as $column){
			$column['column_name']	=	$column['Field'];
			$column['type']			=	preg_replace("#[\(\)0-9]*#i","",$column['Type']);
			$column['length']		=	preg_replace("#[^0-9]*#i","",$column['Type']);
			$column['comment']		=	$column['Comment'];
			$column['default']		=	$column['Default'];
			$column['is_null']		=	$column['Null'];
			if($column_name&&$column['column_name']==$column_name){
				return $column;
			}
			$fields[]				=	$column;
		}
		
		return $fields;
	}
	function drop_column($table=false,$column=false){
		return $this->db->drop_column($table,$column);
	}
	function list_fields($table){
		return $this->db->list_fields($table);
	}
	function getTableStructure($table){
		return $this->db->query("show create table ".DBFIX."$table")->current();
	}
	function getColumnList($table_name){
		return $this->db->list_fields($table_name);
	}
}