Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SQlite and column names

216 views
Skip to first unread message

Casey

unread,
Jul 29, 2014, 3:09:23 PM7/29/14
to
How would I get all column names from a table with TCL code?

From the examples that I have found, I need to specifically specify the names.

Peter Dean

unread,
Jul 29, 2014, 5:06:58 PM7/29/14
to
On 30/07/14 05:09, Casey wrote:
> How would I get all column names from a table with TCL code?
>
> From the examples that I have found, I need to specifically specify the names.
>

PRAGMA table_info(table-name);

here's an extract from something I wrote

db eval "pragma table_info('$table')" values {
set column $values(name)
set type $values(type)
set pk $values(pk)
if {$pk} {
set pkey $column
continue
}
if {$column eq $geometry} {continue}
lappend columns $column
set types($column) $type
}

Björn Lundin

unread,
Jul 30, 2014, 12:27:28 PM7/30/14
to
On 2014-07-29 21:09, Casey wrote:
> How would I get all column names from a table with TCL code?
>
> From the examples that I have found, I need to specifically specify the names.
>

most db engines have a way to lookup meta info of tables
Many db have the view information_schema

select * from information_schema.columns
where table_name = 'My_Table'

/Bj�rn

Sp...@controlq.com

unread,
Jul 30, 2014, 2:51:37 PM7/30/14
to
On Wed, 30 Jul 2014, Bj?rn Lundin wrote:

> Date: Wed, 30 Jul 2014 18:27:28 +0200
> From: Bj?rn Lundin <b.f.l...@gmail.com>
> Newsgroups: comp.lang.tcl
> Subject: Re: SQlite and column names
> /Bj?rn

IIRC, this is a compile option in SQLite ...

YUP -- SQLITE_ENABLE_COLUMN_METADATA ...

Cheers,
Rob.

Harm Olthof

unread,
Jul 31, 2014, 4:59:46 PM7/31/14
to
On Tuesday, July 29, 2014 9:09:23 PM UTC+2, Casey wrote:
> How would I get all column names from a table with TCL code?
>
>
>
> From the examples that I have found, I need to specifically specify the names.

A more general method, which works for other supported databases also, would be to use tdbc:

package require tdbc::sqlite3
tdbc::sqlite3::connection create db {}
db allrows {create table test(col1, col2, col3)}
foreach {c i} [db columns test] {puts $c}


Harm
0 new messages