If first query with monitoring tables in transaction not returned blob fields to the client (i.e. blob fields was not present in SELECT list) than subsequent queries in the same transaction which referenced blob fields will fail with "Invalid BLOB ID" error.
The reason is :
- first query in transaction involving any monitoring table triggers creation of monitoring snapshot for this transaction
- when snapshot is created some temporary blobs is created too and bound to the transaction and to the request
- if this blobs not passed to the client its remains bound to the request
- when request finish its execution all temporary blobs bound to it released
- when another request going to open blob it fails
Example
firebird\bin>isql -user SYSDBA -pass masterkey s:\TEST.FDB -ch UNICODE_FSS
Database: s:\TEST.FDB, User: SYSDBA
SQL> select 1 from mon$database;
CONSTANT
============
1
SQL> select mon$sql_text from mon$statements;
MON$SQL_TEXT
=================
0:1
==============================================================================
MON$SQL_TEXT:
Statement failed, SQLSTATE = 42000
invalid BLOB ID
SQL> commit;
SQL> select mon$sql_text from mon$statements;
MON$SQL_TEXT
=================
0:1
==============================================================================
MON$SQL_TEXT:
select mon$sql_text from mon$statements
==============================================================================
SQL> select mon$sql_text from mon$statements;
MON$SQL_TEXT
=================
0:1
==============================================================================
MON$SQL_TEXT:
select mon$sql_text from mon$statements
==============================================================================
SQL> exit;
Note, i used UNICODE_FSS connection charset. This is needed to avoid involving transliteration filter which is used by the engine if connection charset is different from blob field charset (see also patch for
CORE-2602)