1 /************** PlgDBSem H Declares Source Code File (.H) **************/
2 /*  Name: PLGDBSEM.H  Version 3.8                                      */
3 /*                                                                     */
4 /*  (C) Copyright to the author Olivier BERTRAND          1998-2019    */
5 /*                                                                     */
6 /*  This file contains the CONNECT storage engine definitions.         */
7 /***********************************************************************/
8 
9 /***********************************************************************/
10 /*  Include required application header files                          */
11 /***********************************************************************/
12 #include "checklvl.h"
13 
14 /***********************************************************************/
15 /*  DB Constant definitions.                                           */
16 /***********************************************************************/
17 #if defined(FRENCH)
18 #define DEFAULT_LOCALE  "French"
19 #else   // !FRENCH
20 #define DEFAULT_LOCALE  "English"
21 #endif  // !FRENCH
22 
23 #define DOS_MAX_PATH    144   /* Must be the same across systems       */
24 #define DOS_BUFF_LEN    100   /* Number of lines in binary file buffer */
25 #undef  DOMAIN                /* For Unix version                      */
26 
27 enum BLKTYP {TYPE_TABLE      = 50,    /* Table Name/Srcdef/... Block   */
28              TYPE_COLUMN     = 51,    /* Column Name/Qualifier Block   */
29              TYPE_TDB        = 53,    /* Table Description Block       */
30              TYPE_COLBLK     = 54,    /* Column Description Block      */
31              TYPE_FILTER     = 55,    /* Filter Description Block      */
32              TYPE_ARRAY      = 63,    /* General array type            */
33              TYPE_PSZ        = 64,    /* Pointer to String ended by 0  */
34              TYPE_SQL        = 65,    /* Pointer to SQL block          */
35              TYPE_XOBJECT    = 69,    /* Extended DB object            */
36              TYPE_COLCRT     = 71,    /* Column creation block         */
37              TYPE_CONST      = 72,    /* Constant                      */
38 
39 /*-------------------- additional values used by LNA ------------------*/
40              TYPE_COLIST     = 14,    /* Column list                   */
41              TYPE_COL        = 41,    /* Column                        */
42 /*-------------------- types used by scalar functions -----------------*/
43              TYPE_NUM        = 12,
44              TYPE_UNDEF      = 13,
45 /*-------------------- file blocks used when closing ------------------*/
46              TYPE_FB_FILE    = 22,    /* File block (stream)           */
47              TYPE_FB_MAP     = 23,    /* Mapped file block (storage)   */
48              TYPE_FB_HANDLE  = 24,    /* File block (handle)           */
49              TYPE_FB_XML     = 21,    /* DOM XML file block            */
50              TYPE_FB_XML2    = 27,    /* libxml2 XML file block        */
51 	           TYPE_FB_ODBC    = 25,    /* ODBC file block               */
52 						 TYPE_FB_ZIP     = 28,    /* ZIP file block                */
53 	           TYPE_FB_JAVA    = 29,    /* JAVA file block               */
54 						 TYPE_FB_MONGO   = 30};   /* MONGO file block              */
55 
56 enum TABTYPE {TAB_UNDEF =  0,   /* Table of undefined type             */
57               TAB_DOS   =  1,   /* Fixed column offset, variable LRECL */
58               TAB_FIX   =  2,   /* Fixed column offset, fixed LRECL    */
59               TAB_BIN   =  3,   /* Like FIX but can have binary fields */
60               TAB_CSV   =  4,   /* DOS files with CSV records          */
61               TAB_FMT   =  5,   /* DOS files with formatted records    */
62               TAB_DBF   =  6,   /* DBF Dbase or Foxpro files           */
63               TAB_XML   =  7,   /* XML or HTML files                   */
64               TAB_INI   =  8,   /* INI or CFG files                    */
65               TAB_VEC   =  9,   /* Vector column arrangement           */
66               TAB_ODBC  = 10,   /* Table accessed via (unix)ODBC       */
67               TAB_MYSQL = 11,   /* MySQL table accessed via MySQL API  */
68               TAB_DIR   = 12,   /* Returns a list of files             */
69               TAB_MAC   = 13,   /* MAC address (Windows only)          */
70               TAB_WMI   = 14,   /* WMI tables  (Windows only)          */
71               TAB_TBL   = 15,   /* Collection of CONNECT tables        */
72               TAB_OEM   = 16,   /* OEM implemented table               */
73               TAB_XCL   = 17,   /* XCL table                           */
74               TAB_OCCUR = 18,   /* OCCUR table                         */
75               TAB_PRX   = 19,   /* Proxy (catalog) table               */
76               TAB_PLG   = 20,   /* PLG NIY                             */
77               TAB_PIVOT = 21,   /* PIVOT table                         */
78               TAB_VIR   = 22,   /* Virtual tables                      */
79               TAB_JSON  = 23,   /* JSON tables                         */
80               TAB_JCT   = 24,   /* Junction tables NIY                 */
81               TAB_DMY   = 25,   /* DMY Dummy tables NIY                */
82 							TAB_JDBC  = 26,   /* Table accessed via JDBC             */
83 							TAB_ZIP   = 27,   /* ZIP file info table                 */
84 							TAB_MONGO = 28,   /* Table retrieved from MongoDB        */
85 							TAB_REST  = 29,   /* Table retrieved from Rest           */
86               TAB_BSON  = 30,   /* BSON Table (development)            */
87               TAB_NIY   = 31};  /* Table not implemented yet           */
88 
89 enum AMT {TYPE_AM_ERROR =   0,        /* Type not defined              */
90           TYPE_AM_ROWID =   1,        /* ROWID type (special column)   */
91           TYPE_AM_FILID =   2,        /* FILEID type (special column)  */
92           TYPE_AM_TAB   =   3,        /* Table (any type)              */
93           TYPE_AM_VIEW  =   4,        /* VIEW (any type)               */
94           TYPE_AM_SRVID =   5,        /* SERVID type (special column)  */
95           TYPE_AM_TABID =   6,        /* TABID  type (special column)  */
96           TYPE_AM_CNSID =   7,        /* CONSTID type (special column) */
97           TYPE_AM_PRTID =   8,        /* PARTID type (special column)  */
98           TYPE_AM_COUNT =  10,        /* CPT AM type no (count table)  */
99           TYPE_AM_DCD   =  20,        /* Decode access method type no  */
100           TYPE_AM_CMS   =  30,        /* CMS access method type no     */
101           TYPE_AM_MAP   =  32,        /* MAP access method type no     */
102           TYPE_AM_FMT   =  33,        /* DOS files with formatted recs */
103           TYPE_AM_CSV   =  34,        /* DOS files with CSV records    */
104           TYPE_AM_MCV   =  35,        /* MAP files with CSV records    */
105           TYPE_AM_DOS   =  36,        /* DOS am with Lrecl = V         */
106           TYPE_AM_FIX   =  38,        /* DOS am with Lrecl = F         */
107           TYPE_AM_BIN   =  39,        /* DOS am with Lrecl = B         */
108           TYPE_AM_VCT   =  40,        /* VCT access method type no     */
109           TYPE_AM_VMP   =  43,        /* VMP access method type no     */
110           TYPE_AM_QRY   =  50,        /* QRY access method type no     */
111           TYPE_AM_QRS   =  51,        /* QRYRES access method type no  */
112           TYPE_AM_SQL   =  60,        /* SQL VIEW access method type   */
113           TYPE_AM_PLG   =  70,        /* PLG access method type no     */
114           TYPE_AM_PLM   =  71,        /* PDM access method type no     */
115           TYPE_AM_DOM   =  80,        /* DOM access method type no     */
116           TYPE_AM_DIR   =  90,        /* DIR access method type no     */
117           TYPE_AM_ODBC  = 100,        /* ODBC access method type no    */
118           TYPE_AM_XDBC  = 101,        /* XDBC access method type no    */
119 					TYPE_AM_JDBC  = 102,        /* JDBC access method type no    */
120 					TYPE_AM_XJDC  = 103,        /* XJDC access method type no    */
121 					TYPE_AM_OEM   = 110,        /* OEM access method type no     */
122           TYPE_AM_TBL   = 115,        /* TBL access method type no     */
123           TYPE_AM_PIVOT = 120,        /* PIVOT access method type no   */
124           TYPE_AM_SRC   = 121,        /* PIVOT multiple column type no */
125           TYPE_AM_FNC   = 122,        /* PIVOT source column type no   */
126           TYPE_AM_XCOL  = 124,        /* XCOL access method type no    */
127           TYPE_AM_XML   = 127,        /* XML access method type no     */
128           TYPE_AM_OCCUR = 128,        /* OCCUR access method type no   */
129           TYPE_AM_PRX   = 129,        /* PROXY access method type no   */
130           TYPE_AM_XTB   = 130,        /* SYS table access method type  */
131           TYPE_AM_BLK   = 131,        /* BLK access method type no     */
132           TYPE_AM_GZ    = 132,        /* GZ access method type no      */
133           TYPE_AM_ZLIB  = 133,        /* ZLIB access method type no    */
134           TYPE_AM_JSON  = 134,        /* JSON access method type no    */
135           TYPE_AM_JSN   = 135,        /* JSN access method type no     */
136           TYPE_AM_MAC   = 137,        /* MAC table access method type  */
137           TYPE_AM_WMI   = 139,        /* WMI table access method type  */
138           TYPE_AM_XCL   = 140,        /* SYS column access method type */
139           TYPE_AM_INI   = 150,        /* INI files access method       */
140           TYPE_AM_TFC   = 155,        /* TFC (Circa) (Fuzzy compare)   */
141           TYPE_AM_DBF   = 160,        /* DBF Dbase files am type no    */
142           TYPE_AM_JCT   = 170,        /* Junction tables am type no    */
143           TYPE_AM_VIR   = 171,        /* Virtual tables am type no     */
144           TYPE_AM_DMY   = 172,        /* DMY Dummy tables am type no   */
145           TYPE_AM_SET   = 180,        /* SET Set tables am type no     */
146           TYPE_AM_MYSQL = 190,        /* MYSQL access method type no   */
147           TYPE_AM_MYX   = 191,        /* MYSQL EXEC access method type */
148           TYPE_AM_CAT   = 192,        /* Catalog access method type no */
149 					TYPE_AM_ZIP   = 193,				/* ZIP access method type no     */
150 	        TYPE_AM_MGO   = 194,				/* MGO access method type no     */
151 					TYPE_AM_OUT   = 200};       /* Output relations (storage)    */
152 
153 enum RECFM {RECFM_DFLT  =     0,      /* Default table type            */
154             RECFM_NAF   =     1,      /* Not a file table              */
155             RECFM_OEM   =     2,      /* OEM table                     */
156             RECFM_VAR   =     3,      /* Varying length DOS files      */
157             RECFM_FIX   =     4,      /* Fixed length DOS files        */
158             RECFM_BIN   =     5,      /* Binary DOS files (also fixed) */
159 						RECFM_DBF   =     6,      /* DBase formatted file          */
160 						RECFM_CSV   =     7,      /* CSV file                      */
161 						RECFM_FMT   =     8,      /* FMT formatted file            */
162 						RECFM_VCT   =     9,      /* VCT formatted files           */
163 						RECFM_XML   =    10,      /* XML formatted files           */
164 						RECFM_JSON  =    11,      /* JSON formatted files          */
165 						RECFM_DIR   =    12,      /* DIR table                     */
166 						RECFM_ODBC  =    13,      /* Table accessed via ODBC       */
167 						RECFM_JDBC  =    14,      /* Table accessed via JDBC       */
168 						RECFM_PLG   =    15};     /* Table accessed via PLGconn    */
169 
170 enum MISC {DB_TABNO     =     1,      /* DB routines in Utility Table  */
171            MAX_MULT_KEY =    10,      /* Max multiple key number       */
172            NAM_LEN      =   128,      /* Length of col and tab names   */
173            ARRAY_SIZE   =    50,      /* Default array block size      */
174 //         MAXRES       =   500,      /* Default maximum result lines  */
175 //         MAXLIN       = 10000,      /* Default maximum data lines    */
176            MAXBMP       =    32};     /* Default XDB2 max bitmap size  */
177 
178 #if 0
179 enum ALGMOD {AMOD_AUTO =  0,          /* PLG chooses best algorithm    */
180              AMOD_SQL  =  1,          /* Use SQL algorithm             */
181              AMOD_QRY  =  2};         /* Use QUERY algorithm           */
182 #endif // 0
183 
184 enum MODE {MODE_ERROR   = -1,         /* Invalid mode                  */
185            MODE_ANY     =  0,         /* Unspecified mode              */
186            MODE_READ    = 10,         /* Input/Output mode             */
187            MODE_READX   = 11,         /* Read indexed mode             */
188            MODE_WRITE   = 20,         /* Input/Output mode             */
189            MODE_UPDATE  = 30,         /* Input/Output mode             */
190            MODE_INSERT  = 40,         /* Input/Output mode             */
191            MODE_DELETE  = 50,         /* Input/Output mode             */
192            MODE_ALTER   = 60};        /* alter mode                    */
193 
194 #if !defined(RC_OK_DEFINED)
195 #define RC_OK_DEFINED
196 enum RCODE {RC_OK      =   0,         /* No error return code          */
197             RC_NF      =   1,         /* Not found return code         */
198             RC_EF      =   2,         /* End of file return code       */
199             RC_FX      =   3,         /* Error return code             */
200             RC_INFO    =   4};        /* Success with info             */
201 #endif   // !RC_OK_DEFINED
202 
203 enum OPVAL {OP_EQ      =   1,         /* Filtering operator =          */
204             OP_NE      =   2,         /* Filtering operator !=         */
205             OP_GT      =   3,         /* Filtering operator >          */
206             OP_GE      =   4,         /* Filtering operator >=         */
207             OP_LT      =   5,         /* Filtering operator <          */
208             OP_LE      =   6,         /* Filtering operator <=         */
209             OP_IN      =   7,         /* Filtering operator IN         */
210             OP_NULL    =   8,         /* Filtering operator IS NULL    */
211             OP_EXIST   =   9,         /* Filtering operator EXISTS     */
212             OP_LIKE    =  10,         /* Filtering operator LIKE       */
213             OP_LOJ     =  -1,         /* Filter op LEFT  OUTER JOIN    */
214             OP_ROJ     =  -2,         /* Filter op RIGHT OUTER JOIN    */
215             OP_DTJ     =  -3,         /* Filter op DISTINCT    JOIN    */
216             OP_XX      =  11,         /* Filtering operator unknown    */
217             OP_AND     =  12,         /* Filtering operator AND        */
218             OP_OR      =  13,         /* Filtering operator OR         */
219             OP_CNC     =  14,         /* Expression Concat operator    */
220             OP_NOT     =  15,         /* Filtering operator NOT        */
221             OP_SEP     =  20,         /* Filtering separator           */
222             OP_ADD     =  16,         /* Expression Add operator       */
223             OP_SUB     =  17,         /* Expression Substract operator */
224             OP_MULT    =  18,         /* Expression Multiply operator  */
225             OP_DIV     =  19,         /* Expression Divide operator    */
226             OP_NUM     =  22,         /* Scalar function Op Num        */
227             OP_MAX     =  24,         /* Scalar function Op Max        */
228             OP_MIN     =  25,         /* Scalar function Op Min        */
229 						OP_EXP     =  36,         /* Scalar function Op Exp        */
230 						OP_FDISK   =  94,         /* Operator Disk of fileid       */
231 						OP_FPATH   =  95,         /* Operator Path of fileid       */
232 						OP_FNAME   =  96,         /* Operator Name of fileid       */
233 						OP_FTYPE   =  97,         /* Operator Type of fileid       */
234 						OP_LAST    =  82,         /* Index operator Find Last      */
235 						OP_FIRST   = 106,         /* Index operator Find First     */
236             OP_NEXT    = 107,         /* Index operator Find Next      */
237             OP_SAME    = 108,         /* Index operator Find Next Same */
238 						OP_FSTDIF  = 109,         /* Index operator Find First dif */
239 						OP_NXTDIF  = 110,         /* Index operator Find Next dif  */
240 						OP_PREV    = 116};        /* Index operator Find Previous  */
241 #if 0
242             OP_NOP     =  21,         /* Scalar function is nopped     */
243             OP_ABS     =  23,         /* Scalar function Op Abs        */
244             OP_CEIL    =  26,         /* Scalar function Op Ceil       */
245             OP_FLOOR   =  27,         /* Scalar function Op Floor      */
246             OP_MOD     =  28,         /* Scalar function Op Mod        */
247             OP_ROUND   =  29,         /* Scalar function Op Round      */
248             OP_SIGN    =  30,         /* Scalar function Op Sign       */
249             OP_LEN     =  31,         /* Scalar function Op Len        */
250             OP_INSTR   =  32,         /* Scalar function Op Instr      */
251             OP_LEFT    =  33,         /* Scalar function Op Left       */
252             OP_RIGHT   =  34,         /* Scalar function Op Right      */
253             OP_ASCII   =  35,         /* Scalar function Op Ascii      */
254             OP_EXP     =  36,         /* Scalar function Op Exp        */
255             OP_LN      =  37,         /* Scalar function Op Ln         */
256             OP_LOG     =  38,         /* Scalar function Op Log        */
257             OP_POWER   =  39,         /* Scalar function Op Power      */
258             OP_SQRT    =  40,         /* Scalar function Op Sqrt       */
259             OP_COS     =  41,         /* Scalar function Op Cos        */
260             OP_COSH    =  42,         /* Scalar function Op Cosh       */
261             OP_SIN     =  43,         /* Scalar function Op Sin        */
262             OP_SINH    =  44,         /* Scalar function Op Sinh       */
263             OP_TAN     =  45,         /* Scalar function Op Tan        */
264             OP_TANH    =  46,         /* Scalar function Op Tanh       */
265             OP_USER    =  47,         /* Scalar function Op User       */
266             OP_CHAR    =  48,         /* Scalar function Op Char       */
267             OP_UPPER   =  49,         /* Scalar function Op Upper      */
268             OP_LOWER   =  50,         /* Scalar function Op Lower      */
269             OP_RPAD    =  51,         /* Scalar function Op Rpad       */
270             OP_LPAD    =  52,         /* Scalar function Op Lpad       */
271             OP_LTRIM   =  53,         /* Scalar function Op Ltrim      */
272             OP_RTRIM   =  54,         /* Scalar function Op Rtrim      */
273             OP_REPL    =  55,         /* Scalar function Op Replace    */
274             OP_SUBST   =  56,         /* Scalar function Op Substr     */
275             OP_LJUST   =  57,         /* Scalar function Op Ljustify   */
276             OP_RJUST   =  58,         /* Scalar function Op Rjustify   */
277             OP_CJUST   =  59,         /* Scalar function Op Cjustify   */
278             OP_ENCODE  =  60,         /* Scalar function Op Encode     */
279             OP_DECODE  =  61,         /* Scalar function Op Decode     */
280             OP_SEQU    =  62,         /* Scalar function Op Sequence   */
281             OP_IF      =  63,         /* Scalar function Op If         */
282             OP_STRING  =  64,         /* Scalar function Op String     */
283             OP_TOKEN   =  65,         /* Scalar function Op Token      */
284             OP_SNDX    =  66,         /* Scalar function Op Soundex    */
285             OP_DATE    =  67,         /* Scalar function Op Date       */
286             OP_MDAY    =  68,         /* Scalar function Op Month Day  */
287             OP_MONTH   =  69,         /* Scalar function Op Month of   */
288             OP_YEAR    =  70,         /* Scalar function Op Year of    */
289             OP_WDAY    =  71,         /* Scalar function Op Week Day   */
290             OP_YDAY    =  72,         /* Scalar function Op Year Day   */
291             OP_DBTWN   =  73,         /* Scalar function Op Days betwn */
292             OP_MBTWN   =  74,         /* Scalar function Op Months btw */
293             OP_YBTWN   =  75,         /* Scalar function Op Years btwn */
294             OP_ADDAY   =  76,         /* Scalar function Op Add Days   */
295             OP_ADDMTH  =  77,         /* Scalar function Op Add Months */
296             OP_ADDYR   =  78,         /* Scalar function Op Add Years  */
297             OP_NXTDAY  =  79,         /* Scalar function Op Next Day   */
298             OP_SYSDT   =  80,         /* Scalar function Op SysDate    */
299             OP_DELTA   =  81,         /* Scalar function Op Delta      */
300             OP_LAST    =  82,         /* Scalar function Op Last       */
301             OP_IFF     =  83,         /* Scalar function Op Iff        */
302             OP_MAVG    =  84,         /* Scalar function Op Moving Avg */
303             OP_VWAP    =  85,         /* Scalar function Op VWAP       */
304             OP_TIME    =  86,         /* Scalar function Op TIME       */
305             OP_SETLEN  =  87,         /* Scalar function Op Set Length */
306             OP_TRANSL  =  88,         /* Scalar function Op Translate  */
307             OP_BITAND  =  89,         /* Expression BitAnd operator    */
308             OP_BITOR   =  90,         /* Expression BitOr  operator    */
309             OP_BITXOR  =  91,         /* Expression XOR    operator    */
310             OP_BITNOT  =  92,         /* Expression Complement operator*/
311             OP_CNTIN   =  93,         /* Scalar function Count In      */
312             OP_FDISK   =  94,         /* Scalar function Disk of fileid*/
313             OP_FPATH   =  95,         /* Scalar function Path of fileid*/
314             OP_FNAME   =  96,         /* Scalar function Name of fileid*/
315             OP_FTYPE   =  97,         /* Scalar function Type of fileid*/
316             OP_XDATE   =  98,         /* Scalar function Op Fmt Date   */
317             OP_SWITCH  =  99,         /* Scalar function Op Switch     */
318             OP_EXIT    = 100,         /* Scalar function Op Exit       */
319             OP_LIT     = 101,         /* Scalar function Op Literal    */
320             OP_LOCALE  = 102,         /* Scalar function Op Locale     */
321             OP_FRNCH   = 103,         /* Scalar function Op French     */
322             OP_ENGLSH  = 104,         /* Scalar function Op English    */
323             OP_RAND    = 105,         /* Scalar function Op Rand(om)   */
324             OP_FIRST   = 106,         /* Index operator Find First     */
325             OP_NEXT    = 107,         /* Index operator Find Next      */
326             OP_SAME    = 108,         /* Index operator Find Next Same */
327             OP_FSTDIF  = 109,         /* Index operator Find First dif */
328             OP_NXTDIF  = 110,         /* Index operator Find Next dif  */
329             OP_VAL     = 111,         /* Scalar function Op Valist     */
330             OP_QUART   = 112,         /* Scalar function Op QUARTER    */
331             OP_CURDT   = 113,         /* Scalar function Op CurDate    */
332             OP_NWEEK   = 114,         /* Scalar function Op Week number*/
333             OP_ROW     = 115,         /* Scalar function Op Row        */
334             OP_PREV    = 116,         /* Index operator Find Previous  */
335             OP_SYSTEM  = 200,         /* Scalar function Op System     */
336             OP_REMOVE  = 201,         /* Scalar function Op Remove     */
337             OP_RENAME  = 202,         /* Scalar function Op Rename     */
338             OP_FCOMP   = 203};        /* Scalar function Op Compare    */
339 #endif // 0
340 
341 enum TUSE {USE_NO      =   0,         /* Table is not yet linearized   */
342            USE_LIN     =   1,         /* Table is linearized           */
343            USE_READY   =   2,         /* Column buffers are allocated  */
344            USE_OPEN    =   3,         /* Table is open                 */
345            USE_CNT     =   4,         /* Specific to LNA               */
346            USE_NOKEY   =   5};        /* Specific to SqlToHql          */
347 
348 /***********************************************************************/
349 /*  Following definitions are used to indicate the status of a column. */
350 /***********************************************************************/
351 enum STATUS {BUF_NO      = 0x00,      /* Column buffer not allocated   */
352              BUF_EMPTY   = 0x01,      /* Column buffer is empty        */
353              BUF_READY   = 0x02,      /* Column buffer is ready        */
354              BUF_READ    = 0x04,      /* Column buffer has read value  */
355              BUF_MAPPED  = 0x08};     /* Used by the VMPFAM class      */
356 
357 /***********************************************************************/
358 /*  Following definitions are used to indicate how a column is used.   */
359 /*  Corresponding bits are ON if the column is used in:                */
360 /***********************************************************************/
361 enum COLUSE {U_P         = 0x01,      /* the projection list.          */
362              U_J_EXT     = 0x02,      /* a join filter.                */
363              U_J_INT     = 0x04,      /* a join after linearisation.   */
364 /*-- Such a column have a constant value throughout a subquery eval. --*/
365              U_CORREL    = 0x08,      /* a correlated sub-query        */
366 /*-------------------- additional values used by CONNECT --------------*/
367              U_VAR       = 0x10,      /* a VARCHAR column              */
368              U_VIRTUAL   = 0x20,      /* a VIRTUAL column              */
369              U_NULLS     = 0x40,      /* The column may have nulls     */
370              U_IS_NULL   = 0x80,      /* The column has a null value   */
371              U_SPECIAL   = 0x100,     /* The column is special         */
372              U_UNSIGNED  = 0x200,     /* The column type is unsigned   */
373              U_ZEROFILL  = 0x400,     /* The column is zero filled     */
374 						 U_UUID      = 0x800};    /* The column is a UUID          */
375 
376 /***********************************************************************/
377 /*  DB description class and block pointer definitions.                */
378 /***********************************************************************/
379 typedef class XTAB       *PTABLE;
380 typedef class COLUMN     *PCOLUMN;
381 typedef class XOBJECT    *PXOB;
382 typedef class COLBLK     *PCOL;
383 typedef class TDB        *PTDB;
384 typedef class TDBASE     *PTDBASE;
385 typedef class TDBEXT     *PTDBEXT;
386 typedef class TDBDOS     *PTDBDOS;
387 typedef class TDBFIX     *PTDBFIX;
388 typedef class TDBFMT     *PTDBFMT;
389 typedef class TDBCSV     *PTDBCSV;
390 typedef class TDBDOM     *PTDBDOM;
391 typedef class TDBDIR     *PTDBDIR;
392 typedef class DOSCOL     *PDOSCOL;
393 typedef class CSVCOL     *PCSVCOL;
394 typedef class MAPCOL     *PMAPCOL;
395 typedef class TDBMFT     *PTDBMFT;
396 typedef class TDBMCV     *PTDBMCV;
397 typedef class MCVCOL     *PMCVCOL;
398 typedef class RESCOL     *PRESCOL;
399 typedef class XXBASE     *PKXBASE;
400 typedef class KXYCOL     *PXCOL;
401 typedef class CATALOG    *PCATLG;
402 typedef class RELDEF     *PRELDEF;
403 typedef class TABDEF     *PTABDEF;
404 typedef class EXTDEF     *PEXTBDEF;
405 typedef class DOSDEF     *PDOSDEF;
406 typedef class CSVDEF     *PCSVDEF;
407 typedef class VCTDEF     *PVCTDEF;
408 typedef class PIVOTDEF   *PPIVOTDEF;
409 typedef class DOMDEF     *PDOMDEF;
410 typedef class DIRDEF     *PDIRDEF;
411 typedef class RESTDEF    *PRESTDEF;
412 typedef class OEMDEF     *POEMDEF;
413 typedef class COLCRT     *PCOLCRT;
414 typedef class COLDEF     *PCOLDEF;
415 typedef class CONSTANT   *PCONST;
416 typedef class VALUE      *PVAL;
417 typedef class VALBLK     *PVBLK;
418 typedef class FILTER     *PFIL;
419 
420 typedef struct _fblock   *PFBLOCK;
421 typedef struct _mblock   *PMBLOCK;
422 typedef struct _cblock   *PCBLOCK;
423 typedef struct _tabs     *PTABS;
424 typedef struct _qryres   *PQRYRES;
425 typedef struct _colres   *PCOLRES;
426 typedef struct _datpar   *PDTP;
427 typedef struct indx_used *PXUSED;
428 typedef struct ha_table_option_struct TOS, *PTOS;
429 
430 /***********************************************************************/
431 /*  Utility blocks for file and storage.                               */
432 /***********************************************************************/
433 typedef struct _fblock {               /* Opened (mapped) file block   */
434   struct _fblock *Next;
435   LPCSTR     Fname;                    /* Point on file name           */
436   size_t     Length;                   /* File length  (<4GB)          */
437   short      Count;                    /* Nb of times map is used      */
438   short      Type;                     /* TYPE_FB_FILE or TYPE_FB_MAP  */
439   MODE       Mode;                     /* Open mode                    */
440   char      *Memory;                   /* Pointer to file mapping view */
441   void      *File;                     /* FILE pointer                 */
442   HANDLE     Handle;                   /* File handle                  */
443   } FBLOCK;
444 
445 typedef struct _mblock {               /* Memory block                 */
446   PMBLOCK Next;
447   bool    Inlist;                      /* True if in mblock list       */
448   size_t  Size;                        /* Size of allocation           */
449   bool    Sub;                         /* True if suballocated         */
450   void   *Memp;                        /* Memory pointer               */
451   } MBLOCK;
452 
453 /***********************************************************************/
454 /*  The QUERY application User Block.                                  */
455 /***********************************************************************/
456 typedef struct {                       /* User application block       */
457   NAME       Name;                     /* User application name        */
458   char       Server[17];               /* Server name                  */
459   char       DBName[17];               /* Current database name        */
460   PCATLG     Catalog;                  /* To CATALOG class             */
461   PQRYRES    Result;                   /* To query result blocks       */
462   PFBLOCK    Openlist;                 /* To file/map open list        */
463   PMBLOCK    Memlist;                  /* To memory block list         */
464   PXUSED     Xlist;                    /* To used index list           */
465   int        Maxbmp;                   /* Maximum XDB2 bitmap size     */
466   int        Check;                    /* General level of checking    */
467   int        Numlines;                 /* Number of lines involved     */
468 //USETEMP    UseTemp;                  /* Use temporary file           */
469   int        Vtdbno;                   /* Used for TDB number setting  */
470   bool       Remote;                   /* true: if remotely called     */
471   bool       Proginfo;                 /* true: return progress info   */
472   bool       Subcor;                   /* Used for Progress info       */
473   size_t     ProgMax;                  /* Used for Progress info       */
474   size_t     ProgCur;                  /* Used for Progress info       */
475   size_t     ProgSav;                  /* Used for Progress info       */
476   LPCSTR     Step;                     /* Execution step name          */
477   } DBUSERBLK, *PDBUSER;
478 
479 /***********************************************************************/
480 /*  Column output format.                                              */
481 /***********************************************************************/
482 typedef struct _format {  /* Format descriptor block                   */
483   char   Type[2];         /* C:char, F:double, N:int, Dx: date         */
484   ushort Length;          /* Output length                             */
485   short  Prec;            /* Output precision                          */
486   } FORMAT, *PFORMAT;
487 
488 /***********************************************************************/
489 /*  Definition of blocks used in type and copy routines.               */
490 /***********************************************************************/
491 typedef struct _tabptr {                                   /* start=P1 */
492   struct _tabptr *Next;
493   int   Num;                                             /* alignement */
494   void *Old[50];
495   void *New[50];                  /* old and new values of copied ptrs */
496   } TABPTR, *PTABPTR;
497 
498 typedef struct _tabadr {                                   /* start=P3 */
499   struct _tabadr *Next;
500   int   Num;
501   void *Adx[50];                       /* addr of pointers to be reset */
502   } TABADR, *PTABADR;
503 
504 typedef struct _tabs {
505   PGLOBAL G;
506   PTABPTR P1;
507   PTABADR P3;
508   } TABS;
509 
510 /***********************************************************************/
511 /*  Argument of expression, function, filter etc. (Xobject)            */
512 /***********************************************************************/
513 typedef struct _arg {              /* Argument                         */
514   PXOB    To_Obj;                  /* To the argument object           */
515   PVAL    Value;                   /* Argument value                   */
516   bool    Conv;                    /* TRUE if conversion is required   */
517   } ARGBLK, *PARG;
518 
519 typedef struct _oper {             /* Operator                         */
520   PSZ     Name;                    /* The input/output operator name   */
521   OPVAL   Val;                     /* Operator numeric value           */
522   int     Mod;                     /* The modificator                  */
523   } OPER, *POPER;
524 
525 /***********************************************************************/
526 /*  Following definitions are used to define table fields (columns).   */
527 /***********************************************************************/
528 enum XFLD {FLD_NO       =  0,         /* Not a field definition item   */
529            FLD_NAME     =  1,         /* Item name                     */
530            FLD_TYPE     =  2,         /* Field type                    */
531            FLD_TYPENAME =  3,         /* Field type name               */
532            FLD_PREC     =  4,         /* Field precision (length?)     */
533            FLD_LENGTH   =  5,         /* Field length (?)              */
534            FLD_SCALE    =  6,         /* Field scale (precision)       */
535            FLD_RADIX    =  7,         /* Field radix                   */
536            FLD_NULL     =  8,         /* Field nullable property       */
537            FLD_REM      =  9,         /* Field comment (remark)        */
538            FLD_CHARSET  = 10,         /* Field collation               */
539            FLD_KEY      = 11,         /* Field key property            */
540            FLD_DEFAULT  = 12,         /* Field default value           */
541            FLD_EXTRA    = 13,         /* Field extra info              */
542            FLD_PRIV     = 14,         /* Field priviledges             */
543            FLD_DATEFMT  = 15,         /* Field date format             */
544            FLD_FORMAT   = 16,         /* Field format                  */
545            FLD_CAT      = 17,         /* Table catalog                 */
546            FLD_SCHEM    = 18,         /* Table schema                  */
547            FLD_TABNAME  = 19,         /* Column Table name             */
548 					 FLD_FLAG     = 20};        /* Field flag (CONNECT specific) */
549 
550 /***********************************************************************/
551 /*  Result of last SQL noconv query.                                   */
552 /***********************************************************************/
553 typedef  struct _qryres {
554   PCOLRES Colresp;                 /* Points to columns of result      */
555   bool    Continued;               /* true when more rows to fetch     */
556   bool    Truncated;               /* true when truncated by maxres    */
557   bool    Suball;                  /* true when entirely suballocated  */
558   bool    Info;                    /* true when info msg generated     */
559   int     Maxsize;                 /* Max query number of lines        */
560   int     Maxres;                  /* Allocation size                  */
561   int     Nblin;                   /* Number of rows in result set     */
562   int     Nbcol;                   /* Number of columns in result set  */
563   int     Cursor;                  /* Starting position to get data    */
564   int     BadLines;                /* Skipped bad lines in table file  */
565   } QRYRES, *PQRYRES;
566 
567 typedef  struct _colres {
568   PCOLRES Next;                    /* To next result column            */
569   PCOL    Colp;                    /* To matching column block         */
570   PCSZ    Name;                    /* Column header                    */
571   PVBLK   Kdata;                   /* Column block of values           */
572   char   *Nulls;                   /* Column null value array          */
573   int     Type;                    /* Internal type                    */
574   int     Datasize;                /* Overall data size                */
575   int     Ncol;                    /* Column number                    */
576   int     Clen;                    /* Data individual internal size    */
577   int     Length;                  /* Data individual print length     */
578   int     Prec;                    /* Precision                        */
579   int     Flag;                    /* Flag option value                */
580   XFLD    Fld;                     /* Type of field info               */
581   char    Var;                     /* Type added information           */
582   } COLRES;
583 
584 #if defined(_WIN32) && !defined(NOEX)
585 #define DllExport  __declspec( dllexport )
586 #else   // !_WIN32
587 #define DllExport
588 #endif  // !_WIN32
589 
590 /***********************************************************************/
591 /*  Utility routines.                                                  */
592 /***********************************************************************/
593 PPARM    Vcolist(PGLOBAL, PTDB, PSZ, bool);
594 void     PlugPutOut(PGLOBAL, FILE *, short, void *, uint);
595 void     PlugLineDB(PGLOBAL, PSZ, short, void *, uint);
596 //ar    *PlgGetDataPath(PGLOBAL g);
597 char    *SetPath(PGLOBAL g, const char *path);
598 char    *ExtractFromPath(PGLOBAL, char *, char *, OPVAL);
599 void     AddPointer(PTABS, void *);
600 PDTP     MakeDateFormat(PGLOBAL, PCSZ, bool, bool, int);
601 int      ExtractDate(char *, PDTP, int, int val[6]);
602 
603 /**************************************************************************/
604 /*  Allocate the result structure that will contain result data.          */
605 /**************************************************************************/
606 DllExport PQRYRES PlgAllocResult(PGLOBAL g, int ncol, int maxres, int ids,
607                                  int *buftyp, XFLD *fldtyp,
608                                  unsigned int *length,
609                                  bool blank, bool nonull);
610 
611 /***********************************************************************/
612 /*  Exported utility routines.                                         */
613 /***********************************************************************/
614 DllExport FILE   *PlugOpenFile(PGLOBAL, LPCSTR, LPCSTR);
615 DllExport FILE   *PlugReopenFile(PGLOBAL, PFBLOCK, LPCSTR);
616 DllExport int     PlugCloseFile(PGLOBAL, PFBLOCK, bool all = false);
617 DllExport void    PlugCleanup(PGLOBAL, bool);
618 DllExport bool    GetPromptAnswer(PGLOBAL, char *);
619 DllExport char   *GetAmName(PGLOBAL g, AMT am, void *memp = NULL);
620 DllExport PDBUSER PlgMakeUser(PGLOBAL g);
621 DllExport PDBUSER PlgGetUser(PGLOBAL g);
622 DllExport PCATLG  PlgGetCatalog(PGLOBAL g, bool jump = true);
623 DllExport bool    PlgSetXdbPath(PGLOBAL g, PSZ, PSZ, char *, int, char *, int);
624 DllExport void    PlgDBfree(MBLOCK&);
625 DllExport void   *PlgDBSubAlloc(PGLOBAL g, void *memp, size_t size);
626 DllExport char   *PlgDBDup(PGLOBAL g, const char *str);
627 DllExport void   *PlgDBalloc(PGLOBAL, void *, MBLOCK&);
628 DllExport void   *PlgDBrealloc(PGLOBAL, void *, MBLOCK&, size_t);
629 DllExport void    NewPointer(PTABS, void *, void *);
630 //lExport char   *GetIni(int n= 0);    // Not used anymore
631 DllExport void    SetTrc(void);
632 DllExport PCSZ    GetListOption(PGLOBAL, PCSZ, PCSZ, PCSZ def=NULL);
633 DllExport PCSZ    GetStringTableOption(PGLOBAL, PTOS, PCSZ, PCSZ);
634 DllExport bool    GetBooleanTableOption(PGLOBAL, PTOS, PCSZ, bool);
635 DllExport int     GetIntegerTableOption(PGLOBAL, PTOS, PCSZ, int);
636 
637 #define MSGID_NONE                         0
638 #define MSGID_CANNOT_OPEN                  1
639 #define MSGID_OPEN_MODE_ERROR              2
640 #define MSGID_OPEN_STRERROR                3
641 #define MSGID_OPEN_ERROR_AND_STRERROR      4
642 #define MSGID_OPEN_MODE_STRERROR           5
643 #define MSGID_OPEN_EMPTY_FILE              6
644 
645 FILE *global_fopen(GLOBAL *g, int msgid, const char *path, const char *mode);
646 int global_open(GLOBAL *g, int msgid, const char *filename, int flags);
647 int global_open(GLOBAL *g, int msgid, const char *filename, int flags, int mode);
648 DllExport LPCSTR PlugSetPath(LPSTR to, LPCSTR name, LPCSTR dir);
649 char *MakeEscape(PGLOBAL g, char* str, char q);
650 
651 DllExport bool PushWarning(PGLOBAL, PTDB, int level = 1);
652