How to interpret query result RDB $ FORMATS

To get the table schema change history, I ran a query:

select CAST(SUBSTRING(f.rdb$descriptor FROM 1 FOR 32000) AS VARCHAR(32000)) log 
from rdb$formats f
join rdb$relations r on r.rdb$relation_id = f.rdb$relation_id
where r.rdb$relation_name = 'MY_TABLE_NAME'

Documentation states the following:

RDB $ DESCRIPTOR | BLOCK FORMAT | Saves column names and data attributes as BLOBs since they were at the time the format record was created

The following is the result of the query:

LOG                                                  TABLE FORMAT ID
-------------------------------------------------    ----------------       
4: type=9 (LONG) length=4 sub_type=0 flags=0x0       15
8: type=9 (LONG) length=4 sub_type=0 flags=0x0   
12: type=14 (DATE) length=4 sub_type=0 flags=0x0 
16: type=9 (LONG) length=4 sub_type=0 flags=0x0  
20: type=9 (LONG) length=4 sub_type=0 flags=0x0  
24 <-- probably truncated?
-------------------------------------------------    ----------------
4: type=9 (LONG) length=4 sub_type=0 flags=0x0       16
8: type=3 (VARCHAR) length=12 sub_type=52 flags=0x0
20: type=14 (DATE) length=4 sub_type=0 flags=0x0
24: type=9 (LONG) length=4 sub_type=0 flags=0x0
28: type=9 (LONG) length=4 sub_type=0 flags=0x0

There are 28 event lines in total for the table. But I can not understand the meaning of the numbers 4, 8, 12, 16, 20, 24, 28. Well, let's issue the following query:

SELECT
    RF.RDB$FIELD_POSITION,
    RF.RDB$FIELD_ID,
    F.RDB$FIELD_TYPE,
    F.RDB$FIELD_SUB_TYPE
FROM RDB$RELATION_FIELDS RF
JOIN RDB$FIELDS F ON (F.RDB$FIELD_NAME = RF.RDB$FIELD_SOURCE)
WHERE RF.RDB$RELATION_NAME = 'MY_TABLE_NAME'
ORDER BY RF.RDB$FIELD_POSITION;

And here are the results:

results

As you can see, I have only 22 columns, neither the position nor id can match the 24/28 keys from the log above.

Another conclusion: there type=3 (VARCHAR)s is sub_type=52in the log, while 37 is the VARCHAR code.

? ?

+4
1

, 4, 8, 12, 16, 20, 24, 28

.

= 15 " = 4".
"4, 8, 12, 16, 20, 24"

= 16 4, 12, 4, 4, 4
: 4, 8, 20, 24, 28

  • 1 + 1 = 2
  • 2 + 2 = 3
  • et cetera

, :

select CAST(SUBSTRING....

IBExpert, RDB$Formats.rdb$descriptor, BLOB. , . .

Type=16 Scale=0 Length=8 Subtype=0 Flags=0 Offset=8
Type=17 Scale=4 Length=8 Subtype=1 Flags=0 Offset=16

37 - VARCHAR.

- ibase.h

   #define blr_varying             (unsigned char)37
   #define blr_varying2            (unsigned char)38  

BLR - - Firebird, " ". , .

UPDATE: " 37 - VARCHAR" :
https://firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref-appx04-fields.html

+6

Source: https://habr.com/ru/post/1688952/


All Articles