8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 18:43:03 +01:00

Split dsql_req into dsql_req and CompiledStatement. This should be my last refactoring to 2.5:

- dsql_req becomes a running request;
- CompiledStatement is derived from dsql_req. The compilation state previously in dsql_req comes to here;
- Rename many "request" parameters to "statement" where type is changed from dsql_req to CompiledStatement.
This changes makes easy the path to support compiled statement cache.
This commit is contained in:
asfernandes 2008-05-24 03:19:52 +00:00
parent 7ad8a95582
commit d4bf9ab246
17 changed files with 3078 additions and 3037 deletions

View File

@ -45,9 +45,9 @@ void AlterCharSetNode::print(Firebird::string& text, Firebird::Array<dsql_nod*>&
void AlterCharSetNode::execute(thread_db* tdbb, jrd_tra* transaction)
{
if (dsqlRequest && dsqlRequest->req_dbb) // do not run in CREATE DATABASE
if (compiledStatement && compiledStatement->req_dbb) // do not run in CREATE DATABASE
{
METD_drop_charset(dsqlRequest, charSet);
METD_drop_charset(compiledStatement, charSet);
MET_dsql_cache_release(tdbb, SYM_intlsym_charset, charSet);
}

View File

@ -36,7 +36,7 @@ class Node : public Firebird::PermanentStorage
public:
explicit Node(MemoryPool& pool)
: PermanentStorage(pool),
dsqlRequest(NULL)
compiledStatement(NULL)
{
}
@ -45,9 +45,9 @@ public:
}
public:
virtual Node* dsqlPass(dsql_req* aDsqlRequest)
virtual Node* dsqlPass(CompiledStatement* aCompiledStatement)
{
dsqlRequest = aDsqlRequest;
compiledStatement = aCompiledStatement;
return dsqlPass();
}
@ -61,7 +61,7 @@ protected:
}
protected:
dsql_req* dsqlRequest;
CompiledStatement* compiledStatement;
};
@ -74,10 +74,10 @@ public:
}
public:
virtual Node* dsqlPass(dsql_req* aDsqlRequest)
virtual Node* dsqlPass(CompiledStatement* aCompiledStatement)
{
aDsqlRequest->req_type = REQ_DDL;
return Node::dsqlPass(aDsqlRequest);
aCompiledStatement->req_type = REQ_DDL;
return Node::dsqlPass(aCompiledStatement);
}
public:

View File

