@@ -312,7 +312,7 @@ void InternalTransaction::doCommit(FbStatusVector* status, thread_db* tdbb, bool
312312 {
313313 m_transaction->commit (&s);
314314 m_transaction = NULL ;
315- }
315+ }
316316 }
317317}
318318
@@ -337,7 +337,7 @@ void InternalTransaction::doRollback(FbStatusVector* status, thread_db* tdbb, bo
337337 {
338338 m_transaction->rollback (&s);
339339 m_transaction = NULL ;
340- }
340+ }
341341 }
342342
343343 if (status->getErrors ()[1 ] == isc_att_shutdown && !retain)
@@ -595,9 +595,26 @@ void InternalStatement::doClose(thread_db* tdbb, bool drop)
595595 }
596596}
597597
598+ // We need to copy external blob from\to dynamic statement.
599+ // If external blob is permanent one - we could use its blob_id and avoid
600+ // copying blob contents into new temporary blob.
601+ // If external blob is temporary - we could access it by blob_id only if
602+ // dynamic statement is executed in the same transaction as local (caller)
603+ // statement.
604+
605+ static bool isPermanentBlob (const dsc& src)
606+ {
607+ if (src.isBlob ())
608+ {
609+ const bid* srcBlobID = reinterpret_cast <bid*> (src.dsc_address );
610+ return (srcBlobID->bid_internal .bid_relation_id != 0 );
611+ }
612+ return false ;
613+ }
614+
598615void InternalStatement::putExtBlob (thread_db* tdbb, dsc& src, dsc& dst)
599616{
600- if (m_transaction->getScope () == traCommon)
617+ if (isPermanentBlob (src) || m_transaction->getScope () == traCommon && m_intConnection. isCurrent () )
601618 MOV_move (tdbb, &src, &dst);
602619 else
603620 Statement::putExtBlob (tdbb, src, dst);
@@ -608,7 +625,7 @@ void InternalStatement::getExtBlob(thread_db* tdbb, const dsc& src, dsc& dst)
608625 fb_assert (dst.dsc_length == src.dsc_length );
609626 fb_assert (dst.dsc_length == sizeof (bid));
610627
611- if (m_transaction->getScope () == traCommon)
628+ if (isPermanentBlob (src) || m_transaction->getScope () == traCommon && m_intConnection. isCurrent () )
612629 memcpy (dst.dsc_address , src.dsc_address , sizeof (bid));
613630 else
614631 Statement::getExtBlob (tdbb, src, dst);
0 commit comments