开发者

how to get list of all column names from given table in sqlite 3 ? (table might be empty)

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