@ -83,15 +83,15 @@ DmlNode* InAutonomousTransactionNode::parse(thread_db* tdbb, MemoryPool& pool,
InAutonomousTransactionNode* InAutonomousTransactionNode::dsqlPass()
{
const bool autoTrans = dsqlRequest->req_flags & REQ_in_auto_trans_block;
dsqlRequest->req_flags |= REQ_in_auto_trans_block;
const bool autoTrans = compiledStatement->req_flags & REQ_in_auto_trans_block;
compiledStatement->req_flags |= REQ_in_auto_trans_block;
InAutonomousTransactionNode* node = FB_NEW(getPool()) InAutonomousTransactionNode(getPool());
node->dsqlRequest = dsqlRequest;
node->dsqlAction = PASS1_statement(dsqlRequest, dsqlAction);
node->compiledStatement = compiledStatement;
node->dsqlAction = PASS1_statement(compiledStatement, dsqlAction);
if (!autoTrans)
dsqlRequest->req_flags &= ~REQ_in_auto_trans_block;
compiledStatement->req_flags &= ~REQ_in_auto_trans_block;
return node;
}
@ -107,9 +107,9 @@ void InAutonomousTransactionNode::print(Firebird::string& text,
void InAutonomousTransactionNode::genBlr()
{
stuff(dsqlRequest, blr_auto_trans);
stuff(dsqlRequest, 0); // to extend syntax in the future
GEN_statement(dsqlRequest, dsqlAction);
stuff(compiledStatement, blr_auto_trans);
stuff(compiledStatement, 0); // to extend syntax in the future
GEN_statement(compiledStatement, dsqlAction);
}

File diff suppressed because it is too large Load Diff

View File

@ -32,18 +32,19 @@
namespace Jrd {
class dsql_req;
class CompiledStatement;
class dsql_fld;
class dsql_nod;
class dsql_str;
};
void DDL_execute(Jrd::dsql_req*);
void DDL_generate(Jrd::dsql_req*, Jrd::dsql_nod*);
void DDL_generate(Jrd::CompiledStatement*, Jrd::dsql_nod*);
bool DDL_ids(const Jrd::dsql_req*);
void DDL_put_field_dtype(Jrd::dsql_req*, const Jrd::dsql_fld*, bool);
void DDL_resolve_intl_type(Jrd::dsql_req*, Jrd::dsql_fld*, const Jrd::dsql_str*);
void DDL_resolve_intl_type2(Jrd::dsql_req*, Jrd::dsql_fld*, const Jrd::dsql_str*, bool);
void DDL_gen_block(Jrd::dsql_req*, Jrd::dsql_nod*);
void DDL_put_field_dtype(Jrd::CompiledStatement*, const Jrd::dsql_fld*, bool);
void DDL_resolve_intl_type(Jrd::CompiledStatement*, Jrd::dsql_fld*, const Jrd::dsql_str*);
void DDL_resolve_intl_type2(Jrd::CompiledStatement*, Jrd::dsql_fld*, const Jrd::dsql_str*, bool);
void DDL_gen_block(Jrd::CompiledStatement*, Jrd::dsql_nod*);
#endif // DSQL_DDL_PROTO_H

View File

@ -92,7 +92,7 @@ static bool get_rsb_item(SSHORT*, const SCHAR**, SSHORT*, SCHAR**, USHORT*,
static dsql_dbb* init(Attachment*);
static void map_in_out(dsql_req*, dsql_msg*, USHORT, const UCHAR*, USHORT, UCHAR*, const UCHAR* = 0);
static USHORT parse_blr(USHORT, const UCHAR*, const USHORT, dsql_par*);
static dsql_req* prepare(thread_db*, dsql_req*, USHORT, const TEXT*, USHORT, USHORT);
static dsql_req* prepare(thread_db*, dsql_dbb*, jrd_tra*, USHORT, const TEXT*, USHORT, USHORT);
static UCHAR* put_item(UCHAR, USHORT, const UCHAR*, UCHAR*, const UCHAR* const);
static void release_request(thread_db*, dsql_req*, bool);
static void sql_info(thread_db*, dsql_req*, USHORT, const UCHAR*, USHORT, UCHAR*);
@ -669,8 +669,6 @@ void DSQL_prepare(thread_db* tdbb,
0);
}
Jrd::ContextPoolHolder context(tdbb, database->createPool());
// check to see if old request has an open cursor
if (old_request && (old_request->req_flags & REQ_cursor_open)) {
@ -686,10 +684,7 @@ void DSQL_prepare(thread_db* tdbb,
/* Because that's the client's allocated statement handle and we
don't want to trash the context in it -- 2001-Oct-27 Ann Harrison */
MemoryPool& pool = *tdbb->getDefaultPool();
dsql_req* request = FB_NEW(pool) dsql_req(pool);
request->req_dbb = database;
request->req_transaction = transaction;
dsql_req* request = NULL;
try {
@ -737,9 +732,7 @@ void DSQL_prepare(thread_db* tdbb,
dialect /= 10;
}
request->req_client_dialect = dialect;
request = prepare(tdbb, request, length, string, dialect, parser_version);
request = prepare(tdbb, database, transaction, length, string, dialect, parser_version);
// Can not prepare a CREATE DATABASE/SCHEMA statement
@ -754,16 +747,22 @@ void DSQL_prepare(thread_db* tdbb,
// Now that we know that the new request exists, zap the old one.
{
Jrd::ContextPoolHolder another_context(tdbb, &old_request->req_pool);
Jrd::ContextPoolHolder context(tdbb, &old_request->req_pool);
release_request(tdbb, old_request, true);
}
*req_handle = request;
Jrd::ContextPoolHolder context(tdbb, &request->req_pool);
sql_info(tdbb, request, item_length, items, buffer_length, buffer);
}
catch (const Firebird::Exception&) {
release_request(tdbb, request, true);
catch (const Firebird::Exception&)
{
if (request)
{
Jrd::ContextPoolHolder context(tdbb, &request->req_pool);
release_request(tdbb, request, true);
}
throw;
}
}
@ -1093,14 +1092,8 @@ static void execute_immediate(thread_db* tdbb,
SET_TDBB(tdbb);
dsql_dbb* const database = init(attachment);
Jrd::ContextPoolHolder context(tdbb, database->createPool());
// allocate the request block, then prepare the request
MemoryPool& pool = *tdbb->getDefaultPool();
dsql_req* request = FB_NEW(pool) dsql_req(pool);
request->req_dbb = database;
request->req_transaction = *tra_handle;
dsql_req* request = NULL;
try {
@ -1140,9 +1133,9 @@ static void execute_immediate(thread_db* tdbb,
dialect /= 10;
}
request->req_client_dialect = dialect;
request = prepare(tdbb, database, *tra_handle, length, string, dialect, parser_version);
request = prepare(tdbb, request, length, string, dialect, parser_version);
Jrd::ContextPoolHolder context(tdbb, &request->req_pool);
execute_request(tdbb, request, tra_handle, in_blr_length, in_blr,
in_msg_length, in_msg, out_blr_length, out_blr,
@ -1150,8 +1143,13 @@ static void execute_immediate(thread_db* tdbb,
release_request(tdbb, request, true);
}
catch (const Firebird::Exception&) {
release_request(tdbb, request, true);
catch (const Firebird::Exception&)
{
if (request)
{
Jrd::ContextPoolHolder context(tdbb, &request->req_pool);
release_request(tdbb, request, true);
}
throw;
}
}
@ -2485,8 +2483,7 @@ static USHORT parse_blr(
@param parser_version
**/
static dsql_req* prepare(thread_db* tdbb,
dsql_req* request,
static dsql_req* prepare(thread_db* tdbb, dsql_dbb* database, jrd_tra* transaction,
USHORT string_length,
const TEXT* string,
USHORT client_dialect, USHORT parser_version)
@ -2514,9 +2511,21 @@ static dsql_req* prepare(thread_db* tdbb,
}
}
// allocate the statement block, then prepare the statement
Jrd::ContextPoolHolder context(tdbb, database->createPool());
MemoryPool& pool = *tdbb->getDefaultPool();
CompiledStatement* statement = FB_NEW(pool) CompiledStatement(pool);
statement->req_dbb = database;
statement->req_transaction = transaction;
statement->req_client_dialect = client_dialect;
try {
// Parse the SQL statement. If it croaks, return
Parser parser(*tdbb->getDefaultPool(), client_dialect, request->req_dbb->dbb_db_SQL_dialect,
Parser parser(*tdbb->getDefaultPool(), client_dialect, statement->req_dbb->dbb_db_SQL_dialect,
parser_version, string, string_length, tdbb->getAttachment()->att_charset);
dsql_nod* node = parser.parse();
@ -2531,95 +2540,94 @@ static dsql_req* prepare(thread_db* tdbb,
0);
}
// allocate the send and receive messages
// allocate the send and receive messages
MemoryPool& pool = *tdbb->getDefaultPool();
request->req_send = FB_NEW(pool) dsql_msg;
statement->req_send = FB_NEW(pool) dsql_msg;
dsql_msg* message = FB_NEW(pool) dsql_msg;
request->req_receive = message;
statement->req_receive = message;
message->msg_number = 1;
#ifdef SCROLLABLE_CURSORS
if (request->req_dbb->dbb_base_level >= 5) {
if (statement->req_dbb->dbb_base_level >= 5) {
/* allocate a message in which to send scrolling information
outside of the normal send/receive protocol */
request->req_async = message = FB_NEW(*tdsql->getDefaultPool()) dsql_msg;
statement->req_async = message = FB_NEW(*tdsql->getDefaultPool()) dsql_msg;
message->msg_number = 2;
}
#endif
request->req_type = REQ_SELECT;
request->req_flags &= ~REQ_cursor_open;
statement->req_type = REQ_SELECT;
statement->req_flags &= ~REQ_cursor_open;
/*
* No work is done during pass1 for set transaction - like
* checking for valid table names. This is because that will
* require a valid transaction handle.
* Error will be caught at execute time.
*/
/*
* No work is done during pass1 for set transaction - like
* checking for valid table names. This is because that will
* require a valid transaction handle.
* Error will be caught at execute time.
*/
node = PASS1_statement(request, node);
node = PASS1_statement(statement, node);
if (!node)
return request;
return statement;
// stop here for requests not requiring code generation
// stop here for statements not requiring code generation
if (request->req_type == REQ_DDL && parser.isStmtAmbiguous() &&
request->req_dbb->dbb_db_SQL_dialect != client_dialect)
if (statement->req_type == REQ_DDL && parser.isStmtAmbiguous() &&
statement->req_dbb->dbb_db_SQL_dialect != client_dialect)
{
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 817,
isc_arg_gds, isc_ddl_not_allowed_by_db_sql_dial,
isc_arg_number,
(SLONG) request->req_dbb->dbb_db_SQL_dialect, 0);
(SLONG) statement->req_dbb->dbb_db_SQL_dialect, 0);
}
if (request->req_type == REQ_COMMIT ||
request->req_type == REQ_COMMIT_RETAIN ||
request->req_type == REQ_ROLLBACK ||
request->req_type == REQ_ROLLBACK_RETAIN)
if (statement->req_type == REQ_COMMIT ||
statement->req_type == REQ_COMMIT_RETAIN ||
statement->req_type == REQ_ROLLBACK ||
statement->req_type == REQ_ROLLBACK_RETAIN)
{
return request;
return statement;
}
// Work on blob segment requests
// Work on blob segment statements
if (request->req_type == REQ_GET_SEGMENT ||
request->req_type == REQ_PUT_SEGMENT)
if (statement->req_type == REQ_GET_SEGMENT ||
statement->req_type == REQ_PUT_SEGMENT)
{
GEN_port(request, request->req_blob->blb_open_in_msg);
GEN_port(request, request->req_blob->blb_open_out_msg);
GEN_port(request, request->req_blob->blb_segment_msg);
return request;
GEN_port(statement, statement->req_blob->blb_open_in_msg);
GEN_port(statement, statement->req_blob->blb_open_out_msg);
GEN_port(statement, statement->req_blob->blb_segment_msg);
return statement;
}
// Generate BLR, DDL or TPB for request
// Generate BLR, DDL or TPB for statement
// Start transactions takes parameters via a parameter block.
// The request blr string is used for that
// Start transactions takes parameters via a parameter block.
// The statement blr string is used for that
if (request->req_type == REQ_START_TRANS) {
GEN_start_transaction(request, node);
return request;
if (statement->req_type == REQ_START_TRANS) {
GEN_start_transaction(statement, node);
return statement;
}
if (client_dialect > SQL_DIALECT_V5)
request->req_flags |= REQ_blr_version5;
statement->req_flags |= REQ_blr_version5;
else
request->req_flags |= REQ_blr_version4;
statement->req_flags |= REQ_blr_version4;
GEN_request(request, node);
const USHORT length = request->req_blr_data.getCount();
GEN_request(statement, node);
const USHORT length = statement->req_blr_data.getCount();
// stop here for ddl requests
// stop here for ddl statements
if (request->req_type == REQ_CREATE_DB ||
request->req_type == REQ_DDL)
if (statement->req_type == REQ_CREATE_DB ||
statement->req_type == REQ_DDL)
{
return request;
return statement;
}
// have the access method compile the request
// have the access method compile the statement
#ifdef DSQL_DEBUG
if (DSQL_debug & 64) {
@ -2627,12 +2635,12 @@ static dsql_req* prepare(thread_db* tdbb,
gds__trace_raw("Statement:\n");
gds__trace_raw(string, string_length);
gds__trace_raw("\nBLR:\n");
gds__print_blr(request->req_blr_data.begin(),
gds__print_blr(statement->req_blr_data.begin(),
gds__trace_printer, 0, 0);
}
#endif
// check for warnings
// check for warnings
if (tdbb->tdbb_status_vector[2] == isc_arg_warning) {
// save a status vector
memcpy(local_status, tdbb->tdbb_status_vector, sizeof(ISC_STATUS_ARRAY));
@ -2643,21 +2651,21 @@ static dsql_req* prepare(thread_db* tdbb,
try
{
JRD_compile(tdbb,
request->req_dbb->dbb_attachment,
&request->req_request,
statement->req_dbb->dbb_attachment,
&statement->req_request,
length,
request->req_blr_data.begin(),
statement->req_blr_data.begin(),
string_length,
string,
request->req_debug_data.getCount(),
request->req_debug_data.begin());
statement->req_debug_data.getCount(),
statement->req_debug_data.begin());
}
catch (const Firebird::Exception&)
{
status = tdbb->tdbb_status_vector[1];
}
// restore warnings (if there are any)
// restore warnings (if there are any)
if (local_status[2] == isc_arg_warning)
{
int indx, len, warning;
@ -2675,13 +2683,20 @@ static dsql_req* prepare(thread_db* tdbb,
memcpy(&tdbb->tdbb_status_vector[indx], &local_status[2], sizeof(ISC_STATUS) * len);
}
// free blr memory
request->req_blr_data.free();
// free blr memory
statement->req_blr_data.free();
if (status)
Firebird::status_exception::raise(tdbb->tdbb_status_vector);
return request;
return statement;
}
catch (const Firebird::Exception&)
{
release_request(tdbb, statement, true);
throw;
}
}

View File

@ -366,8 +366,83 @@ enum REQ_TYPE
REQ_EXEC_BLOCK, REQ_SELECT_BLOCK
};
class dsql_req : public pool_alloc<dsql_type_req>
{
public:
explicit dsql_req(MemoryPool& p)
: req_pool(p),
req_blr_data(p)
{
}
dsql_req* req_parent; //!< Source request, if cursor update
dsql_req* req_sibling; //!< Next sibling request, if cursor update
dsql_req* req_offspring; //!< Cursor update requests
MemoryPool& req_pool;
dsql_sym* req_name; //!< Name of request
dsql_sym* req_cursor; //!< Cursor symbol, if any
dsql_dbb* req_dbb; //!< DSQL attachment
jrd_tra* req_transaction; //!< JRD transaction
dsql_nod* req_ddl_node; //!< Store metadata request
class dsql_blb* req_blob; //!< Blob info for blob requests
jrd_req* req_request; //!< JRD request
//dsql_str* req_blr_string; //!< String block during BLR generation
Firebird::HalfStaticArray<BLOB_PTR, 1024> req_blr_data;
class dsql_msg* req_send; //!< Message to be sent to start request
class dsql_msg* req_receive; //!< Per record message to be received
class dsql_msg* req_async; //!< Message for sending scrolling information
dsql_par* req_eof; //!< End of file parameter
dsql_par* req_dbkey; //!< Database key for current of
dsql_par* req_rec_version; //!< Record Version for current of
dsql_par* req_parent_rec_version; //!< parent record version
dsql_par* req_parent_dbkey; //!< Parent database key for current of
//BLOB_PTR* req_blr; //!< Running blr address
//BLOB_PTR* req_blr_yellow; //!< Threshold for upping blr buffer size
ULONG req_inserts; //!< records processed in request
ULONG req_deletes;
ULONG req_updates;
ULONG req_selects;
REQ_TYPE req_type; //!< Type of request
ULONG req_flags; //!< generic flag
protected:
// Request should never be destroyed using delete.
// It dies together with it's pool in release_request().
~dsql_req()
{
}
// To avoid posix warning about missing public destructor declare
// MemoryPool as friend class. In fact IT releases request memory!
friend class MemoryPool;
};
class CompiledStatement : public dsql_req
{
public:
explicit CompiledStatement(MemoryPool& p)
: dsql_req(p),
req_debug_data(p),
req_main_context(p),
req_context(&req_main_context),
req_union_context(p),
req_dt_context(p),
req_labels(p),
req_cursors(p),
req_curr_ctes(p),
req_ctes(p),
req_cte_aliases(p)
{
}
protected:
// Request should never be destroyed using delete.
// It dies together with it's pool in release_request().
~CompiledStatement();
public:
// begin - member functions that should be private
void append_uchar(UCHAR byte);
@ -400,77 +475,6 @@ public:
void append_debug_info();
// end - member functions that should be private
explicit dsql_req(MemoryPool& p)
: req_pool(p),
req_main_context(p),
req_context(&req_main_context),
req_union_context(p),
req_dt_context(p),
req_blr_data(p),
req_labels(p),
req_cursors(p),
req_debug_data(p),
req_curr_ctes(p),
req_ctes(p),
req_cte_aliases(p) { }
dsql_req* req_parent; //!< Source request, if cursor update
dsql_req* req_sibling; //!< Next sibling request, if cursor update
dsql_req* req_offspring; //!< Cursor update requests
MemoryPool& req_pool;
DsqlContextStack req_main_context;
DsqlContextStack* req_context;
DsqlContextStack req_union_context; //!< Save contexts for views of unions
DsqlContextStack req_dt_context; //!< Save contexts for views of derived tables
dsql_sym* req_name; //!< Name of request
dsql_sym* req_cursor; //!< Cursor symbol, if any
dsql_dbb* req_dbb; //!< DSQL attachment
jrd_tra* req_transaction; //!< JRD transaction
dsql_nod* req_ddl_node; //!< Store metadata request
dsql_nod* req_blk_node; //!< exec_block node
class dsql_blb* req_blob; //!< Blob info for blob requests
jrd_req* req_request; //!< JRD request
//dsql_str* req_blr_string; //!< String block during BLR generation
Firebird::HalfStaticArray<BLOB_PTR, 1024> req_blr_data;
class dsql_msg* req_send; //!< Message to be sent to start request
class dsql_msg* req_receive; //!< Per record message to be received
class dsql_msg* req_async; //!< Message for sending scrolling information
dsql_par* req_eof; //!< End of file parameter
dsql_par* req_dbkey; //!< Database key for current of
dsql_par* req_rec_version; //!< Record Version for current of
dsql_par* req_parent_rec_version; //!< parent record version
dsql_par* req_parent_dbkey; //!< Parent database key for current of
dsql_rel* req_relation; //!< relation created by this request (for DDL)
dsql_prc* req_procedure; //!< procedure created by this request (for DDL)
class dsql_ctx* req_outer_agg_context; //!< agg context for outer ref
//BLOB_PTR* req_blr; //!< Running blr address
//BLOB_PTR* req_blr_yellow; //!< Threshold for upping blr buffer size
ULONG req_inserts; //!< records processed in request
ULONG req_deletes;
ULONG req_updates;
ULONG req_selects;
REQ_TYPE req_type; //!< Type of request
ULONG req_base_offset; //!< place to go back and stuff in blr length
USHORT req_context_number; //!< Next available context number
USHORT req_scope_level; //!< Scope level for parsing aliases in subqueries
//USHORT req_message_number; //!< Next available message number
USHORT req_loop_level; //!< Loop level
DsqlStrStack req_labels; //!< Loop labels
USHORT req_cursor_number; //!< Cursor number
DsqlNodStack req_cursors; //!< Cursors
USHORT req_in_select_list; //!< now processing "select list"
USHORT req_in_where_clause; //!< processing "where clause"
USHORT req_in_group_by_clause; //!< processing "group by clause"
USHORT req_in_having_clause; //!< processing "having clause"
USHORT req_in_order_by_clause; //!< processing "order by clause"
USHORT req_error_handlers; //!< count of active error handlers
ULONG req_flags; //!< generic flag
USHORT req_client_dialect; //!< dialect passed into the API call
USHORT req_in_outer_join; //!< processing inside outer-join part
dsql_str* req_alias_relation_prefix; //!< prefix for every relation-alias.
Firebird::HalfStaticArray<BLOB_PTR, 128> req_debug_data;
void addCTEs(dsql_nod* list);
dsql_nod* findCTE(const dsql_str* name);
void clearCTEs();
@ -505,40 +509,59 @@ public:
psql = value;
}
dsql_nod* req_blk_node; //!< exec_block node
dsql_rel* req_relation; //!< relation created by this request (for DDL)
dsql_prc* req_procedure; //!< procedure created by this request (for DDL)
Firebird::HalfStaticArray<BLOB_PTR, 128> req_debug_data;
DsqlContextStack req_main_context;
DsqlContextStack* req_context;
DsqlContextStack req_union_context; //!< Save contexts for views of unions
DsqlContextStack req_dt_context; //!< Save contexts for views of derived tables
class dsql_ctx* req_outer_agg_context; //!< agg context for outer ref
ULONG req_base_offset; //!< place to go back and stuff in blr length
USHORT req_context_number; //!< Next available context number
USHORT req_scope_level; //!< Scope level for parsing aliases in subqueries
//USHORT req_message_number; //!< Next available message number
USHORT req_loop_level; //!< Loop level
DsqlStrStack req_labels; //!< Loop labels
USHORT req_cursor_number; //!< Cursor number
DsqlNodStack req_cursors; //!< Cursors
USHORT req_in_select_list; //!< now processing "select list"
USHORT req_in_where_clause; //!< processing "where clause"
USHORT req_in_group_by_clause; //!< processing "group by clause"
USHORT req_in_having_clause; //!< processing "having clause"
USHORT req_in_order_by_clause; //!< processing "order by clause"
USHORT req_error_handlers; //!< count of active error handlers
USHORT req_client_dialect; //!< dialect passed into the API call
USHORT req_in_outer_join; //!< processing inside outer-join part
dsql_str* req_alias_relation_prefix; //!< prefix for every relation-alias.
DsqlNodStack req_curr_ctes; // current processing CTE's
class dsql_ctx* req_recursive_ctx; // context of recursive CTE
USHORT req_recursive_ctx_id; // id of recursive union stream context
private:
// Request should never be destroyed using delete.
// It dies together with it's pool in release_request().
~dsql_req();
Firebird::HalfStaticArray<dsql_nod*, 4> req_ctes; // common table expressions
Firebird::HalfStaticArray<const dsql_str*, 4> req_cte_aliases; // CTE aliases in recursive members
const dsql_str* const* req_curr_cte_alias;
bool psql;
// To avoid posix warning about missing public destructor declare
// MemoryPool as friend class. In fact IT releases request memory!
friend class MemoryPool;
};
class PsqlChanger
{
public:
PsqlChanger(dsql_req* aRequest, bool value)
: request(aRequest)
PsqlChanger(CompiledStatement* aStatement, bool value)
: statement(aStatement)
{
oldValue = request->isPsql();
request->setPsql(value);
oldValue = statement->isPsql();
statement->setPsql(value);
}
~PsqlChanger()
{
request->setPsql(oldValue);
statement->setPsql(oldValue);
}
private:
@ -546,7 +569,7 @@ private:
PsqlChanger(const PsqlChanger&);
PsqlChanger& operator =(const PsqlChanger&);
dsql_req* request;
CompiledStatement* statement;
bool oldValue;
};

File diff suppressed because it is too large Load Diff

View File

@ -24,15 +24,15 @@
#ifndef DSQL_GEN_PROTO_H
#define DSQL_GEN_PROTO_H
void GEN_expr(Jrd::dsql_req*, Jrd::dsql_nod*);
void GEN_port(Jrd::dsql_req*, Jrd::dsql_msg*);
void GEN_request(Jrd::dsql_req*, Jrd::dsql_nod*);
void GEN_return(Jrd::dsql_req*, const Jrd::dsql_nod*, bool);
void GEN_start_transaction(Jrd::dsql_req*, const Jrd::dsql_nod*);
void GEN_statement(Jrd::dsql_req*, Jrd::dsql_nod*);
void GEN_expr(Jrd::CompiledStatement*, Jrd::dsql_nod*);
void GEN_port(Jrd::CompiledStatement*, Jrd::dsql_msg*);
void GEN_request(Jrd::CompiledStatement*, Jrd::dsql_nod*);
void GEN_return(Jrd::CompiledStatement*, const Jrd::dsql_nod*, bool);
void GEN_start_transaction(Jrd::CompiledStatement*, const Jrd::dsql_nod*);
void GEN_statement(Jrd::CompiledStatement*, Jrd::dsql_nod*);
// CVC: I think this can be replaced by request->append_uchar(byte) in the calling code.
inline void stuff(Jrd::dsql_req* request, const UCHAR byte)
inline void stuff(Jrd::CompiledStatement* request, const UCHAR byte)
{
request->req_blr_data.add(byte);
}

View File

@ -388,7 +388,7 @@ dsql_str* MAKE_cstring(const char* str)
@param null_replacement
**/
void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_replacement)
void MAKE_desc(CompiledStatement* statement, dsc* desc, dsql_nod* node, dsql_nod* null_replacement)
{
dsc desc1, desc2, desc3;
USHORT dtype, dtype1, dtype2;
@ -436,17 +436,17 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
case nod_map:
map = (dsql_map*) node->nod_arg[e_map_map];
MAKE_desc(request, desc, map->map_node, null_replacement);
MAKE_desc(statement, desc, map->map_node, null_replacement);
return;
case nod_agg_min:
case nod_agg_max:
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
MAKE_desc(statement, desc, node->nod_arg[0], null_replacement);
desc->dsc_flags = DSC_nullable;
return;
case nod_agg_average:
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
MAKE_desc(statement, desc, node->nod_arg[0], null_replacement);
desc->dsc_flags = DSC_nullable;
if (!DTYPE_IS_NUMERIC(desc->dsc_dtype) &&
!DTYPE_IS_TEXT(desc->dsc_dtype))
@ -460,7 +460,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_agg_average2:
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
MAKE_desc(statement, desc, node->nod_arg[0], null_replacement);
desc->dsc_flags = DSC_nullable;
dtype = desc->dsc_dtype;
if (!DTYPE_IS_NUMERIC(dtype)) {
@ -478,7 +478,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_agg_total:
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
MAKE_desc(statement, desc, node->nod_arg[0], null_replacement);
if (!DTYPE_IS_NUMERIC(desc->dsc_dtype) &&
!DTYPE_IS_TEXT(desc->dsc_dtype))
{
@ -500,7 +500,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_agg_total2:
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
MAKE_desc(statement, desc, node->nod_arg[0], null_replacement);
dtype = desc->dsc_dtype;
if (!DTYPE_IS_NUMERIC(dtype)) {
ERRD_post(isc_expression_eval_err, 0);
@ -518,24 +518,24 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_agg_list:
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
MAKE_desc(statement, desc, node->nod_arg[0], null_replacement);
desc->makeBlob(desc->getBlobSubType(), desc->getTextType());
desc->setNullable(true);
return;
case nod_concatenate:
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
DSqlDataTypeUtil(request).makeConcatenate(desc, &desc1, &desc2);
MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]);
DSqlDataTypeUtil(statement).makeConcatenate(desc, &desc1, &desc2);
return;
case nod_derived_field:
MAKE_desc(request, desc, node->nod_arg[e_derived_field_value], null_replacement);
MAKE_desc(statement, desc, node->nod_arg[e_derived_field_value], null_replacement);
return;
case nod_upcase:
case nod_lowcase:
MAKE_desc(request, &desc1, node->nod_arg[0], null_replacement);
MAKE_desc(statement, &desc1, node->nod_arg[0], null_replacement);
if (desc1.dsc_dtype <= dtype_any_text || desc1.dsc_dtype == dtype_blob)
{
*desc = desc1;
@ -550,16 +550,16 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_substr:
MAKE_desc(request, &desc1, node->nod_arg[0], null_replacement);
MAKE_desc(request, &desc2, node->nod_arg[1], null_replacement);
MAKE_desc(request, &desc3, node->nod_arg[2], null_replacement);
DSqlDataTypeUtil(request).makeSubstr(desc, &desc1, &desc2, &desc3);
MAKE_desc(statement, &desc1, node->nod_arg[0], null_replacement);
MAKE_desc(statement, &desc2, node->nod_arg[1], null_replacement);
MAKE_desc(statement, &desc3, node->nod_arg[2], null_replacement);
DSqlDataTypeUtil(statement).makeSubstr(desc, &desc1, &desc2, &desc3);
return;
case nod_trim:
MAKE_desc(request, &desc1, node->nod_arg[e_trim_value], null_replacement);
MAKE_desc(statement, &desc1, node->nod_arg[e_trim_value], null_replacement);
if (node->nod_arg[e_trim_characters])
MAKE_desc(request, &desc2, node->nod_arg[e_trim_characters], null_replacement);
MAKE_desc(statement, &desc2, node->nod_arg[e_trim_characters], null_replacement);
else
desc2.dsc_flags = 0;
@ -589,24 +589,24 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
case nod_cast:
field = (dsql_fld*) node->nod_arg[e_cast_target];
MAKE_desc_from_field(desc, field);
MAKE_desc(request, &desc1, node->nod_arg[e_cast_source], NULL);
MAKE_desc(statement, &desc1, node->nod_arg[e_cast_source], NULL);
desc->dsc_flags = desc1.dsc_flags & DSC_nullable;
return;
case nod_simple_case:
MAKE_desc_from_list(request, &desc1, node->nod_arg[e_simple_case_results],
MAKE_desc_from_list(statement, &desc1, node->nod_arg[e_simple_case_results],
null_replacement, "CASE");
*desc = desc1;
return;
case nod_searched_case:
MAKE_desc_from_list(request, &desc1, node->nod_arg[e_searched_case_results],
MAKE_desc_from_list(statement, &desc1, node->nod_arg[e_searched_case_results],
null_replacement, "CASE");
*desc = desc1;
return;
case nod_coalesce:
MAKE_desc_from_list(request, &desc1, node->nod_arg[0],
MAKE_desc_from_list(statement, &desc1, node->nod_arg[0],
null_replacement, "COALESCE");
*desc = desc1;
return;
@ -619,8 +619,8 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
case nod_add:
case nod_subtract:
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]);
if (node->nod_arg[0]->nod_type == nod_null &&
node->nod_arg[1]->nod_type == nod_null)
@ -764,8 +764,8 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
case nod_add2:
case nod_subtract2:
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]);
if (node->nod_arg[0]->nod_type == nod_null &&
node->nod_arg[1]->nod_type == nod_null)
@ -939,8 +939,8 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_multiply:
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]);
if (node->nod_arg[0]->nod_type == nod_null &&
node->nod_arg[1]->nod_type == nod_null)
@ -980,8 +980,8 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_multiply2:
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]);
if (node->nod_arg[0]->nod_type == nod_null &&
node->nod_arg[1]->nod_type == nod_null)
@ -1039,8 +1039,8 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
*/
case nod_divide:
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]);
if (node->nod_arg[0]->nod_type == nod_null &&
node->nod_arg[1]->nod_type == nod_null)
@ -1077,8 +1077,8 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_divide2:
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]);
MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]);
if (node->nod_arg[0]->nod_type == nod_null &&
node->nod_arg[1]->nod_type == nod_null)
@ -1124,7 +1124,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_negate:
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
MAKE_desc(statement, desc, node->nod_arg[0], null_replacement);
if (node->nod_arg[0]->nod_type == nod_null)
{
@ -1136,7 +1136,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
// In Dialect 2 or 3, a string can never partipate in negation
// (use a specific cast instead)
if (DTYPE_IS_TEXT(desc->dsc_dtype)) {
if (request->req_client_dialect >= SQL_DIALECT_V6_TRANSITION) {
if (statement->req_client_dialect >= SQL_DIALECT_V6_TRANSITION) {
ERRD_post(isc_expression_eval_err, 0);
}
desc->dsc_dtype = dtype_double;
@ -1155,7 +1155,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_alias:
MAKE_desc(request, desc, node->nod_arg[e_alias_value], null_replacement);
MAKE_desc(statement, desc, node->nod_arg[e_alias_value], null_replacement);
return;
case nod_dbkey:
@ -1209,19 +1209,19 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
for (dsql_nod** p = nodeArgs->nod_arg;
p < nodeArgs->nod_arg + nodeArgs->nod_count; ++p)
{
MAKE_desc(request, &(*p)->nod_desc, *p, NULL);
MAKE_desc(statement, &(*p)->nod_desc, *p, NULL);
args.add(&(*p)->nod_desc);
}
}
const dsql_str* name = (dsql_str*) node->nod_arg[e_sysfunc_name];
DSqlDataTypeUtil(request).makeSysFunction(desc, name->str_data, args.getCount(), args.begin());
DSqlDataTypeUtil(statement).makeSysFunction(desc, name->str_data, args.getCount(), args.begin());
return;
}
case nod_gen_id:
MAKE_desc(request, &desc1, node->nod_arg[e_gen_id_value], NULL);
MAKE_desc(statement, &desc1, node->nod_arg[e_gen_id_value], NULL);
desc->dsc_dtype = dtype_long;
desc->dsc_sub_type = 0;
desc->dsc_scale = 0;
@ -1230,7 +1230,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_gen_id2:
MAKE_desc(request, &desc1, node->nod_arg[e_gen_id_value], NULL);
MAKE_desc(statement, &desc1, node->nod_arg[e_gen_id_value], NULL);
desc->dsc_dtype = dtype_int64;
desc->dsc_sub_type = 0;
desc->dsc_scale = 0;
@ -1241,7 +1241,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
case nod_limit:
case nod_rows:
if (request->req_client_dialect <= SQL_DIALECT_V5) {
if (statement->req_client_dialect <= SQL_DIALECT_V5) {
desc->dsc_dtype = dtype_long;
desc->dsc_length = sizeof (SLONG);
}
@ -1273,7 +1273,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
desc->dsc_flags = 0;
desc->dsc_ttype() = ttype_metadata;
desc->dsc_length =
USERNAME_LENGTH * METD_get_charset_bpc(request, ttype_metadata) +
USERNAME_LENGTH * METD_get_charset_bpc(statement, ttype_metadata) +
sizeof(USHORT);
return;
@ -1309,7 +1309,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_extract:
MAKE_desc(request, &desc1, node->nod_arg[e_extract_value], NULL);
MAKE_desc(statement, &desc1, node->nod_arg[e_extract_value], NULL);
switch (*(ULONG *) node->nod_arg[e_extract_part]->nod_desc.dsc_address)
{
@ -1331,7 +1331,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_strlen:
MAKE_desc(request, &desc1, node->nod_arg[e_strlen_value], NULL);
MAKE_desc(statement, &desc1, node->nod_arg[e_strlen_value], NULL);
desc->dsc_sub_type = 0;
desc->dsc_scale = 0;
desc->dsc_flags = (desc1.dsc_flags & DSC_nullable);
@ -1367,7 +1367,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
*/
if (null_replacement)
{
MAKE_desc(request, desc, null_replacement, NULL);
MAKE_desc(statement, desc, null_replacement, NULL);
desc->dsc_flags |= (DSC_nullable | DSC_null);
}
else
@ -1377,7 +1377,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
return;
case nod_via:
MAKE_desc(request, desc, node->nod_arg[e_via_value_1], null_replacement);
MAKE_desc(statement, desc, node->nod_arg[e_via_value_1], null_replacement);
/**
Set the descriptor flag as nullable. The
select expression may or may not return
@ -1451,7 +1451,7 @@ void MAKE_desc_from_field(dsc* desc, const dsql_fld* field)
@param expression_name
**/
void MAKE_desc_from_list(dsql_req* request, dsc* desc, dsql_nod* node,
void MAKE_desc_from_list(CompiledStatement* statement, dsc* desc, dsql_nod* node,
dsql_nod* null_replacement,
const TEXT* expression_name)
{
@ -1461,17 +1461,17 @@ void MAKE_desc_from_list(dsql_req* request, dsc* desc, dsql_nod* node,
for (dsql_nod** p = node->nod_arg; p < node->nod_arg + node->nod_count; ++p)
{
MAKE_desc(request, &(*p)->nod_desc, *p, NULL);
MAKE_desc(statement, &(*p)->nod_desc, *p, NULL);
args.add(&(*p)->nod_desc);
}
DSqlDataTypeUtil(request).makeFromList(desc, expression_name, args.getCount(), args.begin());
DSqlDataTypeUtil(statement).makeFromList(desc, expression_name, args.getCount(), args.begin());
// If we have literal NULLs only, let the result be either
// CHAR(1) CHARACTER SET NONE or the context-provided datatype
if (desc->isNull() && null_replacement)
{
MAKE_desc(request, desc, null_replacement, NULL);
MAKE_desc(statement, desc, null_replacement, NULL);
desc->dsc_flags |= DSC_null | DSC_nullable;
return;
}

View File

@ -33,6 +33,7 @@ namespace Jrd {
class dsql_nod;
class dsql_fld;
class dsql_req;
class CompiledStatement;
// Parameters to MAKE_constant
enum dsql_constant_type {
@ -59,9 +60,9 @@ Jrd::dsql_nod* MAKE_const_slong(SLONG);
Jrd::dsql_nod* MAKE_constant(Jrd::dsql_str*, Jrd::dsql_constant_type);
Jrd::dsql_nod* MAKE_str_constant(Jrd::dsql_str*, SSHORT);
Jrd::dsql_str* MAKE_cstring(const char*);
void MAKE_desc(Jrd::dsql_req*, dsc*, Jrd::dsql_nod*, Jrd::dsql_nod*);
void MAKE_desc(Jrd::CompiledStatement*, dsc*, Jrd::dsql_nod*, Jrd::dsql_nod*);
void MAKE_desc_from_field(dsc*, const Jrd::dsql_fld*);
void MAKE_desc_from_list(Jrd::dsql_req*, dsc*, Jrd::dsql_nod*, Jrd::dsql_nod*, const TEXT*);
void MAKE_desc_from_list(Jrd::CompiledStatement*, dsc*, Jrd::dsql_nod*, Jrd::dsql_nod*, const TEXT*);
Jrd::dsql_nod* MAKE_field(Jrd::dsql_ctx*, Jrd::dsql_fld*, Jrd::dsql_nod*);
Jrd::dsql_nod* MAKE_field_name(const char*);
Jrd::dsql_nod* MAKE_list(Jrd::DsqlNodStack&);

View File

@ -1141,7 +1141,7 @@ dsql_nod* METD_get_primary_key(dsql_req* request, const dsql_str* relation_name)
}
dsql_prc* METD_get_procedure(dsql_req* request, const dsql_str* name)
dsql_prc* METD_get_procedure(CompiledStatement* statement, const dsql_str* name)
{
/**************************************
*
@ -1157,37 +1157,37 @@ dsql_prc* METD_get_procedure(dsql_req* request, const dsql_str* name)
**************************************/
thread_db* tdbb = JRD_get_thread_data();
dsql_dbb* dbb = request->req_dbb;
dsql_dbb* dbb = statement->req_dbb;
dsql_fld* parameter;
dsql_fld** ptr;
dsql_prc* temp;
SSHORT type, count, defaults;
// see if the procedure is the one currently being defined in this request
// see if the procedure is the one currently being defined in this statement
if (((temp = request->req_procedure) != NULL) &&
if (((temp = statement->req_procedure) != NULL) &&
temp->prc_name == name->str_data)
{
return temp;
}
MutexHolder holder(request);
MutexHolder holder(statement);
// Start by seeing if symbol is already defined
dsql_sym* symbol = lookup_symbol(request->req_dbb, name, SYM_procedure);
dsql_sym* symbol = lookup_symbol(statement->req_dbb, name, SYM_procedure);
if (symbol)
return (dsql_prc*) symbol->sym_object;
// now see if it is in the database
validateTransaction(request);
validateTransaction(statement);
dsql_prc* procedure = NULL;
jrd_req* handle1 = CMP_find_request(tdbb, irq_procedure, IRQ_REQUESTS);
FOR(REQUEST_HANDLE handle1 TRANSACTION_HANDLE request->req_transaction)
FOR(REQUEST_HANDLE handle1 TRANSACTION_HANDLE statement->req_transaction)
X IN RDB$PROCEDURES WITH
X.RDB$PROCEDURE_NAME EQ name->str_data
@ -1224,7 +1224,7 @@ dsql_prc* METD_get_procedure(dsql_req* request, const dsql_str* name)
jrd_req* handle2 = CMP_find_request(tdbb, irq_parameters, IRQ_REQUESTS);
FOR(REQUEST_HANDLE handle2 TRANSACTION_HANDLE request->req_transaction)
FOR(REQUEST_HANDLE handle2 TRANSACTION_HANDLE statement->req_transaction)
PR IN RDB$PROCEDURE_PARAMETERS CROSS
FLD IN RDB$FIELDS
WITH FLD.RDB$FIELD_NAME EQ PR.RDB$FIELD_SOURCE
@ -1246,7 +1246,7 @@ dsql_prc* METD_get_procedure(dsql_req* request, const dsql_str* name)
{
jrd_req* handle3 = CMP_find_request(tdbb, irq_parameters2, IRQ_REQUESTS);
FOR(REQUEST_HANDLE handle3 TRANSACTION_HANDLE request->req_transaction)
FOR(REQUEST_HANDLE handle3 TRANSACTION_HANDLE statement->req_transaction)
PR2 IN RDB$PROCEDURE_PARAMETERS
WITH PR2.RDB$PROCEDURE_NAME EQ PR.RDB$PROCEDURE_NAME AND
PR2.RDB$PARAMETER_NAME EQ PR.RDB$PARAMETER_NAME
@ -1337,7 +1337,7 @@ dsql_prc* METD_get_procedure(dsql_req* request, const dsql_str* name)
// Since we could give up control due to the THREAD_EXIT and THEAD_ENTER
// calls, another thread may have added the same procedure in the mean time
if ((symbol = lookup_symbol(request->req_dbb, name, SYM_procedure)))
if ((symbol = lookup_symbol(statement->req_dbb, name, SYM_procedure)))
{
// Get rid of all the stuff we just read in. Use existing one
free_procedure(procedure);
@ -1359,14 +1359,14 @@ dsql_prc* METD_get_procedure(dsql_req* request, const dsql_str* name)
symbol->sym_length = procedure->prc_name.length();
symbol->sym_type = SYM_procedure;
symbol->sym_dbb = dbb;
insert_symbol(request->req_dbb, symbol);
insert_symbol(statement->req_dbb, symbol);
}
return procedure;
}
dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name)
dsql_rel* METD_get_relation(CompiledStatement* statement, const dsql_str* name)
{
/**************************************
*
@ -1381,38 +1381,38 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name)
**************************************/
thread_db* tdbb = JRD_get_thread_data();
dsql_dbb* dbb = request->req_dbb;
dsql_dbb* dbb = statement->req_dbb;
dsql_fld* field;
dsql_fld** ptr;
dsql_rel* temp;
// See if the relation is the one currently being defined in this request
// See if the relation is the one currently being defined in this statement
if (((temp = request->req_relation) != NULL) &&
if (((temp = statement->req_relation) != NULL) &&
temp->rel_name == name->str_data)
{
return temp;
}
MutexHolder holder(request);
MutexHolder holder(statement);
// Start by seeing if symbol is already defined
dsql_sym* symbol = lookup_symbol(request->req_dbb, name, SYM_relation);
dsql_sym* symbol = lookup_symbol(statement->req_dbb, name, SYM_relation);
if (symbol)
return (dsql_rel*) symbol->sym_object;
// If the relation id or any of the field ids have not yet been assigned,
// and this is a type of request which does not use ids, prepare a
// and this is a type of statement which does not use ids, prepare a
// temporary relation block to provide information without caching it
validateTransaction(request);
validateTransaction(statement);
bool permanent = true;
jrd_req* handle1 = CMP_find_request(tdbb, irq_rel_ids, IRQ_REQUESTS);
FOR(REQUEST_HANDLE handle1 TRANSACTION_HANDLE request->req_transaction)
FOR(REQUEST_HANDLE handle1 TRANSACTION_HANDLE statement->req_transaction)
REL IN RDB$RELATIONS
CROSS RFR IN RDB$RELATION_FIELDS OVER RDB$RELATION_NAME
WITH REL.RDB$RELATION_NAME EQ name->str_data
@ -1436,7 +1436,7 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name)
jrd_req* handle2 = CMP_find_request(tdbb, irq_relation, IRQ_REQUESTS);
FOR(REQUEST_HANDLE handle2 TRANSACTION_HANDLE request->req_transaction)
FOR(REQUEST_HANDLE handle2 TRANSACTION_HANDLE statement->req_transaction)
X IN RDB$RELATIONS WITH X.RDB$RELATION_NAME EQ name->str_data
if (!DSQL_REQUEST(irq_relation))
@ -1450,7 +1450,7 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name)
relation = FB_NEW(pool) dsql_rel(pool);
relation->rel_id = X.RDB$RELATION_ID;
}
else if (!DDL_ids(request)) {
else if (!DDL_ids(statement)) {
relation = FB_NEW(pool) dsql_rel(pool);
}
@ -1485,7 +1485,7 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name)
jrd_req* handle3 = CMP_find_request(tdbb, irq_fields, IRQ_REQUESTS);
FOR(REQUEST_HANDLE handle3 TRANSACTION_HANDLE request->req_transaction)
FOR(REQUEST_HANDLE handle3 TRANSACTION_HANDLE statement->req_transaction)
FLX IN RDB$FIELDS CROSS
RFR IN RDB$RELATION_FIELDS
WITH FLX.RDB$FIELD_NAME EQ RFR.RDB$FIELD_SOURCE
@ -1509,7 +1509,7 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name)
field = FB_NEW(pool) dsql_fld(pool);
field->fld_id = RFR.RDB$FIELD_ID;
}
else if (!DDL_ids(request))
else if (!DDL_ids(statement))
field = FB_NEW(pool) dsql_fld(pool);
if (field) {
@ -1566,7 +1566,7 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name)
if (!DSQL_REQUEST(irq_fields))
DSQL_REQUEST(irq_fields) = handle3;
if ((symbol = lookup_symbol(request->req_dbb, name, SYM_relation)))
if ((symbol = lookup_symbol(statement->req_dbb, name, SYM_relation)))
{
free_relation(relation);
return (dsql_rel*) symbol->sym_object;
@ -1586,7 +1586,7 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name)
symbol->sym_length = relation->rel_name.length();
symbol->sym_type = SYM_relation;
symbol->sym_dbb = dbb;
insert_symbol(request->req_dbb, symbol);
insert_symbol(statement->req_dbb, symbol);
}
else {
relation->rel_flags |= REL_new_relation;
@ -1688,7 +1688,7 @@ bool METD_get_type(dsql_req* request, const dsql_str* name, char* field, SSHORT*
}
dsql_rel* METD_get_view_base(dsql_req* request,
dsql_rel* METD_get_view_base(CompiledStatement* statement,
const char* view_name, // UTF-8
MetaNamePairMap& fields)
{
@ -1709,11 +1709,11 @@ dsql_rel* METD_get_view_base(dsql_req* request,
**************************************/
thread_db* tdbb = JRD_get_thread_data();
validateTransaction(request);
validateTransaction(statement);
dsql_rel* relation = NULL;
dsql_dbb* dbb = request->req_dbb;
dsql_dbb* dbb = statement->req_dbb;
bool first = true;
bool cont = true;
MetaNamePairMap previousAux;
@ -1724,7 +1724,7 @@ dsql_rel* METD_get_view_base(dsql_req* request,
{
jrd_req* handle1 = CMP_find_request(tdbb, irq_view_base, IRQ_REQUESTS);
FOR(REQUEST_HANDLE handle1 TRANSACTION_HANDLE request->req_transaction)
FOR(REQUEST_HANDLE handle1 TRANSACTION_HANDLE statement->req_transaction)
X IN RDB$VIEW_RELATIONS
WITH X.RDB$VIEW_NAME EQ view_name
@ -1744,7 +1744,7 @@ dsql_rel* METD_get_view_base(dsql_req* request,
dsql_str* relation_name =
MAKE_string(X.RDB$RELATION_NAME, strlen(X.RDB$RELATION_NAME));
relation = METD_get_relation(request, relation_name);
relation = METD_get_relation(statement, relation_name);
delete relation_name;
Firebird::Array<Firebird::MetaName> ambiguities;
@ -1758,7 +1758,7 @@ dsql_rel* METD_get_view_base(dsql_req* request,
jrd_req* handle2 = CMP_find_request(tdbb, irq_view_base_flds, IRQ_REQUESTS);
FOR(REQUEST_HANDLE handle2 TRANSACTION_HANDLE request->req_transaction)
FOR(REQUEST_HANDLE handle2 TRANSACTION_HANDLE statement->req_transaction)
RFL IN RDB$RELATION_FIELDS
WITH RFL.RDB$RELATION_NAME EQ X.RDB$VIEW_NAME
@ -1832,7 +1832,7 @@ dsql_rel* METD_get_view_base(dsql_req* request,
}
dsql_rel* METD_get_view_relation(dsql_req* request,
dsql_rel* METD_get_view_relation(CompiledStatement* statement,
const char* view_name, // UTF-8
const char* relation_or_alias) // UTF-8
{
@ -1850,15 +1850,15 @@ dsql_rel* METD_get_view_relation(dsql_req* request,
**************************************/
thread_db* tdbb = JRD_get_thread_data();
validateTransaction(request);
validateTransaction(statement);
dsql_rel* relation = NULL;
dsql_dbb* dbb = request->req_dbb;
dsql_dbb* dbb = statement->req_dbb;
jrd_req* handle = CMP_find_request(tdbb, irq_view, IRQ_REQUESTS);
FOR(REQUEST_HANDLE handle TRANSACTION_HANDLE request->req_transaction)
FOR(REQUEST_HANDLE handle TRANSACTION_HANDLE statement->req_transaction)
X IN RDB$VIEW_RELATIONS WITH X.RDB$VIEW_NAME EQ view_name
if (!DSQL_REQUEST(irq_view))
@ -1872,13 +1872,13 @@ dsql_rel* METD_get_view_relation(dsql_req* request,
{
dsql_str* relation_name = MAKE_string(X.RDB$RELATION_NAME,
strlen(X.RDB$RELATION_NAME));
relation = METD_get_relation(request, relation_name);
relation = METD_get_relation(statement, relation_name);
delete relation_name;
return relation;
}
relation =
METD_get_view_relation(request, X.RDB$RELATION_NAME, relation_or_alias);
METD_get_view_relation(statement, X.RDB$RELATION_NAME, relation_or_alias);
if (relation) {
return relation;
}

View File

@ -37,6 +37,7 @@ typedef Firebird::GenericMap<MetaNamePair> MetaNamePairMap;
namespace Jrd {
class dsql_req;
class dsql_str;
class CompiledStatement;
};
void METD_drop_charset(Jrd::dsql_req*, const Firebird::MetaName&);
@ -56,14 +57,14 @@ USHORT METD_get_domain_default(Jrd::dsql_req*, const TEXT*, bool*, UCHAR*, USH
bool METD_get_exception(Jrd::dsql_req*, const Jrd::dsql_str*);
Jrd::dsql_udf* METD_get_function(Jrd::dsql_req*, const Jrd::dsql_str*);
Jrd::dsql_nod* METD_get_primary_key(Jrd::dsql_req*, const Jrd::dsql_str*);
Jrd::dsql_prc* METD_get_procedure(Jrd::dsql_req*, const Jrd::dsql_str*);
Jrd::dsql_rel* METD_get_relation(Jrd::dsql_req*, const Jrd::dsql_str*);
Jrd::dsql_prc* METD_get_procedure(Jrd::CompiledStatement*, const Jrd::dsql_str*);
Jrd::dsql_rel* METD_get_relation(Jrd::CompiledStatement*, const Jrd::dsql_str*);
bool METD_get_trigger(Jrd::dsql_req*, const Jrd::dsql_str*, Jrd::dsql_str**, USHORT*);
bool METD_get_type(Jrd::dsql_req*, const Jrd::dsql_str*, char*, SSHORT*);
Jrd::dsql_rel* METD_get_view_base(Jrd::dsql_req* request,
Jrd::dsql_rel* METD_get_view_base(Jrd::CompiledStatement* request,
const char* view_name, // UTF-8
MetaNamePairMap& fields);
Jrd::dsql_rel* METD_get_view_relation(Jrd::dsql_req* request,
Jrd::dsql_rel* METD_get_view_relation(Jrd::CompiledStatement* request,
const char* view_name, // UTF-8
const char* relation_or_alias); // UTF-8

File diff suppressed because it is too large Load Diff

View File

@ -24,10 +24,10 @@
#ifndef DSQL_PASS1_PROTO_H
#define DSQL_PASS1_PROTO_H
Jrd::dsql_ctx* PASS1_make_context(Jrd::dsql_req* request, const Jrd::dsql_nod* relation_node);
Jrd::dsql_nod* PASS1_node(Jrd::dsql_req*, Jrd::dsql_nod*);
Jrd::dsql_nod* PASS1_rse(Jrd::dsql_req*, Jrd::dsql_nod*, Jrd::dsql_nod*);
Jrd::dsql_nod* PASS1_statement(Jrd::dsql_req*, Jrd::dsql_nod*);
Jrd::dsql_ctx* PASS1_make_context(Jrd::CompiledStatement* request, const Jrd::dsql_nod* relation_node);
Jrd::dsql_nod* PASS1_node(Jrd::CompiledStatement*, Jrd::dsql_nod*);
Jrd::dsql_nod* PASS1_rse(Jrd::CompiledStatement*, Jrd::dsql_nod*, Jrd::dsql_nod*);
Jrd::dsql_nod* PASS1_statement(Jrd::CompiledStatement*, Jrd::dsql_nod*);
#endif // DSQL_PASS1_PROTO_H

View File

@ -1082,12 +1082,12 @@ static void xsqlvar_to_sqlvar(const XSQLVAR* xsqlvar, SQLVAR* sqlvar)
UCHAR DSqlDataTypeUtil::maxBytesPerChar(UCHAR charSet)
{
return METD_get_charset_bpc(request, charSet);
return METD_get_charset_bpc(statement, charSet);
}
USHORT DSqlDataTypeUtil::getDialect() const
{
return request->req_client_dialect;
return statement->req_client_dialect;
}
#endif

View File

@ -46,13 +46,13 @@ SCHAR* UTLD_skip_sql_info(SCHAR*);
namespace Jrd {
class dsql_req;
class CompiledStatement;
class DSqlDataTypeUtil : public DataTypeUtilBase
{
public:
explicit DSqlDataTypeUtil(dsql_req* req)
: request(req)
explicit DSqlDataTypeUtil(CompiledStatement* aStatement)
: statement(aStatement)
{
}
@ -61,7 +61,7 @@ namespace Jrd {
virtual USHORT getDialect() const;
private:
dsql_req* request;
CompiledStatement* statement;
};
} // namespace