douque9982 2010-07-19 15:00
浏览 125

如何从sqlite 3中的给定表中获取所有列名的列表? (表可能是空的)

now I use:

PRAGMA table_info(table_name)

construct, but it don't allow me to narrow search result to only column names, as it turns out much of unwanted data. That is array of arrays

Array
(
    [0] => Array
        (
            [cid] => 0
            [name] => id
            [type] => INTEGER
            [notnull] => 0
            [dflt_value] => 
            [pk] => 1
        )

    [1] => Array
        (
            [cid] => 1
            [name] => name
            [type] => TEXT
            [notnull] => 0
            [dflt_value] => 
            [pk] => 0
        )

    [2] => Array
        (
            [cid] => 2
            [name] => timestamp
            [type] => INTEGER
            [notnull] => 0
            [dflt_value] => 
            [pk] => 0
        )

    [3] => Array
        (
            [cid] => 3
            [name] => note
            [type] => TEXT
            [notnull] => 0
            [dflt_value] => 
            [pk] => 0
        )

)

it would be better for the result to be

Array
(
    [0] => id
    [1] => title
    [2] => timestamp
    [3] => note
)

but SELECT name from PRAGMA table_info(table_name) doesn't work

  • 写回答

1条回答 默认 最新

  • duanji1899 2010-07-19 17:26
    关注

    You can't change the output of table_info, but it's trivial to loop over your result object and build the array of column names you want.

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题