Skip to content

BLOB metadata fields truncated by CAST to VARCHAR(8000) #22

@arvanus

Description

@arvanus

Bug

The describe* functions in src/db/metadata.ts use CAST(RDB$*_SOURCE AS VARCHAR(8000)) to read source code from system tables. This causes:

  • String truncation error on Firebird 5.0: "Arithmetic exception, numeric overflow, or string truncation, string right truncation, expected length 8000, actual 10037"
  • Silent truncation on other versions when source code exceeds 8000 characters

Affected functions

Function Column Line
describeTrigger RDB$TRIGGER_SOURCE L126
describeProcedure RDB$PROCEDURE_SOURCE L218
describeFunction RDB$FUNCTION_SOURCE L312
describePackage RDB$PACKAGE_HEADER_SOURCE, RDB$PACKAGE_BODY_SOURCE L400-401

Root cause

The source columns in Firebird system tables (RDB$TRIGGER_SOURCE, RDB$PROCEDURE_SOURCE, etc.) are BLOB SUB_TYPE TEXT. Casting them to VARCHAR(8000) imposes an artificial size limit that fails for large stored procedures, triggers, functions, and packages.

Proposed fix

Read the BLOB fields natively instead of casting to VARCHAR:

  1. Remove all CAST(... AS VARCHAR(8000)) from the SQL queries and select the raw BLOB columns directly
  2. Add a readBlobField() utility that handles BLOB resolution for both drivers:
    • node-firebird (pure JS): BLOB fields come back as a callback function that returns an EventEmitter stream
    • node-firebird-driver-native: BLOB fields come back as Buffer objects
  3. Resolve the BLOB fields after query execution using await readBlobField(row.SOURCE)

This removes any size limitation and works across all Firebird versions.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions