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