8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-26 07:23:08 +01:00
firebird-mirror/src/jrd/exe.cpp

1533 lines
38 KiB
C++
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: JRD Access Method
2003-10-08 10:42:48 +02:00
* MODULE: exe.cpp
2001-05-23 15:26:42 +02:00
* DESCRIPTION: Statement execution
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
2002-06-30 11:58:20 +02:00
*
* 2001.6.21 Claudio Valderrama: Allow inserting strings into blob fields.
* 2001.6.28 Claudio Valderrama: Move code to cleanup_rpb() as directed
2002-06-30 11:58:20 +02:00
* by Ann Harrison and cleanup of new record in store() routine.
* 2001.10.11 Claudio Valderrama: Fix SF Bug #436462: From now, we only
* count real store, modify and delete operations either in an external
* file or in a table. Counting on a view caused up to three operations
* being reported instead of one.
* 2001.12.03 Claudio Valderrama: new visit to the same issue: views need
* to count virtual operations, not real I/O on the underlying tables.
* 2002.09.28 Dmitry Yemanov: Reworked internal_info stuff, enhanced
* exception handling in SPs/triggers,
* implemented ROWS_AFFECTED system variable
*
2008-12-05 02:20:14 +01:00
* 2002.10.21 Nickolay Samofatov: Added support for explicit pessimistic locks
* 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "MPEXL" port
* 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "DecOSF" port
* 2002.10.29 Nickolay Samofatov: Added support for savepoints
* 2002.10.30 Sean Leyne - Removed support for obsolete "PC_PLATFORM" define
* 2003.10.05 Dmitry Yemanov: Added support for explicit cursors in PSQL
2007-03-06 03:29:48 +01:00
* Adriano dos Santos Fernandes
*
2001-05-23 15:26:42 +02:00
*/
#include "firebird.h"
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
2001-05-23 15:26:42 +02:00
#include "../jrd/ibsetjmp.h"
#include "../common/classes/VaryStr.h"
2001-05-23 15:26:42 +02:00
#include <string.h>
#include "../jrd/jrd.h"
#include "../jrd/req.h"
#include "../jrd/val.h"
#include "../jrd/exe.h"
#include "../jrd/extds/ExtDS.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/tra.h"
#include "gen/iberror.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/ods.h"
#include "../jrd/btr.h"
#include "../jrd/rse.h"
#include "../jrd/lck.h"
#include "../jrd/intl.h"
#include "../jrd/sbm.h"
#include "../jrd/blb.h"
#include "../jrd/blr.h"
#include "../dsql/ExprNodes.h"
#include "../dsql/StmtNodes.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/blb_proto.h"
#include "../jrd/btr_proto.h"
#include "../jrd/cmp_proto.h"
#include "../jrd/dfw_proto.h"
#include "../jrd/dpm_proto.h"
#include "../jrd/err_proto.h"
#include "../jrd/evl_proto.h"
#include "../jrd/exe_proto.h"
#include "../jrd/ext_proto.h"
2010-10-12 10:02:57 +02:00
#include "../yvalve/gds_proto.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/idx_proto.h"
2005-05-28 00:45:31 +02:00
#include "../jrd/intl_proto.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/jrd_proto.h"
#include "../jrd/lck_proto.h"
#include "../jrd/met_proto.h"
#include "../jrd/mov_proto.h"
#include "../jrd/opt_proto.h"
#include "../jrd/par_proto.h"
#include "../jrd/rlck_proto.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/tra_proto.h"
#include "../jrd/vio_proto.h"
2010-10-12 10:02:57 +02:00
#include "../common/isc_s_proto.h"
2001-05-23 15:26:42 +02:00
2003-04-22 10:45:52 +02:00
#include "../dsql/dsql_proto.h"
#include "../jrd/rpb_chain.h"
#include "../jrd/RecordSourceNodes.h"
#include "../jrd/VirtualTable.h"
2009-02-01 23:10:12 +01:00
#include "../jrd/trace/TraceManager.h"
#include "../jrd/trace/TraceJrdHelpers.h"
#include "../dsql/Nodes.h"
#include "../jrd/recsrc/RecordSource.h"
#include "../jrd/recsrc/Cursor.h"
#include "../jrd/Function.h"
using namespace Jrd;
using namespace Firebird;
2005-06-24 14:56:34 +02:00
// AffectedRows class implementation
AffectedRows::AffectedRows()
{
clear();
}
void AffectedRows::clear()
{
writeFlag = false;
fetchedRows = modifiedRows = 0;
}
void AffectedRows::bumpFetched()
{
fetchedRows++;
}
void AffectedRows::bumpModified(bool increment)
{
if (increment) {
modifiedRows++;
}
else {
writeFlag = true;
}
}
int AffectedRows::getCount() const
{
return writeFlag ? modifiedRows : fetchedRows;
}
// StatusXcp class implementation
StatusXcp::StatusXcp()
: status(*getDefaultMemoryPool())
{
clear();
}
void StatusXcp::clear()
{
status->init();
}
void StatusXcp::init(const FbStatusVector* vector)
{
fb_utils::copyStatus(&status, vector);
}
void StatusXcp::copyTo(FbStatusVector* vector) const
{
fb_utils::copyStatus(vector, &status);
}
2001-05-23 15:26:42 +02:00
bool StatusXcp::success() const
{
2015-03-28 01:36:04 +01:00
return !(status->getState() & IStatus::STATE_ERRORS);
}
SLONG StatusXcp::as_gdscode() const
{
return status->getErrors()[1];
}
SLONG StatusXcp::as_sqlcode() const
{
return gds__sqlcode(status->getErrors());
}
void StatusXcp::as_sqlstate(char* sqlstate) const
{
fb_sqlstate(sqlstate, status->getErrors());
}
SLONG StatusXcp::as_xcpcode() const
{
return (status->getErrors()[1] == isc_except) ? (SLONG) status->getErrors()[3] : 0;
}
string StatusXcp::as_text() const
{
const ISC_STATUS* status_ptr = status->getErrors();
string errorText;
TEXT buffer[BUFFER_LARGE];
while (fb_interpret(buffer, sizeof(buffer), &status_ptr))
{
if (errorText.hasData())
errorText += "\n";
errorText += buffer;
}
return errorText;
}
static void execute_looper(thread_db*, jrd_req*, jrd_tra*, const StmtNode*, jrd_req::req_s);
static void looper_seh(thread_db*, jrd_req*, const StmtNode*);
static void release_blobs(thread_db*, jrd_req*);
static void trigger_failure(thread_db*, jrd_req*);
static void stuff_stack_trace(const jrd_req*);
2001-05-23 15:26:42 +02:00
2004-11-07 15:30:38 +01:00
const size_t MAX_STACK_TRACE = 2048;
// Perform an assignment.
void EXE_assignment(thread_db* tdbb, const AssignmentNode* node)
2001-05-23 15:26:42 +02:00
{
DEV_BLKCHK(node, type_nod);
SET_TDBB(tdbb);
jrd_req* request = tdbb->getRequest();
2001-05-23 15:26:42 +02:00
2007-06-27 04:08:25 +02:00
// Get descriptors of src field/parameter/variable, etc.
request->req_flags &= ~req_null;
dsc* from_desc = EVL_expr(tdbb, request, node->asgnFrom);
EXE_assignment(tdbb, node->asgnTo, from_desc, (request->req_flags & req_null),
node->missing, node->missing2);
}
// Perform an assignment.
void EXE_assignment(thread_db* tdbb, const ValueExprNode* source, const ValueExprNode* target)
{
SET_TDBB(tdbb);
jrd_req* request = tdbb->getRequest();
// Get descriptors of src field/parameter/variable, etc.
request->req_flags &= ~req_null;
dsc* from_desc = EVL_expr(tdbb, request, source);
EXE_assignment(tdbb, target, from_desc, (request->req_flags & req_null), NULL, NULL);
}
// Perform an assignment.
void EXE_assignment(thread_db* tdbb, const ValueExprNode* to, dsc* from_desc, bool from_null,
const ValueExprNode* missing_node, const ValueExprNode* missing2_node)
{
SET_TDBB(tdbb);
jrd_req* request = tdbb->getRequest();
// Get descriptors of receiving and sending fields/parameters, variables, etc.
2001-05-23 15:26:42 +02:00
dsc* missing = NULL;
if (missing_node)
missing = EVL_expr(tdbb, request, missing_node);
2001-12-24 03:51:06 +01:00
2007-06-27 04:08:25 +02:00
// Get descriptor of target field/parameter/variable, etc.
2001-12-24 03:51:06 +01:00
DSC* to_desc = EVL_assign_to(tdbb, to);
2001-05-23 15:26:42 +02:00
request->req_flags &= ~req_null;
// NS: If we are assigning to NULL, we finished.
// This functionality is currently used to allow calling UDF routines
// without assigning resulting value anywhere.
if (!to_desc)
return;
SSHORT null = from_null ? -1 : 0;
2001-12-24 03:51:06 +01:00
if (!null && missing && MOV_compare(tdbb, missing, from_desc) == 0)
2001-05-23 15:26:42 +02:00
null = -1;
USHORT* impure_flags = NULL;
2010-11-02 18:05:01 +01:00
const ParameterNode* toParam;
const VariableNode* toVar;
if ((toParam = nodeAs<ParameterNode>(to)))
{
const MessageNode* message = toParam->message;
if (toParam->argInfo)
{
EVL_validate(tdbb, Item(Item::TYPE_PARAMETER, message->messageNumber, toParam->argNumber),
toParam->argInfo, from_desc, null == -1);
}
impure_flags = request->getImpure<USHORT>(
message->impureFlags + (sizeof(USHORT) * toParam->argNumber));
}
else if ((toVar = nodeAs<VariableNode>(to)))
{
2010-11-02 18:05:01 +01:00
if (toVar->varInfo)
{
2010-11-02 18:05:01 +01:00
EVL_validate(tdbb, Item(Item::TYPE_VARIABLE, toVar->varId),
toVar->varInfo, from_desc, null == -1);
}
2010-11-02 18:05:01 +01:00
impure_flags = &request->getImpure<impure_value>(
toVar->varDecl->impureOffset)->vlu_flags;
}
if (impure_flags != NULL)
*impure_flags |= VLU_checked;
// If the value is non-missing, move/convert it. Otherwise fill the
// field with appropriate nulls.
2004-01-13 10:52:19 +01:00
dsc temp;
2001-05-23 15:26:42 +02:00
2001-12-24 03:51:06 +01:00
if (!null)
{
// if necessary and appropriate, use the indicator variable
2001-05-23 15:26:42 +02:00
if (toParam && toParam->argIndicator)
2001-12-24 03:51:06 +01:00
{
dsc* indicator = EVL_assign_to(tdbb, toParam->argIndicator);
temp.dsc_dtype = dtype_short;
temp.dsc_length = sizeof(SSHORT);
temp.dsc_scale = 0;
2001-05-23 15:26:42 +02:00
temp.dsc_sub_type = 0;
2001-12-24 03:51:06 +01:00
SSHORT len;
2008-12-20 09:12:19 +01:00
if ((from_desc->dsc_dtype <= dtype_varying) && (to_desc->dsc_dtype <= dtype_varying) &&
2001-05-23 15:26:42 +02:00
(TEXT_LEN(from_desc) > TEXT_LEN(to_desc)))
2001-12-24 03:51:06 +01:00
{
2001-05-23 15:26:42 +02:00
len = TEXT_LEN(from_desc);
}
else
2001-05-23 15:26:42 +02:00
len = 0;
2003-10-08 10:42:48 +02:00
temp.dsc_address = (UCHAR *) &len;
MOV_move(tdbb, &temp, indicator);
2001-05-23 15:26:42 +02:00
2009-11-23 06:24:29 +01:00
if (len)
{
2001-05-23 15:26:42 +02:00
temp = *from_desc;
temp.dsc_length = TEXT_LEN(to_desc);
if (temp.dsc_dtype == dtype_cstring)
2001-05-23 15:26:42 +02:00
temp.dsc_length += 1;
else if (temp.dsc_dtype == dtype_varying)
2001-05-23 15:26:42 +02:00
temp.dsc_length += 2;
2001-05-23 15:26:42 +02:00
from_desc = &temp;
}
}
// Validate range for datetime values
if (DTYPE_IS_DATE(from_desc->dsc_dtype))
{
switch (from_desc->dsc_dtype)
{
case dtype_sql_date:
if (!Firebird::TimeStamp::isValidDate(*(GDS_DATE*) from_desc->dsc_address))
{
ERR_post(Arg::Gds(isc_date_range_exceeded));
}
break;
case dtype_sql_time:
if (!Firebird::TimeStamp::isValidTime(*(GDS_TIME*) from_desc->dsc_address))
{
ERR_post(Arg::Gds(isc_time_range_exceeded));
}
break;
case dtype_timestamp:
if (!Firebird::TimeStamp::isValidTimeStamp(*(GDS_TIMESTAMP*) from_desc->dsc_address))
{
ERR_post(Arg::Gds(isc_datetime_range_exceeded));
}
break;
default:
fb_assert(false);
}
}
2008-12-20 09:12:19 +01:00
if (DTYPE_IS_BLOB_OR_QUAD(from_desc->dsc_dtype) || DTYPE_IS_BLOB_OR_QUAD(to_desc->dsc_dtype))
{
// ASF: Don't let MOV_move call blb::move because MOV
// will not pass the destination field to blb::_move.
blb::move(tdbb, from_desc, to_desc, to);
}
else if (!DSC_EQUIV(from_desc, to_desc, false))
{
MOV_move(tdbb, from_desc, to_desc);
}
else if (from_desc->dsc_dtype == dtype_short)
{
2009-01-14 09:22:32 +01:00
*((SSHORT*) to_desc->dsc_address) = *((SSHORT*) from_desc->dsc_address);
2004-01-13 10:52:19 +01:00
}
else if (from_desc->dsc_dtype == dtype_long)
{
2009-01-14 09:22:32 +01:00
*((SLONG*) to_desc->dsc_address) = *((SLONG*) from_desc->dsc_address);
2004-01-13 10:52:19 +01:00
}
else if (from_desc->dsc_dtype == dtype_int64)
{
2009-01-14 09:22:32 +01:00
*((SINT64*) to_desc->dsc_address) = *((SINT64*) from_desc->dsc_address);
2004-01-13 10:52:19 +01:00
}
else
{
2008-01-16 09:54:50 +01:00
memcpy(to_desc->dsc_address, from_desc->dsc_address, from_desc->dsc_length);
}
2008-01-16 09:54:50 +01:00
2001-05-23 15:26:42 +02:00
to_desc->dsc_flags &= ~DSC_null;
}
2001-12-24 03:51:06 +01:00
else
{
if (missing2_node && (missing = EVL_expr(tdbb, request, missing2_node)))
MOV_move(tdbb, missing, to_desc);
else
memset(to_desc->dsc_address, 0, to_desc->dsc_length);
2001-05-23 15:26:42 +02:00
to_desc->dsc_flags |= DSC_null;
}
// Handle the null flag as appropriate for fields and message arguments.
2001-05-23 15:26:42 +02:00
2011-04-02 06:27:07 +02:00
const FieldNode* toField = nodeAs<FieldNode>(to);
2011-04-02 06:27:07 +02:00
if (toField)
2001-12-24 03:51:06 +01:00
{
Record* record = request->req_rpb[toField->fieldStream].rpb_record;
if (null)
2013-03-17 18:35:53 +01:00
record->setNull(toField->fieldId);
else
2013-03-17 18:35:53 +01:00
record->clearNull(toField->fieldId);
2001-05-23 15:26:42 +02:00
}
else if (toParam && toParam->argFlag)
2001-12-24 03:51:06 +01:00
{
to_desc = EVL_assign_to(tdbb, toParam->argFlag);
2001-05-23 15:26:42 +02:00
// If the null flag is a string with an effective length of one,
// then -1 will not fit. Therefore, store 1 instead.
2001-05-23 15:26:42 +02:00
2008-12-20 09:12:19 +01:00
if (null && to_desc->dsc_dtype <= dtype_varying)
2001-12-24 03:51:06 +01:00
{
2008-12-20 09:12:19 +01:00
USHORT minlen;
2008-12-20 09:12:19 +01:00
switch (to_desc->dsc_dtype)
{
case dtype_text:
minlen = 1;
break;
case dtype_cstring:
minlen = 2;
break;
case dtype_varying:
minlen = 3;
break;
}
2008-12-20 09:12:19 +01:00
if (to_desc->dsc_length <= minlen)
null = 1;
2001-12-24 03:51:06 +01:00
}
2001-05-23 15:26:42 +02:00
temp.dsc_dtype = dtype_short;
temp.dsc_length = sizeof(SSHORT);
temp.dsc_scale = 0;
temp.dsc_sub_type = 0;
2009-01-14 10:19:00 +01:00
temp.dsc_address = (UCHAR*) &null;
MOV_move(tdbb, &temp, to_desc);
if (null && toParam->argIndicator)
2009-11-23 06:24:29 +01:00
{
to_desc = EVL_assign_to(tdbb, toParam->argIndicator);
MOV_move(tdbb, &temp, to_desc);
2001-05-23 15:26:42 +02:00
}
}
}
void EXE_execute_db_triggers(thread_db* tdbb, jrd_tra* transaction, TriggerAction trigger_action)
{
/**************************************
*
* E X E _ e x e c u t e _ d b _ t r i g g e r s
*
**************************************
*
* Functional description
* Execute database triggers
*
**************************************/
2011-05-09 12:15:19 +02:00
Jrd::Attachment* attachment = tdbb->getAttachment();
2011-05-10 03:12:14 +02:00
// Do nothing if user doesn't want database triggers.
2011-05-09 12:15:19 +02:00
if (attachment->att_flags & ATT_no_db_triggers)
return;
int type = 0;
switch (trigger_action)
{
case TRIGGER_CONNECT:
type = DB_TRIGGER_CONNECT;
break;
case TRIGGER_DISCONNECT:
type = DB_TRIGGER_DISCONNECT;
break;
case TRIGGER_TRANS_START:
type = DB_TRIGGER_TRANS_START;
break;
case TRIGGER_TRANS_COMMIT:
type = DB_TRIGGER_TRANS_COMMIT;
break;
case TRIGGER_TRANS_ROLLBACK:
type = DB_TRIGGER_TRANS_ROLLBACK;
break;
default:
fb_assert(false);
return;
}
2011-05-09 12:15:19 +02:00
if (attachment->att_triggers[type])
{
jrd_tra* old_transaction = tdbb->getTransaction();
tdbb->setTransaction(transaction);
try
{
2011-05-09 12:15:19 +02:00
EXE_execute_triggers(tdbb, &attachment->att_triggers[type],
NULL, NULL, trigger_action, StmtNode::ALL_TRIGS);
tdbb->setTransaction(old_transaction);
}
catch (...)
{
tdbb->setTransaction(old_transaction);
throw;
}
}
}
// Execute DDL triggers.
void EXE_execute_ddl_triggers(thread_db* tdbb, jrd_tra* transaction, bool preTriggers, int action)
{
2011-05-09 12:15:19 +02:00
Jrd::Attachment* attachment = tdbb->getAttachment();
// Our caller verifies (ATT_no_db_triggers) if DDL triggers should not run.
2011-05-09 12:15:19 +02:00
if (attachment->att_ddl_triggers)
{
2009-10-31 02:46:06 +01:00
jrd_tra* const oldTransaction = tdbb->getTransaction();
tdbb->setTransaction(transaction);
try
{
TrigVector triggers;
TrigVector* triggersPtr = &triggers;
for (TrigVector::iterator i = attachment->att_ddl_triggers->begin();
2011-05-09 12:15:19 +02:00
i != attachment->att_ddl_triggers->end();
++i)
{
if ((i->type & (1LL << action)) &&
((preTriggers && (i->type & 0x1) == 0) || (!preTriggers && (i->type & 0x1) == 0x1)))
{
triggers.add() = *i;
}
}
EXE_execute_triggers(tdbb, &triggersPtr, NULL, NULL, TRIGGER_DDL,
StmtNode::ALL_TRIGS);
2009-10-31 02:46:06 +01:00
tdbb->setTransaction(oldTransaction);
}
catch (...)
{
2009-10-31 02:46:06 +01:00
tdbb->setTransaction(oldTransaction);
throw;
}
}
}
void EXE_receive(thread_db* tdbb,
jrd_req* request,
USHORT msg,
ULONG length,
UCHAR* buffer,
bool top_level)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* E X E _ r e c e i v e
*
**************************************
*
* Functional description
* Move a message from JRD to the host program. This corresponds to
* a JRD BLR/Stmtode* send.
2001-05-23 15:26:42 +02:00
*
**************************************/
SET_TDBB(tdbb);
DEV_BLKCHK(request, type_req);
2004-10-03 14:10:19 +02:00
if (--tdbb->tdbb_quantum < 0)
JRD_reschedule(tdbb, 0, true);
2003-12-31 06:36:12 +01:00
jrd_tra* transaction = request->req_transaction;
2001-05-23 15:26:42 +02:00
if (!(request->req_flags & req_active)) {
ERR_post(Arg::Gds(isc_req_sync));
2001-05-23 15:26:42 +02:00
}
const SavNumber mergeSavNumber = transaction->tra_save_point ?
transaction->tra_save_point->getNumber() : 0;
2001-05-23 15:26:42 +02:00
if (request->req_flags & req_proc_fetch)
{
/* request->req_proc_sav_point stores the request savepoints.
2001-05-23 15:26:42 +02:00
When going to continue execution put request save point list
into transaction->tra_save_point so that it is used in looper.
When we come back to EXE_receive() merge all work done under
2001-05-23 15:26:42 +02:00
stored procedure savepoints into the current transaction
savepoint, which is the savepoint for fetch and save them into the list. */
2001-05-23 15:26:42 +02:00
if (request->req_proc_sav_point)
{
// Push all saved savepoints to the top of transaction savepoints stack
Savepoint::mergeStacks(transaction->tra_save_point, request->req_proc_sav_point);
fb_assert(!request->req_proc_sav_point);
}
else
transaction->startSavepoint();
2001-05-23 15:26:42 +02:00
}
2008-12-05 02:20:14 +01:00
2012-01-19 05:54:39 +01:00
const JrdStatement* statement = request->getStatement();
if (StmtNode::is<StallNode>(request->req_message))
execute_looper(tdbb, request, transaction, request->req_next, jrd_req::req_sync);
2001-05-23 15:26:42 +02:00
if (!(request->req_flags & req_active) || request->req_operation != jrd_req::req_send)
ERR_post(Arg::Gds(isc_req_sync));
2001-05-23 15:26:42 +02:00
const MessageNode* message = StmtNode::as<MessageNode>(request->req_message);
const Format* format = message->format;
2001-05-23 15:26:42 +02:00
if (msg != message->messageNumber)
ERR_post(Arg::Gds(isc_req_sync));
2001-05-23 15:26:42 +02:00
if (length != format->fmt_length)
2008-12-20 09:12:19 +01:00
ERR_post(Arg::Gds(isc_port_len) << Arg::Num(length) << Arg::Num(format->fmt_length));
2001-05-23 15:26:42 +02:00
memcpy(buffer, request->getImpure<UCHAR>(message->impureOffset), length);
2001-05-23 15:26:42 +02:00
// ASF: temporary blobs returned to the client should not be released
// with the request, but in the transaction end.
if (top_level)
{
for (int i = 0; i < format->fmt_count; ++i)
{
const DSC* desc = &format->fmt_desc[i];
if (desc->isBlob())
{
const bid* id = (bid*) (buffer + (ULONG)(IPTR)desc->dsc_address);
if (transaction->tra_blobs->locate(id->bid_temp_id()))
{
BlobIndex* current = &transaction->tra_blobs->current();
if (current->bli_request &&
current->bli_request->req_blobs.locate(id->bid_temp_id()))
{
current->bli_request->req_blobs.fastRemove();
current->bli_request = NULL;
}
}
}
}
}
execute_looper(tdbb, request, transaction, request->req_next, jrd_req::req_proceed);
2001-05-23 15:26:42 +02:00
if (request->req_flags & req_proc_fetch)
{
// At this point request->req_proc_sav_point == NULL that is assured by code above
fb_assert(!request->req_proc_sav_point);
try
{
// Merge work into target savepoint and save request's savepoints (with numbers!!!)
// till the next looper iteration
while (transaction->tra_save_point &&
transaction->tra_save_point->getNumber() > mergeSavNumber)
{
Savepoint* const savepoint = transaction->tra_save_point;
transaction->rollforwardSavepoint(tdbb);
fb_assert(transaction->tra_save_free == savepoint);
transaction->tra_save_free = savepoint->moveToStack(request->req_proc_sav_point);
fb_assert(request->req_proc_sav_point == savepoint);
}
}
catch (...)
{
// If something went wrong, drop already stored savepoints to prevent memory leak
Savepoint::destroy(request->req_proc_sav_point);
fb_assert(!request->req_proc_sav_point);
throw;
}
2001-05-23 15:26:42 +02:00
}
}
// Release a request instance.
void EXE_release(thread_db* tdbb, jrd_req* request)
{
DEV_BLKCHK(request, type_req);
SET_TDBB(tdbb);
EXE_unwind(tdbb, request);
// system requests are released after all attachments gone and with
// req_attachment not cleared
const Jrd::Attachment* attachment = tdbb->getAttachment();
if (request->req_attachment && request->req_attachment == attachment)
{
2014-07-17 20:48:46 +02:00
FB_SIZE_T pos;
if (request->req_attachment->att_requests.find(request, pos))
request->req_attachment->att_requests.remove(pos);
request->req_attachment = NULL;
}
}
void EXE_send(thread_db* tdbb, jrd_req* request, USHORT msg, ULONG length, const UCHAR* buffer)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* E X E _ s e n d
*
**************************************
*
* Functional description
2008-12-05 02:20:14 +01:00
* Send a message from the host program to the engine.
2001-05-23 15:26:42 +02:00
* This corresponds to a blr_receive or blr_select statement.
*
**************************************/
SET_TDBB(tdbb);
DEV_BLKCHK(request, type_req);
2004-10-03 14:10:19 +02:00
if (--tdbb->tdbb_quantum < 0)
JRD_reschedule(tdbb, 0, true);
2001-05-23 15:26:42 +02:00
if (!(request->req_flags & req_active))
ERR_post(Arg::Gds(isc_req_sync));
2001-05-23 15:26:42 +02:00
2014-02-16 22:52:14 +01:00
const StmtNode* message = NULL;
const StmtNode* node;
if (request->req_operation != jrd_req::req_receive)
ERR_post(Arg::Gds(isc_req_sync));
node = request->req_message;
2001-05-23 15:26:42 +02:00
2003-12-31 06:36:12 +01:00
jrd_tra* transaction = request->req_transaction;
const JrdStatement* statement = request->getStatement();
const SelectNode* selectNode;
2001-05-23 15:26:42 +02:00
if (StmtNode::is<MessageNode>(node))
message = node;
else if ((selectNode = StmtNode::as<SelectNode>(node)))
2009-01-14 09:22:32 +01:00
{
const NestConst<StmtNode>* ptr = selectNode->statements.begin();
for (const NestConst<StmtNode>* end = selectNode->statements.end(); ptr != end; ++ptr)
2003-12-31 06:36:12 +01:00
{
const ReceiveNode* receiveNode = nodeAs<ReceiveNode>(*ptr);
message = receiveNode->message;
if (nodeAs<MessageNode>(message)->messageNumber == msg)
2009-01-14 09:22:32 +01:00
{
request->req_next = *ptr;
break;
2001-05-23 15:26:42 +02:00
}
}
2009-01-14 09:22:32 +01:00
}
else
BUGCHECK(167); // msg 167 invalid SEND request
2001-05-23 15:26:42 +02:00
const Format* format = StmtNode::as<MessageNode>(message)->format;
2001-05-23 15:26:42 +02:00
if (msg != StmtNode::as<MessageNode>(message)->messageNumber)
ERR_post(Arg::Gds(isc_req_sync));
2001-05-23 15:26:42 +02:00
if (length != format->fmt_length)
2008-12-20 09:12:19 +01:00
ERR_post(Arg::Gds(isc_port_len) << Arg::Num(length) << Arg::Num(format->fmt_length));
2001-05-23 15:26:42 +02:00
memcpy(request->getImpure<UCHAR>(message->impureOffset), buffer, length);
2001-05-23 15:26:42 +02:00
execute_looper(tdbb, request, transaction, request->req_next, jrd_req::req_proceed);
2001-05-23 15:26:42 +02:00
}
void EXE_start(thread_db* tdbb, jrd_req* request, jrd_tra* transaction)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* E X E _ s t a r t
*
**************************************
*
* Functional description
* Start an execution running.
*
**************************************/
SET_TDBB(tdbb);
BLKCHK(request, type_req);
BLKCHK(transaction, type_tra);
if (request->req_flags & req_active)
2008-08-30 05:14:08 +02:00
ERR_post(Arg::Gds(isc_req_sync) << Arg::Gds(isc_reqinuse));
2001-05-23 15:26:42 +02:00
if (transaction->tra_flags & TRA_prepared)
ERR_post(Arg::Gds(isc_req_no_trans));
2001-05-23 15:26:42 +02:00
JrdStatement* statement = request->getStatement();
const jrd_prc* proc = statement->procedure;
2009-11-22 04:56:20 +01:00
/* Post resources to transaction block. In particular, the interest locks
on relations/indices are copied to the transaction, which is very
important for (short-lived) dynamically compiled requests. This will
provide transaction stability by preventing a relation from being
dropped after it has been referenced from an active transaction. */
2001-05-23 15:26:42 +02:00
TRA_post_resources(tdbb, transaction, statement->resources);
2001-05-23 15:26:42 +02:00
TRA_attach_request(transaction, request);
request->req_flags &= req_in_use;
2001-05-23 15:26:42 +02:00
request->req_flags |= req_active;
request->req_flags &= ~req_reserved;
2009-11-22 04:56:20 +01:00
// set up to count records affected by request
2001-05-23 15:26:42 +02:00
request->req_records_selected = 0;
request->req_records_updated = 0;
request->req_records_inserted = 0;
request->req_records_deleted = 0;
request->req_records_affected.clear();
// Store request start time for timestamp work
request->req_timestamp.validate();
2001-05-23 15:26:42 +02:00
// Set all invariants to not computed.
const ULONG* const* ptr, * const* end;
for (ptr = statement->invariants.begin(), end = statement->invariants.end();
ptr < end; ++ptr)
{
impure_value* impure = request->getImpure<impure_value>(**ptr);
impure->vlu_flags = 0;
2001-05-23 15:26:42 +02:00
}
request->req_src_line = 0;
request->req_src_column = 0;
2015-04-22 18:39:45 +02:00
TRA_setup_request_snapshot(tdbb, request);
execute_looper(tdbb, request, transaction,
request->getStatement()->topNode,
jrd_req::req_evaluate);
2001-05-23 15:26:42 +02:00
}
void EXE_unwind(thread_db* tdbb, jrd_req* request)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* E X E _ u n w i n d
*
**************************************
*
* Functional description
* Unwind a request, maybe active, maybe not.
2001-05-23 15:26:42 +02:00
*
**************************************/
DEV_BLKCHK(request, type_req);
SET_TDBB(tdbb);
2008-12-05 02:20:14 +01:00
if (request->req_flags & req_active)
{
const JrdStatement* statement = request->getStatement();
if (statement->fors.getCount() || request->req_ext_resultset || request->req_ext_stmt)
{
Jrd::ContextPoolHolder context(tdbb, request->req_pool);
jrd_req* old_request = tdbb->getRequest();
jrd_tra* old_transaction = tdbb->getTransaction();
try {
tdbb->setRequest(request);
tdbb->setTransaction(request->req_transaction);
2003-12-31 06:36:12 +01:00
for (const RecordSource* const* ptr = statement->fors.begin();
ptr != statement->fors.end(); ++ptr)
{
(*ptr)->close(tdbb);
}
2006-03-10 18:46:18 +01:00
if (request->req_ext_resultset)
{
delete request->req_ext_resultset;
request->req_ext_resultset = NULL;
}
while (request->req_ext_stmt)
request->req_ext_stmt->close(tdbb);
}
2007-12-05 01:03:15 +01:00
catch (const Firebird::Exception&)
2006-03-10 18:46:18 +01:00
{
tdbb->setRequest(old_request);
tdbb->setTransaction(old_transaction);
throw;
2006-03-10 18:46:18 +01:00
}
tdbb->setRequest(old_request);
tdbb->setTransaction(old_transaction);
2006-03-10 18:46:18 +01:00
}
2001-05-23 15:26:42 +02:00
release_blobs(tdbb, request);
}
request->req_sorts.unlinkAll();
2001-05-23 15:26:42 +02:00
if (request->req_proc_sav_point && (request->req_flags & req_proc_fetch))
{
// Release savepoints used by this request
Savepoint::destroy(request->req_proc_sav_point);
fb_assert(!request->req_proc_sav_point);
}
2001-05-23 15:26:42 +02:00
2015-04-22 18:39:45 +02:00
TRA_release_request_snapshot(tdbb, request);
TRA_detach_request(request);
2001-05-23 15:26:42 +02:00
request->req_flags &= ~(req_active | req_proc_fetch | req_reserved);
request->req_flags |= req_abort | req_stall;
request->req_timestamp.invalidate();
request->req_caller = NULL;
2009-02-01 23:10:12 +01:00
request->req_proc_inputs = NULL;
request->req_proc_caller = NULL;
2001-05-23 15:26:42 +02:00
}
2008-12-20 09:12:19 +01:00
static void execute_looper(thread_db* tdbb,
jrd_req* request,
jrd_tra* transaction,
const StmtNode* node,
jrd_req::req_s next_state)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* e x e c u t e _ l o o p e r
*
**************************************
*
* Functional description
* Wrapper around looper. This will execute
* looper with the save point mechanism.
*
**************************************/
DEV_BLKCHK(request, type_req);
SET_TDBB(tdbb);
Jrd::Attachment* const attachment = tdbb->getAttachment();
// Ensure the cancellation lock can be triggered
Lock* const lock = attachment->att_cancel_lock;
if (lock && lock->lck_logical == LCK_none)
LCK_lock(tdbb, lock, LCK_SR, LCK_WAIT);
2001-05-23 15:26:42 +02:00
2009-11-22 04:56:20 +01:00
// Start a save point
2001-05-23 15:26:42 +02:00
if (!(request->req_flags & req_proc_fetch) && request->req_transaction)
2008-03-04 07:02:32 +01:00
{
if (transaction && !(transaction->tra_flags & TRA_system))
2016-05-26 16:21:21 +02:00
{
if (request->req_savepoints)
{
request->req_savepoints = request->req_savepoints->moveToStack(transaction->tra_save_point);
}
else
transaction->startSavepoint();
}
2008-03-04 07:02:32 +01:00
}
2001-05-23 15:26:42 +02:00
request->req_flags &= ~req_stall;
request->req_operation = next_state;
looper_seh(tdbb, request, node);
2001-05-23 15:26:42 +02:00
2009-11-22 04:56:20 +01:00
// If any requested modify/delete/insert ops have completed, forget them
2001-05-23 15:26:42 +02:00
2009-01-14 10:19:00 +01:00
if (!(request->req_flags & req_proc_fetch) && request->req_transaction)
{
if (transaction && !(transaction->tra_flags & TRA_system) &&
transaction->tra_save_point &&
transaction->tra_save_point->isSystem() &&
!transaction->tra_save_point->isChanging())
2003-12-31 06:36:12 +01:00
{
2016-05-26 16:21:21 +02:00
Savepoint* savepoint = transaction->tra_save_point;
2009-11-22 04:56:20 +01:00
// Forget about any undo for this verb
transaction->rollforwardSavepoint(tdbb);
2016-05-26 16:21:21 +02:00
// Preserve savepoint for reuse
fb_assert(savepoint == transaction->tra_save_free);
transaction->tra_save_free = savepoint->moveToStack(request->req_savepoints);
fb_assert(savepoint != transaction->tra_save_free);
2001-05-23 15:26:42 +02:00
}
2003-12-31 06:36:12 +01:00
}
2001-05-23 15:26:42 +02:00
}
void EXE_execute_triggers(thread_db* tdbb,
TrigVector** triggers,
record_param* old_rpb,
record_param* new_rpb,
TriggerAction trigger_action, StmtNode::WhichTrigger which_trig)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* e x e c u t e _ t r i g g e r s
*
**************************************
*
* Functional description
* Execute group of triggers. Return pointer to failing trigger
* if any blow up.
*
**************************************/
if (!*triggers)
return;
2001-05-23 15:26:42 +02:00
SET_TDBB(tdbb);
jrd_req* const request = tdbb->getRequest();
jrd_tra* const transaction = request ? request->req_transaction : tdbb->getTransaction();
TrigVector* vector = *triggers;
Record* const old_rec = old_rpb ? old_rpb->rpb_record : NULL;
Record* const new_rec = new_rpb ? new_rpb->rpb_record : NULL;
2001-05-23 15:26:42 +02:00
2013-03-17 18:35:53 +01:00
AutoPtr<Record> null_rec;
const bool is_db_trigger = (!old_rec && !new_rec);
2013-10-14 01:44:57 +02:00
if (!is_db_trigger && (!old_rec || !new_rec))
{
const Record* const record = old_rec ? old_rec : new_rec;
fb_assert(record && record->getFormat());
// copy the record
MemoryPool& pool = *tdbb->getDefaultPool();
null_rec = FB_NEW_POOL(pool) Record(pool, record->getFormat());
// initialize all fields to missing
2013-03-17 18:35:53 +01:00
null_rec->nullify();
}
const Firebird::TimeStamp timestamp =
request ? request->req_timestamp : Firebird::TimeStamp::getCurrentTimeStamp();
jrd_req* trigger = NULL;
2001-12-28 07:31:38 +01:00
try
{
for (TrigVector::iterator ptr = vector->begin(); ptr != vector->end(); ++ptr)
2001-12-28 07:31:38 +01:00
{
ptr->compile(tdbb);
trigger = ptr->statement->findRequest(tdbb);
if (!is_db_trigger)
{
if (trigger->req_rpb.getCount() > 0)
{
trigger->req_rpb[0].rpb_record = old_rec ? old_rec : null_rec.get();
if (old_rec)
{
trigger->req_rpb[0].rpb_number = old_rpb->rpb_number;
trigger->req_rpb[0].rpb_number.setValid(true);
}
else
trigger->req_rpb[0].rpb_number.setValid(false);
}
if (which_trig == StmtNode::PRE_TRIG && trigger_action == TRIGGER_UPDATE)
{
new_rpb->rpb_number = old_rpb->rpb_number;
}
if (trigger->req_rpb.getCount() > 1)
{
trigger->req_rpb[1].rpb_record = new_rec ? new_rec : null_rec.get();
if (new_rec)
{
trigger->req_rpb[1].rpb_number = new_rpb->rpb_number;
trigger->req_rpb[1].rpb_number.setValid(true);
}
else
trigger->req_rpb[1].rpb_number.setValid(false);
}
}
2009-02-02 04:35:52 +01:00
trigger->req_timestamp = timestamp;
trigger->req_trigger_action = trigger_action;
2009-02-01 23:10:12 +01:00
TraceTrigExecute trace(tdbb, trigger, which_trig);
2009-02-01 23:10:12 +01:00
EXE_start(tdbb, trigger, transaction);
2009-02-01 23:10:12 +01:00
const bool ok = (trigger->req_operation != jrd_req::req_unwind);
trace.finish(ok ? ITracePlugin::RESULT_SUCCESS : ITracePlugin::RESULT_FAILED);
EXE_unwind(tdbb, trigger);
trigger->req_attachment = NULL;
trigger->req_flags &= ~req_in_use;
if (!ok)
trigger_failure(tdbb, trigger);
trigger = NULL;
2001-05-23 15:26:42 +02:00
}
if (vector != *triggers)
MET_release_triggers(tdbb, &vector);
2001-12-28 07:31:38 +01:00
}
catch (const Firebird::Exception& ex)
2001-12-28 07:31:38 +01:00
{
if (vector != *triggers)
MET_release_triggers(tdbb, &vector);
if (trigger)
{
EXE_unwind(tdbb, trigger);
trigger->req_attachment = NULL;
trigger->req_flags &= ~req_in_use;
ex.stuffException(tdbb->tdbb_status_vector);
trigger_failure(tdbb, trigger);
}
throw;
2001-12-24 03:51:06 +01:00
}
2001-05-23 15:26:42 +02:00
}
static void stuff_stack_trace(const jrd_req* request)
{
string sTrace;
for (const jrd_req* req = request; req; req = req->req_caller)
{
const JrdStatement* const statement = req->getStatement();
string context, name;
if (statement->triggerName.length())
2009-11-23 06:24:29 +01:00
{
context = "At trigger";
name = statement->triggerName.c_str();
}
else if (statement->procedure)
2009-11-23 06:24:29 +01:00
{
context = statement->parentStatement ? "At sub procedure" : "At procedure";
name = statement->procedure->getName().toString();
}
else if (statement->function)
{
context = statement->parentStatement ? "At sub function" : "At function";
name = statement->function->getName().toString();
}
else if (req->req_src_line)
{
2016-04-28 19:23:39 +02:00
context = "At block";
}
if (context.hasData())
{
name.trim();
if (name.hasData())
context += string(" '") + name + string("'");
if (sTrace.length() + context.length() > MAX_STACK_TRACE)
break;
if (sTrace.hasData())
sTrace += "\n";
sTrace += context;
if (req->req_src_line)
{
string src_info;
src_info.printf(" line: %" ULONGFORMAT", col: %" ULONGFORMAT,
2013-01-25 13:34:54 +01:00
req->req_src_line, req->req_src_column);
if (sTrace.length() + src_info.length() > MAX_STACK_TRACE)
break;
2006-07-06 04:54:59 +02:00
sTrace += src_info;
}
}
}
if (sTrace.hasData())
ERR_post_nothrow(Arg::Gds(isc_stack_trace) << Arg::Str(sTrace));
}
2004-08-21 11:29:46 +02:00
2013-04-11 18:04:25 +02:00
const StmtNode* EXE_looper(thread_db* tdbb, jrd_req* request, const StmtNode* node)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* E X E _ l o o p e r
2001-05-23 15:26:42 +02:00
*
**************************************
*
* Functional description
* Cycle thru request execution tree. Return next node for
* execution on stall or request complete.
*
**************************************/
if (!request->req_transaction)
ERR_post(Arg::Gds(isc_req_no_trans));
2001-05-23 15:26:42 +02:00
SET_TDBB(tdbb);
Database* dbb = tdbb->getDatabase();
if (!node || node->kind != DmlNode::KIND_STATEMENT)
BUGCHECK(147);
2001-05-23 15:26:42 +02:00
2001-12-28 07:31:38 +01:00
// Save the old pool and request to restore on exit
StmtNode::ExeState exeState(tdbb, request, request->req_transaction);
Jrd::ContextPoolHolder context(tdbb, request->req_pool);
2001-12-28 07:31:38 +01:00
2013-04-11 18:09:46 +02:00
fb_assert(request->req_caller == NULL);
2013-04-11 18:04:25 +02:00
request->req_caller = exeState.oldRequest;
2001-12-28 07:31:38 +01:00
const SavNumber savNumber = (request->req_transaction->tra_save_point) ?
request->req_transaction->tra_save_point->getNumber() : 0;
2001-05-23 15:26:42 +02:00
tdbb->tdbb_flags &= ~(TDBB_stack_trace_done | TDBB_sys_error);
2001-05-23 15:26:42 +02:00
2001-12-29 12:41:29 +01:00
// Execute stuff until we drop
2001-05-23 15:26:42 +02:00
const JrdStatement* statement = request->getStatement();
2013-04-11 18:04:25 +02:00
while (node && !(request->req_flags & req_stall))
2001-12-29 12:41:29 +01:00
{
try
{
if (request->req_operation == jrd_req::req_evaluate)
{
if (--tdbb->tdbb_quantum < 0)
JRD_reschedule(tdbb, 0, true);
if (node->hasLineColumn)
{
request->req_src_line = node->line;
request->req_src_column = node->column;
}
}
node = node->execute(tdbb, request, &exeState);
if (exeState.exit)
return node;
} // try
catch (const Firebird::Exception& ex)
{
ex.stuffException(tdbb->tdbb_status_vector);
request->adjustCallerStats();
// Ensure the transaction hasn't disappeared in the meantime
fb_assert(request->req_transaction);
// Skip this handling for errors coming from the nested looper calls,
// as they're already handled properly. The only need is to undo
// our own savepoints.
if (exeState.catchDisabled)
2009-11-23 06:24:29 +01:00
{
// Put cleanup off till the point where it has meaning to avoid
// sequence 1->2->3->4 being undone as 4->3->2->1 instead of 4->1
ERR_punt();
}
// If the database is already bug-checked, then get out
if (dbb->dbb_flags & DBB_bugcheck)
Firebird::status_exception::raise(tdbb->tdbb_status_vector);
exeState.errorPending = true;
exeState.catchDisabled = true;
request->req_operation = jrd_req::req_unwind;
request->req_label = 0;
if (!(tdbb->tdbb_flags & TDBB_stack_trace_done) && !(tdbb->tdbb_flags & TDBB_sys_error))
{
stuff_stack_trace(request);
tdbb->tdbb_flags |= TDBB_stack_trace_done;
}
2001-05-23 15:26:42 +02:00
}
} // while()
2001-05-23 15:26:42 +02:00
request->adjustCallerStats();
2001-05-23 15:26:42 +02:00
fb_assert(request->req_auto_trans.getCount() == 0);
2001-05-23 15:26:42 +02:00
// If there is no node, assume we have finished processing the
// request unless we are in the middle of processing an
// asynchronous message
2001-05-23 15:26:42 +02:00
2013-04-11 18:04:25 +02:00
if (!node)
2008-11-30 03:23:01 +01:00
{
// Close active cursors
for (const Cursor* const* ptr = request->req_cursors.begin();
ptr < request->req_cursors.end(); ++ptr)
{
if (*ptr)
(*ptr)->close(tdbb);
}
2015-04-22 18:39:45 +02:00
TRA_release_request_snapshot(tdbb, request);
request->req_flags &= ~(req_active | req_reserved);
request->req_timestamp.invalidate();
release_blobs(tdbb, request);
2001-05-23 15:26:42 +02:00
}
request->req_next = node;
2001-05-23 15:26:42 +02:00
2013-04-11 18:04:25 +02:00
fb_assert(request->req_caller == exeState.oldRequest);
request->req_caller = NULL;
// Ensure the transaction hasn't disappeared in the meantime
fb_assert(request->req_transaction);
// In the case of a pending error condition (one which did not
// result in a exception to the top of looper), we need to
// delete the last savepoint
2001-05-23 15:26:42 +02:00
if (exeState.errorPending)
{
if (!(request->req_transaction->tra_flags & TRA_system))
request->req_transaction->rollbackToSavepoint(tdbb, savNumber);
ERR_punt();
2001-05-23 15:26:42 +02:00
}
// if the request was aborted, assume that we have already
// longjmp'ed to the top of looper, and therefore that the
// last savepoint has already been deleted
if (request->req_flags & req_abort) {
ERR_post(Arg::Gds(isc_req_sync));
2001-05-23 15:26:42 +02:00
}
return node;
2001-05-23 15:26:42 +02:00
}
// Start looper under Windows SEH (Structured Exception Handling) control
static void looper_seh(thread_db* tdbb, jrd_req* request, const StmtNode* node)
{
#ifdef WIN_NT
START_CHECK_FOR_EXCEPTIONS(NULL);
#endif
// TODO:
// 1. Try to fix the problem with MSVC C++ runtime library, making
// even C++ exceptions that are implemented in terms of Win32 SEH
// getting catched by the SEH handler below.
// 2. Check if it really is correct that only Win32 catches CPU
// exceptions (such as SEH) here. Shouldn't any platform capable
// of handling signals use this stuff?
// (see jrd/ibsetjmp.h for implementation of these macros)
2001-05-23 15:26:42 +02:00
EXE_looper(tdbb, request, node);
2001-05-23 15:26:42 +02:00
#ifdef WIN_NT
END_CHECK_FOR_EXCEPTIONS(NULL);
#endif
2001-05-23 15:26:42 +02:00
}
static void release_blobs(thread_db* tdbb, jrd_req* request)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* r e l e a s e _ b l o b s
*
**************************************
*
* Functional description
* Release temporary blobs assigned by this request.
*
**************************************/
SET_TDBB(tdbb);
DEV_BLKCHK(request, type_req);
2003-12-31 06:36:12 +01:00
jrd_tra* transaction = request->req_transaction;
2009-01-14 10:19:00 +01:00
if (transaction)
{
2001-05-23 15:26:42 +02:00
DEV_BLKCHK(transaction, type_tra);
transaction = transaction->getOuter();
2001-05-23 15:26:42 +02:00
2009-11-22 04:56:20 +01:00
// Release blobs bound to this request
2001-05-23 15:26:42 +02:00
if (request->req_blobs.getFirst())
{
2008-12-05 02:20:14 +01:00
while (true)
2006-04-06 10:18:53 +02:00
{
const ULONG blob_temp_id = request->req_blobs.current();
if (transaction->tra_blobs->locate(blob_temp_id))
2008-01-16 09:54:50 +01:00
{
BlobIndex *current = &transaction->tra_blobs->current();
if (current->bli_materialized)
{
request->req_blobs.fastRemove();
current->bli_request = NULL;
}
else
{
2008-12-05 02:20:14 +01:00
// Blob was created by request, is accounted for internal needs,
2006-04-06 10:18:53 +02:00
// but is not materialized. Get rid of it.
current->bli_blob_object->BLB_cancel(tdbb);
2008-12-05 02:20:14 +01:00
// Since the routine above modifies req_blobs
2006-04-06 10:18:53 +02:00
// we need to reestablish accessor position
}
if (request->req_blobs.locate(Firebird::locGreat, blob_temp_id))
continue;
2008-01-16 09:54:50 +01:00
break;
}
2008-01-16 09:54:50 +01:00
// Blob accounting inconsistent, only detected in DEV_BUILD.
fb_assert(false);
2006-04-06 10:18:53 +02:00
if (!request->req_blobs.getNext())
break;
}
}
request->req_blobs.clear();
2001-05-23 15:26:42 +02:00
2009-11-22 04:56:20 +01:00
// Release arrays assigned by this request
2001-05-23 15:26:42 +02:00
2009-01-14 10:19:00 +01:00
for (ArrayField** array = &transaction->tra_arrays; *array;)
{
2001-05-23 15:26:42 +02:00
DEV_BLKCHK(*array, type_arr);
if ((*array)->arr_request == request)
blb::release_array(*array);
2001-05-23 15:26:42 +02:00
else
array = &(*array)->arr_next;
}
}
}
static void trigger_failure(thread_db* tdbb, jrd_req* trigger)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* t r i g g e r _ f a i l u r e
*
**************************************
*
* Functional description
* Trigger failed, report error.
*
**************************************/
SET_TDBB(tdbb);
2001-12-29 12:41:29 +01:00
if (trigger->req_flags & req_leave)
{
2001-05-23 15:26:42 +02:00
trigger->req_flags &= ~req_leave;
string msg;
MET_trigger_msg(tdbb, msg, trigger->getStatement()->triggerName, trigger->req_label);
if (msg.hasData())
2001-12-29 12:41:29 +01:00
{
if (trigger->getStatement()->flags & JrdStatement::FLAG_SYS_TRIGGER)
2001-12-29 12:41:29 +01:00
{
2003-04-10 08:49:16 +02:00
ISC_STATUS code = PAR_symbol_to_gdscode(msg);
2001-05-23 15:26:42 +02:00
if (code)
2001-12-29 12:41:29 +01:00
{
ERR_post(Arg::Gds(isc_integ_fail) << Arg::Num(trigger->req_label) <<
Arg::Gds(code));
2001-12-29 12:41:29 +01:00
}
2001-05-23 15:26:42 +02:00
}
ERR_post(Arg::Gds(isc_integ_fail) << Arg::Num(trigger->req_label) <<
Arg::Gds(isc_random) << Arg::Str(msg));
2001-05-23 15:26:42 +02:00
}
else
2001-12-29 12:41:29 +01:00
{
ERR_post(Arg::Gds(isc_integ_fail) << Arg::Num(trigger->req_label));
2001-12-29 12:41:29 +01:00
}
2001-05-23 15:26:42 +02:00
}
else
2001-12-29 12:41:29 +01:00
{
2001-05-23 15:26:42 +02:00
ERR_punt();
2001-12-29 12:41:29 +01:00
}
2001-05-23 15:26:42 +02:00
}