2001-05-23 15:26:42 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: Dynamic SQL runtime support
|
2003-10-05 08:27:16 +02:00
|
|
|
* MODULE: make.cpp
|
2001-05-23 15:26:42 +02:00
|
|
|
* DESCRIPTION: Routines to make various blocks.
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Interbase Public
|
|
|
|
* License Version 1.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy
|
|
|
|
* of the License at http://www.Inprise.com/IPL.html
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an
|
|
|
|
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Inprise Corporation
|
|
|
|
* and its predecessors. Portions created by Inprise Corporation are
|
|
|
|
* Copyright (C) Inprise Corporation.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
2002-06-29 08:56:51 +02:00
|
|
|
* 2001.11.21 Claudio Valderrama: Finally solved the mystery of DSQL
|
|
|
|
* not recognizing when a UDF returns NULL. This fixes SF bug #484399.
|
|
|
|
* See case nod_udf in MAKE_desc().
|
|
|
|
* 2001.02.23 Claudio Valderrama: Fix SF bug #518350 with substring()
|
|
|
|
* and text blobs containing charsets other than ASCII/NONE/BINARY.
|
2002-08-03 17:27:20 +02:00
|
|
|
* 2002.07.30 Arno Brinkman:
|
|
|
|
* COALESCE, CASE support added
|
|
|
|
* procedure MAKE_desc_from_list added
|
2003-01-15 13:00:33 +01:00
|
|
|
* 2003.01.25 Dmitry Yemanov: Fixed problem with concatenation which
|
|
|
|
* trashed RDB$FIELD_LENGTH in the system tables. This change may
|
|
|
|
* potentially interfere with the one made by Claudio one year ago.
|
2001-05-23 15:26:42 +02:00
|
|
|
*/
|
2001-12-24 03:51:06 +01:00
|
|
|
|
|
|
|
//This MUST be before any other includes
|
|
|
|
#ifdef DARWIN
|
|
|
|
#define _STLP_CCTYPE
|
|
|
|
#endif
|
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 <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "../dsql/dsql.h"
|
2003-11-08 00:27:24 +01:00
|
|
|
#include "../jrd/ibase.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../jrd/intl.h"
|
|
|
|
#include "../jrd/constants.h"
|
|
|
|
#include "../jrd/align.h"
|
|
|
|
#include "../dsql/alld_proto.h"
|
|
|
|
#include "../dsql/errd_proto.h"
|
|
|
|
#include "../dsql/hsh_proto.h"
|
|
|
|
#include "../dsql/make_proto.h"
|
2005-05-28 00:45:31 +02:00
|
|
|
#include "../dsql/metd_proto.h"
|
2004-06-08 15:41:08 +02:00
|
|
|
#include "../jrd/thd.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../jrd/dsc_proto.h"
|
|
|
|
#include "../jrd/cvt_proto.h"
|
2005-05-28 00:45:31 +02:00
|
|
|
#include "../jrd/inf_proto.h"
|
|
|
|
#include "../jrd/thread_proto.h"
|
2002-12-03 14:37:06 +01:00
|
|
|
#include "../common/config/config.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* InterBase provides transparent conversion from string to date in
|
|
|
|
* contexts where it makes sense. This macro checks a descriptor to
|
|
|
|
* see if it is something that *could* represent a date value
|
|
|
|
*/
|
2003-09-29 14:43:14 +02:00
|
|
|
static inline bool could_be_date(const dsc& d)
|
2003-09-28 02:36:28 +02:00
|
|
|
{
|
2003-09-29 14:43:14 +02:00
|
|
|
return DTYPE_IS_DATE(d.dsc_dtype) || (d.dsc_dtype <= dtype_any_text);
|
2003-09-28 02:36:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-28 07:48:34 +01:00
|
|
|
// One of d1, d2 is time, the other is date
|
2003-09-29 14:43:14 +02:00
|
|
|
static inline bool is_date_and_time(const dsc& d1, const dsc& d2)
|
2003-09-28 02:36:28 +02:00
|
|
|
{
|
2003-09-29 14:43:14 +02:00
|
|
|
return ((d1.dsc_dtype == dtype_sql_time) && (d2.dsc_dtype == dtype_sql_date)) ||
|
|
|
|
((d2.dsc_dtype == dtype_sql_time) && (d1.dsc_dtype == dtype_sql_date));
|
2003-09-28 02:36:28 +02:00
|
|
|
}
|
2001-12-24 03:51:06 +01:00
|
|
|
|
2005-02-14 06:51:25 +01:00
|
|
|
static void make_null(dsc* const desc);
|
|
|
|
static void make_placeholder_null(dsc* const desc);
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_constant
|
|
|
|
|
|
|
|
@brief Make a constant node.
|
|
|
|
|
|
|
|
|
|
|
|
@param constant
|
|
|
|
@param numeric_flag
|
|
|
|
|
|
|
|
**/
|
2003-11-10 10:16:38 +01:00
|
|
|
dsql_nod* MAKE_constant(dsql_str* constant, dsql_constant_type numeric_flag)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2004-05-22 16:23:10 +02:00
|
|
|
tsql* tdsql = DSQL_get_thread_data();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-08-16 14:28:43 +02:00
|
|
|
dsql_nod* node = FB_NEW_RPT(*tdsql->getDefaultPool(),
|
2001-12-24 03:51:06 +01:00
|
|
|
(numeric_flag == CONSTANT_TIMESTAMP ||
|
2002-11-21 00:18:16 +01:00
|
|
|
numeric_flag == CONSTANT_SINT64) ? 2 : 1) dsql_nod;
|
2001-05-23 15:26:42 +02:00
|
|
|
node->nod_type = nod_constant;
|
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
switch (numeric_flag)
|
|
|
|
{
|
|
|
|
case CONSTANT_SLONG:
|
2001-05-23 15:26:42 +02:00
|
|
|
node->nod_desc.dsc_dtype = dtype_long;
|
|
|
|
node->nod_desc.dsc_length = sizeof(SLONG);
|
|
|
|
node->nod_desc.dsc_scale = 0;
|
|
|
|
node->nod_desc.dsc_sub_type = 0;
|
2004-01-21 08:18:30 +01:00
|
|
|
node->nod_desc.dsc_address = (UCHAR*) node->nod_arg;
|
2003-11-01 11:26:43 +01:00
|
|
|
node->nod_arg[0] = (dsql_nod*) constant;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONSTANT_DOUBLE:
|
2001-12-24 03:51:06 +01:00
|
|
|
DEV_BLKCHK(constant, dsql_type_str);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
/* This is a numeric value which is transported to the engine as
|
|
|
|
* a string. The engine will convert it. Use dtype_double so that
|
|
|
|
the engine can distinguish it from an actual string.
|
|
|
|
Note: Due to the size of dsc_scale we are limited to numeric
|
|
|
|
constants of less than 256 bytes.
|
|
|
|
*/
|
|
|
|
node->nod_desc.dsc_dtype = dtype_double;
|
2003-11-01 11:26:43 +01:00
|
|
|
// Scale has no use for double
|
2005-02-14 06:51:25 +01:00
|
|
|
node->nod_desc.dsc_scale = static_cast<signed char>(constant->str_length);
|
2001-05-23 15:26:42 +02:00
|
|
|
node->nod_desc.dsc_sub_type = 0;
|
|
|
|
node->nod_desc.dsc_length = sizeof(double);
|
2004-01-21 08:18:30 +01:00
|
|
|
node->nod_desc.dsc_address = (UCHAR*) constant->str_data;
|
2004-05-21 08:16:17 +02:00
|
|
|
node->nod_desc.dsc_ttype() = ttype_ascii;
|
2003-11-01 11:26:43 +01:00
|
|
|
node->nod_arg[0] = (dsql_nod*) constant;
|
|
|
|
break;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
case CONSTANT_SINT64:
|
|
|
|
{
|
|
|
|
/* We convert the string to an int64. We treat the two adjacent
|
|
|
|
32-bit words node->nod_arg[0] and node->nod_arg[1] as a
|
|
|
|
64-bit integer: if we ever port to a platform which requires
|
|
|
|
8-byte alignment of int64 data, we will have to force 8-byte
|
|
|
|
alignment of node->nod_arg, which is now only guaranteed
|
|
|
|
4-byte alignment. -- ChrisJ 1999-02-20 */
|
|
|
|
|
|
|
|
node->nod_desc.dsc_dtype = dtype_int64;
|
|
|
|
node->nod_desc.dsc_length = sizeof(SINT64);
|
|
|
|
node->nod_desc.dsc_scale = 0;
|
|
|
|
node->nod_desc.dsc_sub_type = 0;
|
2004-01-21 08:18:30 +01:00
|
|
|
node->nod_desc.dsc_address = (UCHAR*) node->nod_arg;
|
2003-11-01 11:26:43 +01:00
|
|
|
|
|
|
|
/* Now convert the string to an int64. We can omit testing for
|
|
|
|
overflow, because we would never have gotten here if yylex
|
|
|
|
hadn't recognized the string as a valid 64-bit integer value.
|
|
|
|
We *might* have "9223372936854775808", which works an an int64
|
|
|
|
only if preceded by a '-', but that issue is handled in GEN_expr,
|
|
|
|
and need not be addressed here. */
|
|
|
|
|
2003-12-22 11:00:59 +01:00
|
|
|
UINT64 value = 0;
|
|
|
|
const char* p = constant->str_data;
|
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
while (isdigit(*p))
|
|
|
|
value = 10 * value + (*(p++) - '0');
|
|
|
|
if (*p++ == '.') {
|
|
|
|
while (isdigit(*p)) {
|
|
|
|
value = 10 * value + (*p++ - '0');
|
|
|
|
node->nod_desc.dsc_scale--;
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
2003-11-01 11:26:43 +01:00
|
|
|
|
|
|
|
*(UINT64 *) (node->nod_desc.dsc_address) = value;
|
|
|
|
break;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
case CONSTANT_DATE:
|
|
|
|
case CONSTANT_TIME:
|
|
|
|
case CONSTANT_TIMESTAMP:
|
|
|
|
{
|
2003-11-28 07:48:34 +01:00
|
|
|
// Setup the constant's descriptor
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
switch (numeric_flag) {
|
|
|
|
case CONSTANT_DATE:
|
|
|
|
node->nod_desc.dsc_dtype = dtype_sql_date;
|
|
|
|
break;
|
|
|
|
case CONSTANT_TIME:
|
|
|
|
node->nod_desc.dsc_dtype = dtype_sql_time;
|
|
|
|
break;
|
|
|
|
case CONSTANT_TIMESTAMP:
|
|
|
|
node->nod_desc.dsc_dtype = dtype_timestamp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
node->nod_desc.dsc_sub_type = 0;
|
|
|
|
node->nod_desc.dsc_scale = 0;
|
|
|
|
node->nod_desc.dsc_length = type_lengths[node->nod_desc.dsc_dtype];
|
2004-01-21 08:18:30 +01:00
|
|
|
node->nod_desc.dsc_address = (UCHAR*) node->nod_arg;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-28 07:48:34 +01:00
|
|
|
// Set up a descriptor to point to the string
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
dsc tmp;
|
|
|
|
tmp.dsc_dtype = dtype_text;
|
|
|
|
tmp.dsc_scale = 0;
|
|
|
|
tmp.dsc_flags = 0;
|
2004-05-21 08:16:17 +02:00
|
|
|
tmp.dsc_ttype() = ttype_ascii;
|
2003-11-01 11:26:43 +01:00
|
|
|
tmp.dsc_length = static_cast<USHORT>(constant->str_length);
|
2004-01-21 08:18:30 +01:00
|
|
|
tmp.dsc_address = (UCHAR*) constant->str_data;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-28 07:48:34 +01:00
|
|
|
// Now invoke the string_to_date/time/timestamp routines
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-03 18:14:45 +01:00
|
|
|
CVT_move(&tmp, &node->nod_desc, ERRD_post);
|
2003-11-01 11:26:43 +01:00
|
|
|
break;
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
default:
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(numeric_flag == CONSTANT_STRING);
|
2001-12-24 03:51:06 +01:00
|
|
|
DEV_BLKCHK(constant, dsql_type_str);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
node->nod_desc.dsc_dtype = dtype_text;
|
|
|
|
node->nod_desc.dsc_sub_type = 0;
|
|
|
|
node->nod_desc.dsc_scale = 0;
|
|
|
|
node->nod_desc.dsc_length =
|
2001-12-24 03:51:06 +01:00
|
|
|
static_cast<USHORT>(constant->str_length);
|
2004-01-21 08:18:30 +01:00
|
|
|
node->nod_desc.dsc_address = (UCHAR*) constant->str_data;
|
2004-05-21 08:16:17 +02:00
|
|
|
node->nod_desc.dsc_ttype() = ttype_dynamic;
|
2003-11-28 07:48:34 +01:00
|
|
|
// carry a pointer to the constant to resolve character set in pass1
|
2003-11-01 11:26:43 +01:00
|
|
|
node->nod_arg[0] = (dsql_nod*) constant;
|
|
|
|
break;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
2004-09-05 09:23:42 +02:00
|
|
|
MAKE_str_constant
|
2003-02-15 04:01:51 +01:00
|
|
|
|
|
|
|
@brief Make a constant node when the
|
|
|
|
character set ID is already known.
|
|
|
|
|
|
|
|
|
|
|
|
@param constant
|
|
|
|
@param character_set
|
|
|
|
|
|
|
|
**/
|
2003-11-10 10:16:38 +01:00
|
|
|
dsql_nod* MAKE_str_constant(dsql_str* constant, SSHORT character_set)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2004-05-22 16:23:10 +02:00
|
|
|
tsql* tdsql = DSQL_get_thread_data();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-08-16 14:28:43 +02:00
|
|
|
dsql_nod* node = FB_NEW_RPT(*tdsql->getDefaultPool(), 1) dsql_nod;
|
2001-05-23 15:26:42 +02:00
|
|
|
node->nod_type = nod_constant;
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
DEV_BLKCHK(constant, dsql_type_str);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
node->nod_desc.dsc_dtype = dtype_text;
|
|
|
|
node->nod_desc.dsc_sub_type = 0;
|
|
|
|
node->nod_desc.dsc_scale = 0;
|
2001-12-24 03:51:06 +01:00
|
|
|
node->nod_desc.dsc_length = static_cast<USHORT>(constant->str_length);
|
2004-01-21 08:18:30 +01:00
|
|
|
node->nod_desc.dsc_address = (UCHAR*) constant->str_data;
|
2004-05-21 08:16:17 +02:00
|
|
|
node->nod_desc.dsc_ttype() = character_set;
|
2003-11-28 07:48:34 +01:00
|
|
|
// carry a pointer to the constant to resolve character set in pass1
|
2003-11-01 11:26:43 +01:00
|
|
|
node->nod_arg[0] = (dsql_nod*) constant;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_cstring
|
|
|
|
|
|
|
|
@brief Make a string node for a string whose
|
|
|
|
length is not known, but is null-terminated.
|
|
|
|
|
|
|
|
|
|
|
|
@param str
|
|
|
|
|
|
|
|
**/
|
2003-11-10 10:16:38 +01:00
|
|
|
dsql_str* MAKE_cstring(const char* str)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
|
2003-02-12 20:28:13 +01:00
|
|
|
return MAKE_string(str, strlen(str));
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_desc
|
|
|
|
|
|
|
|
@brief Make a descriptor from input node.
|
2003-10-05 08:27:16 +02:00
|
|
|
This function can modify node->nod_flags to add NOD_COMP_DIALECT
|
2003-02-15 04:01:51 +01:00
|
|
|
|
|
|
|
@param desc
|
|
|
|
@param node
|
2004-09-04 20:24:12 +02:00
|
|
|
@param null_replacement
|
2003-02-15 04:01:51 +01:00
|
|
|
|
|
|
|
**/
|
2005-05-28 00:45:31 +02:00
|
|
|
void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_replacement)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-10-05 08:27:16 +02:00
|
|
|
dsc desc1, desc2;
|
2001-05-23 15:26:42 +02:00
|
|
|
USHORT dtype, dtype1, dtype2;
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_map* map;
|
2003-11-10 10:16:38 +01:00
|
|
|
dsql_ctx* context;
|
|
|
|
dsql_rel* relation;
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_fld* field;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
DEV_BLKCHK(node, dsql_type_nod);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-09-05 09:23:42 +02:00
|
|
|
// If we already know the datatype, don't worry about anything.
|
|
|
|
//
|
|
|
|
// dimitr: But let's re-evaluate descriptors for expression arguments
|
|
|
|
// (when a NULL replacement node is provided) to always
|
|
|
|
// choose the correct resulting datatype. Example:
|
|
|
|
// NULLIF(NULL, 0) => CHAR(1), but
|
|
|
|
// 1 + NULLIF(NULL, 0) => INT
|
|
|
|
// This is required because of MAKE_desc() being called
|
|
|
|
// from custom pass1 handlers for some node types and thus
|
|
|
|
// causing an incorrect datatype (determined without
|
|
|
|
// context) to be cached in nod_desc.
|
|
|
|
|
|
|
|
if (node->nod_desc.dsc_dtype && !null_replacement)
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
*desc = node->nod_desc;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (node->nod_type) {
|
2004-09-05 09:23:42 +02:00
|
|
|
case nod_constant:
|
2004-09-13 21:36:30 +02:00
|
|
|
case nod_variable:
|
2004-09-05 09:23:42 +02:00
|
|
|
*desc = node->nod_desc;
|
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_agg_count:
|
|
|
|
/* count2
|
|
|
|
case nod_agg_distinct:
|
|
|
|
*/
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_length = sizeof(SLONG);
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_flags = 0;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_map:
|
2003-11-01 11:26:43 +01:00
|
|
|
map = (dsql_map*) node->nod_arg[e_map_map];
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, desc, map->map_node, null_replacement);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_agg_min:
|
|
|
|
case nod_agg_max:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_flags = DSC_nullable;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_agg_average:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_flags = DSC_nullable;
|
|
|
|
dtype = desc->dsc_dtype;
|
|
|
|
if (!DTYPE_CAN_AVERAGE(dtype))
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_expression_eval_err, 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_agg_average2:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_flags = DSC_nullable;
|
|
|
|
dtype = desc->dsc_dtype;
|
|
|
|
if (!DTYPE_CAN_AVERAGE(dtype))
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_expression_eval_err, 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
if (DTYPE_IS_EXACT(dtype)) {
|
|
|
|
desc->dsc_dtype = dtype_int64;
|
|
|
|
desc->dsc_length = sizeof(SINT64);
|
|
|
|
node->nod_flags |= NOD_COMP_DIALECT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
desc->dsc_dtype = dtype_double;
|
|
|
|
desc->dsc_length = sizeof(double);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_agg_total:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
|
2001-05-23 15:26:42 +02:00
|
|
|
if (desc->dsc_dtype == dtype_short) {
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_length = sizeof(SLONG);
|
|
|
|
}
|
|
|
|
else if (desc->dsc_dtype == dtype_int64) {
|
|
|
|
desc->dsc_dtype = dtype_double;
|
|
|
|
desc->dsc_length = sizeof(double);
|
|
|
|
}
|
|
|
|
desc->dsc_flags = DSC_nullable;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_agg_total2:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
|
2001-05-23 15:26:42 +02:00
|
|
|
dtype = desc->dsc_dtype;
|
|
|
|
if (DTYPE_IS_EXACT(dtype)) {
|
|
|
|
desc->dsc_dtype = dtype_int64;
|
|
|
|
desc->dsc_length = sizeof(SINT64);
|
|
|
|
node->nod_flags |= NOD_COMP_DIALECT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
desc->dsc_dtype = dtype_double;
|
|
|
|
desc->dsc_length = sizeof(double);
|
|
|
|
}
|
|
|
|
desc->dsc_flags = DSC_nullable;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_concatenate:
|
2003-01-15 13:00:33 +01:00
|
|
|
{
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
|
|
|
|
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
|
2004-09-04 20:24:12 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_dtype = dtype_varying;
|
2004-09-04 20:24:12 +02:00
|
|
|
|
|
|
|
if (node->nod_arg[0]->nod_type == nod_null &&
|
|
|
|
node->nod_arg[1]->nod_type == nod_null)
|
|
|
|
{
|
|
|
|
// NULL || NULL = NULL of VARCHAR(1) CHARACTER SET NONE
|
|
|
|
desc->dsc_ttype() = 0;
|
|
|
|
desc->dsc_length = sizeof(USHORT) + 1;
|
|
|
|
desc->dsc_flags |= DSC_nullable;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
if (desc1.dsc_dtype <= dtype_any_text)
|
2004-05-21 08:16:17 +02:00
|
|
|
desc->dsc_ttype() = desc1.dsc_ttype();
|
2003-11-01 11:26:43 +01:00
|
|
|
else
|
2004-05-21 08:16:17 +02:00
|
|
|
desc->dsc_ttype() = ttype_ascii;
|
2004-09-04 20:24:12 +02:00
|
|
|
|
2005-01-05 13:15:51 +01:00
|
|
|
ULONG length =
|
2005-05-28 00:45:31 +02:00
|
|
|
((node->nod_arg[0]->nod_type == nod_null) ? 0 : DSC_string_length(&desc1)) /
|
|
|
|
METD_get_charset_bpc(request, INTL_GET_CHARSET(&desc1));
|
|
|
|
|
|
|
|
length +=
|
|
|
|
((node->nod_arg[1]->nod_type == nod_null) ? 0 : DSC_string_length(&desc2)) /
|
|
|
|
METD_get_charset_bpc(request, INTL_GET_CHARSET(&desc2));
|
|
|
|
|
|
|
|
length *= METD_get_charset_bpc(request, INTL_GET_CHARSET(desc));
|
2004-09-04 20:24:12 +02:00
|
|
|
|
2005-01-05 13:15:51 +01:00
|
|
|
if (length > MAX_COLUMN_SIZE - sizeof(USHORT))
|
2004-08-02 21:49:12 +02:00
|
|
|
{
|
2004-09-12 12:48:55 +02:00
|
|
|
length = MAX_COLUMN_SIZE - sizeof(USHORT);
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
2004-09-04 20:24:12 +02:00
|
|
|
|
2005-01-05 13:15:51 +01:00
|
|
|
desc->dsc_length = length + sizeof(USHORT);
|
2003-11-01 11:26:43 +01:00
|
|
|
desc->dsc_flags = (desc1.dsc_flags | desc2.dsc_flags) & DSC_nullable;
|
2003-01-15 13:00:33 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
2003-09-04 17:02:22 +02:00
|
|
|
case nod_derived_field:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, desc, node->nod_arg[e_derived_field_value], null_replacement);
|
2003-09-04 17:02:22 +02:00
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_upcase:
|
2005-05-28 00:45:31 +02:00
|
|
|
case nod_lowcase:
|
2002-06-29 08:56:51 +02:00
|
|
|
case nod_substr:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, &desc1, node->nod_arg[0], null_replacement);
|
2001-05-23 15:26:42 +02:00
|
|
|
if (desc1.dsc_dtype <= dtype_any_text) {
|
|
|
|
*desc = desc1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
desc->dsc_dtype = dtype_varying;
|
|
|
|
desc->dsc_scale = 0;
|
2002-06-29 08:56:51 +02:00
|
|
|
|
2003-10-05 08:27:16 +02:00
|
|
|
/* Beware that JRD treats substring() always as returning CHAR
|
|
|
|
instead of VARCHAR for historical reasons. */
|
2004-08-02 21:49:12 +02:00
|
|
|
if (node->nod_type == nod_substr && desc1.dsc_dtype == dtype_blob)
|
|
|
|
{
|
2003-11-10 10:16:38 +01:00
|
|
|
dsql_nod* for_node = node->nod_arg[e_substr_length];
|
2005-05-28 00:45:31 +02:00
|
|
|
// Migrate the charset and collation from the blob to the string.
|
|
|
|
desc->dsc_ttype() = desc1.dsc_blob_ttype();
|
2004-08-02 21:49:12 +02:00
|
|
|
// Set maximum possible length
|
|
|
|
SLONG length = MAX_COLUMN_SIZE - sizeof(USHORT);
|
|
|
|
if (for_node->nod_type == nod_constant &&
|
|
|
|
for_node->nod_desc.dsc_dtype == dtype_long)
|
|
|
|
{
|
|
|
|
// We have a constant passed as length, so
|
|
|
|
// use the real length
|
2005-05-28 00:45:31 +02:00
|
|
|
length = *(SLONG *) for_node->nod_desc.dsc_address *
|
|
|
|
METD_get_charset_bpc(request, desc1.dsc_scale);
|
|
|
|
|
2004-09-12 12:48:55 +02:00
|
|
|
if (length < 0 || length > MAX_COLUMN_SIZE - sizeof(USHORT))
|
2004-08-02 21:49:12 +02:00
|
|
|
{
|
|
|
|
length = MAX_COLUMN_SIZE - sizeof(USHORT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
desc->dsc_length = sizeof(USHORT) + length;
|
2002-06-29 08:56:51 +02:00
|
|
|
}
|
2004-08-02 21:49:12 +02:00
|
|
|
else
|
|
|
|
{
|
2004-05-21 08:16:17 +02:00
|
|
|
desc->dsc_ttype() = ttype_ascii;
|
2004-08-02 21:49:12 +02:00
|
|
|
desc->dsc_length = sizeof(USHORT) + DSC_string_length(&desc1);
|
2002-06-29 08:56:51 +02:00
|
|
|
}
|
2003-10-05 08:27:16 +02:00
|
|
|
desc->dsc_flags = desc1.dsc_flags & DSC_nullable;
|
|
|
|
return;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2005-05-28 00:45:31 +02:00
|
|
|
case nod_trim:
|
2005-06-06 22:18:12 +02:00
|
|
|
MAKE_desc(request, &desc1, node->nod_arg[e_trim_value], null_replacement);
|
2005-05-28 00:45:31 +02:00
|
|
|
|
|
|
|
if (desc1.dsc_dtype <= dtype_any_text) {
|
|
|
|
*desc = desc1;
|
|
|
|
desc->dsc_dtype = dtype_varying;
|
|
|
|
desc->dsc_length = sizeof(USHORT) + DSC_string_length(&desc1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc->dsc_dtype = dtype_varying;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_ttype() = ttype_ascii;
|
|
|
|
desc->dsc_length = sizeof(USHORT) + DSC_string_length(&desc1);
|
|
|
|
desc->dsc_flags = desc1.dsc_flags & DSC_nullable;
|
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_cast:
|
2003-11-01 11:26:43 +01:00
|
|
|
field = (dsql_fld*) node->nod_arg[e_cast_target];
|
2001-05-23 15:26:42 +02:00
|
|
|
MAKE_desc_from_field(desc, field);
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, &desc1, node->nod_arg[e_cast_source], NULL);
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_flags = desc1.dsc_flags & DSC_nullable;
|
|
|
|
return;
|
|
|
|
|
2002-08-03 17:27:20 +02:00
|
|
|
case nod_simple_case:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc_from_list(request, &desc1, node->nod_arg[e_simple_case_results],
|
2004-09-05 09:23:42 +02:00
|
|
|
null_replacement, "CASE");
|
2002-08-03 17:27:20 +02:00
|
|
|
*desc = desc1;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_searched_case:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc_from_list(request, &desc1, node->nod_arg[e_searched_case_results],
|
2004-09-05 09:23:42 +02:00
|
|
|
null_replacement, "CASE");
|
2002-08-03 17:27:20 +02:00
|
|
|
*desc = desc1;
|
|
|
|
return;
|
|
|
|
|
2003-10-05 08:27:16 +02:00
|
|
|
case nod_coalesce:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc_from_list(request, &desc1, node->nod_arg[0],
|
2004-09-05 09:23:42 +02:00
|
|
|
null_replacement, "COALESCE");
|
2002-08-03 17:27:20 +02:00
|
|
|
*desc = desc1;
|
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
#ifdef DEV_BUILD
|
|
|
|
case nod_collate:
|
|
|
|
ERRD_bugcheck("Not expecting nod_collate in dsql/MAKE_desc");
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case nod_add:
|
|
|
|
case nod_subtract:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
|
|
|
|
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
|
2004-09-04 20:24:12 +02:00
|
|
|
|
|
|
|
if (node->nod_arg[0]->nod_type == nod_null &&
|
|
|
|
node->nod_arg[1]->nod_type == nod_null)
|
|
|
|
{
|
|
|
|
// NULL + NULL = NULL of INT
|
2005-02-14 06:51:25 +01:00
|
|
|
make_null(desc);
|
2004-09-04 20:24:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
dtype1 = desc1.dsc_dtype;
|
|
|
|
dtype2 = desc2.dsc_dtype;
|
|
|
|
|
|
|
|
if (dtype_int64 == dtype1)
|
|
|
|
dtype1 = dtype_double;
|
|
|
|
if (dtype_int64 == dtype2)
|
|
|
|
dtype2 = dtype_double;
|
|
|
|
|
|
|
|
dtype = MAX(dtype1, dtype2);
|
|
|
|
|
2003-12-22 11:00:59 +01:00
|
|
|
if (DTYPE_IS_BLOB(dtype)) {
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 607,
|
|
|
|
isc_arg_gds, isc_dsql_no_blob_array, 0);
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
desc->dsc_flags = (desc1.dsc_flags | desc2.dsc_flags) & DSC_nullable;
|
|
|
|
switch (dtype) {
|
|
|
|
case dtype_sql_time:
|
|
|
|
case dtype_sql_date:
|
|
|
|
/* Forbid <date/time> +- <string> */
|
2003-10-21 00:41:11 +02:00
|
|
|
if (DTYPE_IS_TEXT(desc1.dsc_dtype) ||
|
|
|
|
DTYPE_IS_TEXT(desc2.dsc_dtype))
|
|
|
|
{
|
2004-09-04 20:24:12 +02:00
|
|
|
ERRD_post(isc_expression_eval_err, 0);
|
2003-10-21 00:41:11 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
case dtype_timestamp:
|
|
|
|
|
|
|
|
/* Allow <timestamp> +- <string> (historical) */
|
2003-09-28 02:36:28 +02:00
|
|
|
if (could_be_date(desc1) && could_be_date(desc2)) {
|
2001-05-23 15:26:42 +02:00
|
|
|
if (node->nod_type == nod_subtract) {
|
|
|
|
/* <any date> - <any date> */
|
|
|
|
|
|
|
|
/* Legal permutations are:
|
|
|
|
<timestamp> - <timestamp>
|
|
|
|
<timestamp> - <date>
|
|
|
|
<date> - <date>
|
|
|
|
<date> - <timestamp>
|
|
|
|
<time> - <time>
|
|
|
|
<timestamp> - <string>
|
|
|
|
<string> - <timestamp>
|
|
|
|
<string> - <string> */
|
|
|
|
|
2003-10-21 00:41:11 +02:00
|
|
|
if (DTYPE_IS_TEXT(dtype1))
|
2001-05-23 15:26:42 +02:00
|
|
|
dtype = dtype_timestamp;
|
2003-10-21 00:41:11 +02:00
|
|
|
else if (DTYPE_IS_TEXT(dtype2))
|
2001-05-23 15:26:42 +02:00
|
|
|
dtype = dtype_timestamp;
|
|
|
|
else if (dtype1 == dtype2)
|
|
|
|
dtype = dtype1;
|
|
|
|
else if ((dtype1 == dtype_timestamp) &&
|
|
|
|
(dtype2 == dtype_sql_date))
|
2003-12-22 11:00:59 +01:00
|
|
|
{
|
2004-09-04 20:24:12 +02:00
|
|
|
dtype = dtype_timestamp;
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
else if ((dtype2 == dtype_timestamp) &&
|
|
|
|
(dtype1 == dtype_sql_date))
|
2003-12-22 11:00:59 +01:00
|
|
|
{
|
2004-09-04 20:24:12 +02:00
|
|
|
dtype = dtype_timestamp;
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
|
|
|
else {
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_expression_eval_err, 0);
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
if (dtype == dtype_sql_date) {
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_length = sizeof(SLONG);
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
}
|
|
|
|
else if (dtype == dtype_sql_time) {
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_length = sizeof(SLONG);
|
|
|
|
desc->dsc_scale = ISC_TIME_SECONDS_PRECISION_SCALE;
|
|
|
|
}
|
|
|
|
else {
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(dtype == dtype_timestamp);
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_dtype = dtype_double;
|
|
|
|
desc->dsc_length = sizeof(double);
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
}
|
|
|
|
}
|
2003-09-28 02:36:28 +02:00
|
|
|
else if (is_date_and_time(desc1, desc2)) {
|
2001-05-23 15:26:42 +02:00
|
|
|
/* <date> + <time> */
|
|
|
|
/* <time> + <date> */
|
|
|
|
desc->dsc_dtype = dtype_timestamp;
|
|
|
|
desc->dsc_length = type_lengths[dtype_timestamp];
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
}
|
2003-12-22 11:00:59 +01:00
|
|
|
else {
|
2001-05-23 15:26:42 +02:00
|
|
|
/* <date> + <date> */
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_expression_eval_err, 0);
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
else if (DTYPE_IS_DATE(desc1.dsc_dtype) ||
|
|
|
|
/* <date> +/- <non-date> */
|
|
|
|
(node->nod_type == nod_add))
|
|
|
|
/* <non-date> + <date> */
|
|
|
|
{
|
|
|
|
desc->dsc_dtype = desc1.dsc_dtype;
|
|
|
|
if (!DTYPE_IS_DATE(desc->dsc_dtype))
|
|
|
|
desc->dsc_dtype = desc2.dsc_dtype;
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(DTYPE_IS_DATE(desc->dsc_dtype));
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_length = type_lengths[desc->dsc_dtype];
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* <non-date> - <date> */
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(node->nod_type == nod_subtract);
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_expression_eval_err, 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case dtype_varying:
|
|
|
|
case dtype_cstring:
|
|
|
|
case dtype_text:
|
|
|
|
case dtype_double:
|
|
|
|
case dtype_real:
|
|
|
|
desc->dsc_dtype = dtype_double;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_length = sizeof(double);
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_length = sizeof(SLONG);
|
|
|
|
desc->dsc_scale = MIN(NUMERIC_SCALE(desc1), NUMERIC_SCALE(desc2));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_add2:
|
|
|
|
case nod_subtract2:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
|
|
|
|
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
|
2004-09-04 20:24:12 +02:00
|
|
|
|
|
|
|
if (node->nod_arg[0]->nod_type == nod_null &&
|
|
|
|
node->nod_arg[1]->nod_type == nod_null)
|
|
|
|
{
|
|
|
|
// NULL + NULL = NULL of INT
|
2005-02-14 06:51:25 +01:00
|
|
|
make_null(desc);
|
2004-09-04 20:24:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
dtype1 = desc1.dsc_dtype;
|
|
|
|
dtype2 = desc2.dsc_dtype;
|
|
|
|
|
2003-11-28 07:48:34 +01:00
|
|
|
// Arrays and blobs can never partipate in addition/subtraction
|
2003-12-22 11:00:59 +01:00
|
|
|
if (DTYPE_IS_BLOB(desc1.dsc_dtype) || DTYPE_IS_BLOB(desc2.dsc_dtype)) {
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 607,
|
|
|
|
isc_arg_gds, isc_dsql_no_blob_array, 0);
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
/* In Dialect 2 or 3, strings can never partipate in addition / sub
|
|
|
|
(Use a specific cast instead) */
|
2003-10-21 00:41:11 +02:00
|
|
|
if (DTYPE_IS_TEXT(desc1.dsc_dtype) ||
|
|
|
|
DTYPE_IS_TEXT(desc2.dsc_dtype))
|
|
|
|
{
|
2004-09-04 20:24:12 +02:00
|
|
|
ERRD_post(isc_expression_eval_err, 0);
|
2003-10-21 00:41:11 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
/* Determine the TYPE of arithmetic to perform, store it
|
|
|
|
in dtype. Note: this is different from the result of
|
|
|
|
the operation, as <timestamp>-<timestamp> uses
|
|
|
|
<timestamp> arithmetic, but returns a <double> */
|
|
|
|
if (DTYPE_IS_EXACT(desc1.dsc_dtype)
|
|
|
|
&& DTYPE_IS_EXACT(desc2.dsc_dtype)) dtype = dtype_int64;
|
|
|
|
else if (DTYPE_IS_NUMERIC(desc1.dsc_dtype)
|
2003-12-22 11:00:59 +01:00
|
|
|
&& DTYPE_IS_NUMERIC(desc2.dsc_dtype))
|
|
|
|
{
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(DTYPE_IS_APPROX(desc1.dsc_dtype) ||
|
2001-05-23 15:26:42 +02:00
|
|
|
DTYPE_IS_APPROX(desc2.dsc_dtype));
|
|
|
|
dtype = dtype_double;
|
|
|
|
}
|
|
|
|
else {
|
2003-11-28 07:48:34 +01:00
|
|
|
// mixed numeric and non-numeric:
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(DTYPE_IS_DATE(dtype1) || DTYPE_IS_DATE(dtype2));
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-03-07 08:58:55 +01:00
|
|
|
// The MAX(dtype) rule doesn't apply with dtype_int64
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
if (dtype_int64 == dtype1)
|
|
|
|
dtype1 = dtype_double;
|
|
|
|
if (dtype_int64 == dtype2)
|
|
|
|
dtype2 = dtype_double;
|
|
|
|
|
|
|
|
dtype = MAX(dtype1, dtype2);
|
|
|
|
}
|
|
|
|
|
|
|
|
desc->dsc_flags = (desc1.dsc_flags | desc2.dsc_flags) & DSC_nullable;
|
|
|
|
switch (dtype) {
|
|
|
|
case dtype_sql_time:
|
|
|
|
case dtype_sql_date:
|
|
|
|
case dtype_timestamp:
|
|
|
|
|
2003-12-22 11:00:59 +01:00
|
|
|
if ((DTYPE_IS_DATE(dtype1) || (dtype1 == dtype_unknown)) &&
|
|
|
|
(DTYPE_IS_DATE(dtype2) || (dtype2 == dtype_unknown)))
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
if (node->nod_type == nod_subtract2) {
|
|
|
|
/* <any date> - <any date> */
|
|
|
|
/* Legal permutations are:
|
|
|
|
<timestamp> - <timestamp>
|
|
|
|
<timestamp> - <date>
|
|
|
|
<date> - <date>
|
|
|
|
<date> - <timestamp>
|
|
|
|
<time> - <time> */
|
|
|
|
|
|
|
|
if (dtype1 == dtype2)
|
|
|
|
dtype = dtype1;
|
|
|
|
else if ((dtype1 == dtype_timestamp) &&
|
|
|
|
(dtype2 == dtype_sql_date))
|
2003-12-22 11:00:59 +01:00
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
dtype = dtype_timestamp;
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
else if ((dtype2 == dtype_timestamp) &&
|
|
|
|
(dtype1 == dtype_sql_date))
|
2003-12-22 11:00:59 +01:00
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
dtype = dtype_timestamp;
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
|
|
|
else {
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_expression_eval_err, 0);
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
if (dtype == dtype_sql_date) {
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_length = sizeof(SLONG);
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
}
|
|
|
|
else if (dtype == dtype_sql_time) {
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_length = sizeof(SLONG);
|
|
|
|
desc->dsc_scale = ISC_TIME_SECONDS_PRECISION_SCALE;
|
|
|
|
}
|
|
|
|
else {
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(dtype == dtype_timestamp);
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_dtype = dtype_int64;
|
|
|
|
desc->dsc_length = sizeof(SINT64);
|
|
|
|
desc->dsc_scale = -9;
|
|
|
|
}
|
|
|
|
}
|
2003-09-28 02:36:28 +02:00
|
|
|
else if (is_date_and_time(desc1, desc2)) {
|
2001-05-23 15:26:42 +02:00
|
|
|
/* <date> + <time> */
|
|
|
|
/* <time> + <date> */
|
|
|
|
desc->dsc_dtype = dtype_timestamp;
|
|
|
|
desc->dsc_length = type_lengths[dtype_timestamp];
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
}
|
2003-12-22 11:00:59 +01:00
|
|
|
else {
|
2001-05-23 15:26:42 +02:00
|
|
|
/* <date> + <date> */
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_expression_eval_err, 0);
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
else if (DTYPE_IS_DATE(desc1.dsc_dtype) ||
|
|
|
|
/* <date> +/- <non-date> */
|
|
|
|
(node->nod_type == nod_add2))
|
|
|
|
/* <non-date> + <date> */
|
|
|
|
{
|
|
|
|
desc->dsc_dtype = desc1.dsc_dtype;
|
|
|
|
if (!DTYPE_IS_DATE(desc->dsc_dtype))
|
|
|
|
desc->dsc_dtype = desc2.dsc_dtype;
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(DTYPE_IS_DATE(desc->dsc_dtype));
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_length = type_lengths[desc->dsc_dtype];
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* <non-date> - <date> */
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(node->nod_type == nod_subtract2);
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_expression_eval_err, 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case dtype_varying:
|
|
|
|
case dtype_cstring:
|
|
|
|
case dtype_text:
|
|
|
|
case dtype_double:
|
|
|
|
case dtype_real:
|
|
|
|
desc->dsc_dtype = dtype_double;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_length = sizeof(double);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case dtype_short:
|
|
|
|
case dtype_long:
|
|
|
|
case dtype_int64:
|
|
|
|
desc->dsc_dtype = dtype_int64;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_length = sizeof(SINT64);
|
|
|
|
|
|
|
|
/* The result type is int64 because both operands are
|
|
|
|
exact numeric: hence we don't need the NUMERIC_SCALE
|
|
|
|
macro here. */
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(DTYPE_IS_EXACT(desc1.dsc_dtype));
|
|
|
|
fb_assert(DTYPE_IS_EXACT(desc2.dsc_dtype));
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
desc->dsc_scale = MIN(desc1.dsc_scale, desc2.dsc_scale);
|
|
|
|
node->nod_flags |= NOD_COMP_DIALECT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-11-28 07:48:34 +01:00
|
|
|
// a type which cannot participate in an add or subtract
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_expression_eval_err, 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_multiply:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
|
|
|
|
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
|
2004-09-04 20:24:12 +02:00
|
|
|
|
|
|
|
if (node->nod_arg[0]->nod_type == nod_null &&
|
|
|
|
node->nod_arg[1]->nod_type == nod_null)
|
|
|
|
{
|
|
|
|
// NULL * NULL = NULL of INT
|
2005-02-14 06:51:25 +01:00
|
|
|
make_null(desc);
|
2004-09-04 20:24:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
dtype = DSC_multiply_blr4_result[desc1.dsc_dtype][desc2.dsc_dtype];
|
|
|
|
|
2003-12-22 11:00:59 +01:00
|
|
|
if (dtype_unknown == dtype) {
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 607,
|
|
|
|
isc_arg_gds, isc_dsql_no_blob_array, 0);
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
desc->dsc_flags = (desc1.dsc_flags | desc2.dsc_flags) & DSC_nullable;
|
|
|
|
switch (dtype) {
|
|
|
|
case dtype_double:
|
|
|
|
desc->dsc_dtype = dtype_double;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_length = sizeof(double);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_long:
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_length = sizeof(SLONG);
|
|
|
|
desc->dsc_scale = NUMERIC_SCALE(desc1) + NUMERIC_SCALE(desc2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_expression_eval_err, 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_multiply2:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
|
|
|
|
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
|
2004-09-04 20:24:12 +02:00
|
|
|
|
|
|
|
if (node->nod_arg[0]->nod_type == nod_null &&
|
|
|
|
node->nod_arg[1]->nod_type == nod_null)
|
|
|
|
{
|
|
|
|
// NULL * NULL = NULL of INT
|
2005-02-14 06:51:25 +01:00
|
|
|
make_null(desc);
|
2004-09-04 20:24:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
dtype = DSC_multiply_result[desc1.dsc_dtype][desc2.dsc_dtype];
|
|
|
|
|
|
|
|
desc->dsc_flags = (desc1.dsc_flags | desc2.dsc_flags) & DSC_nullable;
|
|
|
|
switch (dtype) {
|
|
|
|
case dtype_double:
|
|
|
|
desc->dsc_dtype = dtype_double;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_length = sizeof(double);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_int64:
|
|
|
|
desc->dsc_dtype = dtype_int64;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_length = sizeof(SINT64);
|
|
|
|
desc->dsc_scale = NUMERIC_SCALE(desc1) + NUMERIC_SCALE(desc2);
|
|
|
|
node->nod_flags |= NOD_COMP_DIALECT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 607,
|
|
|
|
isc_arg_gds, isc_dsql_no_blob_array, 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_count:
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_length = sizeof(SLONG);
|
|
|
|
desc->dsc_flags = 0;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_divide:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
|
|
|
|
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
|
2004-09-04 20:24:12 +02:00
|
|
|
|
|
|
|
if (node->nod_arg[0]->nod_type == nod_null &&
|
|
|
|
node->nod_arg[1]->nod_type == nod_null)
|
|
|
|
{
|
|
|
|
// NULL / NULL = NULL of INT
|
2005-02-14 06:51:25 +01:00
|
|
|
make_null(desc);
|
2004-09-04 20:24:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
dtype1 = desc1.dsc_dtype;
|
|
|
|
if (dtype_int64 == dtype1)
|
|
|
|
dtype1 = dtype_double;
|
|
|
|
|
|
|
|
dtype2 = desc2.dsc_dtype;
|
|
|
|
if (dtype_int64 == dtype2)
|
|
|
|
dtype2 = dtype_double;
|
|
|
|
|
|
|
|
dtype = MAX(dtype1, dtype2);
|
|
|
|
|
2003-12-22 11:00:59 +01:00
|
|
|
if (!DTYPE_CAN_DIVIDE(dtype)) {
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 607,
|
|
|
|
isc_arg_gds, isc_dsql_no_blob_array, 0);
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_dtype = dtype_double;
|
|
|
|
desc->dsc_length = sizeof(double);
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_flags = (desc1.dsc_flags | desc2.dsc_flags) & DSC_nullable;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_divide2:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]);
|
|
|
|
MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]);
|
2004-09-04 20:24:12 +02:00
|
|
|
|
|
|
|
if (node->nod_arg[0]->nod_type == nod_null &&
|
|
|
|
node->nod_arg[1]->nod_type == nod_null)
|
|
|
|
{
|
|
|
|
// NULL / NULL = NULL of INT
|
2005-02-14 06:51:25 +01:00
|
|
|
make_null(desc);
|
2004-09-04 20:24:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
dtype = DSC_multiply_result[desc1.dsc_dtype][desc2.dsc_dtype];
|
2001-12-24 03:51:06 +01:00
|
|
|
desc->dsc_dtype = static_cast<UCHAR>(dtype);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
desc->dsc_flags = (desc1.dsc_flags | desc2.dsc_flags) & DSC_nullable;
|
|
|
|
switch (dtype) {
|
|
|
|
case dtype_int64:
|
|
|
|
desc->dsc_length = sizeof(SINT64);
|
|
|
|
desc->dsc_scale = NUMERIC_SCALE(desc1) + NUMERIC_SCALE(desc2);
|
|
|
|
node->nod_flags |= NOD_COMP_DIALECT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dtype_double:
|
|
|
|
desc->dsc_length = sizeof(double);
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 607,
|
|
|
|
isc_arg_gds, isc_dsql_no_blob_array, 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_negate:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, desc, node->nod_arg[0], null_replacement);
|
2004-09-04 20:24:12 +02:00
|
|
|
|
|
|
|
if (node->nod_arg[0]->nod_type == nod_null)
|
|
|
|
{
|
|
|
|
// -NULL = NULL of INT
|
2005-02-14 06:51:25 +01:00
|
|
|
make_null(desc);
|
2004-09-04 20:24:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-22 11:00:59 +01:00
|
|
|
if (!DTYPE_CAN_NEGATE(desc->dsc_dtype)) {
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 607,
|
|
|
|
isc_arg_gds, isc_dsql_no_blob_array, 0);
|
2003-12-22 11:00:59 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_alias:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, desc, node->nod_arg[e_alias_value], null_replacement);
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_dbkey:
|
2003-11-28 07:48:34 +01:00
|
|
|
// Fix for bug 10072 check that the target is a relation
|
2003-11-10 10:16:38 +01:00
|
|
|
context = (dsql_ctx*) node->nod_arg[0]->nod_arg[0];
|
2003-10-05 08:27:16 +02:00
|
|
|
relation = context->ctx_relation;
|
2002-07-06 07:32:02 +02:00
|
|
|
if (relation != 0) {
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_dtype = dtype_text;
|
|
|
|
desc->dsc_length = relation->rel_dbkey_length;
|
|
|
|
desc->dsc_flags = 0;
|
2004-05-21 08:16:17 +02:00
|
|
|
desc->dsc_ttype() = ttype_binary;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
else {
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 607,
|
|
|
|
isc_arg_gds, isc_dsql_dbkey_from_non_table, 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_udf:
|
2003-11-01 11:26:43 +01:00
|
|
|
{
|
2003-11-10 10:16:38 +01:00
|
|
|
const dsql_udf* userFunc = (dsql_udf*) node->nod_arg[0];
|
2003-11-01 11:26:43 +01:00
|
|
|
desc->dsc_dtype = static_cast<UCHAR>(userFunc->udf_dtype);
|
|
|
|
desc->dsc_length = userFunc->udf_length;
|
|
|
|
desc->dsc_scale = static_cast<SCHAR>(userFunc->udf_scale);
|
|
|
|
/* CVC: Setting flags to zero obviously impeded DSQL to acknowledge
|
|
|
|
the fact that any UDF can return NULL simply returning a NULL
|
|
|
|
pointer. */
|
|
|
|
desc->dsc_flags = DSC_nullable;
|
|
|
|
|
|
|
|
if (desc->dsc_dtype <= dtype_any_text) {
|
2004-05-21 08:16:17 +02:00
|
|
|
desc->dsc_ttype() = userFunc->udf_character_set_id;
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
|
|
|
else {
|
2004-05-21 08:16:17 +02:00
|
|
|
desc->dsc_ttype() = userFunc->udf_sub_type;
|
2003-11-01 11:26:43 +01:00
|
|
|
}
|
|
|
|
return;
|
2002-11-21 00:48:34 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
case nod_gen_id:
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_length = sizeof(SLONG);
|
|
|
|
desc->dsc_flags = node->nod_arg[e_gen_id_value]->nod_desc.dsc_flags;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_gen_id2:
|
|
|
|
desc->dsc_dtype = dtype_int64;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_length = sizeof(SINT64);
|
|
|
|
desc->dsc_flags = node->nod_arg[e_gen_id_value]->nod_desc.dsc_flags;
|
|
|
|
node->nod_flags |= NOD_COMP_DIALECT;
|
|
|
|
return;
|
|
|
|
|
2003-10-05 08:27:16 +02:00
|
|
|
case nod_limit:
|
2003-11-07 15:10:16 +01:00
|
|
|
case nod_rows:
|
2003-10-05 08:27:16 +02:00
|
|
|
if (node->nod_desc.dsc_scale <= SQL_DIALECT_V5) {
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_length = sizeof (SLONG);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
desc->dsc_dtype = dtype_int64;
|
|
|
|
desc->dsc_length = sizeof (SINT64);
|
|
|
|
}
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_flags = 0; /* Can first/skip accept NULL in the future? */
|
|
|
|
return;
|
2002-06-29 08:56:51 +02:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_field:
|
2004-09-05 23:50:54 +02:00
|
|
|
if (node->nod_desc.dsc_dtype)
|
|
|
|
{
|
|
|
|
*desc = node->nod_desc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 203,
|
|
|
|
isc_arg_gds, isc_dsql_field_ref, 0);
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_user_name:
|
2003-10-05 08:27:16 +02:00
|
|
|
case nod_current_role:
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_dtype = dtype_varying;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_flags = 0;
|
2004-05-21 08:16:17 +02:00
|
|
|
desc->dsc_ttype() = ttype_dynamic;
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_length = USERNAME_LENGTH + sizeof(USHORT);
|
|
|
|
return;
|
|
|
|
|
2002-06-14 14:07:20 +02:00
|
|
|
case nod_internal_info:
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_flags = 0;
|
|
|
|
desc->dsc_length = sizeof(SLONG);
|
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_current_time:
|
|
|
|
desc->dsc_dtype = dtype_sql_time;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_flags = 0;
|
|
|
|
desc->dsc_length = type_lengths[desc->dsc_dtype];
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_current_date:
|
|
|
|
desc->dsc_dtype = dtype_sql_date;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_flags = 0;
|
|
|
|
desc->dsc_length = type_lengths[desc->dsc_dtype];
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_current_timestamp:
|
|
|
|
desc->dsc_dtype = dtype_timestamp;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_flags = 0;
|
|
|
|
desc->dsc_length = type_lengths[desc->dsc_dtype];
|
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_extract:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, &desc1, node->nod_arg[e_extract_value], NULL);
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_flags = (desc1.dsc_flags & DSC_nullable);
|
|
|
|
if (*(ULONG *) node->nod_arg[e_extract_part]->nod_desc.dsc_address
|
2003-12-22 11:00:59 +01:00
|
|
|
== blr_extract_second)
|
|
|
|
{
|
2004-03-07 08:58:55 +01:00
|
|
|
// QUADDATE - maybe this should be DECIMAL(6,4)
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_scale = ISC_TIME_SECONDS_PRECISION_SCALE;
|
|
|
|
desc->dsc_length = sizeof(ULONG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
desc->dsc_dtype = dtype_short;
|
|
|
|
desc->dsc_length = sizeof(SSHORT);
|
|
|
|
return;
|
|
|
|
|
2005-06-06 20:14:10 +02:00
|
|
|
case nod_strlen:
|
|
|
|
MAKE_desc(request, &desc1, node->nod_arg[e_strlen_value], NULL);
|
2005-05-28 00:45:31 +02:00
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_flags = (desc1.dsc_flags & DSC_nullable);
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_length = sizeof(ULONG);
|
|
|
|
return;
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
case nod_parameter:
|
|
|
|
/* We don't actually know the datatype of a parameter -
|
|
|
|
we have to guess it based on the context that the
|
|
|
|
parameter appears in. (This is done is pass1.c::set_parameter_type())
|
|
|
|
However, a parameter can appear as part of an expression.
|
|
|
|
As MAKE_desc is used for both determination of parameter
|
|
|
|
types and for expression type checking, we just continue. */
|
2004-09-22 08:54:17 +02:00
|
|
|
if (node->nod_desc.dsc_dtype)
|
|
|
|
{
|
|
|
|
*desc = node->nod_desc;
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_null:
|
|
|
|
/* This occurs when SQL statement specifies a literal NULL, eg:
|
|
|
|
* SELECT NULL FROM TABLE1;
|
|
|
|
* As we don't have a <dtype_null, SQL_NULL> datatype pairing,
|
|
|
|
* we don't know how to map this NULL to a host-language
|
|
|
|
* datatype. Therefore we now describe it as a
|
|
|
|
* CHAR(1) CHARACTER SET NONE type.
|
|
|
|
* No value will ever be sent back, as the value of the select
|
|
|
|
* will be NULL - this is only for purposes of DESCRIBING
|
2003-12-22 11:00:59 +01:00
|
|
|
* the statement. Note that this mapping could be done in dsql.cpp
|
2001-05-23 15:26:42 +02:00
|
|
|
* as part of the DESCRIBE statement - but I suspect other areas
|
2003-12-22 11:00:59 +01:00
|
|
|
* of the code would break if this is declared dtype_unknown.
|
2001-05-23 15:26:42 +02:00
|
|
|
*/
|
2004-09-04 20:24:12 +02:00
|
|
|
if (null_replacement)
|
|
|
|
{
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, desc, null_replacement, NULL);
|
2005-04-20 15:06:42 +02:00
|
|
|
desc->dsc_flags |= (DSC_nullable | DSC_null);
|
2004-09-04 20:24:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-14 06:51:25 +01:00
|
|
|
make_placeholder_null(desc);
|
2004-09-04 20:24:12 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
case nod_via:
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, desc, node->nod_arg[e_via_value_1], null_replacement);
|
2001-05-23 15:26:42 +02:00
|
|
|
/**
|
|
|
|
Set the descriptor flag as nullable. The
|
|
|
|
select expression may or may not return
|
|
|
|
this row based on the WHERE clause. Setting this
|
|
|
|
flag warns the client to expect null values.
|
|
|
|
(bug 10379)
|
|
|
|
**/
|
|
|
|
desc->dsc_flags |= DSC_nullable;
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
2003-11-28 07:48:34 +01:00
|
|
|
fb_assert(false); // unexpected dsql_nod type
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-28 07:48:34 +01:00
|
|
|
case nod_dom_value: // computed value not used
|
2001-05-23 15:26:42 +02:00
|
|
|
/* By the time we get here, any nod_dom_value node should have had
|
|
|
|
* its descriptor set to the type of the domain being created, or
|
|
|
|
* to the type of the existing domain to which a CHECK constraint
|
|
|
|
* is being added.
|
|
|
|
*/
|
2003-12-22 11:00:59 +01:00
|
|
|
fb_assert(node->nod_desc.dsc_dtype != dtype_unknown);
|
2001-05-23 15:26:42 +02:00
|
|
|
if (desc != &node->nod_desc)
|
|
|
|
*desc = node->nod_desc;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_desc_from_field
|
|
|
|
|
|
|
|
@brief Compute a DSC from a field's description information.
|
|
|
|
|
|
|
|
|
|
|
|
@param desc
|
|
|
|
@param field
|
|
|
|
|
|
|
|
**/
|
2003-10-05 08:27:16 +02:00
|
|
|
void MAKE_desc_from_field(dsc* desc, const dsql_fld* field)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
DEV_BLKCHK(field, dsql_type_fld);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
desc->dsc_dtype = static_cast<UCHAR>(field->fld_dtype);
|
|
|
|
desc->dsc_scale = static_cast<SCHAR>(field->fld_scale);
|
2001-05-23 15:26:42 +02:00
|
|
|
desc->dsc_sub_type = field->fld_sub_type;
|
|
|
|
desc->dsc_length = field->fld_length;
|
|
|
|
desc->dsc_flags = (field->fld_flags & FLD_nullable) ? DSC_nullable : 0;
|
|
|
|
if (desc->dsc_dtype <= dtype_any_text) {
|
|
|
|
INTL_ASSIGN_DSC(desc, field->fld_character_set_id,
|
|
|
|
field->fld_collation_id);
|
|
|
|
}
|
|
|
|
else if (desc->dsc_dtype == dtype_blob)
|
2005-05-28 00:45:31 +02:00
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
desc->dsc_scale = static_cast<SCHAR>(field->fld_character_set_id);
|
2005-05-28 00:45:31 +02:00
|
|
|
desc->dsc_flags |= field->fld_collation_id << 8;
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_desc_from_list
|
|
|
|
|
|
|
|
@brief Make a descriptor from a list of values
|
2003-08-25 00:15:23 +02:00
|
|
|
according to the sql-standard.
|
2003-02-15 04:01:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
@param desc
|
|
|
|
@param node
|
2003-08-28 01:00:43 +02:00
|
|
|
@param expression_name
|
2003-02-15 04:01:51 +01:00
|
|
|
|
|
|
|
**/
|
2005-05-28 00:45:31 +02:00
|
|
|
void MAKE_desc_from_list(dsql_req* request, dsc* desc, dsql_nod* node,
|
2004-09-05 09:23:42 +02:00
|
|
|
dsql_nod* null_replacement,
|
|
|
|
const TEXT* expression_name)
|
2002-08-03 17:27:20 +02:00
|
|
|
{
|
2003-08-25 00:15:23 +02:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
// [Arno Brinkman] 2003-08-23
|
|
|
|
//
|
2004-06-21 04:48:47 +02:00
|
|
|
// This function is made to determine a output descriptor from a given list
|
2003-08-25 00:15:23 +02:00
|
|
|
// of expressions according to the latest SQL-standard that was available.
|
|
|
|
// (ISO/ANSI SQL:200n WG3:DRS-013 H2-2002-358 August, 2002)
|
|
|
|
//
|
|
|
|
// If any datatype has a character type then :
|
2003-08-26 01:35:30 +02:00
|
|
|
// - the output will always be a character type except unconvertable types.
|
2003-08-25 00:15:23 +02:00
|
|
|
// (dtype_text, dtype_cstring, dtype_varying, dtype_blob sub_type TEXT)
|
|
|
|
// !! Currently engine cannot convert string to BLOB therefor BLOB isn't allowed. !!
|
|
|
|
// - first character-set and collation are used as output descriptor.
|
2003-08-26 01:35:30 +02:00
|
|
|
// - if all types have datatype CHAR then output should be CHAR else
|
|
|
|
// VARCHAR and with the maximum length used from the given list.
|
2003-08-25 00:15:23 +02:00
|
|
|
//
|
|
|
|
// If all of the datatypes are EXACT numeric then the output descriptor
|
|
|
|
// shall be EXACT numeric with the maximum scale and the maximum precision
|
|
|
|
// used. (dtype_byte, dtype_short, dtype_long, dtype_int64)
|
|
|
|
//
|
|
|
|
// If any of the datatypes is APPROXIMATE numeric then each datatype in the
|
|
|
|
// list shall be numeric else a error is thrown and the output descriptor
|
|
|
|
// shall be APPROXIMATE numeric. (dtype_real, dtype_double, dtype_d_float)
|
|
|
|
//
|
|
|
|
// If any of the datatypes is a datetime type then each datatype in the
|
|
|
|
// list shall be the same datetime type else a error is thrown.
|
|
|
|
// numeric. (dtype_sql_date, dtype_sql_time, dtype_timestamp)
|
|
|
|
//
|
|
|
|
// If any of the datatypes is a BLOB datatype then :
|
|
|
|
// - all types should be a BLOB else throw error.
|
|
|
|
// - all types should have the same sub_type else throw error.
|
|
|
|
// - when TEXT type then use first character-set and collation as output
|
|
|
|
// descriptor.
|
|
|
|
// (dtype_blob)
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2003-10-05 08:27:16 +02:00
|
|
|
// Initialize values.
|
2003-08-25 00:15:23 +02:00
|
|
|
UCHAR max_dtype = 0;
|
|
|
|
SCHAR max_scale = 0;
|
2004-06-19 23:29:50 +02:00
|
|
|
USHORT max_length = 0, max_dtype_length = 0, maxtextlength = 0, max_significant_digits = 0;
|
2003-08-25 00:15:23 +02:00
|
|
|
SSHORT max_sub_type = 0, first_sub_type, ttype = ttype_ascii; // default type if all nodes are nod_null.
|
2004-06-19 23:29:50 +02:00
|
|
|
SSHORT max_numeric_sub_type = 0;
|
2004-09-05 09:23:42 +02:00
|
|
|
bool firstarg = true, all_same_sub_type = true, all_equal = true, all_nulls = true;
|
2004-06-19 23:29:50 +02:00
|
|
|
bool all_numeric = true, any_numeric = false, any_approx = false, any_float = false;
|
2003-08-25 00:15:23 +02:00
|
|
|
bool all_text = true, any_text = false, any_varying = false;
|
2003-08-26 01:35:30 +02:00
|
|
|
bool all_date = true, all_time = true, all_timestamp = true, any_datetime = false;
|
|
|
|
bool all_blob = true, any_blob = false, any_text_blob = false;
|
2003-08-25 00:15:23 +02:00
|
|
|
|
|
|
|
// Walk through arguments list.
|
2003-10-05 08:27:16 +02:00
|
|
|
const dsql_nod* err_node = NULL;
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod** arg = node->nod_arg;
|
|
|
|
for (dsql_nod** end = arg + node->nod_count; arg < end; arg++) {
|
|
|
|
dsql_nod* tnod = *arg;
|
2005-04-19 11:55:53 +02:00
|
|
|
|
|
|
|
// If this is an alias pick the source datatype
|
|
|
|
if (tnod->nod_type == nod_alias) {
|
|
|
|
tnod = tnod->nod_arg[e_alias_value];
|
|
|
|
}
|
|
|
|
|
2004-09-05 09:23:42 +02:00
|
|
|
// do we have only literal NULLs?
|
|
|
|
if (tnod->nod_type != nod_null) {
|
2005-04-20 15:06:42 +02:00
|
|
|
if (!(tnod->nod_desc.dsc_flags & DSC_null)) {
|
|
|
|
all_nulls = false;
|
|
|
|
}
|
2004-09-05 09:23:42 +02:00
|
|
|
}
|
|
|
|
// ignore NULL and parameter value from walking
|
2005-04-20 15:06:42 +02:00
|
|
|
if (tnod->nod_type == nod_null ||
|
|
|
|
tnod->nod_desc.dsc_flags & DSC_null ||
|
|
|
|
tnod->nod_type == nod_parameter)
|
|
|
|
{
|
2002-08-03 17:27:20 +02:00
|
|
|
continue;
|
2002-10-19 02:49:23 +02:00
|
|
|
}
|
2003-08-25 00:15:23 +02:00
|
|
|
|
|
|
|
// Get the descriptor from current node.
|
2003-10-05 08:27:16 +02:00
|
|
|
dsc desc1;
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, &desc1, tnod, NULL);
|
2003-08-25 00:15:23 +02:00
|
|
|
|
|
|
|
// Check if we support this datatype.
|
|
|
|
if (!(DTYPE_IS_TEXT(desc1.dsc_dtype) || DTYPE_IS_NUMERIC(desc1.dsc_dtype) ||
|
|
|
|
DTYPE_IS_DATE(desc1.dsc_dtype) || DTYPE_IS_BLOB(desc1.dsc_dtype)))
|
|
|
|
{
|
|
|
|
// ERROR !!!!
|
2003-12-22 11:00:59 +01:00
|
|
|
// Unknown datatype
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 804,
|
|
|
|
isc_arg_gds, isc_dsql_datatype_err, 0);
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
2003-08-25 00:15:23 +02:00
|
|
|
|
|
|
|
// Initialize some values if this is the first time.
|
|
|
|
if (firstarg) {
|
|
|
|
max_scale = desc1.dsc_scale;
|
|
|
|
max_length = max_dtype_length = desc1.dsc_length;
|
|
|
|
max_sub_type = first_sub_type = desc1.dsc_sub_type;
|
|
|
|
max_dtype = desc1.dsc_dtype;
|
|
|
|
firstarg = false;
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
2004-06-19 23:29:50 +02:00
|
|
|
else {
|
|
|
|
if (all_equal) {
|
|
|
|
all_equal =
|
|
|
|
(max_dtype == desc1.dsc_dtype) &&
|
|
|
|
(max_scale == desc1.dsc_scale) &&
|
|
|
|
(max_length == desc1.dsc_length) &&
|
|
|
|
(max_sub_type == desc1.dsc_sub_type);
|
|
|
|
}
|
|
|
|
}
|
2003-08-25 00:15:23 +02:00
|
|
|
|
|
|
|
// numeric datatypes :
|
|
|
|
if (DTYPE_IS_NUMERIC(desc1.dsc_dtype)) {
|
2003-08-26 01:35:30 +02:00
|
|
|
any_numeric = true;
|
2003-08-25 00:15:23 +02:00
|
|
|
// Is there any approximate numeric?
|
|
|
|
if (DTYPE_IS_APPROX(desc1.dsc_dtype)) {
|
|
|
|
any_approx = true;
|
2004-06-19 23:29:50 +02:00
|
|
|
// Dialect 1 NUMERIC and DECIMAL are stored as sub-types
|
|
|
|
// 1 and 2 from float types dtype_real, dtype_double
|
|
|
|
if (!any_float) {
|
|
|
|
any_float = (desc1.dsc_sub_type == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
if (desc1.dsc_sub_type > max_numeric_sub_type) {
|
|
|
|
max_numeric_sub_type = desc1.dsc_sub_type;
|
2003-08-11 02:43:42 +02:00
|
|
|
}
|
2003-08-25 00:15:23 +02:00
|
|
|
}
|
2002-10-19 02:49:23 +02:00
|
|
|
else {
|
2003-08-25 00:15:23 +02:00
|
|
|
all_numeric = false;
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
2003-08-25 00:15:23 +02:00
|
|
|
|
|
|
|
// Get the max scale and length (precision)
|
|
|
|
// scale is negative so check less than < !
|
|
|
|
if (desc1.dsc_scale < max_scale) {
|
|
|
|
max_scale = desc1.dsc_scale;
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
2003-08-25 00:15:23 +02:00
|
|
|
if (desc1.dsc_length > max_length) {
|
|
|
|
max_length = desc1.dsc_length;
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
2004-06-19 23:29:50 +02:00
|
|
|
// Get max significant bits
|
|
|
|
if (type_significant_bits[desc1.dsc_dtype] > max_significant_digits) {
|
|
|
|
max_significant_digits = type_significant_bits[desc1.dsc_dtype];
|
|
|
|
}
|
2003-08-25 00:15:23 +02:00
|
|
|
// Get max dtype and sub_type
|
|
|
|
if (desc1.dsc_dtype > max_dtype) {
|
|
|
|
max_dtype = desc1.dsc_dtype;
|
|
|
|
max_dtype_length = desc1.dsc_length;
|
|
|
|
}
|
|
|
|
if (desc1.dsc_sub_type > max_sub_type) {
|
|
|
|
max_sub_type = desc1.dsc_sub_type;
|
|
|
|
}
|
|
|
|
if (desc1.dsc_sub_type != first_sub_type) {
|
|
|
|
all_same_sub_type = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is this a text type?
|
|
|
|
if (DTYPE_IS_TEXT(desc1.dsc_dtype))// ||
|
|
|
|
//((desc1.dsc_dtype == dtype_blob) &&
|
|
|
|
//(desc1.dsc_sub_type == 1))) // SUB_TYPE 1 = TEXT
|
|
|
|
//
|
|
|
|
// AB: We should support TEXT BLOB in the near future, but
|
|
|
|
// currently we can't
|
|
|
|
//
|
|
|
|
{
|
2003-12-22 11:00:59 +01:00
|
|
|
const dsc* ptr = &desc1;
|
2003-10-05 08:27:16 +02:00
|
|
|
const USHORT cnvlength = TEXT_LEN(ptr);
|
2002-10-19 02:49:23 +02:00
|
|
|
if (cnvlength > maxtextlength) {
|
2002-08-03 17:27:20 +02:00
|
|
|
maxtextlength = cnvlength;
|
|
|
|
}
|
2003-08-25 00:15:23 +02:00
|
|
|
if (desc1.dsc_dtype == dtype_varying) {
|
|
|
|
any_varying = true;
|
|
|
|
}
|
2002-08-03 17:27:20 +02:00
|
|
|
|
2003-08-25 00:15:23 +02:00
|
|
|
// Pick first characterset-collate from args-list
|
|
|
|
//
|
|
|
|
// Is there an better way to determine the
|
|
|
|
// characterset / collate from the list ?
|
|
|
|
// Maybe first according SQL-standard which has an order
|
|
|
|
// UTF32 -> UTF16 -> UTF8 then by a Firebird specified order
|
|
|
|
//
|
2003-11-22 23:43:24 +01:00
|
|
|
// At least give any first charset other then ASCII/NONE precedence
|
2003-08-25 00:15:23 +02:00
|
|
|
if (!any_text) {
|
2004-05-21 08:16:17 +02:00
|
|
|
ttype = desc1.dsc_ttype();
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
2003-11-22 23:43:24 +01:00
|
|
|
else {
|
|
|
|
if ((ttype == ttype_none) || (ttype == ttype_ascii)) {
|
2004-05-21 08:16:17 +02:00
|
|
|
ttype = desc1.dsc_ttype();
|
2003-11-22 23:43:24 +01:00
|
|
|
}
|
|
|
|
}
|
2003-08-25 00:15:23 +02:00
|
|
|
any_text = true;
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
2002-10-19 02:49:23 +02:00
|
|
|
else {
|
2003-08-25 00:15:23 +02:00
|
|
|
// Get max needed-length for not text types suchs as int64,timestamp etc..
|
2003-10-05 08:27:16 +02:00
|
|
|
const USHORT cnvlength = DSC_convert_to_text_length(desc1.dsc_dtype);
|
2003-08-26 01:35:30 +02:00
|
|
|
if (cnvlength > maxtextlength) {
|
|
|
|
maxtextlength = cnvlength;
|
|
|
|
}
|
2003-08-25 00:15:23 +02:00
|
|
|
all_text = false;
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
2003-08-25 00:15:23 +02:00
|
|
|
|
2002-10-19 02:49:23 +02:00
|
|
|
if (DTYPE_IS_DATE(desc1.dsc_dtype)) {
|
2003-08-26 01:35:30 +02:00
|
|
|
any_datetime = true;
|
2003-08-25 00:15:23 +02:00
|
|
|
if (desc1.dsc_dtype == dtype_sql_date) {
|
|
|
|
all_time = false;
|
|
|
|
all_timestamp = false;
|
2003-08-28 01:00:43 +02:00
|
|
|
}
|
|
|
|
else if (desc1.dsc_dtype == dtype_sql_time) {
|
2003-08-25 00:15:23 +02:00
|
|
|
all_date = false;
|
|
|
|
all_timestamp = false;
|
|
|
|
}
|
2003-08-28 01:00:43 +02:00
|
|
|
else if (desc1.dsc_dtype == dtype_timestamp) {
|
2003-08-25 00:15:23 +02:00
|
|
|
all_date = false;
|
|
|
|
all_time = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
all_date = false;
|
|
|
|
all_time = false;
|
|
|
|
all_timestamp = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc1.dsc_dtype == dtype_blob) {
|
2003-08-28 01:00:43 +02:00
|
|
|
// When there was already another datatype raise immediately exception
|
|
|
|
if (!all_blob || !all_same_sub_type) {
|
|
|
|
err_node = tnod;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-08-26 01:35:30 +02:00
|
|
|
any_blob = true;
|
2005-03-13 13:17:32 +01:00
|
|
|
if (desc1.dsc_sub_type == 1) {
|
2003-08-25 00:15:23 +02:00
|
|
|
// TEXT BLOB
|
2003-08-26 01:35:30 +02:00
|
|
|
if (!any_text_blob) {
|
2003-08-25 00:15:23 +02:00
|
|
|
// Save first characterset and collation
|
2005-05-28 00:45:31 +02:00
|
|
|
ttype = desc1.dsc_blob_ttype();
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
2003-08-26 01:35:30 +02:00
|
|
|
any_text_blob = true;
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
|
|
|
}
|
2002-10-19 02:49:23 +02:00
|
|
|
else {
|
2003-08-25 00:15:23 +02:00
|
|
|
all_blob = false;
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-05 09:23:42 +02:00
|
|
|
// If we have literal NULLs only, let the result be either
|
|
|
|
// CHAR(1) CHARACTER SET NONE or the context-provided datatype
|
|
|
|
if (all_nulls)
|
|
|
|
{
|
|
|
|
if (null_replacement)
|
|
|
|
{
|
2005-05-28 00:45:31 +02:00
|
|
|
MAKE_desc(request, desc, null_replacement, NULL);
|
2004-09-05 09:23:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-14 06:51:25 +01:00
|
|
|
make_placeholder_null(desc);
|
2004-09-05 09:23:42 +02:00
|
|
|
}
|
2005-04-20 15:06:42 +02:00
|
|
|
desc->dsc_flags |= DSC_null;
|
2004-09-05 09:23:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-08-25 00:15:23 +02:00
|
|
|
// If we haven't had a type at all then all values are NULL and/or parameter nodes.
|
2002-10-19 02:49:23 +02:00
|
|
|
if (firstarg) {
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 804,
|
|
|
|
isc_arg_gds, isc_dsql_datatype_err, 0);
|
2003-08-25 00:15:23 +02:00
|
|
|
// Dynamic SQL Error SQL error code = -804 Data type unknown
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
|
|
|
|
2003-08-28 01:00:43 +02:00
|
|
|
if (err_node) {
|
|
|
|
//TEXT error_info[45];
|
|
|
|
//sprintf(error_info, "%s at line %d, column %d.", expression_name,
|
|
|
|
// (int) err_node->nod_line, (int) err_node->nod_column);
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104,
|
|
|
|
isc_arg_gds, isc_dsql_datatypes_not_comparable,
|
|
|
|
isc_arg_string, "",
|
|
|
|
isc_arg_string, expression_name, 0);
|
2003-08-28 01:00:43 +02:00
|
|
|
// "Datatypes %sare not comparable in expression %s"
|
|
|
|
}
|
|
|
|
|
2002-08-03 17:27:20 +02:00
|
|
|
desc->dsc_flags = DSC_nullable;
|
2004-06-19 23:29:50 +02:00
|
|
|
|
|
|
|
// If all the datatypes we've seen are exactly the same, we're done
|
|
|
|
if (all_equal) {
|
|
|
|
desc->dsc_dtype = max_dtype;
|
|
|
|
desc->dsc_length = max_length;
|
|
|
|
desc->dsc_scale = max_scale;
|
|
|
|
desc->dsc_sub_type = max_sub_type;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-08-25 00:15:23 +02:00
|
|
|
// If all of the arguments are from type text use a text type.
|
2003-08-26 01:35:30 +02:00
|
|
|
// Firebird behaves a little bit different than standard here, because
|
|
|
|
// any datatype (except BLOB) can be converted to a character-type we
|
|
|
|
// allow to use numeric and datetime types together with a
|
|
|
|
// character-type, but output will always be varying !
|
|
|
|
if (all_text || (any_text && (any_numeric || any_datetime))) {
|
|
|
|
if (any_varying || (any_text && (any_numeric || any_datetime))) {
|
2002-08-03 17:27:20 +02:00
|
|
|
desc->dsc_dtype = dtype_varying;
|
|
|
|
maxtextlength += sizeof(USHORT);
|
|
|
|
}
|
2002-10-19 02:49:23 +02:00
|
|
|
else {
|
2002-08-03 17:27:20 +02:00
|
|
|
desc->dsc_dtype = dtype_text;
|
|
|
|
}
|
2004-05-21 08:16:17 +02:00
|
|
|
desc->dsc_ttype() = ttype; // same as dsc_subtype
|
2002-08-03 17:27:20 +02:00
|
|
|
desc->dsc_length = maxtextlength;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
return;
|
|
|
|
}
|
2003-08-28 01:00:43 +02:00
|
|
|
else if (all_numeric) {
|
|
|
|
// If all of the arguments are a numeric datatype.
|
2003-08-25 00:15:23 +02:00
|
|
|
if (any_approx) {
|
2004-06-19 23:29:50 +02:00
|
|
|
if (max_significant_digits <= type_significant_bits[dtype_real]) {
|
2003-08-25 00:15:23 +02:00
|
|
|
desc->dsc_dtype = dtype_real;
|
|
|
|
desc->dsc_length = type_lengths[desc->dsc_dtype];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
desc->dsc_dtype = dtype_double;
|
|
|
|
desc->dsc_length = type_lengths[desc->dsc_dtype];
|
|
|
|
}
|
2004-06-19 23:29:50 +02:00
|
|
|
if (any_float) {
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
desc->dsc_scale = max_scale;
|
|
|
|
desc->dsc_sub_type = max_numeric_sub_type;
|
|
|
|
}
|
2003-08-25 00:15:23 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
desc->dsc_dtype = max_dtype;
|
|
|
|
desc->dsc_length = max_dtype_length;
|
2004-06-19 23:29:50 +02:00
|
|
|
desc->dsc_sub_type = max_numeric_sub_type;
|
2003-08-25 00:15:23 +02:00
|
|
|
desc->dsc_scale = max_scale;
|
|
|
|
}
|
2002-08-03 17:27:20 +02:00
|
|
|
return;
|
|
|
|
}
|
2003-08-28 01:00:43 +02:00
|
|
|
else if (all_date || all_time || all_timestamp) {
|
|
|
|
// If all of the arguments are the same datetime datattype.
|
2003-08-25 00:15:23 +02:00
|
|
|
desc->dsc_dtype = max_dtype;
|
|
|
|
desc->dsc_length = max_dtype_length;
|
2002-08-03 17:27:20 +02:00
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
return;
|
|
|
|
}
|
2003-08-28 01:00:43 +02:00
|
|
|
else if (all_blob && all_same_sub_type) {
|
|
|
|
// If all of the arguments are the same BLOB datattype.
|
2003-08-25 00:15:23 +02:00
|
|
|
desc->dsc_dtype = max_dtype;
|
|
|
|
desc->dsc_sub_type = max_sub_type;
|
2005-03-13 13:17:32 +01:00
|
|
|
if (max_sub_type == 1) {
|
2003-08-25 00:15:23 +02:00
|
|
|
// TEXT BLOB
|
|
|
|
desc->dsc_scale = ttype;
|
2005-05-28 00:45:31 +02:00
|
|
|
desc->dsc_flags |= ttype & 0xFF00; // collation
|
2003-08-25 00:15:23 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
desc->dsc_scale = max_scale;
|
|
|
|
}
|
|
|
|
desc->dsc_length = max_length;
|
2002-08-03 17:27:20 +02:00
|
|
|
return;
|
|
|
|
}
|
2003-08-28 01:00:43 +02:00
|
|
|
else {
|
|
|
|
// We couldn't do anything with this list, mostly because the
|
|
|
|
// datatypes aren't comparable.
|
|
|
|
// Let's try to give a usefull error message.
|
2003-11-08 00:27:24 +01:00
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104,
|
|
|
|
isc_arg_gds, isc_dsql_datatypes_not_comparable,
|
|
|
|
isc_arg_string, "",
|
|
|
|
isc_arg_string, expression_name, 0);
|
2003-08-28 01:00:43 +02:00
|
|
|
// "Datatypes %sare not comparable in expression %s"
|
|
|
|
}
|
2002-08-03 17:27:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_field
|
|
|
|
|
|
|
|
@brief Make up a field node.
|
|
|
|
|
|
|
|
|
|
|
|
@param context
|
|
|
|
@param field
|
|
|
|
@param indices
|
|
|
|
|
|
|
|
**/
|
2003-11-10 10:16:38 +01:00
|
|
|
dsql_nod* MAKE_field(dsql_ctx* context, dsql_fld* field, dsql_nod* indices)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
DEV_BLKCHK(context, dsql_type_ctx);
|
|
|
|
DEV_BLKCHK(field, dsql_type_fld);
|
|
|
|
DEV_BLKCHK(indices, dsql_type_nod);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* node = MAKE_node(nod_field, e_fld_count);
|
|
|
|
node->nod_arg[e_fld_context] = (dsql_nod*) context;
|
|
|
|
node->nod_arg[e_fld_field] = (dsql_nod*) field;
|
2001-05-23 15:26:42 +02:00
|
|
|
if (field->fld_dimensions) {
|
|
|
|
if (indices) {
|
|
|
|
node->nod_arg[e_fld_indices] = indices;
|
|
|
|
MAKE_desc_from_field(&node->nod_desc, field);
|
|
|
|
node->nod_desc.dsc_dtype =
|
2001-12-24 03:51:06 +01:00
|
|
|
static_cast<UCHAR>(field->fld_element_dtype);
|
2001-05-23 15:26:42 +02:00
|
|
|
node->nod_desc.dsc_length = field->fld_element_length;
|
|
|
|
/*
|
|
|
|
node->nod_desc.dsc_scale = field->fld_scale;
|
|
|
|
node->nod_desc.dsc_sub_type = field->fld_sub_type;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node->nod_desc.dsc_dtype = dtype_array;
|
2003-11-11 13:19:20 +01:00
|
|
|
node->nod_desc.dsc_length = sizeof(ISC_QUAD);
|
2001-05-23 15:26:42 +02:00
|
|
|
node->nod_desc.dsc_scale =
|
2001-12-24 03:51:06 +01:00
|
|
|
static_cast<SCHAR>(field->fld_scale);
|
2001-05-23 15:26:42 +02:00
|
|
|
node->nod_desc.dsc_sub_type = field->fld_sub_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(!indices);
|
2001-05-23 15:26:42 +02:00
|
|
|
MAKE_desc_from_field(&node->nod_desc, field);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((field->fld_flags & FLD_nullable) ||
|
2003-11-10 10:16:38 +01:00
|
|
|
(context->ctx_flags & CTX_outer_join))
|
|
|
|
{
|
2003-04-06 12:09:38 +02:00
|
|
|
node->nod_desc.dsc_flags = DSC_nullable;
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2005-05-28 00:45:31 +02:00
|
|
|
if (node->nod_desc.dsc_dtype <= dtype_varying)
|
|
|
|
{
|
|
|
|
Firebird::HalfStaticArray<UCHAR, sizeof(UCHAR) + sizeof(UCHAR) + sizeof(UCHAR)> inputBuffer;
|
|
|
|
UCHAR* input = inputBuffer.begin();
|
|
|
|
char buffer[16];
|
|
|
|
|
|
|
|
*input++ = isc_info_internal;
|
|
|
|
*input++ = INF_internal_db_info_intl_is_legacy_charset;
|
|
|
|
*input++ = INTL_GET_CHARSET(&node->nod_desc);
|
|
|
|
|
|
|
|
ISC_STATUS_ARRAY user_status;
|
|
|
|
THREAD_EXIT();
|
2005-06-06 10:30:03 +02:00
|
|
|
const ISC_STATUS s =
|
|
|
|
isc_database_info(user_status, &context->ctx_request->req_dbb->dbb_database_handle,
|
2005-05-28 00:45:31 +02:00
|
|
|
inputBuffer.getCapacity(), (SCHAR*)inputBuffer.begin(),
|
|
|
|
sizeof(buffer), buffer);
|
|
|
|
THREAD_ENTER();
|
2005-06-06 10:30:03 +02:00
|
|
|
if (s)
|
|
|
|
;
|
|
|
|
#pragma FB_COMPILER_MESSAGE("Adriano should put an error message here.")
|
2005-05-28 00:45:31 +02:00
|
|
|
|
|
|
|
if (*((UCHAR*)buffer + sizeof(UCHAR) + sizeof(USHORT))) // CHARSET_LEGACY_SEMANTICS
|
|
|
|
{
|
2005-06-06 10:30:03 +02:00
|
|
|
USHORT adjust = 0;
|
2005-05-28 00:45:31 +02:00
|
|
|
if (node->nod_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 (node->nod_desc.dsc_dtype == dtype_cstring)
|
2005-06-06 10:30:03 +02:00
|
|
|
adjust = 1;
|
|
|
|
|
|
|
|
node->nod_desc.dsc_length -= adjust;
|
2005-05-28 00:45:31 +02:00
|
|
|
|
|
|
|
node->nod_desc.dsc_length *=
|
|
|
|
METD_get_charset_bpc(context->ctx_request, INTL_GET_CHARSET(&node->nod_desc));
|
|
|
|
|
2005-06-06 10:30:03 +02:00
|
|
|
node->nod_desc.dsc_length += adjust;
|
2005-05-28 00:45:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_list
|
|
|
|
|
|
|
|
@brief Make a list node from a linked list stack of things.
|
|
|
|
|
|
|
|
|
|
|
|
@param stack
|
|
|
|
|
|
|
|
**/
|
2004-04-18 16:22:27 +02:00
|
|
|
dsql_nod* MAKE_list(DsqlNodStack& stack)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2004-04-18 16:22:27 +02:00
|
|
|
USHORT count = stack.getCount();
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* node = MAKE_node(nod_list, count);
|
|
|
|
dsql_nod** ptr = node->nod_arg + count;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-05-27 18:26:52 +02:00
|
|
|
while (stack.hasData())
|
2004-04-18 16:22:27 +02:00
|
|
|
{
|
|
|
|
*--ptr = stack.pop();
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_node
|
|
|
|
|
|
|
|
@brief Make a node of given type.
|
|
|
|
|
|
|
|
|
|
|
|
@param type
|
|
|
|
@param count
|
|
|
|
|
|
|
|
**/
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* MAKE_node(NOD_TYPE type, int count)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2004-05-22 16:23:10 +02:00
|
|
|
tsql* tdsql = DSQL_get_thread_data();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-08-16 14:28:43 +02:00
|
|
|
dsql_nod* node = FB_NEW_RPT(*tdsql->getDefaultPool(), count) dsql_nod;
|
2001-05-23 15:26:42 +02:00
|
|
|
node->nod_type = type;
|
|
|
|
node->nod_count = count;
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_parameter
|
|
|
|
|
|
|
|
@brief Generate a parameter block for a message. If requested,
|
|
|
|
set up for a null flag as well.
|
|
|
|
|
|
|
|
|
|
|
|
@param message
|
|
|
|
@param sqlda_flag
|
|
|
|
@param null_flag
|
|
|
|
@param sqlda_index
|
|
|
|
|
|
|
|
**/
|
2004-02-02 12:02:12 +01:00
|
|
|
dsql_par* MAKE_parameter(dsql_msg* message, bool sqlda_flag, bool null_flag,
|
2003-10-05 08:27:16 +02:00
|
|
|
USHORT sqlda_index)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2005-05-12 19:46:31 +02:00
|
|
|
if (!message) {
|
|
|
|
ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 901,
|
|
|
|
isc_arg_gds, isc_badmsgnum, 0);
|
|
|
|
}
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
DEV_BLKCHK(message, dsql_type_msg);
|
2002-11-24 16:22:03 +01:00
|
|
|
|
2003-03-31 21:11:55 +02:00
|
|
|
if (sqlda_flag && sqlda_index && (sqlda_index <= message->msg_index) &&
|
2002-12-03 14:48:18 +01:00
|
|
|
!Config::getOldParameterOrdering())
|
|
|
|
{
|
2002-11-24 16:22:03 +01:00
|
|
|
// This parameter possibly already here. Look for it
|
2004-02-02 12:02:12 +01:00
|
|
|
for (dsql_par* temp = message->msg_parameters; temp; temp = temp->par_next) {
|
2002-11-24 16:22:03 +01:00
|
|
|
if (temp->par_index == sqlda_index)
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-05-22 16:23:10 +02:00
|
|
|
tsql* tdsql = DSQL_get_thread_data();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-08-16 14:28:43 +02:00
|
|
|
dsql_par* parameter = FB_NEW(*tdsql->getDefaultPool()) dsql_par;
|
2001-05-23 15:26:42 +02:00
|
|
|
parameter->par_message = message;
|
2003-10-05 08:27:16 +02:00
|
|
|
parameter->par_next = message->msg_parameters;
|
2002-07-06 07:32:02 +02:00
|
|
|
if (parameter->par_next != 0)
|
2001-05-23 15:26:42 +02:00
|
|
|
parameter->par_next->par_ordered = parameter;
|
|
|
|
else
|
|
|
|
message->msg_par_ordered = parameter;
|
|
|
|
message->msg_parameters = parameter;
|
|
|
|
parameter->par_parameter = message->msg_parameter++;
|
|
|
|
parameter->par_rel_name = NULL;
|
|
|
|
parameter->par_owner_name = NULL;
|
2005-01-23 16:53:36 +01:00
|
|
|
parameter->par_rel_alias = NULL;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-11-28 07:48:34 +01:00
|
|
|
// If the parameter is used declared, set SQLDA index
|
2002-11-24 16:22:03 +01:00
|
|
|
if (sqlda_flag) {
|
2002-12-03 14:37:06 +01:00
|
|
|
if (sqlda_index && !Config::getOldParameterOrdering()) {
|
2002-11-24 16:22:03 +01:00
|
|
|
parameter->par_index = sqlda_index;
|
2003-12-22 11:00:59 +01:00
|
|
|
if (message->msg_index < sqlda_index)
|
|
|
|
message->msg_index = sqlda_index;
|
|
|
|
}
|
|
|
|
else {
|
2002-11-24 16:22:03 +01:00
|
|
|
parameter->par_index = ++message->msg_index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-28 07:48:34 +01:00
|
|
|
// If a null handing has been requested, set up a null flag
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
if (null_flag) {
|
2004-02-02 12:02:12 +01:00
|
|
|
dsql_par* null = MAKE_parameter(message, false, false, 0);
|
2003-10-05 08:27:16 +02:00
|
|
|
parameter->par_null = null;
|
2001-05-23 15:26:42 +02:00
|
|
|
null->par_desc.dsc_dtype = dtype_short;
|
|
|
|
null->par_desc.dsc_scale = 0;
|
|
|
|
null->par_desc.dsc_length = sizeof(SSHORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parameter;
|
|
|
|
}
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_string
|
|
|
|
|
|
|
|
@brief Generalized routine for making a string block.
|
|
|
|
|
|
|
|
|
|
|
|
@param str
|
|
|
|
@param length
|
|
|
|
|
|
|
|
**/
|
2003-11-10 10:16:38 +01:00
|
|
|
dsql_str* MAKE_string(const char* str, int length)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
|
|
|
return MAKE_tagged_string(str, length, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_symbol
|
|
|
|
|
|
|
|
@brief Make a symbol for an object and insert symbol into hash table.
|
|
|
|
|
|
|
|
|
|
|
|
@param database
|
|
|
|
@param name
|
|
|
|
@param length
|
|
|
|
@param type
|
|
|
|
@param object
|
|
|
|
|
|
|
|
**/
|
2004-02-02 12:02:12 +01:00
|
|
|
dsql_sym* MAKE_symbol(dsql_dbb* database,
|
2003-11-01 11:26:43 +01:00
|
|
|
const TEXT* name, USHORT length, SYM_TYPE type, dsql_req* object)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
DEV_BLKCHK(database, dsql_type_dbb);
|
|
|
|
DEV_BLKCHK(object, dsql_type_req);
|
2003-11-04 00:59:24 +01:00
|
|
|
fb_assert(name);
|
|
|
|
fb_assert(length > 0);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-05-22 16:23:10 +02:00
|
|
|
tsql* tdsql = DSQL_get_thread_data();
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-08-16 14:28:43 +02:00
|
|
|
dsql_sym* symbol = FB_NEW_RPT(*tdsql->getDefaultPool(), length) dsql_sym;
|
2001-05-23 15:26:42 +02:00
|
|
|
symbol->sym_type = type;
|
|
|
|
symbol->sym_object = (BLK) object;
|
|
|
|
symbol->sym_dbb = database;
|
|
|
|
symbol->sym_length = length;
|
2003-10-05 08:27:16 +02:00
|
|
|
TEXT* p = symbol->sym_name;
|
|
|
|
symbol->sym_string = p;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
if (length)
|
|
|
|
MOVE_FAST(name, p, length);
|
|
|
|
|
|
|
|
HSHD_insert(symbol);
|
|
|
|
|
|
|
|
return symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_tagged_string
|
|
|
|
|
|
|
|
@brief Generalized routine for making a string block.
|
|
|
|
Which is tagged with a character set descriptor.
|
|
|
|
|
|
|
|
|
|
|
|
@param str_
|
|
|
|
@param length
|
|
|
|
@param charset
|
|
|
|
|
|
|
|
**/
|
2004-05-31 04:34:35 +02:00
|
|
|
dsql_str* MAKE_tagged_string(const char* strvar, size_t length, const char* charset)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2004-05-22 16:23:10 +02:00
|
|
|
tsql* tdsql = DSQL_get_thread_data();
|
2003-02-12 20:28:13 +01:00
|
|
|
|
2004-08-16 14:28:43 +02:00
|
|
|
dsql_str* string = FB_NEW_RPT(*tdsql->getDefaultPool(), length) dsql_str;
|
2003-02-12 20:28:13 +01:00
|
|
|
string->str_charset = charset;
|
|
|
|
string->str_length = length;
|
2004-05-31 04:34:35 +02:00
|
|
|
memcpy(string->str_data, strvar, length);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_trigger_type
|
|
|
|
|
|
|
|
@brief Make a trigger type
|
|
|
|
|
|
|
|
|
|
|
|
@param prefix_node
|
|
|
|
@param suffix_node
|
|
|
|
|
|
|
|
**/
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* MAKE_trigger_type(dsql_nod* prefix_node, dsql_nod* suffix_node)
|
2002-06-14 14:07:20 +02:00
|
|
|
{
|
2003-10-05 08:27:16 +02:00
|
|
|
const long prefix = (long) prefix_node->nod_arg[0];
|
|
|
|
const long suffix = (long) suffix_node->nod_arg[0];
|
2002-06-14 14:07:20 +02:00
|
|
|
delete prefix_node;
|
|
|
|
delete suffix_node;
|
2003-11-10 10:16:38 +01:00
|
|
|
return MAKE_constant((dsql_str*) (prefix + suffix - 1), CONSTANT_SLONG);
|
2002-06-14 14:07:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 04:01:51 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
MAKE_variable
|
|
|
|
|
|
|
|
@brief Make up a field node.
|
|
|
|
|
|
|
|
|
|
|
|
@param field
|
|
|
|
@param name
|
|
|
|
@param type
|
|
|
|
@param msg_number
|
|
|
|
@param item_number
|
|
|
|
@param local_number
|
|
|
|
|
|
|
|
**/
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* MAKE_variable(dsql_fld* field,
|
2003-10-05 08:27:16 +02:00
|
|
|
const TEXT* name,
|
2001-05-23 15:26:42 +02:00
|
|
|
USHORT type,
|
|
|
|
USHORT msg_number, USHORT item_number, USHORT local_number)
|
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
DEV_BLKCHK(field, dsql_type_fld);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-05-22 16:23:10 +02:00
|
|
|
tsql* tdsql = DSQL_get_thread_data();
|
2003-10-05 08:27:16 +02:00
|
|
|
|
2004-08-16 14:28:43 +02:00
|
|
|
dsql_var* variable = FB_NEW_RPT(*tdsql->getDefaultPool(), strlen(name)) dsql_var;
|
2003-11-01 11:26:43 +01:00
|
|
|
dsql_nod* node = MAKE_node(nod_variable, e_var_count);
|
|
|
|
node->nod_arg[e_var_variable] = (dsql_nod*) variable;
|
2003-10-05 08:27:16 +02:00
|
|
|
variable->var_msg_number = msg_number;
|
|
|
|
variable->var_msg_item = item_number;
|
|
|
|
variable->var_variable_number = local_number;
|
|
|
|
variable->var_field = field;
|
|
|
|
strcpy(variable->var_name, name);
|
|
|
|
variable->var_flags = type;
|
2001-05-23 15:26:42 +02:00
|
|
|
MAKE_desc_from_field(&node->nod_desc, field);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2005-02-14 06:51:25 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
make_null
|
|
|
|
|
|
|
|
@brief Prepare a descriptor to signal SQL NULL
|
|
|
|
|
|
|
|
@param desc
|
|
|
|
|
|
|
|
**/
|
|
|
|
static void make_null(dsc* const desc)
|
|
|
|
{
|
|
|
|
desc->dsc_dtype = dtype_long;
|
|
|
|
desc->dsc_sub_type = 0;
|
|
|
|
desc->dsc_length = sizeof(SLONG);
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_flags |= DSC_nullable;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
make_placeholder_null
|
|
|
|
|
|
|
|
@brief Prepare a descriptor to signal SQL NULL with a char(1) when
|
|
|
|
the type is unknown. The descriptor will be a placeholder only.
|
|
|
|
|
|
|
|
@param desc
|
|
|
|
|
|
|
|
**/
|
|
|
|
static void make_placeholder_null(dsc* const desc)
|
|
|
|
{
|
|
|
|
desc->dsc_dtype = dtype_text;
|
|
|
|
desc->dsc_length = 1;
|
|
|
|
desc->dsc_scale = 0;
|
|
|
|
desc->dsc_ttype() = 0;
|
2005-04-20 15:06:42 +02:00
|
|
|
desc->dsc_flags = DSC_nullable | DSC_null;
|
2005-02-14 06:51:25 +01:00
|
|
|
}
|
|
|
|
|