def column_info
retval = []
return [] if @res_handle.nil?
unique_key_flag = MysqlField.const_get(:UNIQUE_KEY_FLAG)
multiple_key_flag = MysqlField.const_get(:MULTIPLE_KEY_FLAG)
indexed = (unique_key_flag | multiple_key_flag)
@res_handle.fetch_fields.each {|col|
mysql_type_name, dbi_type = Database::TYPE_MAP[col.type] rescue [nil, nil]
xopen_info = Database::MYSQL_to_XOPEN[mysql_type_name] ||
Database::MYSQL_to_XOPEN[nil]
sql_type = xopen_info[0]
type_name = DBI::SQL_TYPE_NAMES[sql_type]
retval << {
'name' => col.name,
'sql_type' => sql_type,
'type_name' => type_name,
'precision' => type_name == "NUMERIC" ? col.length - 2 : col.length,
'scale' => col.decimals,
'nullable' => !col.is_not_null?,
'indexed' => ((col.flags & indexed) != 0) ||
col.is_pri_key?,
'primary' => col.is_pri_key?,
'unique' => ((col.flags & unique_key_flag) != 0) ||
col.is_pri_key?,
'mysql_type' => col.type,
'mysql_type_name' => mysql_type_name,
'mysql_length' => col.length,
'mysql_max_length' => col.max_length,
'mysql_flags' => col.flags
}
if retval[-1]['sql_type'] == DBI::SQL_TINYINT and retval[-1]['precision'] == 1
retval[-1]['dbi_type'] = DBI::Type::Boolean
elsif dbi_type
retval[-1]['dbi_type'] = dbi_type
end
}
retval
rescue MyError => err
error(err)
end