1418 lines
50 KiB
C
1418 lines
50 KiB
C
|
#ifndef h_query
|
||
|
#define h_query
|
||
|
/******************************************************************************
|
||
|
*
|
||
|
* Query routine macros and variables
|
||
|
*
|
||
|
* Module %M% Version %I% Date %H%
|
||
|
*
|
||
|
* (c) Copyright 1998 Ardent Software Inc. - All Rights Reserved
|
||
|
* This is unpublished proprietary source code of Ardent Software Inc.
|
||
|
* The copyright notice above does not evidence any actual or intented
|
||
|
* publication of such source code.
|
||
|
*
|
||
|
*******************************************************************************
|
||
|
*
|
||
|
* Maintenence log - insert most recent change descriptions at top
|
||
|
*
|
||
|
* Date.... GTAR# WHO Description.........................................
|
||
|
* 10/14/98 23801 SAP Change copyrights.
|
||
|
* 07/17/98 23314 RGA Added next field to node structure.
|
||
|
* 06/25/98 23186 JSM Added byexp flag to query block and Byexpcalc global
|
||
|
* 03/19/98 22756 JBG Incr number of verbs
|
||
|
* 03/05/98 22676 RGA Add short for paramdup to qfilenode struct
|
||
|
* 03/06/98 22658 JBG Add groupsel to fblock
|
||
|
* 12/02/97 22241 RGA Add two ccodeptr to qfilenode.
|
||
|
* 10/17/97 21657 JBG Add size storage to lstnode
|
||
|
* 09/02/97 21285 JBG define token NOISE
|
||
|
* 08/28/97 21285 JBG Added updatelockall, updatelock in fblock, define NOWAIT
|
||
|
* 08/07/97 21260 NDP Correct Qmaxadd macro for NLS case - calculation
|
||
|
* was incorrect.
|
||
|
* 03/06/97 20207 JBG Add orignf1 to qfilenode
|
||
|
* 02/13/97 19986 JBG Added key_cnt to qfilenode
|
||
|
* 02/05/97 19986 JBG Added separator to qfilenode.
|
||
|
* 01/31/97 18790 JSM Added ufname to qfilenode
|
||
|
* 01/06/97 19838 MGM Add sqlexp and sqlexplen to vnode
|
||
|
* 12/31/96 19829 JBG Add field to qfilenode
|
||
|
* 10/29/96 19394 MGM Add oldnvalue to vnode
|
||
|
* 10/16/96 19404 MGM Add ictext to vnode
|
||
|
* 08/30/96 18109 MGM Add smrwd to qfilenode
|
||
|
* 08/09/96 18825 MGM Add pmeids to qfilenode
|
||
|
* 07/11/96 18704 JBG @ASSOCROW, savedassocrow, suppress_empty, assoc_keykey
|
||
|
* 18707 @ODBC.EMPTY, odbc_empty
|
||
|
* 06/13/96 18162 JBG Add proc_tail for CALL in fb
|
||
|
* 06/13/96 18321 DTM Added USC Optimizations
|
||
|
* 05/31/96 18395 JBG Change currtime to txstarted
|
||
|
* 05/16/96 18321 MGM Add GB_ #defines
|
||
|
* 04/30/96 18321 MGM Add Altchoose extern
|
||
|
* 04/25/96 18321 MGM Moved sqlidx to DBFILE.h
|
||
|
* 04/18/96 18321 MGM Add sqlidx struct and fix MACRO LOCKED for SGI
|
||
|
* 04/17/96 18294 EAP Fixed Qmaxadd macro to use display width if NLSon
|
||
|
* 03/18/96 18162 JBG CALL
|
||
|
* 03/14/96 18156 NXC Port 9 to IBM
|
||
|
* 03/13/96 17772 JBG Defing CHARLENGTH token
|
||
|
* 01/31/96 17772 JBG Define string op tokens
|
||
|
* 12/21/95 17772 JBG Define string operator TOKENS
|
||
|
* 12/12/95 17730 JBG Increase JMAX to 20
|
||
|
* 12/11/95 17682 JBG Define currtime and currdate in fblock structure
|
||
|
* 12/11/95 17681 JBG Define FILESTAR
|
||
|
* 12/05/95 17730 JBG increase JMAX to 12
|
||
|
* 11/16/95 17538 TMC Allow type 1/19 joins, remove scandir scant25 glob
|
||
|
* 10/31/95 17500 JBG Define bypassbup and duplicate as int in vnode
|
||
|
* 10/26/95 17500 JBG Define opcode egnore switch for duplicate vnodes
|
||
|
* 10/17/95 17500 JBG Define duplicate field in vnode
|
||
|
* 09/28/95 17398 ENF Define UNION token
|
||
|
* 09/25/95 17398 ENF Add a UNION cursor pointer to qblock
|
||
|
* 09/25/95 17348 RM Added tokens needed by yyswap for outer joins
|
||
|
* 09/19/95 17348 RM Added LONJ logic
|
||
|
* 08/31/95 14087 RM Added group by projection flag
|
||
|
* 08/23/95 17242 AGM Replace COMPUTER==WINNT test by MSWIN test
|
||
|
* 08/15/95 17151 JBG Add field to vnode, original value of date/time
|
||
|
* 07/31/95 17054 AGM Don't declare mktemp on WINNT
|
||
|
* 06/27/95 15116 JSM Added EXTERN definition for Qtslot
|
||
|
* 06/07/95 16383 JBG Add chain, evaluation status to node struct
|
||
|
* 05/26/95 16592 EAP Modified STRmcat macro for NLS
|
||
|
* 05/25/95 16554 RM Remove fields not used anymore
|
||
|
* 05/16/95 15752 RM Second phase of sort/merge join
|
||
|
* 05/12/95 15752 RM Implemented sort/merge join
|
||
|
* 05/05/95 16383 JBG Add optimmem, nodechain field to fb
|
||
|
* 04/25/95 15752 RM Add field for sort/merge join
|
||
|
* 04/24/95 16415 RM Add field to support BTWR operator
|
||
|
* 04/13/95 16346 PVW Remove savepoint and orig_isolation from fb
|
||
|
* and add txtype
|
||
|
* 04/07/95 16308 RM Stop more than one scan of a directory file
|
||
|
* 03/29/95 16178 RM Apply early restrictions
|
||
|
* 03/24/95 16221 AGM Don't declare str routine in Windows-NT
|
||
|
* 02/09/95 15751 RM Make do_subquery non-destructive
|
||
|
* 02/01/95 15883 FRA Port to SGI
|
||
|
* 01/31/95 14712 RM Added newidx flag to mfilenode structure
|
||
|
* 01/25/95 15751 RM Added ncsubq to vnode structure
|
||
|
* 01/17/95 15751 RM Added pflag to qblock structure for parameters
|
||
|
* 01/13/95 15634 JBG Define PARAMMARK in vnode, QEVALPARAMMARK
|
||
|
* 01/11/95 15634 JBG Now make qbptr->idata a vnode
|
||
|
* 01/06/95 15634 CSM fix typo vnode -> enode
|
||
|
* 01/06/94 15634 JBG idata in qblock now vnode, add vv,vf, flag to vnode
|
||
|
* 01/06/95 15492 GMH Add AUX.PORT support
|
||
|
* 11/21/94 15080 JBG Add nf1assoccl to qfilenode, list of assoc columns
|
||
|
* 11/09/94 15080 JBG nf1 structures to qfilenode, fblock
|
||
|
* 10/25/94 15152 RM Added altroot
|
||
|
* 09/09/94 14888 JBG Add assocnt_max
|
||
|
* 08/29/94 14381 RM Restore original rel 7 memory management of dstr
|
||
|
* 08/26/94 14785 RM Added has_inserts/updates to master file node
|
||
|
* 08/10/94 14619 EAP Added nosplit flag to fboolean
|
||
|
* 08/10/94 14619 EAP Added o & n fields to brknode and dupsup to lstnode
|
||
|
* 08/08/94 14371 RM Integrate new latch/lock code
|
||
|
* 07/26/94 13897 SHK Port to RS6000
|
||
|
* 06/25/94 14309 RM Added mvs to node structure
|
||
|
* 06/10/94 14070 RM Changes to fldnode and fqnode
|
||
|
* 06/09/94 13928 RM Removed mstr from lstnode
|
||
|
* 05/25/94 14006 RM Added optimization work strings
|
||
|
* 05/25/94 13835 PVW Change filelock from int to uUVLONG
|
||
|
* 05/19/94 14005 ENF Moved Qinstr, Sinstr to query fblock
|
||
|
* 05/19/94 13551 JC Returned is_breaking to external.
|
||
|
* 05/05/94 13840 JBG Added namelist entry to fbock node
|
||
|
* 05/03/94 13762 RM Added inlist to qfilenode
|
||
|
* 04/26/94 13793 RM,PVW Enable WHEN to work with set functions
|
||
|
* 04/22/94 13771 RM Change handling of IN(lists)
|
||
|
* 04/21/94 13747 PVW Tidy up evaluation of value expressions
|
||
|
* 04/19/94 13700 RM Tidy historical EXTERNs
|
||
|
* 04/15/94 13700 RM Tidy up function prototypes
|
||
|
* 04/15/94 13696 PVW Remove reference to Rfmdata
|
||
|
* 04/14/94 13695 PVW Rationalize justification
|
||
|
* 04/12/94 13514 ENF Move Mfileptr to qblock->fb
|
||
|
* 04/12/94 13550 PVW Added whenevaluated to evalnode structure
|
||
|
* 04/11/94 13514 ENF Added in cursor header file
|
||
|
* 04/11/94 13550 PVW Moved SQL WHEN clause into Checksel
|
||
|
* 04/06/94 13550 PVW Moved SQL WHEN clause into Checksel
|
||
|
* 04/06/94 13474 RM New index join logic
|
||
|
* 03/31/94 12998 PVW NF2 design specification - assoc depths
|
||
|
* 03/30/94 12998 PVW NF2 design specification - assoc depths
|
||
|
* 03/30/94 12535 JBG Change lockstatus to int from short.
|
||
|
* 03/28/94 13501 JC Changed is_breaking reference to definition.
|
||
|
* 03/25/94 13474 RM Changes to the jnode structure
|
||
|
* 03/22/94 12998 PVW NF2 design specification - Code Tidyup
|
||
|
* 03/22/94 13474 RM Changes to qfilenode structure
|
||
|
* 03/18/94 12535 JBG ADD vCurUPDATE AND vCurDELETE
|
||
|
* 03/17/94 12998 PVW NF2 design specification - Code Tidyup
|
||
|
* 03/14/94 13266 RM Added subquery children to the qblock
|
||
|
* 03/14/94 12998 PVW NF2 design specification - Code Tidyup
|
||
|
* 03/11/94 13245 RM Re-work rforsel/rforsrt/rforlst optimizations
|
||
|
* 03/09/94 13228 RM Change curscan in qfilenode to be in-line
|
||
|
* 03/08/94 12998 PVW NF2 design specification step 5 - SQL UNNEST clause
|
||
|
* 03/04/94 12998 PVW NF2 design specification - Code Tidyup
|
||
|
* 02/28/94 12535 JBG DML, dmlexpcnt in fblock, assocb in qblock.
|
||
|
* 02/28/94 12912 GMH save orig_evalptr
|
||
|
* 02/28/94 12998 PVW NF2 design specification step 5 - SQL UNNEST clause
|
||
|
* 02/24/94 13032 JSM Added eform to lstnode
|
||
|
* 02/15/94 10481 RM Changes to qfilenode for correlated subqueries
|
||
|
* 02/15/94 13069 PVW Fixed memory leak in Breakprt.c
|
||
|
* 02/11/94 13032 JSM Added notempty flag to lstnode and fnode
|
||
|
* 02/10/94 12535 JBG DML. added lockstatus to qfilenode, 2 keywords
|
||
|
* 02/08/94 13032 JSM Added to lstnode and fnode for PIOPEN aggregates
|
||
|
* 02/08/94 12535 JBG DML, added orig_isolation to fblock.
|
||
|
* 02/04/94 12535 JBG DML, add structure for TX
|
||
|
* 02/04/94 12867 PVW NF2 design specification step 4 - SQL WHEN clause
|
||
|
* 02/02/94 12899 RM More prototype changes
|
||
|
* 01/26/94 12899 RM Added prototype of Altpredicate
|
||
|
* 01/24/94 12744 PVW Fix to previous fix
|
||
|
* 01/18/94 11062 JSM Added ERRmstr to node structure
|
||
|
* 01/17/94 12846 WLG Added nestfld to qfilenode for first BY-EXP field #
|
||
|
* 01/13/94 12744 PVW Change interface to qevalSCAN and remove references
|
||
|
* 01/13/94 12831 JBG Added vCVIEW verb, added fldname to vnode.
|
||
|
* 01/10/94 12808 RM Changes to struct jnode
|
||
|
* 01/10/94 12832 PVW Add duplicate flag to node structure
|
||
|
* 12/13/93 12412 PVW NF2 design specification step 3 - encapsulation
|
||
|
* 12/06/93 12535 JBG DML fields added, qblock
|
||
|
* 12/06/93 5595 PVW Define clprocflg as external routine
|
||
|
* 12/03/93 12412 PVW NF2 design specification step 2 - normalization
|
||
|
* 11/03/93 5595 JBG Add processed field to qblock
|
||
|
* 11/01/93 12412 PVW Changes structures as per NF2 design spec step 1.
|
||
|
* 09/15/93 8810 JWT New DBscanhash code for reliable dynamic select
|
||
|
* 08/23/93 12124 RM Added qllocked to qfilenode
|
||
|
* 08/06/93 11852 RM Tidy up error recovery code in qengine/qjoin
|
||
|
* 08/02/93 10978 SHK Port to DEC AXP
|
||
|
* 07/22/93 11852 RM,PVW Changes to jnode,vnode and qfilenode structures
|
||
|
* 03/17/93 11124 RM Added COUNTSUP
|
||
|
* 03/02/93 11070 RM Move flag vars into a BITMAP
|
||
|
* 01/06/93 10823 RM Added BETWEEN and NOT BETWEEN operators
|
||
|
* 12/22/92 10506 ENF Added per-query EVERY flag to query block
|
||
|
* 12/02/92 10590 RM Added always null nodes
|
||
|
* 11/30/92 10646 ENF Allow for numeric compares on GROUP columns
|
||
|
* 11/24/92 10646 ENF Allow for numeric compares in ORDER BY
|
||
|
* 11/24/92 10590 RM Declaration of comparison routines
|
||
|
* 11/13/92 10590 RM Extend value node structure
|
||
|
* 11/12/92 10589 ENF Add some helpers to resolve outer refs
|
||
|
* 11/11/92 10562 RM Added @KEY to the qfilenode structure
|
||
|
* 10/20/92 10381 ENF Add qdir,qjust,srtkey to each query block
|
||
|
* 10/07/92 10360 JKW Move inlist defs to inlist.h
|
||
|
* 10/06/92 10025 ENF Add INLIST to vnode for DISTINCT set functions
|
||
|
* 10/06/92 10345 DPB Creation of correlated subqueries.
|
||
|
* 10/05/92 10313 ENF Added distinct and INLIST distree to query block
|
||
|
* 09/29/92 10171 ENF Added 'outer reference' flags to fnode, vnode
|
||
|
* 09/28/92 10294 RM Added create/build index logic
|
||
|
* 09/23/92 9577 RM Added Ifree macro
|
||
|
* 09/22/92 10171 ENF Accum defines, put oput -> query block
|
||
|
* 09/22/92 9577 RM Added association name to vnode structure
|
||
|
* 09/17/92 10176 RM Swap Bayer tree to disk as type 25 file
|
||
|
* 09/14/92 10199 JSM Added BADFQUAL macro
|
||
|
* 09/11/92 10067 DPB Changes for quantified subqueries.
|
||
|
* 09/08/92 10171 ENF Put GBselptr -> qblock for GROUP BY.
|
||
|
* Put previous/current result STRINGS into sort node
|
||
|
* Add Havesel and single_grp to qblock
|
||
|
* 09/04/92 10073 RM Added stuff for index joins
|
||
|
* 08/28/92 10067 DPB changes for IN subqueries.
|
||
|
* 08/27/92 10025 JSM Changed vnode structure and added MAX,MIN,SUM,AVE
|
||
|
* 08/19/92 10067 DPB EXISTS and coper NC subqueries.
|
||
|
* 08/19/92 10073 RM Added altkey to vnode structure
|
||
|
* 08/18/92 9935 ENF Additions for GROUP BY
|
||
|
* 08/18/92 10065 RM Added function prototype for sicaphrase()
|
||
|
* 08/13/92 10025 JSM Changed vnode struct for aggregate functions
|
||
|
* 08/07/92 9072 RM Changed mfilenode for Ostat
|
||
|
* 07/30/92 9923 JSM Added GTOTAL and GRAND
|
||
|
* 07/28/92 9923 JSM Changed BREAKSUP to BRKSUP and added BREAK
|
||
|
* 07/28/92 9702 RM Additions for query optimization
|
||
|
* 07/26/92 9702 RM Additions for query optimization
|
||
|
* 07/23/92 9935 ENF Additions for GROUP BY
|
||
|
* 07/23/92 9067 RM Added flag to qblock to indicate SELECT * was used
|
||
|
* 07/23/92 9923 JSM Added CALC
|
||
|
* 07/22/92 9906 RM Added NOT definition
|
||
|
* 07/14/92 9855 DPB Multi-file support
|
||
|
* 06/17/92 9481 RM Moved Qdata and Udict into malloc'ed blocks
|
||
|
* 06/15/92 9662 JSM Moved Qfdesc into qfilenode
|
||
|
* 06/15/92 9668 RM Added IN predicate
|
||
|
* 06/11/92 9668 RM Changes for the WHERE clause
|
||
|
* 05/26/92 9067 RM Added dict flag to mfilenode structure
|
||
|
* 05/14/92 9481 RM Moved global variables into malloc'ed structures
|
||
|
* 05/13/92 9513 JSM added multkey to fblock
|
||
|
* 04/30/92 9067 RM added more report formatting for SQL SELECT
|
||
|
* 04/27/92 9215 JSM added ISN and INN selection operators
|
||
|
* 04/10/92 9215 JSM added fnode structure
|
||
|
* 03/31/92 9215 JSM added dlflg to fqnode structure
|
||
|
* 03/31/92 9067 RM Minor changes to SQL SELECT
|
||
|
* 03/27/92 9215 JSM Added fqnode structure
|
||
|
* 03/19/92 9310 RM added gnode structure for EvalField
|
||
|
* 02/02/92 9067 RM added new structure for SQL SELECT
|
||
|
* 01/07/92 8983 RM added AND & OR needed by qfldlogic & qaltlogic
|
||
|
* maintenance log purged 1/1/92 - see 6.3 for history
|
||
|
*
|
||
|
*****************************************************************************/
|
||
|
|
||
|
#include "DBFILE.h"
|
||
|
#include "scanglob.h"
|
||
|
#include "qdefine.h"
|
||
|
#include "inlist.h"
|
||
|
#if DIR_SV3
|
||
|
#include DIRENT_H
|
||
|
#endif
|
||
|
#include SY_DIR_H
|
||
|
#include "qcursor.h"
|
||
|
|
||
|
/***** Define maximum number of dependent join children ****************/
|
||
|
#define JMAX 20
|
||
|
|
||
|
/***** Define maximum number of subqueries ****************/
|
||
|
#define SMAX 20
|
||
|
|
||
|
#define RECORD_EXISTS -2
|
||
|
|
||
|
/***** Define maximum number of ASSOCIATIONs ****************/
|
||
|
#define assocnt_max 64
|
||
|
|
||
|
/***** Verb numbers used by query modules ******************************/
|
||
|
|
||
|
#define vSETSQL 20
|
||
|
#define vCALL 19
|
||
|
#define vCVIEW 18
|
||
|
#define vCurDELETE 17
|
||
|
#define vCurINSERT 16
|
||
|
#define vSINSERT 15
|
||
|
#define vREFORMAT 14
|
||
|
#define vSREFORMAT 13
|
||
|
#define vCHKSUM 12
|
||
|
#define vLIST 11
|
||
|
#define vSORT 10
|
||
|
#define vSELECT 9
|
||
|
#define vSSELECT 8
|
||
|
#define vCOUNT 7
|
||
|
#define vSUM 6
|
||
|
#define vUPDATE 5
|
||
|
#define vDELETE 4
|
||
|
#define vINSERT 3
|
||
|
#define vTLOAD 2
|
||
|
#define vTDUMP 1
|
||
|
|
||
|
/*
|
||
|
* These are %token definitions in query.y
|
||
|
*/
|
||
|
|
||
|
#define GREATER 3
|
||
|
#define EQUAL 4
|
||
|
#define GREATEQ 5
|
||
|
#define LESS 6
|
||
|
#define NEQUAL 7
|
||
|
#define LESSEQ 8
|
||
|
#define OR 9
|
||
|
#define AND 10
|
||
|
#define TOTAL 15
|
||
|
#define BREAKON 16
|
||
|
#define DETSUP 17
|
||
|
#define HEADER 19
|
||
|
#define DBLSPC 21
|
||
|
#define FIRST 22
|
||
|
#define FOOTING 23
|
||
|
#define USING 24
|
||
|
#define COLSUP 29
|
||
|
#define NOPAGE 30
|
||
|
#define SAMPLD 31
|
||
|
#define COLSPC 32
|
||
|
#define LPTR 33
|
||
|
#define SQUAWK 36
|
||
|
#define ALL 37
|
||
|
#define NOISE 38
|
||
|
#define CALC 39
|
||
|
#define BRKSUP 42
|
||
|
#define PERCENT 44
|
||
|
#define MARGIN 46
|
||
|
#define AVERAGE 47
|
||
|
#define VERT 50
|
||
|
#define WHEN 53
|
||
|
#define REQUIRE 56
|
||
|
#define FORCE 65
|
||
|
#define FROM 66
|
||
|
#define OPAREN 188
|
||
|
#define CPAREN 189
|
||
|
#define ON 193
|
||
|
#define GTOTAL 201
|
||
|
#define FRMFEED 210
|
||
|
#define DETAIL 231
|
||
|
#define GROUP 219
|
||
|
#define BREAK 257
|
||
|
#define AS 260
|
||
|
#define FIELDNM 263
|
||
|
#define COUNTSUP 293
|
||
|
#define BADWORD 294
|
||
|
#define USEERR 295
|
||
|
#define AMBIGUOUS 296
|
||
|
#define FILESTAR 297
|
||
|
#define EVAL 300
|
||
|
#define EVALTEXT 312
|
||
|
#define ASSOCROW 322
|
||
|
#define SUM 377
|
||
|
#define COUNT 378
|
||
|
#define SEMICOLON 500
|
||
|
#define NOT 504
|
||
|
#define IN 505
|
||
|
#define WHERE 506
|
||
|
#define AVE 507
|
||
|
#define NOOPTIMIZE 509
|
||
|
#define HAVING 510
|
||
|
#define ORDER 511
|
||
|
#define ANY 517
|
||
|
#define MIN 518
|
||
|
#define MAX 519
|
||
|
#define PLUS 520
|
||
|
#define MINUS 521
|
||
|
#define STAR 522
|
||
|
#define DIVIDE 523
|
||
|
#define EXISTS 526
|
||
|
#define UMINUS 532
|
||
|
#define SUPPRESS 533
|
||
|
#define COLUMN 534
|
||
|
#define EXPLAIN 535
|
||
|
#define SPACE 536
|
||
|
#define SPACES 537
|
||
|
#define DOUBLE 538
|
||
|
#define GRAND 539
|
||
|
/* vvv JBG 17772 vvv */
|
||
|
#define TRIM 551
|
||
|
#define TRIMB 552
|
||
|
#define TRIMF 553
|
||
|
#define TRIML 554
|
||
|
#define SUBSTRING 555
|
||
|
#define VBAR 557
|
||
|
#define UPPER 560
|
||
|
#define LOWER 561
|
||
|
#define CHARLENGTH 562
|
||
|
/* ^^^ 17772 ^^^ */
|
||
|
#define CAST 563
|
||
|
#define NOWAIT 574 /* <<< 21285 <<< */
|
||
|
#define UNION 603
|
||
|
|
||
|
/* */
|
||
|
/* Macro definitions */
|
||
|
/* */
|
||
|
|
||
|
#define Xfree(x) {Rfree(x); x=nil;}
|
||
|
#define Ifree(x) {if(x) {Rfree(x); x=nil;}}
|
||
|
|
||
|
#define NOT_IMPLEMENT {warning(950011); return(1);}
|
||
|
|
||
|
#define BADFQUAL(x) {if (x == -1) return(1); }
|
||
|
|
||
|
/* c is the maximum length of the new string */
|
||
|
#define STRmcat(a, b, c) STRncat(a, b, (MAX_CHARWIDTH*c)-a.len)
|
||
|
|
||
|
/* Qmaxadd: Assumes that a.text has been pre-filled with spaces and is longer
|
||
|
than a.len. Therefore can simply add (b) spaces. Also assumes
|
||
|
that a.len < c at start and can back up 1 space at a time. */
|
||
|
|
||
|
#define Qmaxadd(a,b,c) { \
|
||
|
if (NLSon) { \
|
||
|
if ((NLSDISlen((a),NLSformatdp_map)+(b)) > (c)) { \
|
||
|
a.len += (b); \
|
||
|
while ((NLSDISlen((a),NLSformatdp_map)) > (c)) \
|
||
|
a.len--; \
|
||
|
} else { \
|
||
|
a.len += (b); \
|
||
|
} \
|
||
|
} else { \
|
||
|
if ((a.len += (b)) > c) a.len = c; \
|
||
|
} \
|
||
|
}
|
||
|
|
||
|
/* Return true if Flavor is one of the specified flavors
|
||
|
Currently, true for x == IN2 when query is PICK type (from the VOC entry)
|
||
|
and Flavor is IN2. All other x's will be true when Pcomp is true */
|
||
|
#define FLAVOR(x) ((x == IN2_FLAVOR) ? Pcomp && (Flavor & IN2_FLAVOR) : Pcomp )
|
||
|
|
||
|
#define TRUE 1
|
||
|
#define FALSE 0
|
||
|
#define SMALLEST_DIGIT 0x30 /* zero in ASCII */
|
||
|
|
||
|
/* Symbol Definitions */
|
||
|
|
||
|
/* logical values for readability */
|
||
|
#define yes 1
|
||
|
#define no 0
|
||
|
#define true 1
|
||
|
#define false 0
|
||
|
|
||
|
#ifdef LOCKED
|
||
|
#undef LOCKED
|
||
|
#endif
|
||
|
#define LOCKED 2
|
||
|
#define LATCHED 1
|
||
|
|
||
|
/* empty pointer value */
|
||
|
#if COMPUTER == DEC_ALPHA
|
||
|
#define nil 0L
|
||
|
#else
|
||
|
#define nil 0
|
||
|
#endif
|
||
|
|
||
|
/* operation evaluation codes for selection */
|
||
|
#define GT 1
|
||
|
#define EQ 2
|
||
|
#define GE 3
|
||
|
#define LT 4
|
||
|
#define NE 5
|
||
|
#define LE 6
|
||
|
#define MA 7
|
||
|
#define NM 8
|
||
|
#define SL 9
|
||
|
#define NS 10
|
||
|
#define ISN 11
|
||
|
#define INN 12
|
||
|
#define IVL 13
|
||
|
#define NIVL 14
|
||
|
#define ISQ 15
|
||
|
#define NISQ 16
|
||
|
#define ATN 17
|
||
|
#define AFN 18
|
||
|
#define ANN 19
|
||
|
#define BTW 20
|
||
|
#define NBTW 21
|
||
|
#define BTWR 22
|
||
|
|
||
|
/* sort option codes */
|
||
|
#define A 0
|
||
|
#define D 1
|
||
|
#define N 0
|
||
|
#define E 1
|
||
|
#define nounique 0
|
||
|
#define yunique 1
|
||
|
|
||
|
/* lexical return codes for non-terminal tokens */
|
||
|
#define condoff 282
|
||
|
|
||
|
/* miscellaneous constants for verb recognition */
|
||
|
#define Verbase 370
|
||
|
#define Verbcnt 24 /* <<< JBG 18162 <<< */
|
||
|
#define verblen 7
|
||
|
|
||
|
/* maximum depth of command input stack */
|
||
|
#define instkmax 31
|
||
|
#define HEAD_max 128
|
||
|
|
||
|
/* maximum tape label length */
|
||
|
#define MLBsiz 80
|
||
|
|
||
|
/* width of LEVEL heading for within keyword */
|
||
|
|
||
|
#define QEVALFIELD 'F'
|
||
|
#define QEVALDML 'D'
|
||
|
#define QEVALCONSTANT 'C'
|
||
|
#define QEVALEXPRESSION 'E'
|
||
|
#define QEVALPARAMMARK 'P'
|
||
|
|
||
|
#define NEST_NORMAL 1
|
||
|
#define NEST_COLUMN 2
|
||
|
#define NEST_DEPTH 3
|
||
|
|
||
|
#define WHEN_NORMAL 1
|
||
|
#define WHEN_APPLY 2
|
||
|
|
||
|
#define LEVELSZ 6
|
||
|
|
||
|
#define SUBQURY 0x1000
|
||
|
|
||
|
/* Defines for set function accumulators */
|
||
|
#define RETURN_ACC 1
|
||
|
#define RESET_ACC 2
|
||
|
/* define bit in query block that records if sort level set up */
|
||
|
#define SORT_ESTABLISHED 2
|
||
|
#define GB_INDEXED 4
|
||
|
#define GB_FIRSTIME 8
|
||
|
|
||
|
|
||
|
#define NOT_OPTIMIZED 0x0000
|
||
|
#define GBOBREDUCE 0x0001
|
||
|
#define DISTREDUCE 0x0010
|
||
|
|
||
|
/* */
|
||
|
/* Structure Definitions */
|
||
|
/* */
|
||
|
|
||
|
/***** qblock structure ************************************************/
|
||
|
|
||
|
struct qblock
|
||
|
{
|
||
|
short blockno; /* block number */
|
||
|
short nfiles; /* number of files */
|
||
|
struct fblock *fb; /* first query block only */
|
||
|
|
||
|
struct qblock *parent; /* parent qblock reference */
|
||
|
struct qblock *next; /* next qblock reference */
|
||
|
struct qblock *schild[SMAX]; /* dependent subqueries */
|
||
|
int snchild; /* number of dependent children */
|
||
|
|
||
|
struct qfilenode *insfile; /* insert qfilenode reference */
|
||
|
struct qfilenode *qfileptr; /* qfilenode reference */
|
||
|
|
||
|
struct evalnode *evalptr; /* constant evalnode reference */
|
||
|
|
||
|
struct lstnode *listflds; /* ptr to output cols */
|
||
|
struct srtnode *sortlist; /* sort specification list */
|
||
|
struct srtnode *groupflds; /* ptr to GROUP BY cols */
|
||
|
struct node *Rootsel; /* selection criteria tree */
|
||
|
struct node *altroot; /* AK selection criteria tree */
|
||
|
struct node *Whensel; /* when clause building tree */
|
||
|
struct node *Byxwhen; /* when clause for BY.EXP */
|
||
|
struct node *Havesel; /* HAVING criteria tree */
|
||
|
|
||
|
struct dbcursor *sqlcp; /* Pointer to a database cursor */
|
||
|
struct dbcursor *unioncp; /* Ptr to a UNION cursor tree */
|
||
|
short assocnt; /* active assoc count */
|
||
|
short assocnp; /* pointer to next slot in the */
|
||
|
/* association table */
|
||
|
STRING assoca[assocnt_max]; /* active assoc name list */
|
||
|
struct qfilenode *assocf[assocnt_max]; /* active assoc file list*/
|
||
|
struct anode *assocl[assocnt_max]; /* active assoc column list*/
|
||
|
struct anode *assocd[assocnt_max]; /* active assoc key list*/
|
||
|
int assocdepthvmc[assocnt_max]; /* active assoc vmc depth*/
|
||
|
STRING assocb[assocnt_max]; /* active assoc mask list*/
|
||
|
struct node *assocw[assocnt_max]; /* active assoc selection tree*/
|
||
|
int assocmv[assocnt_max]; /* active assoc depth lineout*/
|
||
|
int assocsk[assocnt_max]; /* active assoc vmc skip*/
|
||
|
int assocsmv[assocnt_max]; /* active assoc smc depth*/
|
||
|
int assocssk[assocnt_max]; /* active assoc smc skip*/
|
||
|
short when; /* when flag */
|
||
|
short selstar; /* flag for SELECT */
|
||
|
short every; /* Per query EVERY flag */
|
||
|
short distinct; /* set if SELECT DISTINCT */
|
||
|
short single_grp; /* if this is a 1 grp table */
|
||
|
short grouping; /* Flag indicating GROUP BY */
|
||
|
int whncnt; /* count of items when printed */
|
||
|
int reccnt; /* count of records sampled */
|
||
|
int samcnt; /* select period cycle counter */
|
||
|
int Sample; /* selection sampling period */
|
||
|
int NI_counter; /* F corr. current item counter */
|
||
|
int NS_counter; /* F's curr. submultivalue cntr.*/
|
||
|
int ND_counter; /* F's # detail lines since Brk.*/
|
||
|
int Cstotb; /* Check sum total bytes seen */
|
||
|
int Chksum; /* computed check sum value */
|
||
|
int Csbitc; /* Check sum ones bit count */
|
||
|
int Firstn; /* selection limit set by FIRST */
|
||
|
DBFILE *Afile;
|
||
|
SELFILE *GBselptr; /* GROUP BY select list ptr */
|
||
|
STRING oput; /* GROUP BY output string */
|
||
|
int srtkey; /* # GROUP BY fields in query */
|
||
|
int (*qdir)[]; /* Direction of sort for GROUP */
|
||
|
int (*qjust)[]; /* Justification of sort */
|
||
|
int (*qcomptype)[]; /* 'N'=> compare(), else comp() */
|
||
|
char *ERRscni; /* save area for work area to be*/
|
||
|
/* freed by QERROR routine */
|
||
|
char *ERRkptr; /* save area for work area to be*/
|
||
|
/* freed by QERROR routine */
|
||
|
struct jnode *join; /* the join condition list */
|
||
|
INLIST distree; /* Used to check for DISTINCT */
|
||
|
short byexp; /* Used for CALC in EvalItype */
|
||
|
/*
|
||
|
* Subquery input and output results.
|
||
|
*/
|
||
|
STRING cvalue;
|
||
|
STRING ans;
|
||
|
INLIST intree;
|
||
|
short ansflag;
|
||
|
short type;
|
||
|
short coper;
|
||
|
short any;
|
||
|
short exists;
|
||
|
short correlated;
|
||
|
short has_corr_child;
|
||
|
char smv;
|
||
|
unsigned short processed; /* 'U' = not processed this row */
|
||
|
/* 'T','F','N' processed result */
|
||
|
/*
|
||
|
* DML fields (12535)
|
||
|
*/
|
||
|
STRING dmlID; /* DML outpur @ID */
|
||
|
STRING dmlRECORD; /* DML output record */
|
||
|
struct vnode *idata; /* data chain for single row INSERT */
|
||
|
struct node *setlist; /* UPDATE action list */
|
||
|
short sicaphrase; /* the default column list is in use */
|
||
|
short changekey; /* if an UPDATE action changes @ID */
|
||
|
/*
|
||
|
* optimizer fields
|
||
|
*/
|
||
|
int optimizer_mode;
|
||
|
struct node *pred[64]; /* predicate for this subquery */
|
||
|
short npred; /* number of dependent predicate*/
|
||
|
short pflag; /* '?' in WHERE clause */
|
||
|
};
|
||
|
|
||
|
/***** fnode structure - store lexical token and dictionary descriptor */
|
||
|
/***** also record if field is resolved in outer block */
|
||
|
|
||
|
struct fnode
|
||
|
{
|
||
|
STRING name,
|
||
|
item;
|
||
|
int invoc;
|
||
|
int outer;
|
||
|
struct qblock *corrqbptr; /* qblock outer ref found in */
|
||
|
struct qfilenode *qf;
|
||
|
short noempty;
|
||
|
int mnflg;
|
||
|
int mxflg;
|
||
|
int enflg;
|
||
|
int trflg;
|
||
|
STRING kword;
|
||
|
};
|
||
|
|
||
|
/***** evalnode structure - for evaluation *****************************/
|
||
|
|
||
|
struct evalnode
|
||
|
{
|
||
|
struct evalnode *next; /* next evalnode reference */
|
||
|
|
||
|
struct qfilenode *qf; /* reference to query file */
|
||
|
|
||
|
int qevaltype; /* column type */
|
||
|
/* Determines distinct columns depending on qevaltype */
|
||
|
int amc; /* column attribute number */
|
||
|
int just; /* column justification */
|
||
|
int multi; /* column single/multi valued */
|
||
|
STRING corr; /* column correlative */
|
||
|
STRING assoc; /* column association name */
|
||
|
STRING dict; /* column dictionary entry */
|
||
|
|
||
|
int cost; /* column evaluation cost */
|
||
|
short evaluated; /* column evaluation done */
|
||
|
short created; /* index created but not built */
|
||
|
STRING result; /* column evaluation result */
|
||
|
PROGRAM *icode; /* column object code reference */
|
||
|
IDXENT *altkey; /* column index file reference */
|
||
|
struct sqlidx *sqlaltkey; /* SQl i-type index list */
|
||
|
|
||
|
/* Required for the SQL UNNEST operator */
|
||
|
int nestvmc; /* value number requested */
|
||
|
int nestremove; /* value remove pointer */
|
||
|
short unnest; /* column to be unnested */
|
||
|
short nestevaluated; /* value evaluation done */
|
||
|
STRING nestresult; /* value evaluation result */
|
||
|
|
||
|
/* Required for the SQL DML statements */
|
||
|
short dmlkeypartno; /* column key part number */
|
||
|
int dmlnvalue; /* column data type */
|
||
|
STRING dmlconv; /* column conversion code */
|
||
|
STRING dmldefault; /* column default value */
|
||
|
|
||
|
/* Required for the SQL WHEN clause */
|
||
|
int whenassocidx; /* when assoc index - 1 */
|
||
|
int whenevaluated; /* when evaluation done */
|
||
|
STRING whenresult; /* when evaluation result */
|
||
|
};
|
||
|
|
||
|
/***** node structure - for selection **********************************/
|
||
|
/***** built by gensel() and genselv() */
|
||
|
|
||
|
struct node
|
||
|
{
|
||
|
struct node *lchild; /* left-child node reference */
|
||
|
struct node *rchild; /* right-child node reference */
|
||
|
|
||
|
struct evalnode *evalptr; /* evalnode reference */
|
||
|
struct evalnode *orig_evalptr; /* evalnode reference */
|
||
|
|
||
|
short type; /* logical connective: AND/OR/NOT */
|
||
|
short rel; /* predicate type: EQ, GT etc. */
|
||
|
short just; /* justification */
|
||
|
short multi; /* multivaluedness */
|
||
|
short ev; /* every flag */
|
||
|
short correlated; /* correlated flag */
|
||
|
short mva; /* use associated comparison */
|
||
|
short mvs; /* use mvscomp optimization */
|
||
|
short mnx; /* optimize: min/max */
|
||
|
short predeval; /* 0 = not evaluated, else evaluation result */
|
||
|
char level; /* used by tree manipulation */
|
||
|
STRING text; /* retrieve constant text */
|
||
|
STRING btext; /* retrieve constant text for BETWEEN */
|
||
|
STRING ccode; /* text of conversion code */
|
||
|
struct vnode *vl; /* sql left value expression */
|
||
|
struct vnode *vr; /* sql right value expression */
|
||
|
struct vnode *vb; /* sql between value expression */
|
||
|
struct vnode *inlist; /* sql IN (...) constants */
|
||
|
INLIST insq; /* sql IN (subquery) return */
|
||
|
IDXENT *altkey; /* alternate key */
|
||
|
struct sqlidx *sqlaltkey; /* SQl i-type index list */
|
||
|
uchar *ERRmstr; /* save area for work area to be*/
|
||
|
struct node *next; /* next in multipart key opt. */
|
||
|
struct node *dupchain; /* chain of duplicate nodes from fb */
|
||
|
|
||
|
/* NOTE: duplicate must be last in structure */
|
||
|
int duplicate; /* duplicate flag for CNF */
|
||
|
};
|
||
|
|
||
|
/* enode - explicit id list node */
|
||
|
struct enode
|
||
|
{
|
||
|
struct enode *chain;
|
||
|
STRING text;
|
||
|
};
|
||
|
|
||
|
/***** anode structure - association list ******************************/
|
||
|
/***** built in */
|
||
|
|
||
|
struct anode
|
||
|
{
|
||
|
struct anode *chain; /* next anode reference */
|
||
|
|
||
|
struct evalnode *evalptr; /* evalnode reference */
|
||
|
|
||
|
STRING text; /* result of evaluated Itype */
|
||
|
};
|
||
|
|
||
|
/***** srtnode structure - sort criteria *******************************/
|
||
|
/***** built in */
|
||
|
|
||
|
struct srtnode
|
||
|
{
|
||
|
struct srtnode *chain; /* next srtnode reference */
|
||
|
|
||
|
struct evalnode *evalptr; /* evalnode reference */
|
||
|
|
||
|
int qcomptype; /* for GROUP BY 1 => compare */
|
||
|
STRING asname; /* Name of field from clex */
|
||
|
STRING previous; /* previous result for GROUP BY */
|
||
|
STRING current; /* current result for GROUP BY */
|
||
|
STRING oldres; /* result that caused group brk */
|
||
|
short explode; /* exploding? */
|
||
|
short dir; /* ascending or descending */
|
||
|
struct lstnode *column; /* output column */
|
||
|
|
||
|
STRING idata; /* used to store result */
|
||
|
};
|
||
|
|
||
|
/***** lstnode structure - output specification ************************/
|
||
|
/***** built in */
|
||
|
|
||
|
struct lstnode
|
||
|
{
|
||
|
struct lstnode *chain; /* next lstnode reference */
|
||
|
struct evalnode *evalptr; /* evalnode reference */
|
||
|
struct vnode *valexpr; /* value expression tree */
|
||
|
|
||
|
int type; /* itype = 'I', valexpr = 'V' */
|
||
|
/* user = 'U', literal = 'L' */
|
||
|
int flen; /* output column width */
|
||
|
int (*avgs)[1]; /* array of vals used for ave, */
|
||
|
/* or enum calc */
|
||
|
int pctpre; /* pre-processing for percent calc*/
|
||
|
int maxvmc; /* maximum vmc */
|
||
|
int curvmc; /* current vmc */
|
||
|
int maxsmc; /* maximum smc */
|
||
|
int cursmc; /* current smc */
|
||
|
int ntots; /* number of break levels */
|
||
|
int vwlen; /* vertical format */
|
||
|
int iamc; /* AMC for I-types */
|
||
|
double (*(*tots)[1])[1]; /* */
|
||
|
double pctot; /* total used for percentages */
|
||
|
STRING ccode; /* text of the conversion code */
|
||
|
STRING name; /* name of the field */
|
||
|
STRING form; /* format */
|
||
|
STRING uftext; /* unformatted text */
|
||
|
STRING text; /* formatted text */
|
||
|
STRING stext; /* used to maintain formatting */
|
||
|
STRING ssav; /* used to maintain formatting */
|
||
|
STRING sutext; /* used to maintain formatting */
|
||
|
STRING btext; /* used to maintain formatting */
|
||
|
STRING bstext; /* used to maintain formatting */
|
||
|
STRING dstr; /* result of Evaluate_column */
|
||
|
STRING mstr; /* saved ptr to dstr */
|
||
|
short nprt; /* no print */
|
||
|
short AV; /* calc average of this field */
|
||
|
short PC; /* calc percent of this field */
|
||
|
short TL; /* calc total of this field */
|
||
|
short calc; /* calc on this field */
|
||
|
short bfld; /* break on this field */
|
||
|
short u2193; /* */
|
||
|
/* SQL additions: */
|
||
|
short noempty; /* no empty for AV,MN,MX,EN,TR */
|
||
|
short MN; /* calc minimum of this field */
|
||
|
short MX; /* calc maximum of this field */
|
||
|
short EN; /* enumerate of this field */
|
||
|
short TR; /* transport of this field */
|
||
|
short dupsup; /* suppress duplicates */
|
||
|
STRING (*mmtval)[1]; /* array of vals used for min, */
|
||
|
/* max or transport calc */
|
||
|
STRING eform; /* format for ENUM break lines */
|
||
|
int maxtextlen; /* <<< 21657; maximun malloced sixe of text */
|
||
|
int maxuftextlen; /* <<< 21657; maximun malloced sixe of uftext */
|
||
|
};
|
||
|
|
||
|
/* brknode - break-point/sub-total definition node */
|
||
|
struct brknode
|
||
|
{
|
||
|
int bnum, /* */
|
||
|
tcnt; /* */
|
||
|
STRING opts; /* */
|
||
|
struct lstnode *lnod; /* field in listnode it relates to*/
|
||
|
struct brknode *chain; /* */
|
||
|
short b,d,l,n,o,p,v,u, /* option flags */
|
||
|
bchk; /* true if node has been initialized in Breakchk */
|
||
|
struct qfilenode *qf; /* the query file node */
|
||
|
};
|
||
|
|
||
|
/***** fldnode structure used while building other node structures *****/
|
||
|
|
||
|
struct fldnode
|
||
|
{
|
||
|
int amc; /* field attribute number */
|
||
|
int just; /* field justification */
|
||
|
int multi; /* field single/multi valued */
|
||
|
STRING corr; /* field correlative */
|
||
|
STRING assoc; /* field association name */
|
||
|
PROGRAM *icode; /* field object code reference */
|
||
|
|
||
|
int type; /* field type I,D */
|
||
|
int iamc; /* */
|
||
|
int ipos; /* */
|
||
|
int flen; /* effective column width */
|
||
|
int nvalue; /* data type: 'N'umber, 'D'ate */
|
||
|
int comptype; /* use 0=comp() or 1=compare() */
|
||
|
int approx; /* approx=true, exact=false */
|
||
|
int sqltype; /* REAL, INTEGER, FLOAT etc */
|
||
|
int qevaltype; /* column type */
|
||
|
STRING name; /* field's name or COL.HDG */
|
||
|
STRING ccode; /* field conversion */
|
||
|
STRING form; /* field format */
|
||
|
STRING asname; /* text of the AS name */
|
||
|
STRING constant; /* field constant */
|
||
|
|
||
|
/* The following two elements are used by dml */
|
||
|
short dmlkeypartno; /* field key part number */
|
||
|
STRING dmldefault; /* field default value */
|
||
|
|
||
|
STRING dict; /* field dictionary */
|
||
|
int sqlexplen; /* field used by CHAR, VARCHAR */
|
||
|
};
|
||
|
|
||
|
/***** fqnode structure - field qualifiers *****************************/
|
||
|
|
||
|
struct fqnode
|
||
|
{
|
||
|
struct fldnode fq; /* Contents of field qualifiers */
|
||
|
struct fldnode dl; /* Contents of display like */
|
||
|
short dlflag; /* Saw DISPLAY.LIKE qualifer */
|
||
|
short aflag; /* Saw ASSOC qualifier */
|
||
|
short awflag; /* Saw ASSOC.WITH qualifier */
|
||
|
short asflag; /* Saw AS qualifier */
|
||
|
short opcode; /* opcode set on field (CVIEW) */
|
||
|
};
|
||
|
|
||
|
/***** vnode structure - value expression ******************************/
|
||
|
/***** built in */
|
||
|
|
||
|
struct vnode
|
||
|
{
|
||
|
struct vnode *left; /* left-child vnode reference */
|
||
|
struct vnode *right; /* right-child vnode reference */
|
||
|
|
||
|
struct evalnode *evalptr; /* evalnode reference */
|
||
|
|
||
|
short nodetype; /* 1=internal, 2=terminal */
|
||
|
short type; /* operator or terminal type */
|
||
|
int iamc; /* amc for itypes */
|
||
|
short vocflag; /* was field in voc */
|
||
|
short nvalue; /* is constant a numeric */
|
||
|
short outer; /* if field is outer reference */
|
||
|
short extform; /* external=true, internal=false*/
|
||
|
short approx; /* approximate=true, exact=false*/
|
||
|
short comptype; /* true=compare(), false=comp() */
|
||
|
short key; /* boolean; is this the key */
|
||
|
short reuse;
|
||
|
short just;
|
||
|
short opcode; /* aggregate function operation */
|
||
|
short grpflg; /* aggregate function group flag*/
|
||
|
short nulflg; /* aggregate function null flag */
|
||
|
STRING ccode; /* conversion */
|
||
|
STRING ctext; /* text of literal constant */
|
||
|
STRING asname; /* Name of field from clex */
|
||
|
STRING cdesc; /* text of field descriptor */
|
||
|
int count; /* aggregate function counter */
|
||
|
int cntstar; /* aggregate COUNT(*) counter */
|
||
|
double accum; /* aggregate function result */
|
||
|
INLIST distree; /* Used for DISTINCT set functs */
|
||
|
STRING result; /* aggregate function string res*/
|
||
|
STRING *oldres; /* For outer refs/GROUP BY... */
|
||
|
/* where to get last result.. */
|
||
|
/* will point to GB srtnode */
|
||
|
struct qblock *subq; /* ptr to correlated subquery */
|
||
|
struct qblock *corrqbptr; /* where outer ref discovered */
|
||
|
struct vnode *ncsubq; /* non-correlated subquery */
|
||
|
IDXENT *altkey; /* column index file reference */
|
||
|
struct sqlidx *sqlaltkey; /* SQl i-type index list */
|
||
|
STRING fldname; /* original name of field */
|
||
|
struct evalnode *orig_evalptr; /* evalnode reference */
|
||
|
struct vnode *vf; /* sql field chain for sINSERT */
|
||
|
struct vnode *vv; /* sql field value chain for sINSERT */
|
||
|
struct parammark *parammkr; /* sql server parameter marker */
|
||
|
STRING origlit; /* value of literal before conversion to D/T */
|
||
|
int bypassdup; /* <<< 17500 <<< bypass duplicates for opcode vnodes */
|
||
|
int duplicate; /* <<< 17500 <<< non-zero, number of times duplicated */
|
||
|
STRING ictext; /* iconv text used by Altbounds and idx logic */
|
||
|
short oldnvalue; /* value of nvalue before COUNT forces it to integer */
|
||
|
short sqlexp; /* SQL data type used by CAST */
|
||
|
int sqlexplen; /* SQL data length used by CAST */
|
||
|
};
|
||
|
|
||
|
/* mfilenode - master file list */
|
||
|
struct mfilenode
|
||
|
{
|
||
|
struct mfilenode *next; /* pointer to next in chain */
|
||
|
STRING fname, /* text of file name */
|
||
|
fpath, /* path of the file */
|
||
|
dpath; /* path of the dictionary */
|
||
|
DBFILE *dptr; /* the default dictionary */
|
||
|
short refcount, /* the reference count 0=1 */
|
||
|
dflag; /* dictionary flag */
|
||
|
int cost; /* relative processing cost */
|
||
|
};
|
||
|
|
||
|
/* jnode - the join node for multi-file queries */
|
||
|
struct jnode
|
||
|
{
|
||
|
short type, /* 'C'artesian, 'T'rans, 'I'ndex */
|
||
|
status; /* initialized: true/false */
|
||
|
struct qfilenode *pri, /* file to matcg rows against */
|
||
|
*sec; /* file to get matching rows from */
|
||
|
struct jnode *next; /* chain */
|
||
|
struct vnode *rhs; /* field data for right hand side */
|
||
|
struct vnode *eval; /* info for call to EvalField (lhs)*/
|
||
|
struct node *altsel; /* info for call to EvalField (lhs)*/
|
||
|
int (*cfunc)(); /* comparator function for s/m join*/
|
||
|
STRING ijrec; /* index entry */
|
||
|
int remove; /* remove pointer into index record */
|
||
|
STRING *heap; /* work area for heapify routines */
|
||
|
int hcnt, /* count of things on the heap */
|
||
|
scnt; /* saved count on heap */
|
||
|
STRING jkey; /* key to index record */
|
||
|
DBFILE *fptr; /* part desc for distributed file */
|
||
|
short mnx; /* 1=max, 0=use value, -1=min */
|
||
|
short sort; /* true sort in Altselect */
|
||
|
short just; /* just for cfunc call */
|
||
|
short part; /* current part of part file */
|
||
|
};
|
||
|
|
||
|
/* fblock - structure for vars only needed by first query block */
|
||
|
struct fboolean
|
||
|
{
|
||
|
BITMAP sparebt1:((8*sizeof(BITMAP))-29),
|
||
|
updatelockall:1, /* set if FOR UPDATE, <<< 21285 */
|
||
|
updatelock:1, /* set if FOR UPDATE [FOR (list)], <<< 21285 */
|
||
|
used:1, /* query has been executed */
|
||
|
withinflg:1, /* WITHIN format selected */
|
||
|
Labels:1, /* flag to print in label form */
|
||
|
Only:1, /* flag to print @ID field only */
|
||
|
didoutput:1, /* output generated flag */
|
||
|
tapeflg:1, /* tape flag for REFORMAT */
|
||
|
Idgot:1, /* flag set if @ID was in DICT */
|
||
|
lblopt:1, /* have we seen label options? */
|
||
|
sorting:1, /* flag indictating if sorting */
|
||
|
pctseen:1, /* flag to select processor set */
|
||
|
/* if list options include a */
|
||
|
/* percentage calculation, this */
|
||
|
/* will force an intermediate */
|
||
|
/* select list to be use made */
|
||
|
Qprinter:1, /* flag indicating a printer */
|
||
|
/* specification has been made */
|
||
|
nooptim:1, /* flag to switch optimizer off */
|
||
|
explain:1, /* verbose optimizer output */
|
||
|
Qpageflg:1, /* flag for U2193 support */
|
||
|
Dblspc:1, /* flag to double space report */
|
||
|
Detsup:1, /* flag to suppress detail lines*/
|
||
|
Verticle:1, /* flag to force verticle format*/
|
||
|
Colsup:1, /* flag to suppress default */
|
||
|
/* column headings */
|
||
|
Hdrsup:1, /* flag to suppress headings */
|
||
|
force:1, /* force heading on null report */
|
||
|
Nopage:1, /* flag to turn off page mode */
|
||
|
Headed:1, /* set if heading specified */
|
||
|
Footed:1, /* set if footing specified */
|
||
|
Roll:1, /* global rollover mode flag */
|
||
|
bkludge:1, /* flag to prime 'B' option */
|
||
|
nosplit:1, /* flag to not split records */
|
||
|
auxport:1; /* flag to enable/disable aux port */
|
||
|
};
|
||
|
|
||
|
struct fblock
|
||
|
{
|
||
|
short Withinname, /* WITHIN field number */
|
||
|
Withinlvl, /* level of within tree being printed */
|
||
|
Labcol, /* current label column */
|
||
|
Labopt[7], /* options for label mode */
|
||
|
Qverb, /* indictates which verb to use */
|
||
|
prtfns, /* count of columns in report */
|
||
|
multkey, /* # of key parts used by ID.SUP*/
|
||
|
qtMACHINE, /* tape label generation flag */
|
||
|
Bpoints, /* count of sub-total levels */
|
||
|
Qtselect, /* output select list to use */
|
||
|
ten_dozen,
|
||
|
Cspaces, /* column spacing in report */
|
||
|
Lptrnum, /* output channel to print on */
|
||
|
Margin, /* indictate left margin set */
|
||
|
Pmargin, /* size of left margin */
|
||
|
Frmfeed, /* form feed for LIST/SORT.ITEM */
|
||
|
Countsup, /* form feed for LIST/SORT.ITEM */
|
||
|
Lnosup, /* suppress line numbers for */
|
||
|
/* LIST/SORT.ITEM */
|
||
|
Colspc, /* indicate column spacing set */
|
||
|
Statw, /* Width of STAT field */
|
||
|
Prtwid; /* width of formatted report */
|
||
|
STRING Sinstr; /* Saved head of command line */
|
||
|
STRING Qinstr; /* Original command line */
|
||
|
|
||
|
SELFILE *Qtdesc; /* Select descriptor to writeon */
|
||
|
/* Master file list for query */
|
||
|
struct mfilenode *Mfileptr;
|
||
|
struct brknode
|
||
|
*Gbreak, /* break-point grand-total list */
|
||
|
*headb, /* heading break field pointer */
|
||
|
*brklist; /* break-point/sub-total list */
|
||
|
STRING s_tmpstr, /* Str used by L-opt of SEARCH */
|
||
|
Headext, /* save pointer for user heading*/
|
||
|
Footext, /* save pointer for user footing*/
|
||
|
Outhead, /* generated report heading */
|
||
|
(*Lline)[1]; /* label format buffer area */
|
||
|
struct fboolean fbit; /* booleans */
|
||
|
int dmlrowcnt; /* number of rows processed by DML
|
||
|
vDELETE, vUPDATE, vINSERT */
|
||
|
int dmlexpcol; /* number of columns in vINSERT, vSINSERT */
|
||
|
short txtype; /* txtype for this SQL DML statement */
|
||
|
STRING namearray; /* array of fieldnames in INSERT */
|
||
|
STRING workbuf; /* working buffer used bu numify */
|
||
|
int worklen; /* size workbuf is malloc'ed to */
|
||
|
|
||
|
int assocrowct; /* DMLnest, count of assoc 'rows' modified */
|
||
|
int changeassockey; /* DMLnest, did assoc key change on UPDATE */
|
||
|
int nestchange; /* DMLnest, has nestRECORD been modified */
|
||
|
int nestdepth; /* DMLnest, depth of assoc in nestRECORD */
|
||
|
int nestvmcdelta; /* DMLnest, value count delta from UNNEST*/
|
||
|
STRING nestID; /* DMLnest, ID of row being built */
|
||
|
STRING nestRECORD; /* DMLnest, record being built */
|
||
|
STRING nestoldRECORD; /* DMLnest, original read record */
|
||
|
STRING nestupdatevmc; /* DMLnest, UPDATE key vmc array */
|
||
|
struct evalnode *nestevalchain; /* DMLnest, INSERT unnest eevalptr */
|
||
|
int optimmem; /* Maximum optimize memory */
|
||
|
struct node *nodechain; /* preserve orig nodes CNF removed */
|
||
|
int txstarted; /* Was a TX started by query routine */
|
||
|
int currdate; /* was @SQL_DATE set by this qblock */
|
||
|
STRING proc_name; /* <<< JBG 18162 <<<, proc_name */
|
||
|
struct vnode *arg_list; /* <<< JBG 18162 <<<, list of arguments */
|
||
|
STRING proc_tail; /* <<< JBG 18162 <<<, statement after name */
|
||
|
short savedassocrow; /* <<< JBG 18704 <<<, user assocrow value */
|
||
|
short suppress_empty; /* <<< JBG 18704 <<<, suppress empty rows */
|
||
|
SELFILE *grpselptr; /* <<< 22658, group select list ptr */
|
||
|
};
|
||
|
|
||
|
/***** qfilenode structure - query file ********************************/
|
||
|
/***** built in */
|
||
|
|
||
|
/* moved union scanvar to scanglob.h TMC */
|
||
|
|
||
|
struct qfilenode
|
||
|
{
|
||
|
struct qfilenode *next; /* next qfilenode reference */
|
||
|
|
||
|
struct evalnode *evalptr; /* first evalnode reference */
|
||
|
|
||
|
short unnest; /* unnest/explode file */
|
||
|
int nestvmc; /* unnest/explode value */
|
||
|
int nestsmc; /* unnest/explode subvalue */
|
||
|
STRING nestassoc; /* unnest/explode association */
|
||
|
int nestdepth; /* unnest/explode value depth */
|
||
|
STRING nestname; /* unnest/explode name */
|
||
|
struct anode *nestaptr; /* unnest/explode aptr chain */
|
||
|
int nestfld; /* First exploded field number */
|
||
|
|
||
|
STRING name; /* name used/correlation name */
|
||
|
STRING usedict; /* USING dict pathname */
|
||
|
STRING atKEY; /* the dictionary phrase */
|
||
|
STRING atID; /* current @ID for this file */
|
||
|
STRING atRECORD; /* current @RECORD for this file*/
|
||
|
STRING atID_save; /* saved atID for this file */
|
||
|
STRING atRECORD_save; /* saved atRECORD for this file */
|
||
|
struct mfilenode *master; /* entry in master file list */
|
||
|
struct enode *Qskeylst; /* saved id list for restart */
|
||
|
struct vnode *explicit; /* explicit ids for filei */
|
||
|
struct vnode *enext; /* current explicit ID */
|
||
|
struct vnode **eprev; /* previous explicit ID */
|
||
|
struct enode *evalflds; /* eval field id list */
|
||
|
struct enode *evalrecs; /* eval field record list <<< JBG 19829 <<< */
|
||
|
DBFILE *fptr; /* data file pointer */
|
||
|
DBFILE *dptr; /* dictionary file pointer */
|
||
|
SELFILE *Qfdesc; /* Select file to read from */
|
||
|
union scanvar curscan; /* current scan in progress */
|
||
|
short askids; /* inquiring flag */
|
||
|
short required; /* select list required flag */
|
||
|
short noidx; /* suppress secondary indices */
|
||
|
short reqidx; /* require secondary indices */
|
||
|
short Qfselect; /* input select list to use */
|
||
|
short scanpart; /* part file being scanned */
|
||
|
short source; /* data source ( 'F', etc.) */
|
||
|
short rforgrp; /* true=project cols for grouping */
|
||
|
short rforsel; /* flag set if must read data */
|
||
|
/* to perform select operation */
|
||
|
short rforlst; /* flag set if must read data */
|
||
|
/* to generate output report */
|
||
|
short rforsrt; /* flag set if must read data */
|
||
|
/* to build sort keys */
|
||
|
short pkopt; /* true = explicit id optim */
|
||
|
short skey; /* DBscanhash skeytmp optim */
|
||
|
short free_at; /* true=don't free atID, atRECORD*/
|
||
|
short jnchild; /* the number of join children */
|
||
|
short jtype[JMAX]; /* the join type per child */
|
||
|
struct qfilenode *jparent; /* the join parent */
|
||
|
struct qfilenode *jchild[JMAX];/* the join children */
|
||
|
struct vnode *jeval[JMAX]; /* data to EvalField() trans key*/
|
||
|
struct vnode *jrhs[JMAX]; /* data to Findalt the rhs */
|
||
|
struct node *jsel[JMAX]; /* join predicate */
|
||
|
struct node *idxsel; /* indexed predicate tree */
|
||
|
struct node *svarsel; /* non-indexed predicate tree */
|
||
|
struct vnode *inlist; /* correlated explicit ids */
|
||
|
DBDADDR qllocked; /* current group/scan for lock */
|
||
|
STRING (*DMLread)(); /* DML read type, DBrea, DBwread*/
|
||
|
int cost; /* I/O cost for optimizer */
|
||
|
|
||
|
STRING nf1; /* holds assoc_name for NF1 proc */
|
||
|
void *nf1assoc_ptr; /* NF1 ASSOCIATION sica entry */
|
||
|
STRING nf1askid; /* current askid key */
|
||
|
unsigned short *nf1assoccl; /* NF1, assoc column list */
|
||
|
|
||
|
SQLCURSOR *sqlcp1; /* cursor for sort/merge 1o */
|
||
|
SQLCURSOR *sqlcp2; /* cursor for sort/merge 2o */
|
||
|
STRING srtkey1; /* current key for sort/merge 1o */
|
||
|
STRING srtkey2; /* current key for sort/merge 2o */
|
||
|
uchar *readptr1; /* ptr for sort/merge 1o */
|
||
|
uchar *readptr2; /* ptr for sort/merge 2o */
|
||
|
struct vnode *smjeval; /* single-valued optim for sort/merge */
|
||
|
short lonj; /* status for left outer null proj */
|
||
|
short outer; /* true = outer join being performed */
|
||
|
struct node *onpred; /* ON spec for LONJ */
|
||
|
short odbc_empty; /* <<< JBG 18707 <<<, @ODBC.EMPTY setting */
|
||
|
unsigned short *assoc_keykey; /* <<< JBG 18704 <<<, list of keys */
|
||
|
struct vnode *pmeids; /* explicit id list for parameter markers */
|
||
|
short smrwd; /* Flags when a 'P' in a S/M join has been rewound */
|
||
|
STRING ufname; /* USING dict filename */
|
||
|
uchar separator; /* Multi-part PK separator <<< JBG 19986 <<< */
|
||
|
short key_cnt; /* Number of key parts, primarly for files 19986 */
|
||
|
STRING orignf1; /* Inputted ASSOC/NF! */
|
||
|
STRING priccodeptr; /* Format for numeric conv for pri */
|
||
|
STRING secccodeptr; /* Format for numeric conv for sec */
|
||
|
short paramdup; /* check for duplicate explicit IDs */
|
||
|
};
|
||
|
|
||
|
/* */
|
||
|
/* Data Definitions */
|
||
|
/* */
|
||
|
|
||
|
EXTERN char _s_nl[];
|
||
|
|
||
|
EXTERN DBFILE *Rfmfile;
|
||
|
|
||
|
EXTERN struct enode *s_instring; /* Input strings got for SEARCH */
|
||
|
|
||
|
EXTERN struct qblock
|
||
|
*corrqbptr; /* Query block a field resolved in */
|
||
|
|
||
|
EXTERN int Q_PGBRK, /* paging flag for user exit 2193 */
|
||
|
correlated,
|
||
|
Sql,
|
||
|
dummy, /* work variable to throw away */
|
||
|
/* certain "don't care" result */
|
||
|
/* codes returned via int* */
|
||
|
Qtunit, /* unit numb for tape operation */
|
||
|
Qtslot, /* MTfile no of select tape unit*/
|
||
|
*Qdir,
|
||
|
*Qjust,
|
||
|
*Qcomptype,
|
||
|
Transcache, /* Determines when the TRANS() */
|
||
|
/* cache will be active */
|
||
|
_Qcorr, /* flag telling aconv we are in */
|
||
|
/* a correlative not a conversn */
|
||
|
uniopt, /* unique filter qsorter option */
|
||
|
selcnt, /* count of items selected */
|
||
|
srtkey, /* pointer into sortstring used */
|
||
|
/* to build qsorter command */
|
||
|
l_jst, /* Let text extraction output */
|
||
|
/* conversion know if current */
|
||
|
/* field is left justified */
|
||
|
is_breaking; /* Let text extraction output */
|
||
|
/* conversion know that current */
|
||
|
/* report line is a break-point */
|
||
|
|
||
|
EXTERN uchar Acvt[], /* ascii to ebcdic conversions */
|
||
|
Ecvt[], /* ebcdic to ascii conversions */
|
||
|
*junk;
|
||
|
|
||
|
EXTERN STRING TMstr,
|
||
|
Sqlnulstr,
|
||
|
prtline,
|
||
|
barline,
|
||
|
SUMTOT,
|
||
|
SUMAVG,
|
||
|
SUMCNT,
|
||
|
LVLHEAD;
|
||
|
|
||
|
EXTERN short listitem, /* LIST.ITEM, SORT.ITEM flag */
|
||
|
listused,
|
||
|
every,
|
||
|
reqmult,
|
||
|
s_searching, /* Flag for SEARCH and ESEARCH */
|
||
|
s_cnt_instr, /* Count of number of input str.*/
|
||
|
s_size_tmp, /* No. of bytes allocated for tmpstr*/
|
||
|
Idsup,
|
||
|
Stats,
|
||
|
Pcomp,
|
||
|
TAP,
|
||
|
Byexpcalc, /* global BYEXP query flag for Ftotal */
|
||
|
option_A, /* AND option for SEARCH/ESEARCH*/
|
||
|
option_N, /* NOT option for SEARCH/ESEARCH*/
|
||
|
option_I, /* I option for SEARCH/ESEARCH */
|
||
|
option_S, /* S option for SEARCH/ESEARCH */
|
||
|
option_L; /* L option for SEARCH/ESEARCH */
|
||
|
|
||
|
/*
|
||
|
* Subroutine return definitions
|
||
|
*/
|
||
|
EXTERN SQLCURSOR *SMJmakecursor();
|
||
|
EXTERN SQLCURSOR *CursorCreate();
|
||
|
EXTERN PROGRAM *GetIcode(),
|
||
|
*loaditype();
|
||
|
EXTERN IDXENT *GetNextPartindex(), *Altchoose(),
|
||
|
*Findalt();
|
||
|
EXTERN struct sqlidx *SQLFindalt(), *SQLFindmpalt();
|
||
|
EXTERN SELFILE *Altjoin(),
|
||
|
*Altmerge(),
|
||
|
*Altselect(),
|
||
|
*Altsort(),
|
||
|
*Ogetsel();
|
||
|
EXTERN struct enode *Enode();
|
||
|
EXTERN struct lstnode *Outfld(),
|
||
|
*Outcolumn(),
|
||
|
*Outconst();
|
||
|
EXTERN struct fldnode *FieldAnal();
|
||
|
EXTERN struct qblock *addqnode();
|
||
|
EXTERN struct mfilenode *addmfile();
|
||
|
EXTERN struct qfilenode *addqfile();
|
||
|
EXTERN struct passwd *getpwuid();
|
||
|
EXTERN struct vnode *genvex();
|
||
|
EXTERN struct node *cleansel(),
|
||
|
*makeBTW(),
|
||
|
*SVanal(),
|
||
|
*fixPsel(),
|
||
|
*Anode(),
|
||
|
*gensel(),
|
||
|
*genselv(),
|
||
|
*Hashanal(),
|
||
|
*Altanal();
|
||
|
EXTERN struct evalnode *Scan_column_chain();
|
||
|
EXTERN struct fldnode *LiteralCheck();
|
||
|
EXTERN void Altdisp(),
|
||
|
Altprep(),
|
||
|
Altaddsel(),
|
||
|
DBfree_sica_assoc(),
|
||
|
lstnfree(),
|
||
|
FreeRoot(),
|
||
|
jnoderel(),
|
||
|
ins_selptr(),
|
||
|
del_selptr(),
|
||
|
bigger(),
|
||
|
unloadprog(),
|
||
|
sortinit(),
|
||
|
sortfin(),
|
||
|
qinsert(),
|
||
|
transcache(),
|
||
|
clprocflg(),
|
||
|
vexrel(),
|
||
|
vlist(),
|
||
|
within(),
|
||
|
Srtrel(),
|
||
|
Selrel(),
|
||
|
Hashchain(),
|
||
|
Hashtree(),
|
||
|
optimor(),
|
||
|
Lineout(),
|
||
|
Itemout(),
|
||
|
NumValues();
|
||
|
#ifndef MSWIN
|
||
|
EXTERN char *strtok(),
|
||
|
*mktemp();
|
||
|
#endif
|
||
|
EXTERN char *selopcode();
|
||
|
EXTERN double stf(),
|
||
|
num_load(),
|
||
|
maximum(),
|
||
|
summation();
|
||
|
EXTERN STRING *DMLvalfld(),
|
||
|
*DMLconmvfld(),
|
||
|
*DBheapnext(),
|
||
|
readnextmfs(),
|
||
|
MFShdr(),
|
||
|
convert(),
|
||
|
Get_assoc_key_phrase(),
|
||
|
minstr(),
|
||
|
maxstr(),
|
||
|
oconv(),
|
||
|
iconv(),
|
||
|
format(),
|
||
|
dtoa(),
|
||
|
dtx(),
|
||
|
SOUNDEX(),
|
||
|
input(),
|
||
|
Tstr_load(),
|
||
|
Valins(),
|
||
|
dyn_xtract(),
|
||
|
dyn_extract(),
|
||
|
dyn_replace(),
|
||
|
sqlpmconv(),
|
||
|
sicaphrase(),
|
||
|
dyn_remove(),
|
||
|
dyn_xremove(),
|
||
|
readmsg(),
|
||
|
convert(),
|
||
|
vector(),
|
||
|
vec1(),
|
||
|
vec2(),
|
||
|
Evaluate_column(),
|
||
|
EvalField(),
|
||
|
Evalcorr(),
|
||
|
EvalVexpr(),
|
||
|
EvalItype(),
|
||
|
UVraise(),
|
||
|
lower(),
|
||
|
vecif(), /* in vector.c */
|
||
|
TXread(),
|
||
|
xfield(),
|
||
|
DBget_sicaphrase(),
|
||
|
stripconv(),
|
||
|
vexpr_to_text(),
|
||
|
tree_to_text();
|
||
|
|
||
|
/*************************************************/
|
||
|
/* these next five are needed despite being int! */
|
||
|
EXTERN int comp(),
|
||
|
compare(),
|
||
|
Hashpredicate(),
|
||
|
Hashjoin(),
|
||
|
SMJanal();
|
||
|
|
||
|
/***************************************/
|
||
|
/* these are here to shut lint up only */
|
||
|
EXTERN int DBget_sicarowsize(),
|
||
|
MakeCNF(),
|
||
|
join(),
|
||
|
Checksel(),
|
||
|
singlegrp(),
|
||
|
chkgrp(),
|
||
|
gbrel(),
|
||
|
Oaltsel(),
|
||
|
Ostat(),
|
||
|
update_count(),
|
||
|
Init_column_chain(),
|
||
|
Free_column_chain(),
|
||
|
Build_assoc_column_chain(),
|
||
|
DMLclrlatch(),
|
||
|
DMLnestswap(),
|
||
|
DMLclosecursor(),
|
||
|
Free_assoc_column_chain(),
|
||
|
Apply_sql_when(),
|
||
|
Travers(),
|
||
|
SELreset(),
|
||
|
TXHasUpdates(),
|
||
|
CursorAssociate(),
|
||
|
CursorClose(),
|
||
|
CursorDelete();
|
||
|
#endif
|