1 /*************** RelDef H Declares Source Code File (.H) ***************/
2 /*  Name: RELDEF.H  Version 1.6                                        */
3 /*                                                                     */
4 /*  (C) Copyright to the author Olivier BERTRAND          2004-2016    */
5 /*                                                                     */
6 /*  This file contains the DEF classes definitions.                    */
7 /***********************************************************************/
8 
9 #ifndef __RELDEF_H
10 #define __RELDEF_H
11 
12 #include "block.h"
13 #include "catalog.h"
14 //#include "my_sys.h"
15 #include "mycat.h"
16 
17 typedef class  INDEXDEF *PIXDEF;
18 typedef class  ha_connect *PHC;
19 
20 /***********************************************************************/
21 /*  Table or View (relation) definition block.                         */
22 /***********************************************************************/
23 class DllExport RELDEF : public BLOCK {      // Relation definition block
24   friend class CATALOG;
25   friend class PLUGCAT;
26   friend class MYCAT;
27  public:
28   RELDEF(void);                        // Constructor
29 
30   // Implementation
GetNext(void)31   PRELDEF GetNext(void) {return Next;}
GetName(void)32   PSZ     GetName(void) {return Name;}
GetDB(void)33   PSZ     GetDB(void) {return (PSZ)Database;}
GetCols(void)34   PCOLDEF GetCols(void) {return To_Cols;}
GetHandler(void)35   PHC     GetHandler(void) {return Hc;}
SetCols(PCOLDEF pcd)36   void    SetCols(PCOLDEF pcd) {To_Cols = pcd;}
GetCat(void)37   PCATLG  GetCat(void) {return Cat;}
38   virtual const char *GetType(void) = 0;
39   virtual AMT  GetDefType(void) = 0;
SetName(const char * str)40   void    SetName(const char *str) { Name=(char*)str; }
SetCat(PCATLG cat)41   void    SetCat(PCATLG cat) { Cat=cat; }
42 
43   // Methods
44   PTOS    GetTopt(void);
45   bool    GetBoolCatInfo(PCSZ what, bool bdef);
46   bool    SetIntCatInfo(PCSZ what, int ival);
47   bool    Partitioned(void);
48   int     GetIntCatInfo(PCSZ what, int idef);
49   int     GetSizeCatInfo(PCSZ what, PCSZ sdef);
50   int     GetCharCatInfo(PCSZ what, PCSZ sdef, char *buf, int size);
51   char   *GetStringCatInfo(PGLOBAL g, PCSZ what, PCSZ sdef);
Indexable(void)52   virtual int  Indexable(void) {return 0;}
53   virtual bool Define(PGLOBAL g, PCATLG cat,
54 		                  LPCSTR name, LPCSTR schema, LPCSTR am) = 0;
55   virtual PTDB GetTable(PGLOBAL g, MODE mode) = 0;
56 
57  protected:
58   PRELDEF Next;                        /* To next definition block     */
59   PSZ     Name;                        /* Name of the view             */
60   LPCSTR  Database;                    /* Table database               */
61   PCOLDEF To_Cols;                     /* To a list of column desc     */
62   PCATLG  Cat;                         /* To DB catalog info           */
63   PHC     Hc;                          /* The Connect handler          */
64   }; // end of RELDEF
65 
66 /***********************************************************************/
67 /*  This class corresponds to the data base description for tables     */
68 /*  of type DOS, FIX, CSV, DBF, BIN, VCT, JSON, XML...                 */
69 /***********************************************************************/
70 class DllExport TABDEF : public RELDEF {   /* Logical table descriptor */
71   friend class CATALOG;
72   friend class PLUGCAT;
73   friend class MYCAT;
74   friend class TDB;
75 	friend class TDBEXT;
76 public:
77   // Constructor
78   TABDEF(void);                  // Constructor
79 
80   // Implementation
GetDegree(void)81   int     GetDegree(void) {return Degree;}
SetDegree(int d)82   void    SetDegree(int d) {Degree = d;}
GetElemt(void)83   int     GetElemt(void) {return Elemt;}
SetNext(PTABDEF tdfp)84   void    SetNext(PTABDEF tdfp) {Next = tdfp;}
GetMultiple(void)85   int     GetMultiple(void) {return Multiple;}
GetPseudo(void)86   int     GetPseudo(void) {return Pseudo;}
GetRecfm(void)87 	RECFM   GetRecfm(void) {return Recfm;}
88 	PCSZ    GetPath(void);
89 //PSZ     GetPath(void)
90 //          {return (Database) ? (PSZ)Database : Cat->GetDataPath();}
91 	RECFM   GetTableFormat(const char* type);
SepIndex(void)92 	bool    SepIndex(void) {return GetBoolCatInfo("SepIndex", false);}
IsReadOnly(void)93   bool    IsReadOnly(void) {return Read_Only;}
GetDefType(void)94   virtual AMT    GetDefType(void) {return TYPE_AM_TAB;}
GetIndx(void)95   virtual PIXDEF GetIndx(void) {return NULL;}
SetIndx(PIXDEF)96   virtual void   SetIndx(PIXDEF) {}
IsHuge(void)97   virtual bool   IsHuge(void) {return false;}
data_charset()98   const CHARSET_INFO *data_charset() {return m_data_charset;}
GetCsName(void)99 	const   char  *GetCsName(void) {return csname;}
100 
101   // Methods
102           int  GetColCatInfo(PGLOBAL g);
103           void SetIndexInfo(void);
104           bool DropTable(PGLOBAL g, PSZ name);
105 	virtual bool Define(PGLOBAL g, PCATLG cat,
106 						          LPCSTR name, LPCSTR schema, LPCSTR am);
107 	virtual bool DefineAM(PGLOBAL, LPCSTR, int) = 0;
108 
109  protected:
110   // Members
111   PCSZ    Schema;               /* Table schema (for ODBC)             */
112   PCSZ    Desc;                 /* Table description                   */
113 	RECFM   Recfm;                /* File or table format                */
114 	uint    Catfunc;              /* Catalog function ID                 */
115   int     Card;                 /* (max) number of rows in table       */
116   int     Elemt;                /* Number of rows in blocks or rowset  */
117   int     Sort;                 /* Table already sorted ???            */
118   int     Multiple;             /* 0: No 1: DIR 2: Section 3: filelist */
119   int     Degree;               /* Number of columns in the table      */
120   int     Pseudo;               /* Bit: 1 ROWID }Ok, 2 FILEID Ok       */
121   bool    Read_Only;            /* true for read only tables           */
122   const CHARSET_INFO *m_data_charset;
123   const char *csname;           /* Table charset name                  */
124 }; // end of TABDEF
125 
126 /***********************************************************************/
127 /*  Externally defined OEM tables.                                     */
128 /***********************************************************************/
129 class DllExport OEMDEF : public TABDEF {                  /* OEM table */
130   friend class CATALOG;
131   friend class PLUGCAT;
132   friend class MYCAT;
133  public:
134   // Constructor
OEMDEF(void)135   OEMDEF(void) {Hdll = NULL; Pxdef = NULL; Module = Subtype = NULL;}
136 
137   // Implementation
GetType(void)138   virtual const char *GetType(void) {return "OEM";}
GetDefType(void)139   virtual AMT  GetDefType(void) {return TYPE_AM_OEM;}
140 
141   // Methods
142   virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
143   virtual PTDB GetTable(PGLOBAL g, MODE mode);
144 
145  protected:
146   PTABDEF GetXdef(PGLOBAL g);
147 
148   // Members
149 #if defined(_WIN32)
150   HANDLE  Hdll;               /* Handle to the external DLL            */
151 #else   // !_WIN32
152   void   *Hdll;               /* Handle for the loaded shared library  */
153 #endif  // !_WIN32
154   PTABDEF Pxdef;              /* Pointer to the external TABDEF class  */
155   char   *Module;             /* Path/Name of the DLL implenting it    */
156   char   *Subtype;            /* The name of the OEM table sub type    */
157   }; // end of OEMDEF
158 
159 /***********************************************************************/
160 /*  Column definition block used during creation.                      */
161 /***********************************************************************/
162 class DllExport COLCRT : public BLOCK { /* Column description block              */
163   friend class TABDEF;
164  public:
165   COLCRT(PSZ name);           // Constructor
166   COLCRT(void);               // Constructor (for views)
167 
168   // Implementation
GetName(void)169   PSZ  GetName(void) {return Name;}
GetDecode(void)170   PSZ  GetDecode(void) {return Decode;}
GetFmt(void)171   PSZ  GetFmt(void) {return Fmt;}
GetOpt(void)172   int  GetOpt(void) {return Opt;}
GetFreq(void)173   int  GetFreq(void) {return Freq;}
GetLong(void)174   int  GetLong(void) {return Long;}
GetPrecision(void)175   int  GetPrecision(void) {return Precision;}
GetOffset(void)176   int  GetOffset(void) {return Offset;}
SetOffset(int offset)177   void SetOffset(int offset) {Offset = offset;}
178 
179  protected:
180   PCOLCRT Next;               /* To next block                         */
181   PSZ     Name;               /* Column name                           */
182   PSZ     Desc;               /* Column description                    */
183   PSZ     Decode;             /* Date format                           */
184   PSZ     Fmt;                /* Input format for formatted files      */
185   int     Offset;             /* Offset of field within record         */
186   int     Long;               /* Length of field in file record (!BIN) */
187   int     Key;                /* Key (greater than 1 if multiple)      */
188   int     Precision;          /* Logical column length                 */
189   int     Scale;              /* Decimals for float/decimal values     */
190   int     Opt;                /* 0:Not 1:clustered 2:sorted-asc 3:desc */
191   int     Freq;               /* Estimated number of different values  */
192   char    DataType;           /* Internal data type (C, N, F, T)       */
193   }; // end of COLCRT
194 
195 /***********************************************************************/
196 /*  Column definition block.                                           */
197 /***********************************************************************/
198 class DllExport COLDEF : public COLCRT { /* Column description block   */
199   friend class TABDEF;
200   friend class COLBLK;
201   friend class DBFFAM;
202 	friend class TDB;
203 	friend class TDBASE;
204 	friend class TDBDOS;
205 public:
206   COLDEF(void);                // Constructor
207 
208   // Implementation
GetNext(void)209   PCOLDEF GetNext(void) {return (PCOLDEF)Next;}
SetNext(PCOLDEF pcdf)210   void    SetNext(PCOLDEF pcdf) {Next = pcdf;}
GetLength(void)211   int     GetLength(void) {return (int)F.Length;}
GetClen(void)212   int     GetClen(void) {return Clen;}
GetType(void)213   int     GetType(void) {return Buf_Type;}
GetPoff(void)214   int     GetPoff(void) {return Poff;}
GetMin(void)215   void   *GetMin(void) {return To_Min;}
SetMin(void * minp)216   void    SetMin(void *minp) {To_Min = minp;}
GetMax(void)217   void   *GetMax(void) {return To_Max;}
SetMax(void * maxp)218   void    SetMax(void *maxp) {To_Max = maxp;}
GetXdb2(void)219   bool    GetXdb2(void) {return Xdb2;}
SetXdb2(bool b)220   void    SetXdb2(bool b) {Xdb2 = b;}
GetBmap(void)221   void   *GetBmap(void) {return To_Bmap;}
SetBmap(void * bmp)222   void    SetBmap(void *bmp) {To_Bmap = bmp;}
GetDval(void)223   void   *GetDval(void) {return To_Dval;}
SetDval(void * dvp)224   void    SetDval(void *dvp) {To_Dval = dvp;}
GetNdv(void)225   int     GetNdv(void) {return Ndv;}
SetNdv(int ndv)226   void    SetNdv(int ndv) {Ndv = ndv;}
GetNbm(void)227   int     GetNbm(void) {return Nbm;}
SetNbm(int nbm)228   void    SetNbm(int nbm) {Nbm = nbm;}
229   int     Define(PGLOBAL g, void *memp, PCOLINFO cfp, int poff);
230   void    Define(PGLOBAL g, PCOL colp);
IsSpecial(void)231   bool    IsSpecial(void) {return (Flags & U_SPECIAL) ? true : false;}
IsVirtual(void)232   bool    IsVirtual(void) {return (Flags & U_VIRTUAL) ? true : false;}
233 
234  protected:
235   void   *To_Min;              /* Point to array of block min values   */
236   void   *To_Max;              /* Point to array of block max values   */
237   int    *To_Pos;              /* Point to array of block positions    */
238   bool    Xdb2;                /* TRUE if to be optimized by XDB2      */
239   void   *To_Bmap;             /* To array of block bitmap values      */
240   void   *To_Dval;             /* To array of column distinct values   */
241   int     Ndv;                 /* Number of distinct values            */
242   int     Nbm;                 /* Number of ULONG in bitmap (XDB2)     */
243   int     Buf_Type;            /* Internal data type                   */
244   int     Clen;                /* Internal data size in chars (bytes)  */
245   int     Poff;                /* Calculated offset for Packed tables  */
246   FORMAT  F;                   /* Output format (should be in COLCRT)  */
247   ushort  Flags;               /* Used by MariaDB CONNECT handler      */
248   }; // end of COLDEF
249 
250 #endif // __RELDEF_H
251 
252