2001-05-23 15:26:42 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: Dynamic SQL runtime support
|
2003-10-05 08:27:16 +02:00
|
|
|
* MODULE: gen.cpp
|
2001-05-23 15:26:42 +02:00
|
|
|
* DESCRIPTION: Routines to generate BLR.
|
|
|
|
*
|
|
|
|
* 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.
|
2002-06-29 08:56:51 +02:00
|
|
|
* Contributor(s): ______________________________________
|
|
|
|
* 2001.6.21 Claudio Valderrama: BREAK and SUBSTRING.
|
2002-09-28 16:04:35 +02:00
|
|
|
* 2001.07.28 John Bellardo: Added code to generate blr_skip.
|
|
|
|
* 2002.07.30 Arno Brinkman: Added code, procedures to generate COALESCE, CASE
|
|
|
|
* 2002.09.28 Dmitry Yemanov: Reworked internal_info stuff, enhanced
|
|
|
|
* exception handling in SPs/triggers,
|
|
|
|
* implemented ROWS_AFFECTED system variable
|
2002-10-29 21:20:44 +01:00
|
|
|
* 2002.10.21 Nickolay Samofatov: Added support for explicit pessimistic locks
|
|
|
|
* 2002.10.29 Nickolay Samofatov: Added support for savepoints
|
2003-11-02 13:28:30 +01:00
|
|
|
* 2003.10.05 Dmitry Yemanov: Added support for explicit cursors in PSQL
|
2008-09-27 11:51:53 +02:00
|
|
|
* 2004.01.16 Vlad Horsun: Added support for default parameters and
|
2004-01-16 11:43:21 +01:00
|
|
|
* EXECUTE BLOCK statement
|
2007-04-13 03:37:44 +02:00
|
|
|
* Adriano dos Santos Fernandes
|
2001-05-23 15:26:42 +02:00
|
|
|
*/
|
|
|
|
|
2001-07-30 01:43:24 +02:00
|
|
|
#include "firebird.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "../dsql/dsql.h"
|
2008-02-28 14:48:16 +01:00
|
|
|
#include "../dsql/node.h"
|
2009-10-21 02:42:38 +02:00
|
|
|
#include "../dsql/DdlNodes.h"
|
2008-05-19 15:47:48 +02:00
|
|
|
#include "../dsql/StmtNodes.h"
|
2003-11-08 00:27:24 +01:00
|
|
|
#include "../jrd/ibase.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../jrd/align.h"
|
2005-05-28 00:45:31 +02:00
|
|
|
#include "../jrd/constants.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../jrd/intl.h"
|
2008-02-28 14:48:16 +01:00
|
|
|
#include "../jrd/jrd.h"
|
2006-07-20 11:57:04 +02:00
|
|
|
#include "../jrd/val.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../dsql/ddl_proto.h"
|
|
|
|
#include "../dsql/errd_proto.h"
|
|
|
|
#include "../dsql/gen_proto.h"
|
|
|
|
#include "../dsql/make_proto.h"
|
|
|
|
#include "../dsql/metd_proto.h"
|
2002-09-28 16:04:35 +02:00
|
|
|
#include "../dsql/misc_func.h"
|
2005-06-10 04:03:08 +02:00
|
|
|
#include "../dsql/utld_proto.h"
|
2005-05-28 00:45:31 +02:00
|
|
|
#include "../jrd/thread_proto.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../jrd/dsc_proto.h"
|
2005-08-21 17:52:30 +02:00
|
|
|
#include "../jrd/why_proto.h"
|
2001-07-30 01:43:24 +02:00
|
|
|
#include "gen/iberror.h"
|
2008-08-15 13:21:47 +02:00
|
|
|
#include "../common/StatusArg.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-02-28 14:48:16 +01:00
|
|
|
using namespace Jrd;
|
|
|
|
using namespace Dsql;
|
2008-08-15 13:21:47 +02:00
|
|
|
using namespace Firebird;
|
2008-02-28 14:48:16 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_aggregate(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_cast(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_coalesce(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_constant(DsqlCompilerScratch*, const dsc*, bool);
|
|
|
|
static void gen_constant(DsqlCompilerScratch*, dsql_nod*, bool);
|
|
|
|
static void gen_error_condition(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_exec_stmt(DsqlCompilerScratch* dsqlScratch, const dsql_nod* node);
|
|
|
|
static void gen_field(DsqlCompilerScratch*, const dsql_ctx*, const dsql_fld*, dsql_nod*);
|
|
|
|
static void gen_for_select(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_gen_id(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_join_rse(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_map(DsqlCompilerScratch*, dsql_map*);
|
|
|
|
static inline void gen_optional_expr(DsqlCompilerScratch*, const UCHAR code, dsql_nod*);
|
|
|
|
static void gen_parameter(DsqlCompilerScratch*, const dsql_par*);
|
|
|
|
static void gen_plan(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_relation(DsqlCompilerScratch*, dsql_ctx*);
|
|
|
|
static void gen_rse(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_searched_case(DsqlCompilerScratch*, const dsql_nod*);
|
2009-12-21 15:20:26 +01:00
|
|
|
static void gen_select(DsqlCompilerScratch*, dsql_nod*);
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_simple_case(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_sort(DsqlCompilerScratch*, dsql_nod*);
|
|
|
|
static void gen_statement(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_sys_function(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_table_lock(DsqlCompilerScratch*, const dsql_nod*, USHORT);
|
|
|
|
static void gen_udf(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void gen_union(DsqlCompilerScratch*, const dsql_nod*);
|
|
|
|
static void stuff_context(DsqlCompiledStatement*, const dsql_ctx*);
|
|
|
|
static void stuff_meta_string(DsqlCompiledStatement*, const char*);
|
|
|
|
static void stuff_word(DsqlCompiledStatement*, USHORT);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-09-27 11:51:53 +02:00
|
|
|
// STUFF is defined in dsql.h for use in common with ddl.c
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-09-27 11:51:53 +02:00
|
|
|
// The following are passed as the third argument to gen_constant
|
2003-09-28 02:36:28 +02:00
|
|
|
const bool NEGATE_VALUE = true;
|
|
|
|
const bool USE_VALUE = false;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-02-12 20:28:13 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
void GEN_hidden_variables(DsqlCompilerScratch* dsqlScratch, bool inExpression)
|
2008-08-15 18:32:42 +02:00
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* G E N _ h i d d e n _ v a r i a b l e s
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Function
|
|
|
|
* Emit BLR for hidden variables.
|
|
|
|
*
|
|
|
|
**************************************/
|
2009-12-20 22:01:10 +01:00
|
|
|
if (dsqlScratch->hiddenVars.isEmpty())
|
2008-09-01 15:18:02 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (inExpression)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_stmt_expr);
|
|
|
|
if (dsqlScratch->hiddenVars.getCount() > 1)
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_begin);
|
2008-09-01 15:18:02 +02:00
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
for (DsqlNodStack::const_iterator i(dsqlScratch->hiddenVars); i.hasData(); ++i)
|
2008-08-15 18:32:42 +02:00
|
|
|
{
|
2008-09-03 14:18:59 +02:00
|
|
|
const dsql_nod* varNode = i.object()->nod_arg[1];
|
|
|
|
const dsql_var* var = (dsql_var*) varNode->nod_arg[e_var_variable];
|
2009-12-20 22:01:10 +01:00
|
|
|
dsqlScratch->getStatement()->append_uchar(blr_dcl_variable);
|
|
|
|
dsqlScratch->getStatement()->append_ushort(var->var_variable_number);
|
|
|
|
GEN_descriptor(dsqlScratch, &varNode->nod_desc, true);
|
2008-08-15 18:32:42 +02:00
|
|
|
}
|
2008-09-01 15:18:02 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
if (inExpression && dsqlScratch->hiddenVars.getCount() > 1)
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2008-09-01 15:18:02 +02:00
|
|
|
|
|
|
|
// Clear it for GEN_expr not regenerate them.
|
2009-12-20 22:01:10 +01:00
|
|
|
dsqlScratch->hiddenVars.clear();
|
2008-08-15 18:32:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
GEN_expr
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate blr for an arbitrary expression.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
void GEN_expr(DsqlCompilerScratch* dsqlScratch, dsql_nod* node)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
UCHAR blr_operator;
|
2008-07-02 11:46:44 +02:00
|
|
|
const dsql_ctx* context;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-01-06 06:53:34 +01:00
|
|
|
switch (node->nod_type)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_alias:
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_alias_value]);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_aggregate:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_aggregate(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_constant:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_constant(dsqlScratch, node, USE_VALUE);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
2003-09-04 17:02:22 +02:00
|
|
|
case nod_derived_field:
|
2008-09-07 21:44:48 +02:00
|
|
|
// ASF: If we are not referencing a field, we should evaluate the expression based on
|
|
|
|
// a set (ORed) of contexts. If any of them are in a valid position the expression is
|
|
|
|
// evaluated, otherwise a NULL will be returned. This is fix for CORE-1246.
|
2009-11-15 00:58:17 +01:00
|
|
|
if (node->nod_arg[e_derived_field_value]->nod_type != nod_derived_field &&
|
|
|
|
node->nod_arg[e_derived_field_value]->nod_type != nod_field &&
|
2008-09-07 21:44:48 +02:00
|
|
|
node->nod_arg[e_derived_field_value]->nod_type != nod_dbkey &&
|
|
|
|
node->nod_arg[e_derived_field_value]->nod_type != nod_map)
|
|
|
|
{
|
2009-01-07 10:30:57 +01:00
|
|
|
const dsql_ctx* ctx = (dsql_ctx*) node->nod_arg[e_derived_field_context];
|
2008-09-07 21:44:48 +02:00
|
|
|
|
|
|
|
if (ctx->ctx_main_derived_contexts.hasData())
|
|
|
|
{
|
|
|
|
if (ctx->ctx_main_derived_contexts.getCount() > MAX_UCHAR)
|
|
|
|
{
|
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-204) <<
|
|
|
|
Arg::Gds(isc_imp_exc) <<
|
|
|
|
Arg::Gds(isc_ctx_too_big));
|
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_derived_expr);
|
|
|
|
stuff(dsqlScratch->getStatement(), ctx->ctx_main_derived_contexts.getCount());
|
2008-09-07 21:44:48 +02:00
|
|
|
|
2009-01-07 10:30:57 +01:00
|
|
|
for (DsqlContextStack::const_iterator stack(ctx->ctx_main_derived_contexts);
|
2008-09-07 21:44:48 +02:00
|
|
|
stack.hasData(); ++stack)
|
|
|
|
{
|
2008-10-04 04:48:35 +02:00
|
|
|
fb_assert(stack.object()->ctx_context <= MAX_UCHAR);
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), stack.object()->ctx_context);
|
2008-09-07 21:44:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_derived_field_value]);
|
2003-09-04 17:02:22 +02:00
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_extract:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_extract);
|
|
|
|
stuff(dsqlScratch->getStatement(), node->nod_arg[e_extract_part]->getSlong());
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_extract_value]);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
2005-06-06 20:14:10 +02:00
|
|
|
case nod_strlen:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_strlen);
|
|
|
|
stuff(dsqlScratch->getStatement(), node->nod_arg[e_strlen_type]->getSlong());
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_strlen_value]);
|
2005-05-28 00:45:31 +02:00
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_dbkey:
|
|
|
|
node = node->nod_arg[0];
|
2003-11-01 11:26:43 +01:00
|
|
|
context = (dsql_ctx*) node->nod_arg[e_rel_context];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_dbkey);
|
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_rec_version:
|
|
|
|
node = node->nod_arg[0];
|
2003-11-01 11:26:43 +01:00
|
|
|
context = (dsql_ctx*) node->nod_arg[e_rel_context];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_record_version);
|
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_dom_value:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_fid);
|
|
|
|
stuff(dsqlScratch->getStatement(), 0); // Context
|
|
|
|
stuff_word(dsqlScratch->getStatement(), 0); // Field id
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_field:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_field(dsqlScratch,
|
2003-11-01 11:26:43 +01:00
|
|
|
(dsql_ctx*) node->nod_arg[e_fld_context],
|
|
|
|
(dsql_fld*) node->nod_arg[e_fld_field],
|
2001-05-23 15:26:42 +02:00
|
|
|
node->nod_arg[e_fld_indices]);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_user_name:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_user_name);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_current_time:
|
2009-11-16 10:18:24 +01:00
|
|
|
if (node->nod_arg[0])
|
|
|
|
{
|
2005-08-24 11:22:40 +02:00
|
|
|
const dsql_nod* const_node = node->nod_arg[0];
|
|
|
|
fb_assert(const_node->nod_type == nod_constant);
|
2007-10-19 13:51:58 +02:00
|
|
|
const int precision = (int) const_node->getSlong();
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_current_time2);
|
|
|
|
stuff(dsqlScratch->getStatement(), precision);
|
2005-08-24 11:22:40 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_current_time);
|
2005-08-24 11:22:40 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_current_timestamp:
|
2009-11-16 10:18:24 +01:00
|
|
|
if (node->nod_arg[0])
|
|
|
|
{
|
2005-08-24 11:22:40 +02:00
|
|
|
const dsql_nod* const_node = node->nod_arg[0];
|
|
|
|
fb_assert(const_node->nod_type == nod_constant);
|
2007-10-19 13:51:58 +02:00
|
|
|
const int precision = (int) const_node->getSlong();
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_current_timestamp2);
|
|
|
|
stuff(dsqlScratch->getStatement(), precision);
|
2005-08-24 11:22:40 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_current_timestamp);
|
2005-08-24 11:22:40 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_current_date:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_current_date);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
2007-04-12 17:56:34 +02:00
|
|
|
case nod_current_role:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_current_role);
|
2007-04-12 17:56:34 +02:00
|
|
|
return;
|
2002-06-29 08:56:51 +02:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_udf:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_udf(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
2007-04-12 17:56:34 +02:00
|
|
|
case nod_sys_function:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_sys_function(dsqlScratch, node);
|
2007-04-12 17:56:34 +02:00
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_variable:
|
2008-07-02 11:46:44 +02:00
|
|
|
{
|
|
|
|
const dsql_var* variable = (dsql_var*) node->nod_arg[e_var_variable];
|
2009-11-16 10:18:24 +01:00
|
|
|
if (variable->var_type == VAR_input)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_parameter2);
|
|
|
|
stuff(dsqlScratch->getStatement(), variable->var_msg_number);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), variable->var_msg_item);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), variable->var_msg_item + 1);
|
2008-07-02 11:46:44 +02:00
|
|
|
}
|
2009-11-16 10:18:24 +01:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_variable);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), variable->var_variable_number);
|
2008-07-02 11:46:44 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_join:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_join_rse(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_map:
|
2008-07-02 11:46:44 +02:00
|
|
|
{
|
|
|
|
const dsql_map* map = (dsql_map*) node->nod_arg[e_map_map];
|
|
|
|
context = (dsql_ctx*) node->nod_arg[e_map_context];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_fid);
|
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), map->map_position);
|
2008-07-02 11:46:44 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_parameter:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_parameter(dsqlScratch, (dsql_par*) node->nod_arg[e_par_parameter]);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_relation:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_relation(dsqlScratch, (dsql_ctx*) node->nod_arg[e_rel_context]);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_rse:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_rse(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
2003-08-15 01:34:37 +02:00
|
|
|
case nod_derived_table:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_rse(dsqlScratch, node->nod_arg[e_derived_table_rse]);
|
2003-08-15 01:34:37 +02:00
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_exists:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_any);
|
|
|
|
gen_rse(dsqlScratch, node->nod_arg[0]);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_singular:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_unique);
|
|
|
|
gen_rse(dsqlScratch, node->nod_arg[0]);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_agg_count:
|
2005-09-10 09:15:24 +02:00
|
|
|
if (node->nod_count)
|
|
|
|
blr_operator = (node->nod_flags & NOD_AGG_DISTINCT) ?
|
|
|
|
blr_agg_count_distinct : blr_agg_count2;
|
2001-05-23 15:26:42 +02:00
|
|
|
else
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_agg_count;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_agg_min:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_agg_min;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_agg_max:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_agg_max;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
case nod_window:
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[0]);
|
2009-10-21 02:42:38 +02:00
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_agg_average:
|
2005-09-10 09:15:24 +02:00
|
|
|
blr_operator = (node->nod_flags & NOD_AGG_DISTINCT) ?
|
|
|
|
blr_agg_average_distinct : blr_agg_average;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_agg_total:
|
2009-01-07 10:30:57 +01:00
|
|
|
blr_operator = (node->nod_flags & NOD_AGG_DISTINCT) ? blr_agg_total_distinct : blr_agg_total;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_agg_average2:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = (node->nod_flags & NOD_AGG_DISTINCT) ?
|
2001-05-23 15:26:42 +02:00
|
|
|
blr_agg_average_distinct : blr_agg_average;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_agg_total2:
|
2009-01-07 10:30:57 +01:00
|
|
|
blr_operator = (node->nod_flags & NOD_AGG_DISTINCT) ? blr_agg_total_distinct : blr_agg_total;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
2006-04-24 19:24:26 +02:00
|
|
|
case nod_agg_list:
|
2009-01-07 10:30:57 +01:00
|
|
|
blr_operator = (node->nod_flags & NOD_AGG_DISTINCT) ? blr_agg_list_distinct : blr_agg_list;
|
2006-04-24 19:24:26 +02:00
|
|
|
break;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_and:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_and;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_or:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_or;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_not:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_not;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_eql_all:
|
|
|
|
case nod_eql_any:
|
|
|
|
case nod_eql:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_eql;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
2004-10-14 20:54:54 +02:00
|
|
|
case nod_equiv:
|
|
|
|
blr_operator = blr_equiv;
|
|
|
|
break;
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_neq_all:
|
|
|
|
case nod_neq_any:
|
|
|
|
case nod_neq:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_neq;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_gtr_all:
|
|
|
|
case nod_gtr_any:
|
|
|
|
case nod_gtr:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_gtr;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_leq_all:
|
|
|
|
case nod_leq_any:
|
|
|
|
case nod_leq:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_leq;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_geq_all:
|
|
|
|
case nod_geq_any:
|
|
|
|
case nod_geq:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_geq;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_lss_all:
|
|
|
|
case nod_lss_any:
|
|
|
|
case nod_lss:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_lss;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_between:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_between;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_containing:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_containing;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
2008-01-16 07:52:43 +01:00
|
|
|
case nod_similar:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_similar);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_similar_value]);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_similar_pattern]);
|
2008-01-16 07:52:43 +01:00
|
|
|
|
|
|
|
if (node->nod_arg[e_similar_escape])
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), 1);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_similar_escape]);
|
2008-01-16 07:52:43 +01:00
|
|
|
}
|
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), 0);
|
2008-01-16 07:52:43 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_starting:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_starting;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_missing:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_missing;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_like:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = (node->nod_count == 2) ? blr_like : blr_ansi_like;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_add:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_add;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_subtract:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_subtract;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_multiply:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_multiply;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_negate:
|
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* child = node->nod_arg[0];
|
2009-01-06 06:53:34 +01:00
|
|
|
if (child->nod_type == nod_constant && DTYPE_IS_NUMERIC(child->nod_desc.dsc_dtype))
|
2005-11-17 05:22:10 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_constant(dsqlScratch, child, NEGATE_VALUE);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_negate;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_divide:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_divide;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_add2:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_add;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_subtract2:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_subtract;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_multiply2:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_multiply;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_divide2:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_divide;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_concatenate:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_concatenate;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_null:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_null;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_any:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_any;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_ansi_any:
|
2006-04-24 19:24:26 +02:00
|
|
|
blr_operator = blr_ansi_any;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_ansi_all:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_ansi_all;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
case nod_via:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_via;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
2002-06-14 14:07:20 +02:00
|
|
|
case nod_internal_info:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_internal_info;
|
2002-06-14 14:07:20 +02:00
|
|
|
break;
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_upcase:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_upcase;
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
2005-05-28 00:45:31 +02:00
|
|
|
case nod_lowcase:
|
|
|
|
blr_operator = blr_lowcase;
|
|
|
|
break;
|
2008-09-27 11:51:53 +02:00
|
|
|
case nod_substr:
|
2003-11-01 11:26:43 +01:00
|
|
|
blr_operator = blr_substring;
|
2002-06-29 08:56:51 +02:00
|
|
|
break;
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_cast:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_cast(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
case nod_gen_id:
|
|
|
|
case nod_gen_id2:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_gen_id(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
2008-09-27 11:51:53 +02:00
|
|
|
case nod_coalesce:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_coalesce(dsqlScratch, node);
|
2002-08-03 17:27:20 +02:00
|
|
|
return;
|
2008-09-27 11:51:53 +02:00
|
|
|
case nod_simple_case:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_simple_case(dsqlScratch, node);
|
2002-08-03 17:27:20 +02:00
|
|
|
return;
|
2008-09-27 11:51:53 +02:00
|
|
|
case nod_searched_case:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_searched_case(dsqlScratch, node);
|
2002-08-03 17:27:20 +02:00
|
|
|
return;
|
2008-07-03 09:12:36 +02:00
|
|
|
|
2005-05-28 00:45:31 +02:00
|
|
|
case nod_trim:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_trim);
|
|
|
|
stuff(dsqlScratch->getStatement(), node->nod_arg[e_trim_specification]->getSlong());
|
2005-05-28 00:45:31 +02:00
|
|
|
|
|
|
|
if (node->nod_arg[e_trim_characters])
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_trim_characters);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_trim_characters]);
|
2005-05-28 00:45:31 +02:00
|
|
|
}
|
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_trim_spaces);
|
2005-05-28 00:45:31 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_trim_value]);
|
2005-05-28 00:45:31 +02:00
|
|
|
return;
|
|
|
|
|
2008-08-20 03:54:45 +02:00
|
|
|
case nod_assign:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_assignment);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[0]);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[1]);
|
2008-08-20 03:54:45 +02:00
|
|
|
return;
|
|
|
|
|
2008-09-01 15:18:02 +02:00
|
|
|
case nod_hidden_var:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_stmt_expr);
|
2008-09-01 15:18:02 +02:00
|
|
|
|
|
|
|
// If it was not pre-declared, declare it now.
|
2009-12-20 22:01:10 +01:00
|
|
|
if (dsqlScratch->hiddenVars.hasData())
|
2008-09-01 15:18:02 +02:00
|
|
|
{
|
2008-09-03 14:18:59 +02:00
|
|
|
const dsql_var* var = (dsql_var*) node->nod_arg[e_hidden_var_var]->nod_arg[e_var_variable];
|
2008-09-01 15:18:02 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_begin);
|
|
|
|
dsqlScratch->getStatement()->append_uchar(blr_dcl_variable);
|
|
|
|
dsqlScratch->getStatement()->append_ushort(var->var_variable_number);
|
|
|
|
GEN_descriptor(dsqlScratch, &node->nod_arg[e_hidden_var_var]->nod_desc, true);
|
2008-09-01 15:18:02 +02:00
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_assignment);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_hidden_var_expr]);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_hidden_var_var]);
|
2008-09-01 15:18:02 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
if (dsqlScratch->hiddenVars.hasData())
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2008-09-01 15:18:02 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_hidden_var_var]);
|
2008-09-01 15:18:02 +02:00
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
default:
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-901) <<
|
|
|
|
Arg::Gds(isc_dsql_internal_err) <<
|
2008-09-27 11:51:53 +02:00
|
|
|
// expression evaluation not supported
|
|
|
|
Arg::Gds(isc_expression_eval_err) <<
|
|
|
|
Arg::Gds(isc_dsql_eval_unknode) << Arg::Num(node->nod_type));
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_operator);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* const* ptr = node->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + node->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr);
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// Check whether the node we just processed is for a dialect 3
|
|
|
|
// operation which gives a different result than the corresponding
|
|
|
|
// operation in dialect 1. If it is, and if the client dialect is 2,
|
|
|
|
// issue a warning about the difference.
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-01-06 06:53:34 +01:00
|
|
|
switch (node->nod_type)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-01-06 06:53:34 +01:00
|
|
|
case nod_add2:
|
|
|
|
case nod_subtract2:
|
|
|
|
case nod_multiply2:
|
|
|
|
case nod_divide2:
|
|
|
|
case nod_agg_total2:
|
|
|
|
case nod_agg_average2:
|
2003-11-01 11:26:43 +01:00
|
|
|
dsc desc;
|
2009-12-20 22:01:10 +01:00
|
|
|
MAKE_desc(dsqlScratch, &desc, node, NULL);
|
2008-07-03 09:12:36 +02:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
if ((node->nod_flags & NOD_COMP_DIALECT) &&
|
2009-12-20 22:01:10 +01:00
|
|
|
(dsqlScratch->clientDialect == SQL_DIALECT_V6_TRANSITION))
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2008-07-03 09:12:36 +02:00
|
|
|
const char* s = 0;
|
|
|
|
char message_buf[8];
|
|
|
|
|
|
|
|
switch (node->nod_type)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_add2:
|
|
|
|
s = "add";
|
|
|
|
break;
|
|
|
|
case nod_subtract2:
|
|
|
|
s = "subtract";
|
|
|
|
break;
|
|
|
|
case nod_multiply2:
|
|
|
|
s = "multiply";
|
|
|
|
break;
|
|
|
|
case nod_divide2:
|
|
|
|
s = "divide";
|
|
|
|
break;
|
|
|
|
case nod_agg_total2:
|
|
|
|
s = "sum";
|
|
|
|
break;
|
|
|
|
case nod_agg_average2:
|
|
|
|
s = "avg";
|
|
|
|
break;
|
|
|
|
default:
|
2003-11-01 11:26:43 +01:00
|
|
|
sprintf(message_buf, "blr %d", (int) blr_operator);
|
2001-05-23 15:26:42 +02:00
|
|
|
s = message_buf;
|
|
|
|
}
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post_warning(Arg::Warning(isc_dsql_dialect_warning_expr) << Arg::Str(s));
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
GEN_port
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate a port from a message. Feel free to rearrange the
|
|
|
|
order of parameters.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param message
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
void GEN_port(DsqlCompilerScratch* dsqlScratch, dsql_msg* message)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2008-02-28 14:48:16 +01:00
|
|
|
thread_db* tdbb = JRD_get_thread_data();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
// if (dsqlScratch->req_blr_string) {
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_message);
|
|
|
|
stuff(dsqlScratch->getStatement(), message->msg_number);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), message->msg_parameter);
|
2004-04-18 16:22:27 +02:00
|
|
|
// }
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2006-07-20 11:57:04 +02:00
|
|
|
ULONG offset = 0;
|
2009-12-19 19:50:38 +01:00
|
|
|
|
|
|
|
for (size_t i = 0; i < message->msg_parameters.getCount(); ++i)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-19 19:50:38 +01:00
|
|
|
dsql_par* parameter = message->msg_parameters[i];
|
|
|
|
|
|
|
|
parameter->par_parameter = (USHORT) i;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2007-07-08 10:43:30 +02:00
|
|
|
const USHORT fromCharSet = parameter->par_desc.getCharSet();
|
|
|
|
const USHORT toCharSet = (fromCharSet == CS_NONE || fromCharSet == CS_BINARY) ?
|
2009-10-21 02:42:38 +02:00
|
|
|
fromCharSet : tdbb->getCharSet();
|
2007-06-28 17:27:28 +02:00
|
|
|
|
|
|
|
if (parameter->par_desc.dsc_dtype <= dtype_any_text &&
|
2009-10-21 02:42:38 +02:00
|
|
|
tdbb->getCharSet() != CS_NONE && tdbb->getCharSet() != CS_BINARY)
|
2005-05-28 00:45:31 +02:00
|
|
|
{
|
2005-06-06 10:30:03 +02:00
|
|
|
USHORT adjust = 0;
|
2005-05-28 00:45:31 +02:00
|
|
|
if (parameter->par_desc.dsc_dtype == dtype_varying)
|
2005-06-06 10:30:03 +02:00
|
|
|
adjust = sizeof(USHORT);
|
2005-05-28 00:45:31 +02:00
|
|
|
else if (parameter->par_desc.dsc_dtype == dtype_cstring)
|
2005-06-06 10:30:03 +02:00
|
|
|
adjust = 1;
|
|
|
|
|
|
|
|
parameter->par_desc.dsc_length -= adjust;
|
2005-05-28 00:45:31 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
const USHORT fromCharSetBPC = METD_get_charset_bpc(dsqlScratch->getTransaction(), fromCharSet);
|
|
|
|
const USHORT toCharSetBPC = METD_get_charset_bpc(dsqlScratch->getTransaction(), toCharSet);
|
2005-05-28 00:45:31 +02:00
|
|
|
|
2009-11-28 20:39:23 +01:00
|
|
|
parameter->par_desc.setTextType(INTL_CS_COLL_TO_TTYPE(toCharSet,
|
2006-01-15 19:11:31 +01:00
|
|
|
(fromCharSet == toCharSet ? INTL_GET_COLLATE(¶meter->par_desc) : 0)));
|
|
|
|
|
2005-05-28 00:45:31 +02:00
|
|
|
parameter->par_desc.dsc_length =
|
2005-06-10 04:03:08 +02:00
|
|
|
UTLD_char_length_to_byte_length(parameter->par_desc.dsc_length / fromCharSetBPC, toCharSetBPC);
|
2005-05-28 00:45:31 +02:00
|
|
|
|
2005-06-06 10:30:03 +02:00
|
|
|
parameter->par_desc.dsc_length += adjust;
|
2005-05-28 00:45:31 +02:00
|
|
|
}
|
2009-11-27 03:33:40 +01:00
|
|
|
else if (parameter->par_desc.dsc_dtype == dtype_blob &&
|
2007-07-08 10:43:30 +02:00
|
|
|
parameter->par_desc.dsc_sub_type == isc_blob_text &&
|
2009-10-21 02:42:38 +02:00
|
|
|
tdbb->getCharSet() != CS_NONE && tdbb->getCharSet() != CS_BINARY)
|
2007-06-28 17:27:28 +02:00
|
|
|
{
|
|
|
|
if (fromCharSet != toCharSet)
|
|
|
|
parameter->par_desc.setTextType(toCharSet);
|
|
|
|
}
|
2005-05-28 00:45:31 +02:00
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// For older clients - generate an error should they try and
|
|
|
|
// access data types which did not exist in the older dialect
|
2009-12-20 22:01:10 +01:00
|
|
|
if (dsqlScratch->clientDialect <= SQL_DIALECT_V5)
|
2009-12-19 19:50:38 +01:00
|
|
|
{
|
2009-01-06 06:53:34 +01:00
|
|
|
switch (parameter->par_desc.dsc_dtype)
|
|
|
|
{
|
2009-04-18 16:13:26 +02:00
|
|
|
// In V6.0 - older clients, which we distinguish by
|
|
|
|
// their use of SQL DIALECT 0 or 1, are forbidden
|
|
|
|
// from selecting values of new datatypes
|
2003-02-10 20:57:57 +01:00
|
|
|
case dtype_sql_date:
|
|
|
|
case dtype_sql_time:
|
|
|
|
case dtype_int64:
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-804) <<
|
|
|
|
Arg::Gds(isc_dsql_datatype_err) <<
|
2009-01-06 06:53:34 +01:00
|
|
|
Arg::Gds(isc_sql_dialect_datatype_unsupport) <<
|
2009-12-20 22:01:10 +01:00
|
|
|
Arg::Num(dsqlScratch->clientDialect) <<
|
2009-01-06 06:53:34 +01:00
|
|
|
Arg::Str(DSC_dtype_tostring(parameter->par_desc.dsc_dtype)));
|
2003-02-10 20:57:57 +01:00
|
|
|
break;
|
|
|
|
default:
|
2008-09-27 11:51:53 +02:00
|
|
|
// No special action for other data types
|
2003-02-10 20:57:57 +01:00
|
|
|
break;
|
2004-11-07 11:38:13 +01:00
|
|
|
}
|
2009-12-19 19:50:38 +01:00
|
|
|
}
|
2009-01-07 10:30:57 +01:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
const USHORT align = type_alignments[parameter->par_desc.dsc_dtype];
|
2001-05-23 15:26:42 +02:00
|
|
|
if (align)
|
2006-07-20 11:57:04 +02:00
|
|
|
offset = FB_ALIGN(offset, align);
|
|
|
|
parameter->par_desc.dsc_address = (UCHAR*)(IPTR) offset;
|
|
|
|
offset += parameter->par_desc.dsc_length;
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_descriptor(dsqlScratch, ¶meter->par_desc, false);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
if (offset > MAX_FORMAT_SIZE)
|
|
|
|
{
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-204) <<
|
|
|
|
Arg::Gds(isc_imp_exc) <<
|
|
|
|
Arg::Gds(isc_blktoobig));
|
2006-07-20 11:57:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
message->msg_length = (USHORT) offset;
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
dsqlScratch->ports.add(message);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
GEN_request
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@brief Generate complete blr for a dsqlScratch.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
void GEN_request(dsql_req* request, DsqlCompilerScratch* scratch, dsql_nod* node)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
thread_db* tdbb = JRD_get_thread_data();
|
|
|
|
|
2009-12-20 23:42:43 +01:00
|
|
|
DsqlCompiledStatement* statement = scratch->getStatement();
|
2009-12-20 22:01:10 +01:00
|
|
|
|
2009-12-20 23:42:43 +01:00
|
|
|
if (statement->type == REQ_CREATE_DB || statement->type == REQ_DDL)
|
2008-02-28 14:48:16 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
DDL_generate(scratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-20 23:42:43 +01:00
|
|
|
if (statement->flags & DsqlCompiledStatement::FLAG_BLR_VERSION4)
|
|
|
|
stuff(statement, blr_version4);
|
2001-05-23 15:26:42 +02:00
|
|
|
else
|
2009-12-20 23:42:43 +01:00
|
|
|
stuff(statement, blr_version5);
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2009-12-20 23:42:43 +01:00
|
|
|
if (statement->type == REQ_SAVEPOINT)
|
2002-10-29 21:20:44 +01:00
|
|
|
{
|
2009-12-20 23:42:43 +01:00
|
|
|
// Do not generate BEGIN..END block around savepoint statement
|
2002-10-29 21:20:44 +01:00
|
|
|
// to avoid breaking of savepoint logic
|
2009-12-20 23:42:43 +01:00
|
|
|
statement->sendMsg = NULL;
|
|
|
|
statement->receiveMsg = NULL;
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_statement(scratch, node);
|
2008-09-27 11:51:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-20 23:42:43 +01:00
|
|
|
stuff(statement, blr_begin);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_hidden_variables(scratch, false);
|
2008-08-15 18:32:42 +02:00
|
|
|
|
2009-12-20 23:42:43 +01:00
|
|
|
switch (statement->type)
|
2004-10-26 09:21:47 +02:00
|
|
|
{
|
2008-01-16 07:52:43 +01:00
|
|
|
case REQ_SELECT:
|
|
|
|
case REQ_SELECT_UPD:
|
2009-12-21 15:20:26 +01:00
|
|
|
gen_select(scratch, node);
|
2008-01-16 07:52:43 +01:00
|
|
|
break;
|
|
|
|
case REQ_EXEC_BLOCK:
|
|
|
|
case REQ_SELECT_BLOCK:
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_statement(scratch, node);
|
2008-01-16 07:52:43 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
2009-12-20 23:42:43 +01:00
|
|
|
dsql_msg* message = statement->sendMsg;
|
2008-01-16 07:52:43 +01:00
|
|
|
if (!message->msg_parameter)
|
2009-12-20 23:42:43 +01:00
|
|
|
statement->sendMsg = NULL;
|
2009-11-16 10:18:24 +01:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_port(scratch, message);
|
2009-12-20 23:42:43 +01:00
|
|
|
stuff(statement, blr_receive);
|
|
|
|
stuff(statement, message->msg_number);
|
2008-01-16 07:52:43 +01:00
|
|
|
}
|
2009-12-20 23:42:43 +01:00
|
|
|
message = statement->receiveMsg;
|
2008-01-16 07:52:43 +01:00
|
|
|
if (!message->msg_parameter)
|
2009-12-20 23:42:43 +01:00
|
|
|
statement->receiveMsg = NULL;
|
2008-01-16 07:52:43 +01:00
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_port(scratch, message);
|
|
|
|
GEN_statement(scratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2008-09-27 11:51:53 +02:00
|
|
|
}
|
2009-12-20 23:42:43 +01:00
|
|
|
stuff(statement, blr_end);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2009-12-20 23:42:43 +01:00
|
|
|
stuff(statement, blr_eoc);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
GEN_start_transaction
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@brief Generate tpb for set transaction. Use blr string of dsqlScratch.
|
2003-02-15 04:01:51 +01:00
|
|
|
If a value is not specified, default is not STUFF'ed, let the
|
|
|
|
engine handle it.
|
|
|
|
Do not allow an option to be specified more than once.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param tran_node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
void GEN_start_transaction( DsqlCompilerScratch* dsqlScratch, const dsql_nod* tran_node)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
SSHORT count = tran_node->nod_count;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return;
|
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_nod* node = tran_node->nod_arg[0];
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
|
2005-11-17 05:22:10 +01:00
|
|
|
// Find out isolation level - if specified. This is required for
|
|
|
|
// specifying the correct lock level in reserving clause.
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-08 00:27:24 +01:00
|
|
|
USHORT lock_level = isc_tpb_shared;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-01-07 10:30:57 +01:00
|
|
|
if (count = node->nod_count)
|
|
|
|
{
|
2009-11-16 10:18:24 +01:00
|
|
|
while (count--)
|
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_nod* ptr = node->nod_arg[count];
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-06-06 04:25:35 +02:00
|
|
|
if (!ptr || ptr->nod_type != nod_isolation)
|
2001-05-23 15:26:42 +02:00
|
|
|
continue;
|
|
|
|
|
2009-01-06 06:53:34 +01:00
|
|
|
lock_level = (ptr->nod_flags & NOD_CONSISTENCY) ? isc_tpb_protected : isc_tpb_shared;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
bool sw_access = false, sw_wait = false, sw_isolation = false,
|
2005-11-17 05:22:10 +01:00
|
|
|
sw_reserve = false, sw_lock_timeout = false;
|
|
|
|
int misc_flags = 0;
|
2003-11-01 11:26:43 +01:00
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// Stuff some version info.
|
2001-05-23 15:26:42 +02:00
|
|
|
if (count = node->nod_count)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_version1);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2005-11-17 05:22:10 +01:00
|
|
|
while (count--)
|
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_nod* ptr = node->nod_arg[count];
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
continue;
|
|
|
|
|
2009-01-06 06:53:34 +01:00
|
|
|
switch (ptr->nod_type)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_access:
|
|
|
|
if (sw_access)
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) <<
|
|
|
|
Arg::Gds(isc_dsql_dup_option));
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
sw_access = true;
|
2001-05-23 15:26:42 +02:00
|
|
|
if (ptr->nod_flags & NOD_READ_ONLY)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_read);
|
2001-05-23 15:26:42 +02:00
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_write);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_wait:
|
|
|
|
if (sw_wait)
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) <<
|
|
|
|
Arg::Gds(isc_dsql_dup_option));
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
sw_wait = true;
|
2001-05-23 15:26:42 +02:00
|
|
|
if (ptr->nod_flags & NOD_NO_WAIT)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_nowait);
|
2001-05-23 15:26:42 +02:00
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_wait);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_isolation:
|
|
|
|
if (sw_isolation)
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) <<
|
|
|
|
Arg::Gds(isc_dsql_dup_option));
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
sw_isolation = true;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
if (ptr->nod_flags & NOD_CONCURRENCY)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_concurrency);
|
2001-05-23 15:26:42 +02:00
|
|
|
else if (ptr->nod_flags & NOD_CONSISTENCY)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_consistency);
|
2009-11-16 10:18:24 +01:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_read_committed);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-01-06 06:53:34 +01:00
|
|
|
if (ptr->nod_count && ptr->nod_arg[0] && ptr->nod_arg[0]->nod_type == nod_version)
|
2004-10-26 09:21:47 +02:00
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
if (ptr->nod_arg[0]->nod_flags & NOD_VERSION)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_rec_version);
|
2001-05-23 15:26:42 +02:00
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_no_rec_version);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_no_rec_version);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_reserve:
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
|
|
|
if (sw_reserve)
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) <<
|
|
|
|
Arg::Gds(isc_dsql_dup_option));
|
2003-11-01 11:26:43 +01:00
|
|
|
|
|
|
|
sw_reserve = true;
|
|
|
|
const dsql_nod* reserve = ptr->nod_arg[0];
|
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
if (reserve)
|
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_nod* const* temp = reserve->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* end = temp + reserve->nod_count; temp < end; temp++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_table_lock(dsqlScratch, *temp, lock_level);
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-07 10:30:57 +01:00
|
|
|
break;
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2005-11-17 05:22:10 +01:00
|
|
|
case nod_tra_misc:
|
|
|
|
if (misc_flags & ptr->nod_flags)
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) <<
|
|
|
|
Arg::Gds(isc_dsql_dup_option));
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2005-11-17 05:22:10 +01:00
|
|
|
misc_flags |= ptr->nod_flags;
|
|
|
|
if (ptr->nod_flags & NOD_NO_AUTO_UNDO)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_no_auto_undo);
|
2005-11-17 05:22:10 +01:00
|
|
|
else if (ptr->nod_flags & NOD_IGNORE_LIMBO)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_ignore_limbo);
|
2005-11-17 05:22:10 +01:00
|
|
|
else if (ptr->nod_flags & NOD_RESTART_REQUESTS)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_restart_requests);
|
2005-11-17 05:22:10 +01:00
|
|
|
break;
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2005-11-17 05:22:10 +01:00
|
|
|
case nod_lock_timeout:
|
|
|
|
if (sw_lock_timeout)
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) <<
|
|
|
|
Arg::Gds(isc_dsql_dup_option));
|
2005-11-17 05:22:10 +01:00
|
|
|
|
|
|
|
sw_lock_timeout = true;
|
|
|
|
if (ptr->nod_count == 1 && ptr->nod_arg[0]->nod_type == nod_constant)
|
|
|
|
{
|
2007-10-19 13:51:58 +02:00
|
|
|
const int lck_timeout = (int) ptr->nod_arg[0]->getSlong();
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), isc_tpb_lock_timeout);
|
|
|
|
stuff(dsqlScratch->getStatement(), 2);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), lck_timeout);
|
2005-11-17 05:22:10 +01:00
|
|
|
}
|
|
|
|
break;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
default:
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) <<
|
|
|
|
Arg::Gds(isc_dsql_tran_err));
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
GEN_statement
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate blr for an arbitrary expression.
|
2006-05-31 20:02:34 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
void GEN_statement( DsqlCompilerScratch* dsqlScratch, dsql_nod* node)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* temp;
|
|
|
|
dsql_nod** ptr;
|
|
|
|
const dsql_nod* const* end;
|
2003-11-10 10:16:38 +01:00
|
|
|
dsql_str* string;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-01-06 06:53:34 +01:00
|
|
|
switch (node->nod_type)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_assign:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_assignment);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[0]);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[1]);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_block:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_block);
|
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_blk_action]);
|
2009-11-16 10:18:24 +01:00
|
|
|
if (node->nod_count > 1)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
temp = node->nod_arg[e_blk_errs];
|
2009-01-06 06:53:34 +01:00
|
|
|
for (ptr = temp->nod_arg, end = ptr + temp->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_statement(dsqlScratch, *ptr);
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
2008-05-19 15:47:48 +02:00
|
|
|
case nod_class_node:
|
2009-11-16 10:18:24 +01:00
|
|
|
{
|
|
|
|
StmtNode* stmtNode = reinterpret_cast<StmtNode*>(node->nod_arg[0]);
|
|
|
|
stmtNode->genBlr();
|
|
|
|
return;
|
|
|
|
}
|
2008-01-16 07:52:43 +01:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_for_select:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_for_select(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_set_generator:
|
|
|
|
case nod_set_generator2:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_set_generator);
|
2003-11-10 10:16:38 +01:00
|
|
|
string = (dsql_str*) node->nod_arg[e_gen_id_name];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_cstring(dsqlScratch->getStatement(), string->str_data);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_gen_id_value]);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_list:
|
2008-08-15 18:32:42 +02:00
|
|
|
if (!(node->nod_flags & NOD_SIMPLE_LIST))
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_begin);
|
2009-01-06 06:53:34 +01:00
|
|
|
for (ptr = node->nod_arg, end = ptr + node->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_statement(dsqlScratch, *ptr);
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
2008-08-15 18:32:42 +02:00
|
|
|
if (!(node->nod_flags & NOD_SIMPLE_LIST))
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
2006-05-31 20:02:34 +02:00
|
|
|
case nod_erase:
|
|
|
|
case nod_erase_current:
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_modify:
|
|
|
|
case nod_modify_current:
|
2006-05-31 20:02:34 +02:00
|
|
|
case nod_store:
|
|
|
|
case nod_exec_procedure:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_statement(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_on_error:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_error_handler);
|
2001-05-23 15:26:42 +02:00
|
|
|
temp = node->nod_arg[e_err_errs];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), temp->nod_count);
|
2009-01-06 06:53:34 +01:00
|
|
|
for (ptr = temp->nod_arg, end = ptr + temp->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_error_condition(dsqlScratch, *ptr);
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_err_action]);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
2002-04-04 15:53:20 +02:00
|
|
|
case nod_exec_sql:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_sql);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_exec_sql_stmnt]);
|
2003-03-01 20:19:23 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_exec_into:
|
2009-11-16 10:18:24 +01:00
|
|
|
if (node->nod_arg[e_exec_into_block])
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_label);
|
|
|
|
stuff(dsqlScratch->getStatement(), (int) (IPTR) node->nod_arg[e_exec_into_label]->nod_arg[e_label_number]);
|
2003-08-26 09:13:33 +02:00
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_into);
|
2003-03-01 20:19:23 +01:00
|
|
|
temp = node->nod_arg[e_exec_into_list];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), temp->nod_count);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_exec_into_stmnt]);
|
2009-11-16 10:18:24 +01:00
|
|
|
if (node->nod_arg[e_exec_into_block])
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), 0); // Non-singleton
|
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_exec_into_block]);
|
2003-03-01 20:19:23 +01:00
|
|
|
}
|
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), 1); // Singleton
|
2009-01-06 06:53:34 +01:00
|
|
|
|
|
|
|
for (ptr = temp->nod_arg, end = ptr + temp->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr);
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
2002-04-04 15:53:20 +02:00
|
|
|
return;
|
2008-04-09 22:18:47 +02:00
|
|
|
|
|
|
|
case nod_exec_stmt:
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_exec_stmt(dsqlScratch, node);
|
2008-04-09 22:18:47 +02:00
|
|
|
return;
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2006-06-02 10:03:22 +02:00
|
|
|
case nod_breakleave:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_leave);
|
|
|
|
stuff(dsqlScratch->getStatement(), (int)(IPTR) node->nod_arg[e_breakleave_label]->nod_arg[e_label_number]);
|
2009-10-21 02:42:38 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_continue:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_continue_loop);
|
|
|
|
stuff(dsqlScratch->getStatement(), (int)(IPTR) node->nod_arg[e_continue_label]->nod_arg[e_label_number]);
|
2006-06-02 10:03:22 +02:00
|
|
|
return;
|
2002-12-18 16:01:50 +01:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_abort:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_leave);
|
|
|
|
stuff(dsqlScratch->getStatement(), (int) (IPTR) node->nod_arg[e_abrt_number]);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_start_savepoint:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_start_savepoint);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_end_savepoint:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_end_savepoint);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
2003-06-10 15:40:19 +02:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_exception_stmt:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_abort);
|
2003-11-10 10:16:38 +01:00
|
|
|
string = (dsql_str*) node->nod_arg[e_xcps_name];
|
2003-10-01 20:11:23 +02:00
|
|
|
temp = node->nod_arg[e_xcps_msg];
|
2009-04-18 16:13:26 +02:00
|
|
|
// if exception name is undefined,
|
|
|
|
// it means we have re-initiate semantics here,
|
|
|
|
// so blr_raise verb should be generated
|
2002-09-28 16:04:35 +02:00
|
|
|
if (!string)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_raise);
|
2002-09-28 16:04:35 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-04-18 16:13:26 +02:00
|
|
|
// if exception value is defined,
|
|
|
|
// it means we have user-defined exception message here,
|
|
|
|
// so blr_exception_msg verb should be generated
|
2002-09-28 16:04:35 +02:00
|
|
|
if (temp)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exception_msg);
|
2002-09-28 16:04:35 +02:00
|
|
|
}
|
2009-04-18 16:13:26 +02:00
|
|
|
// otherwise go usual way,
|
|
|
|
// i.e. generate blr_exception
|
2002-09-28 16:04:35 +02:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exception);
|
2002-09-28 16:04:35 +02:00
|
|
|
}
|
2009-08-30 04:26:50 +02:00
|
|
|
if (string->type != dsql_str::TYPE_DELIMITED)
|
2002-09-28 16:04:35 +02:00
|
|
|
{
|
2008-05-25 14:16:20 +02:00
|
|
|
ULONG id_length = string->str_length;
|
|
|
|
for (TEXT* p = string->str_data; *p && id_length; ++p, --id_length)
|
2002-09-28 16:04:35 +02:00
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
*p = UPPER(*p);
|
|
|
|
}
|
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_cstring(dsqlScratch->getStatement(), string->str_data);
|
2009-04-18 16:13:26 +02:00
|
|
|
// if exception value is defined,
|
|
|
|
// generate appropriate BLR verbs
|
2002-09-28 16:04:35 +02:00
|
|
|
if (temp)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, temp);
|
2002-09-28 16:04:35 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_while:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_label);
|
|
|
|
stuff(dsqlScratch->getStatement(), (int) (IPTR) node->nod_arg[e_while_label]->nod_arg[e_label_number]);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_loop);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_begin);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_if);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_while_cond]);
|
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_while_action]);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_leave);
|
|
|
|
stuff(dsqlScratch->getStatement(), (int) (IPTR) node->nod_arg[e_while_label]->nod_arg[e_label_number]);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_sqlcode:
|
|
|
|
case nod_gdscode:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_abort);
|
|
|
|
gen_error_condition(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
2003-11-02 13:28:30 +01:00
|
|
|
case nod_cursor:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_dcl_cursor);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), (int) (IPTR) node->nod_arg[e_cur_number]);
|
2009-10-31 07:17:49 +01:00
|
|
|
if (node->nod_arg[e_cur_scroll])
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_scrollable);
|
2009-10-31 07:17:49 +01:00
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_rse(dsqlScratch, node->nod_arg[e_cur_rse]);
|
2006-03-07 18:52:33 +01:00
|
|
|
temp = node->nod_arg[e_cur_rse]->nod_arg[e_rse_items];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), temp->nod_count);
|
2006-03-07 18:52:33 +01:00
|
|
|
ptr = temp->nod_arg;
|
|
|
|
end = ptr + temp->nod_count;
|
|
|
|
while (ptr < end) {
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr++);
|
2006-03-07 18:52:33 +01:00
|
|
|
}
|
2003-11-02 13:28:30 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_cursor_open:
|
|
|
|
case nod_cursor_close:
|
|
|
|
case nod_cursor_fetch:
|
|
|
|
{
|
2009-10-31 07:17:49 +01:00
|
|
|
const dsql_nod* scroll = node->nod_arg[e_cur_stmt_scroll];
|
2008-07-03 09:12:36 +02:00
|
|
|
// op-code
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_cursor_stmt);
|
2008-07-03 09:12:36 +02:00
|
|
|
if (node->nod_type == nod_cursor_open)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_cursor_open);
|
2008-07-03 09:12:36 +02:00
|
|
|
else if (node->nod_type == nod_cursor_close)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_cursor_close);
|
2009-10-31 07:17:49 +01:00
|
|
|
else if (scroll)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_cursor_fetch_scroll);
|
2008-07-03 09:12:36 +02:00
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_cursor_fetch);
|
2008-07-03 09:12:36 +02:00
|
|
|
// cursor reference
|
|
|
|
dsql_nod* cursor = node->nod_arg[e_cur_stmt_id];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), (int) (IPTR) cursor->nod_arg[e_cur_number]);
|
2009-10-31 07:17:49 +01:00
|
|
|
// scrolling
|
|
|
|
if (scroll)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), scroll->nod_arg[0]->getSlong());
|
2009-10-31 07:17:49 +01:00
|
|
|
if (scroll->nod_arg[1])
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, scroll->nod_arg[1]);
|
2009-10-31 07:17:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_null);
|
2009-10-31 07:17:49 +01:00
|
|
|
}
|
2008-07-03 09:12:36 +02:00
|
|
|
}
|
|
|
|
// assignment
|
|
|
|
dsql_nod* list_into = node->nod_arg[e_cur_stmt_into];
|
2009-01-07 10:30:57 +01:00
|
|
|
if (list_into)
|
|
|
|
{
|
2008-07-03 09:12:36 +02:00
|
|
|
dsql_nod* list = cursor->nod_arg[e_cur_rse]->nod_arg[e_rse_items];
|
|
|
|
if (list->nod_count != list_into->nod_count)
|
2008-07-06 18:42:52 +02:00
|
|
|
{
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-313) <<
|
|
|
|
Arg::Gds(isc_dsql_count_mismatch));
|
2008-07-06 18:42:52 +02:00
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_begin);
|
2008-07-03 09:12:36 +02:00
|
|
|
ptr = list->nod_arg;
|
|
|
|
end = ptr + list->nod_count;
|
|
|
|
dsql_nod** ptr_to = list_into->nod_arg;
|
2009-11-16 10:18:24 +01:00
|
|
|
while (ptr < end)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_assignment);
|
|
|
|
GEN_expr(dsqlScratch, *ptr++);
|
|
|
|
GEN_expr(dsqlScratch, *ptr_to++);
|
2008-07-03 09:12:36 +02:00
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2003-11-02 13:28:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
2006-07-04 16:44:43 +02:00
|
|
|
case nod_src_info:
|
2009-12-20 22:01:10 +01:00
|
|
|
dsqlScratch->getStatement()->put_debug_src_info(node->nod_line, node->nod_column);
|
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_src_info_stmt]);
|
2006-07-04 16:44:43 +02:00
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
default:
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-901) <<
|
|
|
|
Arg::Gds(isc_dsql_internal_err) <<
|
|
|
|
// gen.c: node not supported
|
|
|
|
Arg::Gds(isc_node_err));
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_aggregate
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate blr for a relation reference.
|
|
|
|
|
2008-09-27 11:51:53 +02:00
|
|
|
|
|
|
|
@param
|
|
|
|
@param
|
2003-02-15 04:01:51 +01:00
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_aggregate( DsqlCompilerScratch* dsqlScratch, const dsql_nod* node)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-10-21 02:42:38 +02:00
|
|
|
dsql_ctx* context = (dsql_ctx*) node->nod_arg[e_agg_context];
|
|
|
|
bool window = (node->nod_flags & NOD_AGG_WINDOW);
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), (window ? blr_window : blr_aggregate));
|
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
|
|
|
gen_rse(dsqlScratch, node->nod_arg[e_agg_rse]);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
// Handle PARTITION BY and GROUP BY clause
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
if (window)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_partition_by);
|
|
|
|
stuff(dsqlScratch->getStatement(), 0); // partition by expression count
|
2009-10-21 02:42:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_group_by);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
dsql_nod* list = node->nod_arg[e_agg_group];
|
2009-11-16 10:18:24 +01:00
|
|
|
if (list != NULL)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), list->nod_count);
|
2009-10-21 02:42:38 +02:00
|
|
|
dsql_nod** ptr = list->nod_arg;
|
|
|
|
for (const dsql_nod* const* end = ptr + list->nod_count; ptr < end; ptr++)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr);
|
2009-10-21 02:42:38 +02:00
|
|
|
}
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
2009-10-21 02:42:38 +02:00
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// Generate value map
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_map(dsqlScratch, context->ctx_map);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_cast
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate BLR for a data-type cast operation
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_cast( DsqlCompilerScratch* dsqlScratch, const dsql_nod* node)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_cast);
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_fld* field = (dsql_fld*) node->nod_arg[e_cast_target];
|
2009-12-20 22:01:10 +01:00
|
|
|
DDL_put_field_dtype(dsqlScratch, field, true);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_cast_source]);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_coalesce
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate BLR for coalesce function
|
2003-03-31 21:11:55 +02:00
|
|
|
|
|
|
|
Generate the blr values, begin with a cast and then :
|
|
|
|
|
|
|
|
blr_value_if
|
|
|
|
blr_missing
|
|
|
|
blr for expression 1
|
|
|
|
blr_value_if
|
|
|
|
blr_missing
|
2005-06-03 23:14:35 +02:00
|
|
|
blr for expression n-1
|
|
|
|
expression n
|
2003-03-31 21:11:55 +02:00
|
|
|
blr for expression n-1
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_coalesce( DsqlCompilerScratch* dsqlScratch, const dsql_nod* node)
|
2002-08-03 17:27:20 +02:00
|
|
|
{
|
2003-03-31 21:11:55 +02:00
|
|
|
// blr_value_if is used for building the coalesce function
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* list = node->nod_arg[0];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_cast);
|
|
|
|
GEN_descriptor(dsqlScratch, &node->nod_desc, true);
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* const* ptr = list->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + (list->nod_count - 1); ptr < end; ptr++)
|
2002-08-03 17:27:20 +02:00
|
|
|
{
|
2003-03-31 21:11:55 +02:00
|
|
|
// IF (expression IS NULL) THEN
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_value_if);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_missing);
|
|
|
|
GEN_expr(dsqlScratch, *ptr);
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
2003-03-31 21:11:55 +02:00
|
|
|
// Return values
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr);
|
2003-03-31 21:11:55 +02:00
|
|
|
list = node->nod_arg[1];
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_nod* const* const begin = list->nod_arg;
|
|
|
|
ptr = list->nod_arg + list->nod_count;
|
2003-03-31 21:11:55 +02:00
|
|
|
// if all expressions are NULL return NULL
|
2003-11-01 11:26:43 +01:00
|
|
|
for (ptr--; ptr >= begin; ptr--)
|
2002-08-03 17:27:20 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr);
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_constant
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate BLR for a constant.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param desc
|
|
|
|
@param negate_value
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_constant( DsqlCompilerScratch* dsqlScratch, const dsc* desc, bool negate_value)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
SLONG value;
|
|
|
|
SINT64 i64value;
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_literal);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
const UCHAR* p = desc->dsc_address;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-01-06 06:53:34 +01:00
|
|
|
switch (desc->dsc_dtype)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
case dtype_short:
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_descriptor(dsqlScratch, desc, true);
|
2001-05-23 15:26:42 +02:00
|
|
|
value = *(SSHORT *) p;
|
|
|
|
if (negate_value)
|
|
|
|
value = -value;
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), value);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_long:
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_descriptor(dsqlScratch, desc, true);
|
2001-05-23 15:26:42 +02:00
|
|
|
value = *(SLONG *) p;
|
|
|
|
if (negate_value)
|
|
|
|
value = -value;
|
2007-10-17 16:35:31 +02:00
|
|
|
//printf("gen.cpp = %p %d\n", *((void**)p), value);
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), value);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), value >> 16);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_sql_time:
|
|
|
|
case dtype_sql_date:
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_descriptor(dsqlScratch, desc, true);
|
2001-05-23 15:26:42 +02:00
|
|
|
value = *(SLONG *) p;
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), value);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), value >> 16);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_double:
|
2008-05-25 14:16:20 +02:00
|
|
|
{
|
2009-04-18 16:13:26 +02:00
|
|
|
// this is used for approximate/large numeric literal
|
|
|
|
// which is transmitted to the engine as a string.
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_descriptor(dsqlScratch, desc, true);
|
2008-05-25 14:16:20 +02:00
|
|
|
// Length of string literal, cast because it could be > 127 bytes.
|
2008-05-28 04:11:00 +02:00
|
|
|
const USHORT l = (USHORT)(UCHAR) desc->dsc_scale;
|
2009-11-16 10:18:24 +01:00
|
|
|
if (negate_value)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), l + 1);
|
|
|
|
stuff(dsqlScratch->getStatement(), '-');
|
2008-05-25 14:16:20 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), l);
|
2008-05-25 14:16:20 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-05-25 14:16:20 +02:00
|
|
|
if (l)
|
2009-12-20 22:01:10 +01:00
|
|
|
dsqlScratch->getStatement()->append_raw_string(p, l);
|
2008-05-25 14:16:20 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_int64:
|
|
|
|
i64value = *(SINT64 *) p;
|
|
|
|
|
|
|
|
if (negate_value)
|
|
|
|
i64value = -i64value;
|
2009-01-06 06:53:34 +01:00
|
|
|
else if (i64value == MIN_SINT64)
|
|
|
|
{
|
2009-04-18 16:13:26 +02:00
|
|
|
// UH OH!
|
|
|
|
// yylex correctly recognized the digits as the most-negative
|
|
|
|
// possible INT64 value, but unfortunately, there was no
|
|
|
|
// preceding '-' (a fact which the lexer could not know).
|
|
|
|
// The value is too big for a positive INT64 value, and it
|
|
|
|
// didn't contain an exponent so it's not a valid DOUBLE
|
|
|
|
// PRECISION literal either, so we have to bounce it.
|
|
|
|
|
2008-09-03 04:26:45 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) <<
|
2008-08-15 13:21:47 +02:00
|
|
|
Arg::Gds(isc_arith_except) <<
|
|
|
|
Arg::Gds(isc_numeric_out_of_range));
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// We and the lexer both agree that this is an SINT64 constant,
|
|
|
|
// and if the value needed to be negated, it already has been.
|
|
|
|
// If the value will fit into a 32-bit signed integer, generate
|
|
|
|
// it that way, else as an INT64.
|
|
|
|
|
2009-01-06 06:53:34 +01:00
|
|
|
if ((i64value >= (SINT64) MIN_SLONG) && (i64value <= (SINT64) MAX_SLONG))
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_long);
|
|
|
|
stuff(dsqlScratch->getStatement(), desc->dsc_scale);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), i64value);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), i64value >> 16);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-11-16 10:18:24 +01:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_int64);
|
|
|
|
stuff(dsqlScratch->getStatement(), desc->dsc_scale);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), i64value);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), i64value >> 16);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), i64value >> 32);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), i64value >> 48);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_quad:
|
|
|
|
case dtype_blob:
|
|
|
|
case dtype_array:
|
|
|
|
case dtype_timestamp:
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_descriptor(dsqlScratch, desc, true);
|
2001-05-23 15:26:42 +02:00
|
|
|
value = *(SLONG *) p;
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), value);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), value >> 16);
|
2001-05-23 15:26:42 +02:00
|
|
|
value = *(SLONG *) (p + 4);
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), value);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), value >> 16);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_text:
|
2005-06-06 10:30:03 +02:00
|
|
|
{
|
2008-05-25 14:16:20 +02:00
|
|
|
const USHORT length = desc->dsc_length;
|
2005-06-06 10:30:03 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_descriptor(dsqlScratch, desc, true);
|
2005-08-21 17:52:30 +02:00
|
|
|
if (length)
|
2009-12-20 22:01:10 +01:00
|
|
|
dsqlScratch->getStatement()->append_raw_string(p, length);
|
2005-06-06 10:30:03 +02:00
|
|
|
}
|
2008-05-25 14:16:20 +02:00
|
|
|
break;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
default:
|
2008-09-27 11:51:53 +02:00
|
|
|
// gen_constant: datatype not understood
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-103) <<
|
|
|
|
Arg::Gds(isc_dsql_constant_err));
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-02 23:37:19 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2006-11-02 23:37:19 +01:00
|
|
|
gen_constant
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2006-11-02 23:37:19 +01:00
|
|
|
@brief Generate BLR for a constant.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2006-11-02 23:37:19 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2006-11-02 23:37:19 +01:00
|
|
|
@param node
|
|
|
|
@param negate_value
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_constant( DsqlCompilerScratch* dsqlScratch, dsql_nod* node, bool negate_value)
|
2006-11-02 23:37:19 +01:00
|
|
|
{
|
|
|
|
if (node->nod_desc.dsc_dtype == dtype_text)
|
|
|
|
node->nod_desc.dsc_length = ((dsql_str*) node->nod_arg[0])->str_length;
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_constant(dsqlScratch, &node->nod_desc, negate_value);
|
2006-11-02 23:37:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2008-08-15 18:32:42 +02:00
|
|
|
GEN_descriptor
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate a blr descriptor from an internal descriptor.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param desc
|
|
|
|
@param texttype
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
void GEN_descriptor( DsqlCompilerScratch* dsqlScratch, const dsc* desc, bool texttype)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-01-06 06:53:34 +01:00
|
|
|
switch (desc->dsc_dtype)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
case dtype_text:
|
2009-11-16 10:18:24 +01:00
|
|
|
if (texttype || desc->dsc_ttype() == ttype_binary || desc->dsc_ttype() == ttype_none)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_text2);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), desc->dsc_ttype());
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-11-16 10:18:24 +01:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_text2); // automatic transliteration
|
|
|
|
stuff_word(dsqlScratch->getStatement(), ttype_dynamic);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), desc->dsc_length);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_varying:
|
2009-11-16 10:18:24 +01:00
|
|
|
if (texttype || desc->dsc_ttype() == ttype_binary || desc->dsc_ttype() == ttype_none)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_varying2);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), desc->dsc_ttype());
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-11-16 10:18:24 +01:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_varying2); // automatic transliteration
|
|
|
|
stuff_word(dsqlScratch->getStatement(), ttype_dynamic);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), desc->dsc_length - sizeof(USHORT));
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_short:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_short);
|
|
|
|
stuff(dsqlScratch->getStatement(), desc->dsc_scale);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_long:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_long);
|
|
|
|
stuff(dsqlScratch->getStatement(), desc->dsc_scale);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_quad:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_quad);
|
|
|
|
stuff(dsqlScratch->getStatement(), desc->dsc_scale);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_int64:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_int64);
|
|
|
|
stuff(dsqlScratch->getStatement(), desc->dsc_scale);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_real:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_float);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_double:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_double);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_sql_date:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_sql_date);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_sql_time:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_sql_time);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_timestamp:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_timestamp);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_array:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_quad);
|
|
|
|
stuff(dsqlScratch->getStatement(), 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
2007-05-22 04:14:20 +02:00
|
|
|
case dtype_blob:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_blob2);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), desc->dsc_sub_type);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), desc->getTextType());
|
2007-05-22 04:14:20 +02:00
|
|
|
break;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
default:
|
2008-09-27 11:51:53 +02:00
|
|
|
// don't understand dtype
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-804) <<
|
|
|
|
Arg::Gds(isc_dsql_datatype_err));
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_error_condition
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate blr for an error condtion
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_error_condition( DsqlCompilerScratch* dsqlScratch, const dsql_nod* node)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-11-10 10:16:38 +01:00
|
|
|
const dsql_str* string;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-01-06 06:53:34 +01:00
|
|
|
switch (node->nod_type)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_sqlcode:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_sql_code);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), (USHORT)(IPTR) node->nod_arg[0]);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_gdscode:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_gds_code);
|
2003-11-10 10:16:38 +01:00
|
|
|
string = (dsql_str*) node->nod_arg[0];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_cstring(dsqlScratch->getStatement(), string->str_data);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_exception:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exception);
|
2003-11-10 10:16:38 +01:00
|
|
|
string = (dsql_str*) node->nod_arg[0];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_cstring(dsqlScratch->getStatement(), string->str_data);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_default:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_default_code);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(false);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-12 11:02:54 +02:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2008-06-12 11:02:54 +02:00
|
|
|
gen_exec_stmt
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2008-06-12 11:02:54 +02:00
|
|
|
@brief Generate blr for the EXECUTE STATEMENT clause
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2008-06-12 11:02:54 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2008-06-12 11:02:54 +02:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_exec_stmt(DsqlCompilerScratch* dsqlScratch, const dsql_nod* node)
|
2008-06-12 11:02:54 +02:00
|
|
|
{
|
2008-09-27 11:51:53 +02:00
|
|
|
if (node->nod_arg[e_exec_stmt_proc_block])
|
2008-06-12 11:02:54 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_label);
|
|
|
|
stuff(dsqlScratch->getStatement(), (int)(IPTR) node->nod_arg[e_exec_stmt_label]->nod_arg[e_label_number]);
|
2008-06-12 11:02:54 +02:00
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_stmt);
|
2008-06-12 11:02:54 +02:00
|
|
|
|
|
|
|
// counts of input and output parameters
|
2008-06-13 03:42:58 +02:00
|
|
|
const dsql_nod* temp = node->nod_arg[e_exec_stmt_inputs];
|
2008-06-12 11:02:54 +02:00
|
|
|
if (temp)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_stmt_inputs);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), temp->nod_count);
|
2008-06-12 11:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
temp = node->nod_arg[e_exec_stmt_outputs];
|
|
|
|
if (temp)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_stmt_outputs);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), temp->nod_count);
|
2008-06-12 11:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// query expression
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_stmt_sql);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_exec_stmt_sql]);
|
2008-06-12 11:02:54 +02:00
|
|
|
|
|
|
|
// proc block body
|
|
|
|
dsql_nod* temp2 = node->nod_arg[e_exec_stmt_proc_block];
|
2008-09-27 11:51:53 +02:00
|
|
|
if (temp2)
|
2008-06-12 11:02:54 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_stmt_proc_block);
|
|
|
|
GEN_statement(dsqlScratch, temp2);
|
2008-06-12 11:02:54 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 12:21:47 +02:00
|
|
|
// external data source, user, password and role
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_optional_expr(dsqlScratch, blr_exec_stmt_data_src, node->nod_arg[e_exec_stmt_data_src]);
|
|
|
|
gen_optional_expr(dsqlScratch, blr_exec_stmt_user, node->nod_arg[e_exec_stmt_user]);
|
|
|
|
gen_optional_expr(dsqlScratch, blr_exec_stmt_pwd, node->nod_arg[e_exec_stmt_pwd]);
|
|
|
|
gen_optional_expr(dsqlScratch, blr_exec_stmt_role, node->nod_arg[e_exec_stmt_role]);
|
2008-06-12 11:02:54 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
// dsqlScratch's transaction behavior
|
2008-06-12 11:02:54 +02:00
|
|
|
temp = node->nod_arg[e_exec_stmt_tran];
|
|
|
|
if (temp)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_stmt_tran_clone); // transaction parameters equal to current transaction
|
|
|
|
stuff(dsqlScratch->getStatement(), (UCHAR)(IPTR) temp->nod_flags);
|
2008-06-12 11:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// inherit caller's privileges ?
|
|
|
|
if (node->nod_arg[e_exec_stmt_privs]) {
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_stmt_privs);
|
2008-06-12 11:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// inputs
|
|
|
|
temp = node->nod_arg[e_exec_stmt_inputs];
|
2008-09-27 11:51:53 +02:00
|
|
|
if (temp)
|
2008-06-12 11:02:54 +02:00
|
|
|
{
|
|
|
|
const dsql_nod* const* ptr = temp->nod_arg;
|
|
|
|
const bool haveNames = ((*ptr)->nod_arg[e_named_param_name] != 0);
|
|
|
|
if (haveNames)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_stmt_in_params2);
|
2008-09-27 11:51:53 +02:00
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_stmt_in_params);
|
2008-06-12 11:02:54 +02:00
|
|
|
|
2008-09-27 11:51:53 +02:00
|
|
|
for (const dsql_nod* const* end = ptr + temp->nod_count; ptr < end; ptr++)
|
2008-06-12 11:02:54 +02:00
|
|
|
{
|
|
|
|
if (haveNames)
|
|
|
|
{
|
|
|
|
const dsql_str* name = (dsql_str*) (*ptr)->nod_arg[e_named_param_name];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_cstring(dsqlScratch->getStatement(), name->str_data);
|
2008-06-12 11:02:54 +02:00
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, (*ptr)->nod_arg[e_named_param_expr]);
|
2008-06-12 11:02:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// outputs
|
|
|
|
temp = node->nod_arg[e_exec_stmt_outputs];
|
2008-09-27 11:51:53 +02:00
|
|
|
if (temp)
|
2008-06-12 11:02:54 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_stmt_out_params);
|
2008-06-12 11:02:54 +02:00
|
|
|
for (size_t i = 0; i < temp->nod_count; ++i) {
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, temp->nod_arg[i]);
|
2008-06-12 11:02:54 +02:00
|
|
|
}
|
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2008-06-12 11:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_field
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate blr for a field - field id's
|
|
|
|
are preferred but not for trigger or view blr.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param context
|
|
|
|
@param field
|
|
|
|
@param indices
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_field( DsqlCompilerScratch* dsqlScratch, const dsql_ctx* context,
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_fld* field, dsql_nod* indices)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-04-18 16:13:26 +02:00
|
|
|
// For older clients - generate an error should they try and
|
|
|
|
// access data types which did not exist in the older dialect
|
2009-12-20 22:01:10 +01:00
|
|
|
if (dsqlScratch->clientDialect <= SQL_DIALECT_V5)
|
2009-01-06 06:53:34 +01:00
|
|
|
{
|
|
|
|
switch (field->fld_dtype)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
case dtype_sql_date:
|
|
|
|
case dtype_sql_time:
|
|
|
|
case dtype_int64:
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-804) <<
|
|
|
|
Arg::Gds(isc_dsql_datatype_err) <<
|
2009-01-06 06:53:34 +01:00
|
|
|
Arg::Gds(isc_sql_dialect_datatype_unsupport) <<
|
2009-12-20 22:01:10 +01:00
|
|
|
Arg::Num(dsqlScratch->clientDialect) <<
|
2009-01-06 06:53:34 +01:00
|
|
|
Arg::Str(DSC_dtype_tostring(static_cast<UCHAR>(field->fld_dtype))));
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
default:
|
2008-09-27 11:51:53 +02:00
|
|
|
// No special action for other data types
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (indices)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_index);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
if (DDL_ids(dsqlScratch))
|
2009-11-16 10:18:24 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_fid);
|
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), field->fld_id);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-11-16 10:18:24 +01:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_field);
|
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
|
|
|
stuff_meta_string(dsqlScratch->getStatement(), field->fld_name.c_str());
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
if (indices)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), indices->nod_count);
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod** ptr = indices->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* end = ptr + indices->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr);
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_for_select
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@brief Generate BLR for a SELECT dsqlScratch.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param for_select
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_for_select( DsqlCompilerScratch* dsqlScratch, const dsql_nod* for_select)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* rse = for_select->nod_arg[e_flp_select];
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2006-06-02 10:03:22 +02:00
|
|
|
// CVC: Only put a label if this is not singular; otherwise,
|
|
|
|
// what loop is the user trying to abandon?
|
2009-11-16 10:18:24 +01:00
|
|
|
if (for_select->nod_arg[e_flp_action])
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_label);
|
|
|
|
stuff(dsqlScratch->getStatement(), (int) (IPTR) for_select->nod_arg[e_flp_label]->nod_arg[e_label_number]);
|
2006-06-02 10:03:22 +02:00
|
|
|
}
|
2002-06-29 08:56:51 +02:00
|
|
|
|
2008-09-27 11:51:53 +02:00
|
|
|
// Generate FOR loop
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_for);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2005-09-10 09:15:24 +02:00
|
|
|
if (!for_select->nod_arg[e_flp_action])
|
2003-10-01 20:11:23 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_singular);
|
2003-10-01 20:11:23 +02:00
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_rse(dsqlScratch, rse);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_begin);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-07-02 11:46:44 +02:00
|
|
|
// Build body of FOR loop
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-09-27 11:51:53 +02:00
|
|
|
// Handle write locks
|
2008-07-02 11:46:44 +02:00
|
|
|
/* CVC: Unused code!
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* streams = rse->nod_arg[e_rse_streams];
|
|
|
|
dsql_ctx* context = NULL;
|
2002-10-29 21:20:44 +01:00
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
if (!rse->nod_arg[e_rse_reduced] && streams->nod_count == 1)
|
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* item = streams->nod_arg[0];
|
2002-10-29 21:20:44 +01:00
|
|
|
if (item && (item->nod_type == nod_relation))
|
2003-11-01 11:26:43 +01:00
|
|
|
context = (dsql_ctx*) item->nod_arg[e_rel_context];
|
2002-10-29 21:20:44 +01:00
|
|
|
}
|
2008-07-02 11:46:44 +02:00
|
|
|
*/
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* list = rse->nod_arg[e_rse_items];
|
|
|
|
dsql_nod* list_to = for_select->nod_arg[e_flp_into];
|
2006-09-14 04:05:32 +02:00
|
|
|
|
|
|
|
if (list_to)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2006-09-14 04:05:32 +02:00
|
|
|
if (list->nod_count != list_to->nod_count)
|
2009-11-16 10:18:24 +01:00
|
|
|
{
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-313) <<
|
|
|
|
Arg::Gds(isc_dsql_count_mismatch));
|
2009-11-16 10:18:24 +01:00
|
|
|
}
|
2006-09-14 04:05:32 +02:00
|
|
|
dsql_nod** ptr = list->nod_arg;
|
|
|
|
dsql_nod** ptr_to = list_to->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++, ptr_to++)
|
2006-09-14 04:05:32 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_assignment);
|
|
|
|
GEN_expr(dsqlScratch, *ptr);
|
|
|
|
GEN_expr(dsqlScratch, *ptr_to);
|
2006-09-14 04:05:32 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2006-09-14 04:05:32 +02:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
if (for_select->nod_arg[e_flp_action])
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_statement(dsqlScratch, for_select->nod_arg[e_flp_action]);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_gen_id
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate BLR for gen_id
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_gen_id( DsqlCompilerScratch* dsqlScratch, const dsql_nod* node)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_gen_id);
|
2003-11-10 10:16:38 +01:00
|
|
|
const dsql_str* string = (dsql_str*) node->nod_arg[e_gen_id_name];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_cstring(dsqlScratch->getStatement(), string->str_data);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_gen_id_value]);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_join_rse
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate a record selection expression
|
|
|
|
with an explicit join type.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param rse
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_join_rse( DsqlCompilerScratch* dsqlScratch, const dsql_nod* rse)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_rs_stream);
|
|
|
|
stuff(dsqlScratch->getStatement(), 2);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, rse->nod_arg[e_join_left_rel]);
|
|
|
|
GEN_expr(dsqlScratch, rse->nod_arg[e_join_rght_rel]);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_nod* node = rse->nod_arg[e_join_type];
|
2009-01-06 06:53:34 +01:00
|
|
|
if (node->nod_type != nod_join_inner)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_join_type);
|
2001-05-23 15:26:42 +02:00
|
|
|
if (node->nod_type == nod_join_left)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_left);
|
2001-05-23 15:26:42 +02:00
|
|
|
else if (node->nod_type == nod_join_right)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_right);
|
2001-05-23 15:26:42 +02:00
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_full);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2004-10-13 20:37:53 +02:00
|
|
|
if (rse->nod_arg[e_join_boolean])
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_boolean);
|
|
|
|
GEN_expr(dsqlScratch, rse->nod_arg[e_join_boolean]);
|
2004-10-13 20:37:53 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_map
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate a value map for a record selection expression.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param map
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_map( DsqlCompilerScratch* dsqlScratch, dsql_map* map)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
USHORT count = 0;
|
|
|
|
dsql_map* temp;
|
2001-05-23 15:26:42 +02:00
|
|
|
for (temp = map; temp; temp = temp->map_next)
|
|
|
|
temp->map_position = count++;
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_map);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), count);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
for (temp = map; temp; temp = temp->map_next)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), temp->map_position);
|
|
|
|
GEN_expr(dsqlScratch, temp->map_node);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_optional_expr(DsqlCompilerScratch* dsqlScratch, const UCHAR code, dsql_nod* node)
|
2008-06-08 22:42:27 +02:00
|
|
|
{
|
|
|
|
if (node)
|
2008-06-11 00:43:30 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), code);
|
|
|
|
GEN_expr(dsqlScratch, node);
|
2008-06-11 00:43:30 +02:00
|
|
|
}
|
2008-06-08 22:42:27 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_parameter
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate a parameter reference.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param parameter
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_parameter( DsqlCompilerScratch* dsqlScratch, const dsql_par* parameter)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_msg* message = parameter->par_message;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-02-02 12:02:12 +01:00
|
|
|
const dsql_par* null = parameter->par_null;
|
2009-11-16 10:18:24 +01:00
|
|
|
if (null != NULL)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_parameter2);
|
|
|
|
stuff(dsqlScratch->getStatement(), message->msg_number);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), parameter->par_parameter);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), null->par_parameter);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_parameter);
|
|
|
|
stuff(dsqlScratch->getStatement(), message->msg_number);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), parameter->par_parameter);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_plan
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate blr for an access plan expression.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param plan_expression
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_plan( DsqlCompilerScratch* dsqlScratch, const dsql_nod* plan_expression)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-04-18 16:13:26 +02:00
|
|
|
// stuff the join type
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_nod* list = plan_expression->nod_arg[1];
|
2009-11-16 10:18:24 +01:00
|
|
|
if (list->nod_count > 1)
|
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
if (plan_expression->nod_arg[0])
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_merge);
|
2001-05-23 15:26:42 +02:00
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_join);
|
|
|
|
stuff(dsqlScratch->getStatement(), list->nod_count);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// stuff one or more plan items
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_nod* const* ptr = list->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
|
|
|
const dsql_nod* node = *ptr;
|
2009-11-16 10:18:24 +01:00
|
|
|
if (node->nod_type == nod_plan_expr)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_plan(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-09-27 11:51:53 +02:00
|
|
|
// if we're here, it must be a nod_plan_item
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_retrieve);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// stuff the relation--the relation id itself is redundant except
|
|
|
|
// when there is a need to differentiate the base tables of views
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_nod* arg = node->nod_arg[0];
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_relation(dsqlScratch, (dsql_ctx*) arg->nod_arg[e_rel_context]);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-09-27 11:51:53 +02:00
|
|
|
// now stuff the access method for this stream
|
2003-11-10 10:16:38 +01:00
|
|
|
const dsql_str* index_string;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
arg = node->nod_arg[1];
|
2009-01-06 06:53:34 +01:00
|
|
|
switch (arg->nod_type)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_natural:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_sequential);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_index_order:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_navigational);
|
2003-11-10 10:16:38 +01:00
|
|
|
index_string = (dsql_str*) arg->nod_arg[0];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_cstring(dsqlScratch->getStatement(), index_string->str_data);
|
2003-09-14 17:37:05 +02:00
|
|
|
if (!arg->nod_arg[1])
|
|
|
|
break;
|
|
|
|
// dimitr: FALL INTO, if the plan item is ORDER ... INDEX (...)
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
case nod_index:
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_indices);
|
2009-01-06 06:53:34 +01:00
|
|
|
arg = (arg->nod_type == nod_index) ? arg->nod_arg[0] : arg->nod_arg[1];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), arg->nod_count);
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_nod* const* ptr2 = arg->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end2 = ptr2 + arg->nod_count; ptr2 < end2; ptr2++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2003-11-10 10:16:38 +01:00
|
|
|
index_string = (dsql_str*) * ptr2;
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_cstring(dsqlScratch->getStatement(), index_string->str_data);
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
|
|
|
break;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(false);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_relation
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate blr for a relation reference.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param context
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_relation( DsqlCompilerScratch* dsqlScratch, dsql_ctx* context)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_rel* relation = context->ctx_relation;
|
|
|
|
const dsql_prc* procedure = context->ctx_procedure;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-09-27 11:51:53 +02:00
|
|
|
// if this is a trigger or procedure, don't want relation id used
|
2009-01-06 06:53:34 +01:00
|
|
|
if (relation)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
if (DDL_ids(dsqlScratch))
|
2009-11-16 10:18:24 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), context->ctx_alias ? blr_rid2 : blr_rid);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), relation->rel_id);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-11-16 10:18:24 +01:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), context->ctx_alias ? blr_relation2 : blr_relation);
|
|
|
|
stuff_meta_string(dsqlScratch->getStatement(), relation->rel_name.c_str());
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (context->ctx_alias)
|
2009-12-14 12:19:26 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_meta_string(dsqlScratch->getStatement(), context->ctx_alias);
|
2009-12-14 12:19:26 +01:00
|
|
|
}
|
2007-05-27 00:08:13 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-01-06 06:53:34 +01:00
|
|
|
else if (procedure)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
if (DDL_ids(dsqlScratch))
|
2009-10-21 02:42:38 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), context->ctx_alias ? blr_pid2 : blr_pid);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), procedure->prc_id);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-10-21 02:42:38 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (procedure->prc_name.qualifier.hasData())
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), context->ctx_alias ? blr_procedure4 : blr_procedure3);
|
|
|
|
stuff_meta_string(dsqlScratch->getStatement(), procedure->prc_name.qualifier.c_str());
|
|
|
|
stuff_meta_string(dsqlScratch->getStatement(), procedure->prc_name.identifier.c_str());
|
2009-10-21 02:42:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), context->ctx_alias ? blr_procedure2 : blr_procedure);
|
|
|
|
stuff_meta_string(dsqlScratch->getStatement(), procedure->prc_name.identifier.c_str());
|
2009-10-21 02:42:38 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-12-14 12:19:26 +01:00
|
|
|
|
|
|
|
if (context->ctx_alias)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_meta_string(dsqlScratch->getStatement(), context->ctx_alias);
|
2009-12-14 12:19:26 +01:00
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
2004-01-16 11:43:21 +01:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* inputs = context->ctx_proc_inputs;
|
2009-11-16 10:18:24 +01:00
|
|
|
if (inputs)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), inputs->nod_count);
|
2004-01-16 11:43:21 +01:00
|
|
|
|
|
|
|
dsql_nod* const* ptr = inputs->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + inputs->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr);
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
2004-01-16 11:43:21 +01:00
|
|
|
}
|
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_return
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate blr for a procedure return.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param procedure
|
|
|
|
@param eos_flag
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
void GEN_return(DsqlCompilerScratch* dsqlScratch, const Array<dsql_nod*>& variables, bool eos_flag)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
if (!eos_flag)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_begin);
|
2009-01-06 06:53:34 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_send);
|
|
|
|
stuff(dsqlScratch->getStatement(), 1);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_begin);
|
2003-08-13 13:09:57 +02:00
|
|
|
|
2009-11-21 21:42:27 +01:00
|
|
|
for (Array<dsql_nod*>::const_iterator i = variables.begin(); i != variables.end(); ++i)
|
2009-01-07 10:30:57 +01:00
|
|
|
{
|
2009-11-21 21:42:27 +01:00
|
|
|
const dsql_nod* parameter = *i;
|
|
|
|
const dsql_var* variable = (dsql_var*) parameter->nod_arg[e_var_variable];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_assignment);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_variable);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), variable->var_variable_number);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_parameter2);
|
|
|
|
stuff(dsqlScratch->getStatement(), variable->var_msg_number);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), variable->var_msg_item);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), variable->var_msg_item + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_assignment);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_literal);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_short);
|
|
|
|
stuff(dsqlScratch->getStatement(), 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
if (eos_flag)
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), 1);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_parameter);
|
|
|
|
stuff(dsqlScratch->getStatement(), 1);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), USHORT(2 * variables.getCount()));
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2009-11-16 10:18:24 +01:00
|
|
|
if (!eos_flag)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_stall);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_rse
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate a record selection expression.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param rse
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_rse( DsqlCompilerScratch* dsqlScratch, const dsql_nod* rse)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2005-09-10 09:15:24 +02:00
|
|
|
if (rse->nod_flags & NOD_SELECT_EXPR_SINGLETON)
|
2003-10-05 08:27:16 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_singular);
|
2003-10-05 08:27:16 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_rse);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* list = rse->nod_arg[e_rse_streams];
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// Handle source streams
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
if (list->nod_type == nod_union)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), 1);
|
|
|
|
gen_union(dsqlScratch, rse);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-01-06 06:53:34 +01:00
|
|
|
else if (list->nod_type == nod_list)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), list->nod_count);
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* const* ptr = list->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
|
|
|
dsql_nod* node = *ptr;
|
2009-01-06 06:53:34 +01:00
|
|
|
switch (node->nod_type)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-01-06 06:53:34 +01:00
|
|
|
case nod_relation:
|
|
|
|
case nod_aggregate:
|
|
|
|
case nod_join:
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, node);
|
2009-01-06 06:53:34 +01:00
|
|
|
break;
|
|
|
|
case nod_derived_table:
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_derived_table_rse]);
|
2009-01-06 06:53:34 +01:00
|
|
|
break;
|
2003-08-15 01:34:37 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
2009-11-16 10:18:24 +01:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), 1);
|
|
|
|
GEN_expr(dsqlScratch, list);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2002-11-18 21:27:24 +01:00
|
|
|
if (rse->nod_arg[e_rse_lock])
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_writelock);
|
2003-08-13 13:09:57 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* node;
|
2003-08-13 13:09:57 +02:00
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
if ((node = rse->nod_arg[e_rse_first]) != NULL)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_first);
|
|
|
|
GEN_expr(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
if ((node = rse->nod_arg[e_rse_skip]) != NULL)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_skip);
|
|
|
|
GEN_expr (dsqlScratch, node);
|
2006-06-02 10:03:22 +02:00
|
|
|
}
|
2002-06-29 08:56:51 +02:00
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
if ((node = rse->nod_arg[e_rse_boolean]) != NULL)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_boolean);
|
|
|
|
GEN_expr(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((list = rse->nod_arg[e_rse_sort]) != NULL)
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_sort(dsqlScratch, list);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
if ((list = rse->nod_arg[e_rse_reduced]) != NULL)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_project);
|
|
|
|
stuff(dsqlScratch->getStatement(), list->nod_count);
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod** ptr = list->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr);
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// if the user specified an access plan to use, add it here
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
if ((node = rse->nod_arg[e_rse_plan]) != NULL)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_plan);
|
|
|
|
gen_plan(dsqlScratch, node);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_searched_case
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate BLR for CASE function (searched)
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_searched_case( DsqlCompilerScratch* dsqlScratch, const dsql_nod* node)
|
2002-08-03 17:27:20 +02:00
|
|
|
{
|
2003-08-13 13:09:57 +02:00
|
|
|
// blr_value_if is used for building the case expression
|
2002-08-03 17:27:20 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_cast);
|
|
|
|
GEN_descriptor(dsqlScratch, &node->nod_desc, true);
|
2009-01-06 06:53:34 +01:00
|
|
|
const SSHORT count = node->nod_arg[e_searched_case_search_conditions]->nod_count;
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* boolean_list = node->nod_arg[e_searched_case_search_conditions];
|
|
|
|
dsql_nod* results_list = node->nod_arg[e_searched_case_results];
|
|
|
|
dsql_nod* const* bptr = boolean_list->nod_arg;
|
|
|
|
dsql_nod* const* rptr = results_list->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = bptr + count; bptr < end; bptr++, rptr++)
|
2002-08-03 17:27:20 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_value_if);
|
|
|
|
GEN_expr(dsqlScratch, *bptr);
|
|
|
|
GEN_expr(dsqlScratch, *rptr);
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
2003-08-13 13:09:57 +02:00
|
|
|
// else_result
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_searched_case_results]->nod_arg[count]);
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_select
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@brief Generate BLR for a SELECT dsqlScratch.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param rse
|
|
|
|
|
|
|
|
**/
|
2009-12-21 15:20:26 +01:00
|
|
|
static void gen_select(DsqlCompilerScratch* dsqlScratch, dsql_nod* rse)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_ctx* context;
|
2005-09-02 07:30:16 +02:00
|
|
|
|
|
|
|
fb_assert(rse->nod_type == nod_rse);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-21 15:20:26 +01:00
|
|
|
DsqlCompiledStatement* statement = dsqlScratch->getStatement();
|
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// Set up parameter for things in the select list
|
2005-09-02 07:30:16 +02:00
|
|
|
const dsql_nod* list = rse->nod_arg[e_rse_items];
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* const* ptr = list->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-21 15:20:26 +01:00
|
|
|
dsql_par* parameter = MAKE_parameter(statement->receiveMsg, true, true, 0, *ptr);
|
2005-09-02 07:30:16 +02:00
|
|
|
parameter->par_node = *ptr;
|
2009-12-20 22:01:10 +01:00
|
|
|
MAKE_desc(dsqlScratch, ¶meter->par_desc, *ptr, NULL);
|
2005-09-02 07:30:16 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// Set up parameter to handle EOF
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-21 15:20:26 +01:00
|
|
|
dsql_par* parameter_eof = MAKE_parameter(statement->receiveMsg, false, false, 0, NULL);
|
|
|
|
statement->eof = parameter_eof;
|
2005-09-02 07:30:16 +02:00
|
|
|
parameter_eof->par_desc.dsc_dtype = dtype_short;
|
|
|
|
parameter_eof->par_desc.dsc_scale = 0;
|
|
|
|
parameter_eof->par_desc.dsc_length = sizeof(SSHORT);
|
2003-08-13 13:09:57 +02:00
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// Save DBKEYs for possible update later
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
list = rse->nod_arg[e_rse_streams];
|
|
|
|
|
2009-01-06 06:53:34 +01:00
|
|
|
if (!rse->nod_arg[e_rse_reduced])
|
|
|
|
{
|
2006-08-17 14:08:49 +02:00
|
|
|
dsql_nod* const* ptr2 = list->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end2 = ptr2 + list->nod_count; ptr2 < end2; ptr2++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2006-08-17 14:08:49 +02:00
|
|
|
dsql_nod* item = *ptr2;
|
2009-01-06 06:53:34 +01:00
|
|
|
if (item && item->nod_type == nod_relation)
|
|
|
|
{
|
2003-11-01 11:26:43 +01:00
|
|
|
context = (dsql_ctx*) item->nod_arg[e_rel_context];
|
2009-11-16 10:18:24 +01:00
|
|
|
const dsql_rel* relation = context->ctx_relation;
|
|
|
|
if (relation)
|
2009-01-06 06:53:34 +01:00
|
|
|
{
|
2003-08-13 13:09:57 +02:00
|
|
|
// Set up dbkey
|
2009-12-21 15:20:26 +01:00
|
|
|
dsql_par* parameter = MAKE_parameter(statement->receiveMsg, false,
|
|
|
|
false, 0, NULL);
|
2001-05-23 15:26:42 +02:00
|
|
|
parameter->par_dbkey_ctx = context;
|
|
|
|
parameter->par_desc.dsc_dtype = dtype_text;
|
2004-05-21 08:16:17 +02:00
|
|
|
parameter->par_desc.dsc_ttype() = ttype_binary;
|
2009-01-06 06:53:34 +01:00
|
|
|
parameter->par_desc.dsc_length = relation->rel_dbkey_length;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-08-13 13:09:57 +02:00
|
|
|
// Set up record version - for post v33 databases
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-21 15:20:26 +01:00
|
|
|
parameter = MAKE_parameter(statement->receiveMsg, false, false, 0, NULL);
|
2005-09-10 09:15:24 +02:00
|
|
|
parameter->par_rec_version_ctx = context;
|
|
|
|
parameter->par_desc.dsc_dtype = dtype_text;
|
|
|
|
parameter->par_desc.dsc_ttype() = ttype_binary;
|
2009-01-06 06:53:34 +01:00
|
|
|
parameter->par_desc.dsc_length = relation->rel_dbkey_length / 2;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
2003-08-13 13:09:57 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// Generate definitions for the messages
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-21 15:20:26 +01:00
|
|
|
GEN_port(dsqlScratch, statement->receiveMsg);
|
|
|
|
dsql_msg* message = statement->sendMsg;
|
2001-05-23 15:26:42 +02:00
|
|
|
if (message->msg_parameter)
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_port(dsqlScratch, message);
|
2001-05-23 15:26:42 +02:00
|
|
|
else
|
2009-12-21 15:20:26 +01:00
|
|
|
statement->sendMsg = NULL;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// If there is a send message, build a RECEIVE
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-21 15:20:26 +01:00
|
|
|
if ((message = statement->sendMsg) != NULL)
|
2009-11-16 10:18:24 +01:00
|
|
|
{
|
2009-12-21 15:20:26 +01:00
|
|
|
stuff(statement, blr_receive);
|
|
|
|
stuff(statement, message->msg_number);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// Generate FOR loop
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-21 15:20:26 +01:00
|
|
|
message = statement->receiveMsg;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-21 15:20:26 +01:00
|
|
|
stuff(statement, blr_for);
|
|
|
|
stuff(statement, blr_stall);
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_rse(dsqlScratch, rse);
|
2003-11-02 13:28:30 +01:00
|
|
|
|
2009-12-21 15:20:26 +01:00
|
|
|
stuff(statement, blr_send);
|
|
|
|
stuff(statement, message->msg_number);
|
|
|
|
stuff(statement, blr_begin);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// Build body of FOR loop
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2005-09-02 07:30:16 +02:00
|
|
|
SSHORT constant;
|
|
|
|
dsc constant_desc;
|
|
|
|
constant_desc.dsc_dtype = dtype_short;
|
|
|
|
constant_desc.dsc_scale = 0;
|
|
|
|
constant_desc.dsc_sub_type = 0;
|
|
|
|
constant_desc.dsc_flags = 0;
|
|
|
|
constant_desc.dsc_length = sizeof(SSHORT);
|
|
|
|
constant_desc.dsc_address = (UCHAR*) & constant;
|
|
|
|
|
2003-08-13 13:09:57 +02:00
|
|
|
// Add invalid usage here
|
2005-09-02 07:30:16 +02:00
|
|
|
|
2009-12-21 15:20:26 +01:00
|
|
|
stuff(statement, blr_assignment);
|
2001-05-23 15:26:42 +02:00
|
|
|
constant = 1;
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_constant(dsqlScratch, &constant_desc, USE_VALUE);
|
2009-12-21 15:20:26 +01:00
|
|
|
gen_parameter(dsqlScratch, statement->eof);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-19 19:50:38 +01:00
|
|
|
for (size_t i = 0; i < message->msg_parameters.getCount(); ++i)
|
2004-10-26 09:21:47 +02:00
|
|
|
{
|
2009-12-19 19:50:38 +01:00
|
|
|
dsql_par* parameter = message->msg_parameters[i];
|
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
if (parameter->par_node)
|
|
|
|
{
|
2009-12-21 15:20:26 +01:00
|
|
|
stuff(statement, blr_assignment);
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, parameter->par_node);
|
|
|
|
gen_parameter(dsqlScratch, parameter);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-11-16 10:18:24 +01:00
|
|
|
if (context = parameter->par_dbkey_ctx)
|
|
|
|
{
|
2009-12-21 15:20:26 +01:00
|
|
|
stuff(statement, blr_assignment);
|
|
|
|
stuff(statement, blr_dbkey);
|
|
|
|
stuff_context(statement, context);
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_parameter(dsqlScratch, parameter);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2009-11-16 10:18:24 +01:00
|
|
|
if (context = parameter->par_rec_version_ctx)
|
|
|
|
{
|
2009-12-21 15:20:26 +01:00
|
|
|
stuff(statement, blr_assignment);
|
|
|
|
stuff(statement, blr_record_version);
|
|
|
|
stuff_context(statement, context);
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_parameter(dsqlScratch, parameter);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-21 15:20:26 +01:00
|
|
|
stuff(statement, blr_end);
|
|
|
|
stuff(statement, blr_send);
|
|
|
|
stuff(statement, message->msg_number);
|
|
|
|
stuff(statement, blr_assignment);
|
2001-05-23 15:26:42 +02:00
|
|
|
constant = 0;
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_constant(dsqlScratch, &constant_desc, USE_VALUE);
|
2009-12-21 15:20:26 +01:00
|
|
|
gen_parameter(dsqlScratch, statement->eof);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_simple_case
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate BLR for CASE function (simple)
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_simple_case( DsqlCompilerScratch* dsqlScratch, const dsql_nod* node)
|
2002-08-03 17:27:20 +02:00
|
|
|
{
|
2008-09-27 11:51:53 +02:00
|
|
|
// blr_value_if is used for building the case expression
|
2002-08-03 17:27:20 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_cast);
|
|
|
|
GEN_descriptor(dsqlScratch, &node->nod_desc, true);
|
2008-08-26 12:28:58 +02:00
|
|
|
const SSHORT count = node->nod_arg[e_simple_case_when_operands]->nod_count;
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* when_list = node->nod_arg[e_simple_case_when_operands];
|
|
|
|
dsql_nod* results_list = node->nod_arg[e_simple_case_results];
|
2003-08-13 13:09:57 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* const* wptr = when_list->nod_arg;
|
|
|
|
dsql_nod* const* rptr = results_list->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = wptr + count; wptr < end; wptr++, rptr++)
|
2002-08-03 17:27:20 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_value_if);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_eql);
|
2009-08-06 04:32:56 +02:00
|
|
|
|
|
|
|
if (wptr == when_list->nod_arg || !node->nod_arg[e_simple_case_case_operand2])
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_simple_case_case_operand]);
|
2009-08-06 04:32:56 +02:00
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_simple_case_case_operand2]);
|
2009-08-06 04:32:56 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *wptr);
|
|
|
|
GEN_expr(dsqlScratch, *rptr);
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
2008-09-27 11:51:53 +02:00
|
|
|
// else_result
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_simple_case_results]->nod_arg[count]);
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_sort
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate a sort clause.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param list
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_sort( DsqlCompilerScratch* dsqlScratch, dsql_nod* list)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_sort);
|
|
|
|
stuff(dsqlScratch->getStatement(), list->nod_count);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* const* ptr = list->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2003-12-21 01:07:03 +01:00
|
|
|
dsql_nod* nulls_placement = (*ptr)->nod_arg[e_order_nulls];
|
2009-01-06 06:53:34 +01:00
|
|
|
if (nulls_placement)
|
|
|
|
{
|
|
|
|
switch (nulls_placement->getSlong())
|
|
|
|
{
|
2003-12-21 01:07:03 +01:00
|
|
|
case NOD_NULLS_FIRST:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_nullsfirst);
|
2003-12-21 01:07:03 +01:00
|
|
|
break;
|
|
|
|
case NOD_NULLS_LAST:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_nullslast);
|
2003-12-21 01:07:03 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-09-10 20:28:23 +02:00
|
|
|
if ((*ptr)->nod_arg[e_order_flag])
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_descending);
|
2001-05-23 15:26:42 +02:00
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_ascending);
|
|
|
|
GEN_expr(dsqlScratch, (*ptr)->nod_arg[e_order_field]);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-31 20:02:34 +02:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2006-05-31 20:02:34 +02:00
|
|
|
gen_statement
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2006-05-31 20:02:34 +02:00
|
|
|
@brief Generate BLR for DML statements.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2006-05-31 20:02:34 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2006-05-31 20:02:34 +02:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_statement(DsqlCompilerScratch* dsqlScratch, const dsql_nod* node)
|
2006-05-31 20:02:34 +02:00
|
|
|
{
|
|
|
|
dsql_nod* rse = NULL;
|
2007-04-24 17:22:05 +02:00
|
|
|
const dsql_msg* message = NULL;
|
2009-12-20 23:42:43 +01:00
|
|
|
bool send_before_for = !(dsqlScratch->flags & DsqlCompilerScratch::FLAG_UPDATE_OR_INSERT);
|
2006-05-31 20:02:34 +02:00
|
|
|
|
2009-01-06 06:53:34 +01:00
|
|
|
switch (node->nod_type)
|
|
|
|
{
|
2006-05-31 20:02:34 +02:00
|
|
|
case nod_store:
|
|
|
|
rse = node->nod_arg[e_sto_rse];
|
|
|
|
break;
|
|
|
|
case nod_modify:
|
|
|
|
rse = node->nod_arg[e_mod_rse];
|
|
|
|
break;
|
|
|
|
case nod_erase:
|
|
|
|
rse = node->nod_arg[e_era_rse];
|
|
|
|
break;
|
|
|
|
default:
|
2007-04-24 17:22:05 +02:00
|
|
|
send_before_for = false;
|
2006-05-31 20:02:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
if (dsqlScratch->getStatement()->type == REQ_EXEC_PROCEDURE && send_before_for)
|
2007-04-24 17:22:05 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
if ((message = dsqlScratch->getStatement()->receiveMsg))
|
2007-04-24 17:22:05 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_send);
|
|
|
|
stuff(dsqlScratch->getStatement(), message->msg_number);
|
2007-04-24 17:22:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-16 10:18:24 +01:00
|
|
|
if (rse)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_for);
|
|
|
|
GEN_expr(dsqlScratch, rse);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
if (dsqlScratch->getStatement()->type == REQ_EXEC_PROCEDURE)
|
2007-04-24 17:22:05 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
if ((message = dsqlScratch->getStatement()->receiveMsg))
|
2007-04-24 17:22:05 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_begin);
|
2007-04-24 17:22:05 +02:00
|
|
|
|
|
|
|
if (!send_before_for)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_send);
|
|
|
|
stuff(dsqlScratch->getStatement(), message->msg_number);
|
2007-04-24 17:22:05 +02:00
|
|
|
}
|
2006-09-03 03:09:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-31 20:02:34 +02:00
|
|
|
dsql_nod* temp;
|
2008-07-02 11:46:44 +02:00
|
|
|
const dsql_ctx* context;
|
|
|
|
const dsql_str* name;
|
2006-05-31 20:02:34 +02:00
|
|
|
|
2009-01-06 06:53:34 +01:00
|
|
|
switch (node->nod_type)
|
|
|
|
{
|
2006-05-31 20:02:34 +02:00
|
|
|
case nod_store:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), node->nod_arg[e_sto_return] ? blr_store2 : blr_store);
|
|
|
|
GEN_expr(dsqlScratch, node->nod_arg[e_sto_relation]);
|
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_sto_statement]);
|
2006-08-19 17:49:28 +02:00
|
|
|
if (node->nod_arg[e_sto_return]) {
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_sto_return]);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_modify:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), node->nod_arg[e_mod_return] ? blr_modify2 : blr_modify);
|
2006-05-31 20:02:34 +02:00
|
|
|
temp = node->nod_arg[e_mod_source];
|
|
|
|
context = (dsql_ctx*) temp->nod_arg[e_rel_context];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
2006-05-31 20:02:34 +02:00
|
|
|
temp = node->nod_arg[e_mod_update];
|
|
|
|
context = (dsql_ctx*) temp->nod_arg[e_rel_context];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_mod_statement]);
|
2006-08-19 17:49:28 +02:00
|
|
|
if (node->nod_arg[e_mod_return]) {
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_mod_return]);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_modify_current:
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), node->nod_arg[e_mdc_return] ? blr_modify2 : blr_modify);
|
2006-05-31 20:02:34 +02:00
|
|
|
context = (dsql_ctx*) node->nod_arg[e_mdc_context];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
2006-05-31 20:02:34 +02:00
|
|
|
temp = node->nod_arg[e_mdc_update];
|
|
|
|
context = (dsql_ctx*) temp->nod_arg[e_rel_context];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_mdc_statement]);
|
2006-08-19 20:18:31 +02:00
|
|
|
if (node->nod_arg[e_mdc_return]) {
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_mdc_return]);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_erase:
|
|
|
|
temp = node->nod_arg[e_era_relation];
|
|
|
|
context = (dsql_ctx*) temp->nod_arg[e_rel_context];
|
2009-11-16 10:18:24 +01:00
|
|
|
if (node->nod_arg[e_era_return])
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_begin);
|
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_era_return]);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_erase);
|
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
2009-11-16 10:18:24 +01:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_erase);
|
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_erase_current:
|
|
|
|
context = (dsql_ctx*) node->nod_arg[e_erc_context];
|
2009-11-16 10:18:24 +01:00
|
|
|
if (node->nod_arg[e_erc_return])
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_begin);
|
|
|
|
GEN_statement(dsqlScratch, node->nod_arg[e_erc_return]);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_erase);
|
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
2009-11-16 10:18:24 +01:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_erase);
|
|
|
|
stuff_context(dsqlScratch->getStatement(), context);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nod_exec_procedure:
|
2009-10-21 02:42:38 +02:00
|
|
|
if (node->nod_arg[e_exe_package])
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_proc2);
|
|
|
|
stuff_meta_string(dsqlScratch->getStatement(), ((dsql_str*) node->nod_arg[e_exe_package])->str_data);
|
2009-10-21 02:42:38 +02:00
|
|
|
}
|
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_exec_proc);
|
2009-10-21 02:42:38 +02:00
|
|
|
|
2006-05-31 20:02:34 +02:00
|
|
|
name = (dsql_str*) node->nod_arg[e_exe_procedure];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_meta_string(dsqlScratch->getStatement(), name->str_data);
|
2007-05-27 00:08:13 +02:00
|
|
|
|
2006-05-31 20:02:34 +02:00
|
|
|
// Input parameters
|
2009-11-16 10:18:24 +01:00
|
|
|
if ( (temp = node->nod_arg[e_exe_inputs]) )
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), temp->nod_count);
|
2006-05-31 20:02:34 +02:00
|
|
|
dsql_nod** ptr = temp->nod_arg;
|
|
|
|
const dsql_nod* const* end = ptr + temp->nod_count;
|
|
|
|
while (ptr < end)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr++);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), 0);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
|
|
|
// Output parameters
|
2009-11-16 10:18:24 +01:00
|
|
|
if ( ( temp = node->nod_arg[e_exe_outputs]) )
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), temp->nod_count);
|
2006-05-31 20:02:34 +02:00
|
|
|
dsql_nod** ptr = temp->nod_arg;
|
|
|
|
const dsql_nod* const* end = ptr + temp->nod_count;
|
|
|
|
while (ptr < end)
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr++);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), 0);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fb_assert(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message) {
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_end);
|
2006-05-31 20:02:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-12 17:56:34 +02:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2007-04-12 17:56:34 +02:00
|
|
|
gen_sys_function
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2007-04-12 17:56:34 +02:00
|
|
|
@brief Generate a system defined function.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2007-04-12 17:56:34 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2007-04-12 17:56:34 +02:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_sys_function(DsqlCompilerScratch* dsqlScratch, const dsql_nod* node)
|
2007-04-12 17:56:34 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_sys_function);
|
|
|
|
stuff_cstring(dsqlScratch->getStatement(), ((dsql_str*) node->nod_arg[e_sysfunc_name])->str_data);
|
2007-04-12 17:56:34 +02:00
|
|
|
|
|
|
|
const dsql_nod* list;
|
2007-04-15 13:25:23 +02:00
|
|
|
if ((node->nod_count == e_sysfunc_args + 1) && (list = node->nod_arg[e_sysfunc_args]))
|
2007-04-13 03:37:44 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), list->nod_count);
|
2007-04-12 17:56:34 +02:00
|
|
|
dsql_nod* const* ptr = list->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++)
|
2007-04-12 17:56:34 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr);
|
2007-04-12 17:56:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), 0);
|
2007-04-12 17:56:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_table_lock
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate tpb for table lock.
|
|
|
|
If lock level is specified, it overrrides the transaction lock level.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param tbl_lock
|
|
|
|
@param lock_level
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_table_lock( DsqlCompilerScratch* dsqlScratch, const dsql_nod* tbl_lock, USHORT lock_level)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2008-06-03 08:14:59 +02:00
|
|
|
if (!tbl_lock || tbl_lock->nod_type != nod_table_lock)
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_nod* tbl_names = tbl_lock->nod_arg[e_lock_tables];
|
2003-08-13 13:09:57 +02:00
|
|
|
SSHORT flags = 0;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
if (tbl_lock->nod_arg[e_lock_mode])
|
|
|
|
flags = tbl_lock->nod_arg[e_lock_mode]->nod_flags;
|
|
|
|
|
|
|
|
if (flags & NOD_PROTECTED)
|
2003-11-08 00:27:24 +01:00
|
|
|
lock_level = isc_tpb_protected;
|
2001-05-23 15:26:42 +02:00
|
|
|
else if (flags & NOD_SHARED)
|
2003-11-08 00:27:24 +01:00
|
|
|
lock_level = isc_tpb_shared;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-01-07 10:30:57 +01:00
|
|
|
const USHORT lock_mode = (flags & NOD_WRITE) ? isc_tpb_lock_write : isc_tpb_lock_read;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2006-06-02 10:03:22 +02:00
|
|
|
const dsql_nod* const* ptr = tbl_names->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + tbl_names->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
if ((*ptr)->nod_type != nod_relation_name)
|
|
|
|
continue;
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), lock_mode);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-09-27 11:51:53 +02:00
|
|
|
// stuff table name
|
2003-11-10 10:16:38 +01:00
|
|
|
const dsql_str* temp = (dsql_str*) ((*ptr)->nod_arg[e_rln_name]);
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_cstring(dsqlScratch->getStatement(), temp->str_data);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), lock_level);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_udf
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate a user defined function.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_udf( DsqlCompilerScratch* dsqlScratch, const dsql_nod* node)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-11-10 10:16:38 +01:00
|
|
|
const dsql_udf* userFunc = (dsql_udf*) node->nod_arg[0];
|
2009-10-21 02:42:38 +02:00
|
|
|
|
|
|
|
if (userFunc->udf_name.qualifier.isEmpty())
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_function);
|
2009-10-21 02:42:38 +02:00
|
|
|
else
|
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_function2);
|
|
|
|
stuff_meta_string(dsqlScratch->getStatement(), userFunc->udf_name.qualifier.c_str());
|
2009-10-21 02:42:38 +02:00
|
|
|
}
|
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_meta_string(dsqlScratch->getStatement(), userFunc->udf_name.identifier.c_str());
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
const dsql_nod* list;
|
2009-10-21 02:42:38 +02:00
|
|
|
if ((node->nod_count == 3) && (list = node->nod_arg[2]))
|
2009-01-06 06:53:34 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), list->nod_count);
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* const* ptr = list->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
GEN_expr(dsqlScratch, *ptr);
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
else
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
gen_union
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Generate a union of substreams.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param union_node
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void gen_union( DsqlCompilerScratch* dsqlScratch, const dsql_nod* union_node)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2006-08-01 22:37:58 +02:00
|
|
|
if (union_node->nod_arg[0]->nod_flags & NOD_UNION_RECURSIVE) {
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_recurse);
|
2006-08-01 22:37:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_union);
|
2006-08-01 22:37:58 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-04-18 16:13:26 +02:00
|
|
|
// Obtain the context for UNION from the first dsql_map* node
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* items = union_node->nod_arg[e_rse_items];
|
|
|
|
dsql_nod* map_item = items->nod_arg[0];
|
2003-09-04 17:02:22 +02:00
|
|
|
// AB: First item could be a virtual field generated by derived table.
|
|
|
|
if (map_item->nod_type == nod_derived_field) {
|
2008-09-27 11:51:53 +02:00
|
|
|
map_item = map_item->nod_arg[e_alias_value];
|
2003-08-15 01:34:37 +02:00
|
|
|
}
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_ctx* union_context = (dsql_ctx*) map_item->nod_arg[e_map_context];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_context(dsqlScratch->getStatement(), union_context);
|
2008-09-27 11:51:53 +02:00
|
|
|
// secondary context number must be present once in generated blr
|
2007-07-21 23:28:56 +02:00
|
|
|
union_context->ctx_flags &= ~CTX_recursive;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* streams = union_node->nod_arg[e_rse_streams];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), streams->nod_count); // number of substreams
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2006-06-02 10:03:22 +02:00
|
|
|
dsql_nod** ptr = streams->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const end = ptr + streams->nod_count; ptr < end; ptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
|
|
|
dsql_nod* sub_rse = *ptr;
|
2009-12-20 22:01:10 +01:00
|
|
|
gen_rse(dsqlScratch, sub_rse);
|
2001-05-23 15:26:42 +02:00
|
|
|
items = sub_rse->nod_arg[e_rse_items];
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch->getStatement(), blr_map);
|
|
|
|
stuff_word(dsqlScratch->getStatement(), items->nod_count);
|
2003-08-13 13:09:57 +02:00
|
|
|
USHORT count = 0;
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod** iptr = items->nod_arg;
|
2009-01-06 06:53:34 +01:00
|
|
|
for (const dsql_nod* const* const iend = iptr + items->nod_count; iptr < iend; iptr++)
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff_word(dsqlScratch->getStatement(), count);
|
|
|
|
GEN_expr(dsqlScratch, *iptr);
|
2001-05-23 15:26:42 +02:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-07 11:20:52 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2006-03-07 11:20:52 +01:00
|
|
|
stuff_context
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2006-03-07 11:20:52 +01:00
|
|
|
@brief Write a context number into the BLR buffer.
|
|
|
|
Check for possible overflow.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2006-03-07 11:20:52 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2006-03-07 11:20:52 +01:00
|
|
|
@param context
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void stuff_context(DsqlCompiledStatement* dsqlScratch, const dsql_ctx* context)
|
2006-03-07 11:20:52 +01:00
|
|
|
{
|
|
|
|
if (context->ctx_context > MAX_UCHAR) {
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_too_many_contexts));
|
2006-03-07 11:20:52 +01:00
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch, context->ctx_context);
|
2007-07-21 23:28:56 +02:00
|
|
|
|
|
|
|
if (context->ctx_flags & CTX_recursive)
|
|
|
|
{
|
|
|
|
if (context->ctx_recursive > MAX_UCHAR) {
|
2008-08-15 13:21:47 +02:00
|
|
|
ERRD_post(Arg::Gds(isc_too_many_contexts));
|
2007-07-21 23:28:56 +02:00
|
|
|
}
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch, context->ctx_recursive);
|
2007-07-21 23:28:56 +02:00
|
|
|
}
|
2006-03-07 11:20:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-27 00:08:13 +02:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2007-05-27 00:08:13 +02:00
|
|
|
stuff_meta_string
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2007-05-27 00:08:13 +02:00
|
|
|
@brief Write out a string in metadata charset with one byte of length.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2007-05-27 00:08:13 +02:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2007-05-27 00:08:13 +02:00
|
|
|
@param string
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void stuff_meta_string(DsqlCompiledStatement* dsqlScratch, const char* string)
|
2007-05-27 00:08:13 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
dsqlScratch->append_meta_string(string);
|
2007-05-27 00:08:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
stuff_word
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
@brief Cram a word into the blr buffer. If the buffer is getting
|
|
|
|
ready to overflow, expand it.
|
2008-09-27 11:51:53 +02:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
|
2009-12-20 22:01:10 +01:00
|
|
|
@param dsqlScratch
|
2003-02-15 04:01:51 +01:00
|
|
|
@param word
|
|
|
|
|
|
|
|
**/
|
2009-12-20 22:01:10 +01:00
|
|
|
static void stuff_word(DsqlCompiledStatement* dsqlScratch, USHORT word)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2009-12-20 22:01:10 +01:00
|
|
|
stuff(dsqlScratch, word);
|
|
|
|
stuff(dsqlScratch, word >> 8);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|