Question : Firebird : to get data types of all fields in user tables

Well i try a query as below in firebird :

SELECT  b.RDB$FIELD_NAME, d.RDB$TYPE_NAME,
       c.RDB$FIELD_LENGTH, b.RDB$NULL_FLAG
FROM   RDB$RELATIONS a
INNER JOIN RDB$RELATION_FIELDS b
ON     a.RDB$RELATION_NAME = b.RDB$RELATION_NAME
INNER JOIN RDB$FIELDS c
ON     b.RDB$FIELD_SOURCE = c.RDB$FIELD_NAME
INNER JOIN RDB$TYPES d
ON     c.RDB$FIELD_TYPE = d.RDB$TYPE
WHERE  a.RDB$SYSTEM_FLAG = 0
  AND  d.RDB$FIELD_NAME = 'RDB$FIELD_TYPE' AND b.RDB$RELATION_NAME='tablename'
ORDER BY a.RDB$RELATION_NAME, b.RDB$FIELD_ID


this query returns me a table but not totally i want.

I need data types of the fields as nvarchar(20) or integer and such. Shortly coulmns i need are

COLUMN_NAME, DATA_TYPE, DATA_LENGTH, NULLABLE.

When i make a query in types as below

select rdb$type_name from RDB$TYPES

that returns me the types. But i don't know what's wrong, because I can not see the types as integer (int32, int or INTEGER) and varchar etc. Also i wonder how i  can list all these types. Thanks already for any help.

Answer : Firebird : to get data types of all fields in user tables

It uses internal datatype names.
SHORT for SMALLINT
LONG for INTEGER
VARYING for VARCHAR
TEXT for CHAR

You can use this idea:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
SELECT DISTINCT CAMPOS.RDB$FIELD_NAME AS COLUMN_NAME, 
CASE 
 WHEN DADOSCAMPO.RDB$FIELD_PRECISION > 0 THEN 'NUMERIC' 
 WHEN TIPOS.RDB$TYPE_NAME = 'LONG' THEN 'INTEGER' 
 WHEN TIPOS.RDB$TYPE_NAME = 'SHORT' THEN 'SMALLINT' 
 WHEN TIPOS.RDB$TYPE_NAME = 'INT64' THEN 'NUMERIC' 
 WHEN TIPOS.RDB$TYPE_NAME = 'VARYING' THEN 'VARCHAR' 
 WHEN TIPOS.RDB$TYPE_NAME = 'TEXT' THEN 'CHAR' 
 WHEN TIPOS.RDB$TYPE_NAME = 'BLOB' THEN 'BLOB SUB_TYPE' 
   ELSE TIPOS.RDB$TYPE_NAME 
 END AS FIELD_TYPE, 
 CASE 
 WHEN DADOSCAMPO.RDB$FIELD_TYPE IN(16,8) THEN DADOSCAMPO.RDB$FIELD_PRECISION 
   ELSE DADOSCAMPO.RDB$FIELD_LENGTH 
 END AS DATA_LENGTH, DADOSCAMPO.RDB$FIELD_SCALE AS DATA_SCALE, 
 CASE CAMPOS.RDB$NULL_FLAG WHEN 1 THEN 'N' ELSE 'Y' END AS NULLABLE 
 FROM 
   RDB$RELATIONS TABELAS, RDB$RELATION_FIELDS CAMPOS, RDB$FIELDS 
   DADOSCAMPO, RDB$TYPES TIPOS 
 WHERE TABELAS.RDB$RELATION_NAME = 'PESSOAS' 
   AND TIPOS.RDB$FIELD_NAME = 'RDB$FIELD_TYPE' 
   AND TABELAS.RDB$RELATION_NAME = CAMPOS.RDB$RELATION_NAME 
   AND CAMPOS.RDB$FIELD_SOURCE = DADOSCAMPO.RDB$FIELD_NAME 
   AND DADOSCAMPO.RDB$FIELD_TYPE = TIPOS.RDB$TYPE 
   ORDER BY CAMPOS.RDB$FIELD_POSITION
Random Solutions  
 
programming4us programming4us