317 lines
13 KiB
C
317 lines
13 KiB
C
|
#ifndef h_qcursor
|
||
|
#define h_qcursor
|
||
|
/******************************************************************************
|
||
|
*
|
||
|
* Header file for uniVerse cursors
|
||
|
*
|
||
|
* 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.........................................
|
||
|
* 03/31/99 23637 JBG Add autoinc to COLUMNDESC
|
||
|
* 10/14/98 23801 SAP Change copyrights.
|
||
|
* 01/06/98 22398 JBG define NOWAIT bit in cursor status
|
||
|
* 09/17/97 21514 RGA Prepare/Execute/Execute performance work
|
||
|
* 10/28/96 18457 JBG add lstnode ptr to COLUMNMAP, 3 short to UPDATABLE
|
||
|
* 07/23/96 18891 JBG column attribute is_updatable
|
||
|
* 05/30/96 18162 ENF Added a bit to prohibit query from doing new TX.
|
||
|
* 05/16/96 18162 MJC Add a char* file name for PRINT output (for delete)
|
||
|
* 03/29/96 18162 ENF Add a param type to paramer structure
|
||
|
* 03/21/96 18162 ENF Add a FILE * for PRINT output
|
||
|
* 03/15/96 18162 ENF Add items to support SQL Procedures
|
||
|
* 12/12/95 17730 JBG Increase JMAX to 20
|
||
|
* 12/05/95 17730 JBG increase JMAX to 12
|
||
|
* 11/03/95 17337 JBG Add to updatable VIEW structure (topview, topselect)
|
||
|
* 11/02/95 17337 JBG Add to updatable VIEW structure (prev2_record, id)
|
||
|
* 11/01/95 17398 MGM Add unsortamc to dbcursor structure
|
||
|
* 11/01/95 17337 JBG Added to updatable VIEW structure (prev_record, id)
|
||
|
* 10/30/95 17337 JBG Add flag to dbcursor cpflags - nofreeid
|
||
|
* 10/19/95 17398 MGM Add unmfslist to dbcursor structure
|
||
|
* 10/12/95 17337 JBG Add qfptr to dbcursor structure
|
||
|
* 09/29/95 17398 ENF Added UNION cursor pointers to cursor struct
|
||
|
* 09/28/95 17337 JBG Add ISSYMMETRIC macro
|
||
|
* 09/28/95 17337 JBG Added Qblock and symmetric to UPDATABLE_VIEW
|
||
|
* 09/22/95 17337 JBG Define updatable VIEW structure
|
||
|
* 06/21/95 15921 ENF Get rid of notxactive bit
|
||
|
* 05/24/95 15752 RM Added no-locking flag
|
||
|
* 05/15/95 15921 ENF Added Sqblock save location
|
||
|
* 04/18/95 15921 JBG Define cursor header open_iso_lvl
|
||
|
* 03/27/95 15921 ENF Make executed => ddlexecuted; add new executed
|
||
|
* 03/07/95 15921 JBG Add ovflow bit to curflags
|
||
|
* 03/02/95 15921 JBG Add prepared and executed bits to curflags
|
||
|
* 02/24/95 15921 JBG Add bit in cursor header
|
||
|
* 02/16/95 15921 ENF Fix type in SRVERRBLK addition
|
||
|
* 02/15/95 15921 ENF Add SRVERRBLK structure to cursor for errors
|
||
|
* 02/10/95 15921 JBG cursor header coldefarray,open_nest_lvl,sql_type
|
||
|
* 01/31/95 15634 JBG Define param set, number param
|
||
|
* 01/26/95 15634 JBG Define column display_size, optimparmk
|
||
|
* 01/18/95 15634 JBG Add vopnode field to parameter marker
|
||
|
* 01/17/95 15634 JBG Redefine COLUMNDEF structure.
|
||
|
* 01/13/95 15634 JBG Server support, server bit in flags, parammarker struct
|
||
|
* 10/21/94 14962 ENF Add a notxactive bit to cursor flags
|
||
|
* 06/16/94 13514 ENF Add flag so integrity constraints can bypass SQL
|
||
|
* permission checks
|
||
|
* 06/07/94 14151 ENF Added 'nodata' bit to detect no generated data
|
||
|
* 05/25/94 13514 ENF Added place to save current globals
|
||
|
* Added parent query block pointer
|
||
|
* 05/19/94 13514 ENF Add test for no cursor pointer to ISAVIEW, NOTAVIEW
|
||
|
* 04/21/94 13514 ENF Change COLUMNDEF to COLUMNDESC, as it conflicted
|
||
|
* 04/15/94 13514 ENF Added save variable context area
|
||
|
* 04/13/94 13514 ENF Added rowsfetched, EOD bit
|
||
|
* 04/11/94 13514 ENF Initial submission
|
||
|
*
|
||
|
*****************************************************************************/
|
||
|
|
||
|
#include "uvsqlsrverr.h"
|
||
|
|
||
|
/***********************************
|
||
|
* Define query operational flags
|
||
|
***********************************/
|
||
|
#define QUERY_INIT 1<<1 /* Initialize query variables */
|
||
|
#define QUERY_COMPILE 1<<2 /* Compile the statement passed in */
|
||
|
#define QUERY_EXECUTE 1<<3 /* After compilation, continue with exec */
|
||
|
|
||
|
#define QUERY_ALL QUERY_INIT | QUERY_COMPILE | QUERY_EXECUTE
|
||
|
|
||
|
/***********************************
|
||
|
* Operations valid for qengine
|
||
|
* calls for cursors
|
||
|
***********************************/
|
||
|
#define CURSOR_INIT 1<<1
|
||
|
#define CURSOR_FETCH 1<<2
|
||
|
|
||
|
/**********************************
|
||
|
* Macros for cursor operations
|
||
|
**********************************/
|
||
|
#define ISAVIEW(sqlcp) ( sqlcp && (sqlcp)->curflags.isaview)
|
||
|
#define NOTAVIEW(sqlcp) ( !sqlcp || !(sqlcp)->curflags.isaview )
|
||
|
#define ISASERVER(sqlcp) (sqlcp && (sqlcp)->curflags.isaserver)
|
||
|
#define ISSYMMETRIC(sqlcp) (sqlcp && (sqlcp)->updatable && (sqlcp)->updatable->symmetric)
|
||
|
#define ISUPDATABLE(sqlcp) (sqlcp && ((sqlcp)->updatable && !(sqlcp)->updatable->read_only)) /* <<< JBG 18457 <<< */
|
||
|
#define ISACALL(sqlcp) (sqlcp && sqlcp->curflags.isacall)
|
||
|
|
||
|
/**********************************
|
||
|
* Defines for cursor routines
|
||
|
**********************************/
|
||
|
#define CURSOR_ALLOC 64 /* Number of cursors to allocate */
|
||
|
#define CURSOR_NAME_MAX 18 /* Max length of cursor name */
|
||
|
#define CURSOR_ERROR(errloc,errnum) { *errloc = errnum; return(0); }
|
||
|
|
||
|
#define EODATA -1
|
||
|
#define JMAX 20 /* Maximum number of JOINs */
|
||
|
|
||
|
/**************************************************
|
||
|
* Define a saved variable structure to hold variables
|
||
|
* we need to save
|
||
|
**************************************************/
|
||
|
typedef struct varsave
|
||
|
{
|
||
|
|
||
|
/* Saved sort context variable */
|
||
|
int srtkey; /* Number of ORDER BY variables */
|
||
|
int (*Qjust)[]; /* Array of justifications */
|
||
|
int (*Qdir)[]; /* Array of ASC/DESC values */
|
||
|
int (*Qcomptype)[]; /* Array of comparison types */
|
||
|
struct qblock *Qblock;
|
||
|
struct qblock *Curblock;
|
||
|
struct qblock *Sqblock;
|
||
|
SELFILE *outselptr; /* Our copy of global Outselptr */
|
||
|
char *atHSTMT; /* The address of @HSTMT hstmt area */
|
||
|
|
||
|
} VARSAVE;
|
||
|
|
||
|
/**************************************************
|
||
|
* Define a structure to hold column definitions
|
||
|
**************************************************/
|
||
|
typedef struct columndesc
|
||
|
{
|
||
|
int colnum;
|
||
|
STRING collabel;
|
||
|
STRING colname;
|
||
|
STRING coltable;
|
||
|
STRING colformat;
|
||
|
STRING colconv;
|
||
|
int sqltype;
|
||
|
int precision;
|
||
|
int scale;
|
||
|
int multivalue;
|
||
|
int display_size;
|
||
|
short nullable;
|
||
|
short money;
|
||
|
short updatable; /* <<< JBG 18891 <<< */
|
||
|
short autoinc; /* <<< 23637 <<< */
|
||
|
struct columndesc *next;
|
||
|
} COLUMNDESC;
|
||
|
|
||
|
/********************************************************
|
||
|
* Define a structure to hold parameter marker defination
|
||
|
********************************************************/
|
||
|
typedef struct parammark
|
||
|
{
|
||
|
struct parammark *next;
|
||
|
int paramnum;
|
||
|
struct evalnode *evalptr;
|
||
|
STRING value;
|
||
|
int sqltype;
|
||
|
int precision;
|
||
|
int scale;
|
||
|
struct vnode *vopnode;
|
||
|
int set; /* true if set at least once */
|
||
|
int piotype; /* IN, OUT or IN_OUT */
|
||
|
} PARAMMARK;
|
||
|
|
||
|
/**************************************************************
|
||
|
* Define structure to hold updatable VIEW column map
|
||
|
**************************************************************/
|
||
|
typedef struct columnmap
|
||
|
{
|
||
|
short vcolno; /* VIEW's column number */
|
||
|
short qfilei; /* column from qfile i */
|
||
|
short scolno; /* qfile i's column number */
|
||
|
short status; /* TRUE if column set */
|
||
|
struct columnmap *corrcol; /* another column of same value */
|
||
|
STRING whereconst; /* column value from WHERE clause */
|
||
|
STRING external; /* saved external STRING */
|
||
|
struct lstnode *lstptr; /* lstnode pointer <<< JBG 18457 <<< */
|
||
|
} COLUMNMAP;
|
||
|
|
||
|
/*****************************************************************
|
||
|
* Define structure defining updatable VIEW
|
||
|
****************************************************************/
|
||
|
typedef struct updatable_view
|
||
|
{
|
||
|
struct node *wheretree; /* original WHERE tree */
|
||
|
short no_columns; /* number of columns in VIEW */
|
||
|
short no_keys; /* number of keys in VIEW */
|
||
|
COLUMNMAP *col_const; /* list of constant values */
|
||
|
COLUMNMAP *col_map; /* ptr to array of column definations */
|
||
|
struct qfilenode *qfilei[JMAX]; /* array of base tables/views */
|
||
|
STRING saved_record[JMAX]; /* id before modification */
|
||
|
STRING saved_id[JMAX];
|
||
|
STRING prev_record[JMAX]; /* image of previous LATCHED read */
|
||
|
STRING prev_id[JMAX];
|
||
|
short modified[JMAX]; /* base table/view modified flag */
|
||
|
short local_cascaded; /* FALSE if CASCADED option */
|
||
|
short symmetric; /* TRUE if symmetric */
|
||
|
short checkoption; /* TRUE WITH CHECK OPTION */
|
||
|
short topview; /* Top view in chain */
|
||
|
short topselect; /* Top view. SELECT */
|
||
|
struct qblock *Qblock; /* Saved Qblock */
|
||
|
STRING prev2_record[JMAX]; /* image of previous LOCKED read */
|
||
|
STRING prev2_id[JMAX];
|
||
|
short topqverb; /* <<< JBG 18457 <<< top qverb */
|
||
|
short imagebuilt; /* <<< JBG 18457 <<< row-record built */
|
||
|
short read_only; /* <<< JBG 18457 <<< read_only */
|
||
|
} UPDATABLE_VIEW;
|
||
|
|
||
|
/**************************************************
|
||
|
* Define bit flags we'll need.
|
||
|
**************************************************/
|
||
|
struct cpflags
|
||
|
{
|
||
|
BITMAP
|
||
|
spare:((8*sizeof(BITMAP))-24),
|
||
|
trignowait:1, /* TRUE if TRIGGER NOWAIT, global off before <<< 22398 */
|
||
|
nowait:1, /* TRUE if NOWAIT set in grammer <<< 22398 */
|
||
|
reexecutable:1, /* TRUE if optimizer determines source scan type is reexecutable */
|
||
|
nofreeid:1, /* TRUE if atID & atRECORD are NOT to be freed, case
|
||
|
for updat VIEW, dynamic norm, UPDATE, DELETE */
|
||
|
isaview:1, /* TRUE if cursor belongs to a view */
|
||
|
icons:1, /* TRUE if op is being done by integrity chk */
|
||
|
needmfs:1, /* TRUE if data will be in mfs list */
|
||
|
mfsstrings:1, /* FALSE if mfslist uses keys. */
|
||
|
mfshasdata:1, /* TRUE if mfslist contains data */
|
||
|
rechasdata:1, /* TRUE if cursor record has valid data */
|
||
|
eod:1, /* TRUE if fetch has reached EOD */
|
||
|
nodata:1, /* TRUE if no data ever generated */
|
||
|
isaserver:1, /* TRUE if curser belongs to a server */
|
||
|
prepared:1, /* TRUE if LS_SQAssociate executed */
|
||
|
ddlexecuted:1, /* TRUE if DDL executed at Prepare time*/
|
||
|
ovflow:1, /* TRUE if last fetch record not fit in server buf */
|
||
|
mfsforce:1, /* TRUE if mfslist must be used */
|
||
|
executed:1, /* TRUE after cursor is executed */
|
||
|
reexecuted:1, /* TRUE if cursor executed without being closed */
|
||
|
no_locking:1, /* TRUE if cursor should do no locking (smjoin) */
|
||
|
unionop:1, /* TRUE if this is a node for UNION */
|
||
|
unionall:1, /* TRUE if UNION ALL node */
|
||
|
nodmltx:1, /* TRUE if query should _NOT_ start a TX for this */
|
||
|
isacall:1; /* TRUE if cursor contains procedure CALL */
|
||
|
};
|
||
|
|
||
|
/**************************************************
|
||
|
* Define the essential cursor structure
|
||
|
**************************************************/
|
||
|
typedef struct dbcursor
|
||
|
{
|
||
|
STRING name; /* Cursor name */
|
||
|
STRING sqltext; /* SQL statement */
|
||
|
STRING record; /* The row buffer */
|
||
|
/* curflags is cursor flags bitmap */
|
||
|
struct cpflags curflags;
|
||
|
struct qblock *parentqb; /* Parent query block (of VIEW only) */
|
||
|
struct qblock *qb; /* Query block compiled from text */
|
||
|
|
||
|
/* These two are used to hold left and right branches of UNION */
|
||
|
struct dbcursor *unleft;
|
||
|
struct dbcursor *unright;
|
||
|
|
||
|
int numcols; /* # columns produced by SELECT */
|
||
|
int numrows; /* Number of rows affected by the
|
||
|
SQL staement */
|
||
|
int rowsfetched; /* # rows fetched so far */
|
||
|
SELFILE *mfslist; /* Multi-file select list holding
|
||
|
the results of the query */
|
||
|
SELFILE *unmfslist; /* sort area for UNION */
|
||
|
STRING errcode;
|
||
|
STRING errtext;
|
||
|
COLUMNDESC *ccolumns; /* A linked list of the column
|
||
|
descriptions for server */
|
||
|
|
||
|
VARSAVE varsave; /* This cursor's working variable */
|
||
|
|
||
|
VARSAVE inglobals; /* Place to save incoming globals */
|
||
|
|
||
|
char status; /* 'I' - Allocated and initialized
|
||
|
'A' - SQL is associated
|
||
|
'O' - Opened */
|
||
|
PARAMMARK *params; /* A linked list of parameter markers
|
||
|
for the server */
|
||
|
int numpars; /* number of parameter marker allocated */
|
||
|
int *coldefarray; /* array of column definations */
|
||
|
SRVERRBLK srverr; /* A place to report errors */
|
||
|
char sql_type; /* 'D' - SQL DDL
|
||
|
'S' - SQL DML SELECT
|
||
|
'M' - SQL DML INSERT, UPDATE, DELETE */
|
||
|
short open_iso_lvl; /* transaction ISO level when cursor opened */
|
||
|
STRING id; /* id of symmetric VIEW */
|
||
|
UPDATABLE_VIEW *updatable; /* updatable VIEW structure */
|
||
|
DBFILE *fptr; /* NOT USED file this view referenced from */
|
||
|
struct qfilenode *qfptr; /* qfilenode this view referenced from */
|
||
|
int *unsortamc; /* array of amc's for union final order by */
|
||
|
FILE *printfp; /* File pointer for PRINT result records */
|
||
|
char *printfname; /* PRINT file name */
|
||
|
} SQLCURSOR;
|
||
|
|
||
|
/*****************************************
|
||
|
* Function declarations will go in here
|
||
|
*****************************************/
|
||
|
EXTERN int CursorAssociate();
|
||
|
EXTERN int CursorClose();
|
||
|
EXTERN struct dbcursor *CursorCreate();
|
||
|
EXTERN int CursorDelete();
|
||
|
EXTERN int CursorFetch();
|
||
|
EXTERN struct dbcursor *CursorLocate();
|
||
|
EXTERN int CursorOpen();
|
||
|
EXTERN int CursorOut();
|
||
|
EXTERN int CursorReset();
|
||
|
|
||
|
#endif
|