int sqlite3_table_column_metadata( sqlite3* db, const char* db_name, const char* tbl_name, const char* col_name, const char** datatype, const char** collation, int* not_null, int* primary_key, int* autoincrement );
db
db_name
A logical database name, encoded in UTF-8. The
name may be main
, temp
, or a name given to ATTACH DATABASE
.
tbl_name
A table name.
col_name
A column name.
datatype
A reference to a string. The declared datatype
will be passed back. This is the datatype that
appears in the CREATE
TABLE
statement.
collation
A reference to a string. The declared collation will be passed back.
not_null
A reference to an integer. If a nonzero value
is passed back, the column has a NOT NULL
constraint.
primary_key
A reference to an integer. If a nonzero value is passed back, the column is part of the table’s primary key.
autoincrement
A reference to an integer. If a nonzero value
is passed back, the column is set to AUTOINCREMENT
. This
implies the column is a ROWID
alias, and has been designated as
an INTEGER PRIMARY
KEY
.
An SQLite result code.
This function is used to retrieve information about a specific
column. Given a database connection, a logical database name, a
table name, and the name of the column, this function will pass
back the original datatype (as given in the CREATE TABLE
statement) and the
default collation name. A set of flags will also be returned,
indicating if the column has a NOT
NULL
constraint, if the column is part of the
table’s PRIMARY KEY
, and if
the column is part of an AUTOINCREMENT
sequence.
If information on the ROWID
,
OID
, or _OID_
column is requested, the
values returned depend on if the table has a user-defined
ROWID
alias column,
designated as INTEGER PRIMARY
KEY
. If the table does have such a column,
information on the user-defined column will be passed back, just
as if it were a normal column. If the table does not have a
ROWID
alias column, the
values ("INTEGER"
, "BINARY"
, 0
, 1
, 0
) will
be passed back in the fifth through ninth parameters,
respectively.
The datatype and collation names are passed back using static
buffers. The application should not free these buffers. The
buffers stay valid until another call to sqlite3_table_column_metadata()
is made.
This function does not work with views. If an application attempts to query information about a view column, and error will be returned.
This function is only available if the SQLite library was
compiled with the SQLITE_ENABLE_COLUMN_METADATA
build
option.