179: def columns(table)
180: dbh = DBI::DatabaseHandle.new(self)
181: uniques = []
182: dbh.execute("SHOW INDEX FROM #{table}") do |sth|
183: sth.each do |row|
184: uniques << row[4] if row[1] == 0
185: end
186: end
187:
188: ret = nil
189: dbh.execute("SHOW FIELDS FROM #{table}") do |sth|
190: ret = sth.collect do |row|
191: name, type, nullable, key, default, extra = row
192:
193:
194:
195:
196:
197: sqltype, type, size, decimal = mysql_type_info(row[1])
198: col = Hash.new
199: col['name'] = name
200: col['sql_type'] = sqltype
201: col['type_name'] = type
202: col['nullable'] = nullable == "YES"
203: col['indexed'] = key != ""
204: col['primary'] = key == "PRI"
205: col['unique'] = uniques.index(name) != nil
206: col['precision'] = size
207: col['scale'] = decimal
208: col['default'] = row[4]
209:
210: case col['type_name']
211: when 'timestamp'
212: col['dbi_type'] = DBI::DBD::Mysql::Type::Timestamp
213: end
214:
215: col
216: end
217: end
218:
219: ret
220: end