I have written a tool for displaying database structures using the GetTableNames and GetFieldNames methods of TSQLConnection. How can I get the types of each field name similar to the following list (which is part of the DDL required to build the table)?
TABLE: ARTICLES
ID INTEGER NOT NULL
PRINTED SMALLINT DEFAULT 0
ACADEMIC SMALLINT
RELEVANCE SMALLINT
SOURCE VARCHAR(64) CHARACTER SET WIN1251 COLLATE WIN1251
NAME VARCHAR(128) CHARACTER SET WIN1251 COLLATE WIN1251
FILENAME VARCHAR(128) CHARACTER SET WIN1251 COLLATE WIN1251
NOTES VARCHAR(2048) CHARACTER SET WIN1251 COLLATE WIN1251
This is incomplete (because I've never used Firebird array data types) and not much tested but perhaps it will give you a good starting point:
Using the link which TLama provided, I found my own solution, which is somewhat similar to the above solutions, but simpler.
p1 is the table name which is passed as a parameter to the query.
In context, I have a treeview which has as its nodes the table names of a given database; for each node, the child nodes are the fields along with their definitions.
Here is a screenshot of the program in action. I realise that the format is not the same as the DDL which I quoted, but it's obvious what each field means (at least to me, and this is a program for my private use).
Use direct access to RDB$ tables. For example:
will give you a list of all tables in a database.
will result in a list of all fields of given table with information of field type. Param RN is a name of the table.
Using information from RDB$tables one can easily construct DDL statement. The query below gives you a hint how to do it:
I made a litle change to the first option to support computed by fields, add field_position and made a view to make more easy.