Skip to content

BLOB parameters in batch commands are disposed before 'AFTER INSERT' trigger is run #9032

@andrewjw1995

Description

@andrewjw1995

I'm using Firebird HQBird 5.0.4 with the .Net provider. We have encountered an issue where batch commands seem to be cleaning up blob parameters before the 'AFTER INSERT' trigger is run.

Steps to reproduce:

  • Create a table with a BLOB column
  • Create an 'AFTER INSERT' trigger on the table which reads the new value of the blob column
  • Execute a batch command to insert a row into the table

This seems specific to the FbBatchCommand implementation. Running a normal command works as expected. We had to switch to batch commands for performance reasons when inserting large amounts of data into our table.

We've tried to reproduce this running Firebird in a docker container but it's working as expected. We are able to consistently reproduce this in our production and shared dev environments and are still trying to identify the exact conditions to reproduce. I'll update this issue once we find it.

Here's an example schema:

CREATE TABLE EXAMPLE_X (
    "SAMPLE_ID" INTEGER NOT NULL,
    "VALUE" BLOB SUB_TYPE TEXT,
    CONSTRAINT PK_EXAMPLE_X PRIMARY KEY ("SAMPLE_ID")
);

CREATE TABLE EXAMPLE_X_LOG (
    "TIMESTAMP" TIMESTAMP NOT NULL,
    "OLD_VALUE" BLOB SUB_TYPE TEXT,
    "NEW_VALUE" BLOB SUB_TYPE TEXT,
    CONSTRAINT PK_EXAMPLE_X_LOG PRIMARY KEY ("TIMESTAMP")
);

CREATE TRIGGER EXAMPLE_X_AFTER_INSERT FOR EXAMPLE_X AFTER INSERT
AS
BEGIN
    INSERT INTO EXAMPLE_X_LOG ("TIMESTAMP", "OLD_VALUE", "NEW_VALUE")
    VALUES (LocalTimeStamp, NULL, NEW."VALUE");
END;

And a simple program to demonstrate the problem:

using FirebirdSql.Data.FirebirdClient;

using var connection = new FbConnection("Database=localhost:/var/lib/firebird/data/MyDatabase.fdb;User=SYSDBA;Password=P@ssw0rd");
await connection.OpenAsync();

using var command = new FbBatchCommand
{
    Connection = connection,
    CommandText = "UPDATE OR INSERT INTO EXAMPLE_X (SAMPLE_ID, \"VALUE\") VALUES (@p0, @p1);",
};

var parameters = command.AddBatchParameters();
parameters.Add("p0", FbDbType.Integer).Value = 1;
parameters.Add("p1", FbDbType.Text).Value = "";

var results = command.ExecuteNonQuery();
results.EnsureSuccess();

This example throws an exception with the following message from Firebird:

BLOB not found
At trigger 'EXAMPLE_X_AFTER_INSERT' line: 5, col: ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions