RDB$DB_KEY and Delphi
By Paul Reeves
I have put together a small delphi project that just selects rdb$db_key from a table and displays the results in a grid, but the db_key field is not displayed properly instead of '000000B600000002', what is displayed as a non readable character. From what I can gather, Delphi returns it as a variant and although I store it in a variable as a variant, I cannot then use it to run another query to locate the same record.
One solution is to cast the db_key to the OCTETS character set which then effectively returns a UUID. You can then convert the UUID to a string:
select uuid_to_char( cast (rdb$db_key as char(16) character set octets) ) FROM EMPLOYEE rows 1; UUID_TO_CHAR ==================================== 83000000-0100-0000-0000-000000000000
You can then retrieve the row using the following:
EMP_NO LAST_NAME ======= ==================== 2 Nelson
It's a bit awkward but it works. In this case we are using the db_key to allow persistence in a web server. The string gets passed to the browser in a url and then when the browser wants that row it sends back the db_key in string format. That format is then easily manipulated by stored procedures.