1.Dd January 24, 2024 2.Dt SQLITE3_TABLE_COLUMN_METADATA 3 3.Os 4.Sh NAME 5.Nm sqlite3_table_column_metadata 6.Nd extract metadata about a column of a table 7.Sh SYNOPSIS 8.In sqlite3.h 9.Ft int 10.Fo sqlite3_table_column_metadata 11.Fa "sqlite3 *db" 12.Fa "const char *zDbName" 13.Fa "const char *zTableName" 14.Fa "const char *zColumnName" 15.Fa "char const **pzDataType" 16.Fa "char const **pzCollSeq" 17.Fa "int *pNotNull" 18.Fa "int *pPrimaryKey" 19.Fa "int *pAutoinc" 20.Fc 21.Sh DESCRIPTION 22The sqlite3_table_column_metadata(X,D,T,C,....) routine returns information 23about column C of table T in database D on database connection 24X. 25The sqlite3_table_column_metadata() interface returns SQLITE_OK and 26fills in the non-NULL pointers in the final five arguments with appropriate 27values if the specified column exists. 28The sqlite3_table_column_metadata() interface returns SQLITE_ERROR 29if the specified column does not exist. 30If the column-name parameter to sqlite3_table_column_metadata() is 31a NULL pointer, then this routine simply checks for the existence of 32the table and returns SQLITE_OK if the table exists and SQLITE_ERROR 33if it does not. 34If the table name parameter T in a call to sqlite3_table_column_metadata(X,D,T,C,...) 35is NULL then the result is undefined behavior. 36.Pp 37The column is identified by the second, third and fourth parameters 38to this function. 39The second parameter is either the name of the database (i.e. "main", 40"temp", or an attached database) containing the specified table or 41NULL. 42If it is NULL, then all attached databases are searched for the table 43using the same algorithm used by the database engine to resolve unqualified 44table references. 45.Pp 46The third and fourth parameters to this function are the table and 47column name of the desired column, respectively. 48.Pp 49Metadata is returned by writing to the memory locations passed as the 505th and subsequent parameters to this function. 51Any of these arguments may be NULL, in which case the corresponding 52element of metadata is omitted. 53.Bd -ragged 54.Pp 55 Parameter Output Type Description 56 5th const char* Data type 57 6th const char* Name of default collation sequence 58 7th int True if column has a NOT NULL constraint 59 8th int True if column is part of the PRIMARY KEY 60 9th int True if column is AUTOINCREMENT 61.Pp 62.Ed 63.Pp 64The memory pointed to by the character pointers returned for the declaration 65type and collation sequence is valid until the next call to any SQLite 66API function. 67.Pp 68If the specified table is actually a view, an error code 69is returned. 70.Pp 71If the specified column is "rowid", "oid" or "_rowid_" and the table 72is not a WITHOUT ROWID table and an INTEGER PRIMARY KEY 73column has been explicitly declared, then the output parameters are 74set for the explicitly declared column. 75If there is no INTEGER PRIMARY KEY column, then 76the outputs for the rowid are set as follows: 77.Bd -literal 78data type: "INTEGER" collation sequence: "BINARY" not null: 0 primary 79key: 1 auto increment: 0 80.Ed 81.Pp 82This function causes all database schemas to be read from disk and 83parsed, if that has not already been done, and returns an error if 84any errors are encountered while loading the schema. 85.Sh IMPLEMENTATION NOTES 86These declarations were extracted from the 87interface documentation at line 7048. 88.Bd -literal 89SQLITE_API int sqlite3_table_column_metadata( 90 sqlite3 *db, /* Connection handle */ 91 const char *zDbName, /* Database name or NULL */ 92 const char *zTableName, /* Table name */ 93 const char *zColumnName, /* Column name */ 94 char const **pzDataType, /* OUTPUT: Declared data type */ 95 char const **pzCollSeq, /* OUTPUT: Collation sequence name */ 96 int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ 97 int *pPrimaryKey, /* OUTPUT: True if column part of PK */ 98 int *pAutoinc /* OUTPUT: True if column is auto-increment */ 99); 100.Ed 101.Sh SEE ALSO 102.Xr sqlite3 3 103