Subject | Re: [firebird-support] Determining column structure in a Firebird table |
---|---|
Author | Ann W. Harrison |
Post date | 2009-10-23T20:40:32Z |
Csaba wrote:
through the RDB$FIELD_SOURCE field.
rdb$relation_fields.rdb$field_source = rdb$fields.rdb$field_name
The types are stored in numeric form, unfortunately based on the
VAX/VMS data types, but you can probably sort through that.
To get the primary key information you need to check the system
table RDB$RELATION_CONSTRAINTS. That will also tell you about
unique and not null constraints - but only at the table level.
For unique and primary key constraints, you need to get the
index name from RDB$RELATION_CONSTRAINTS and look up the fields
in RDB$INDEX_SEGMENTS. Look in the RDB$FIELDS and RDB$RELATION_FIELDS
for the null constraint.
Foreign key constraints are kept in RDB$REF_CONSTRAINTS and also
need a bit of cross referencing to get the full set of fields involved.
Helen Borrie's book "The Firebird Book" from Apress available through
the IBPhoenix web site is a great source of information about Firebird
system tables.
Good luck
Ann
>Look at RDB$FIELDS which is linked to RDB$RELATION_FIELDS
> I'd like to be able to determine the column
> types for each column of a table. (I think) I am
> after a correspondence similar to:
> column1Name => VARCHAR(7)
> column2Name => INTEGER PRIMARY KEY
> and so on.
>
> I've looked through all the tables mentioned at
> http://discuss.joelonsoftware.com/default.asp?design.4.281633.7
> and I can get all the table columns (headers) from
> rdb$relation_fields.rdb$field_name =
> rdb$relations.rdb$relation_name
through the RDB$FIELD_SOURCE field.
rdb$relation_fields.rdb$field_source = rdb$fields.rdb$field_name
The types are stored in numeric form, unfortunately based on the
VAX/VMS data types, but you can probably sort through that.
To get the primary key information you need to check the system
table RDB$RELATION_CONSTRAINTS. That will also tell you about
unique and not null constraints - but only at the table level.
For unique and primary key constraints, you need to get the
index name from RDB$RELATION_CONSTRAINTS and look up the fields
in RDB$INDEX_SEGMENTS. Look in the RDB$FIELDS and RDB$RELATION_FIELDS
for the null constraint.
Foreign key constraints are kept in RDB$REF_CONSTRAINTS and also
need a bit of cross referencing to get the full set of fields involved.
Helen Borrie's book "The Firebird Book" from Apress available through
the IBPhoenix web site is a great source of information about Firebird
system tables.
Good luck
Ann