我正在使用 Ruby mysql 模块。
我想打印出查询结果并包含列名。我找不到给我这些名称的数组的方法。我有如下所示的值。
result = my.query("select * from foo")
result.each do |row| puts row.join(',') end
感谢您的帮助!
最佳答案
result.fetch_fields.each_with_index do |info, i|
printf "--- Column %d (%s) ---\n", i, info.name
printf "table: %s\n", info.table
printf "def: %s\n", info.def
printf "type: %s\n", info.type
printf "length: %s\n", info.length
printf "max_length: %s\n", info.max_length
printf "flags: %s\n", info.flags
printf "decimals: %s\n", info.decimals
end
关于mysql - 从 Ruby 中的 MySQL 结果中获取列标题名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2053096/