118: def column_info
119: retval = []
120:
121: return [] if @res_handle.nil?
122:
123: unique_key_flag = MysqlField.const_get(:UNIQUE_KEY_FLAG)
124: multiple_key_flag = MysqlField.const_get(:MULTIPLE_KEY_FLAG)
125: indexed = (unique_key_flag | multiple_key_flag)
126:
127:
128:
129:
130: @res_handle.fetch_fields.each {|col|
131: mysql_type_name, dbi_type = Database::TYPE_MAP[col.type] rescue [nil, nil]
132: xopen_info = Database::MYSQL_to_XOPEN[mysql_type_name] ||
133: Database::MYSQL_to_XOPEN[nil]
134: sql_type = xopen_info[0]
135: type_name = DBI::SQL_TYPE_NAMES[sql_type]
136:
137: retval << {
138:
139: 'name' => col.name,
140: 'sql_type' => sql_type,
141: 'type_name' => type_name,
142:
143: 'precision' => col.decimals > 0 ? col.length - col.decimals - 1 : col.length,
144: 'scale' => col.decimals,
145: 'nullable' => !col.is_not_null?,
146: 'indexed' => ((col.flags & indexed) != 0) ||
147: col.is_pri_key?,
148: 'primary' => col.is_pri_key?,
149: 'unique' => ((col.flags & unique_key_flag) != 0) ||
150: col.is_pri_key?,
151:
152: 'mysql_type' => col.type,
153: 'mysql_type_name' => mysql_type_name,
154: 'mysql_length' => col.length,
155: 'mysql_max_length' => col.max_length,
156: 'mysql_flags' => col.flags
157: }
158:
159: if retval[-1]['sql_type'] == DBI::SQL_TINYINT and retval[-1]['precision'] == 1
160: retval[-1]['dbi_type'] = DBI::Type::Boolean
161: elsif dbi_type
162: retval[-1]['dbi_type'] = dbi_type
163: end
164: }
165: retval
166: rescue MyError => err
167: error(err)
168: end