1/*************** TabTbl H Declares Source Code File (.H) ***************/
2/* Name: TABTBL.H Version 1.3 */
3/* */
4/* (C) Copyright to the author Olivier BERTRAND 2008-2013 */
5/* */
6/* This file contains the TDBTBL classes declares. */
7/***********************************************************************/
8#include "block.h"
9#include "colblk.h"
10#include "tabutil.h"
11
12typedef class TBLDEF *PTBLDEF;
13typedef class TDBTBL *PTDBTBL;
14typedef class MYSQLC *PMYC;
15
16/***********************************************************************/
17/* TBL table. */
18/***********************************************************************/
19class DllExport TBLDEF : public PRXDEF { /* Logical table description */
20 friend class TDBTBL;
21 friend class TDBTBC;
22 public:
23 // Constructor
24 TBLDEF(void);
25
26 // Implementation
27 virtual const char *GetType(void) {return "TBL";}
28
29 // Methods
30 virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
31 virtual PTDB GetTable(PGLOBAL g, MODE m);
32
33 protected:
34 // Members
35 bool Accept; /* TRUE if bad tables are accepted */
36 bool Thread; /* Use thread for remote tables */
37 int Maxerr; /* Maximum number of bad tables */
38 int Ntables; /* Number of tables */
39 }; // end of TBLDEF
40
41/***********************************************************************/
42/* This is the TBL Access Method class declaration. */
43/***********************************************************************/
44class DllExport TDBTBL : public TDBPRX {
45 friend class TBTBLK;
46 public:
47 // Constructor
48 TDBTBL(PTBLDEF tdp = NULL);
49
50 // Implementation
51 virtual AMT GetAmType(void) {return TYPE_AM_TBL;}
52
53 // Methods
54 virtual void ResetDB(void);
55 virtual int GetRecpos(void) {return Rows;}
56 virtual int GetBadLines(void) {return (int)Nbc;}
57
58 // Database routines
59 virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
60 virtual int Cardinality(PGLOBAL g);
61 virtual int GetMaxSize(PGLOBAL g);
62 virtual int RowNumber(PGLOBAL g, bool b = FALSE);
63 virtual PCOL InsertSpecialColumn(PCOL scp);
64 virtual bool OpenDB(PGLOBAL g);
65 virtual int ReadDB(PGLOBAL g);
66
67 protected:
68 // Internal functions
69 bool InitTableList(PGLOBAL g);
70 bool TestFil(PGLOBAL g, PCFIL filp, PTABLE tabp);
71
72 // Members
73 PTABLE Tablist; // Points to the table list
74 PTABLE CurTable; // Points to the current table
75 bool Accept; // TRUE if bad tables are accepted
76 int Maxerr; // Maximum number of bad tables
77 int Nbc; // Number of bad connections
78 int Rows; // Used for RowID
79 int Crp; // Used for CurPos
80 }; // end of class TDBTBL
81
82/***********************************************************************/
83/* Class TBTBLK: TDBPLG TABID special column descriptor. */
84/***********************************************************************/
85class TBTBLK : public TIDBLK {
86 public:
87 // The constructor must restore Value because XOBJECT has a void
88 // constructor called by default that set Value to NULL
89 TBTBLK(PVAL valp) {Value = valp;}
90
91 // Methods
92 virtual void ReadColumn(PGLOBAL g);
93
94 // Fake operator new used to change TIDBLK into SDTBLK
95 void * operator new(size_t size, TIDBLK *sp) {return sp;}
96
97#if !defined(__BORLANDC__)
98 // Avoid warning C4291 by defining a matching dummy delete operator
99 void operator delete(void *, TIDBLK*) {}
100 void operator delete(void *, size_t size) {}
101#endif
102
103 protected:
104 // Must not have additional members
105}; // end of class TBTBLK
106
107#if defined(DEVELOPMENT)
108/***********************************************************************/
109/* This table type is buggy and removed until a fix is found. */
110/***********************************************************************/
111typedef class TDBTBM *PTDBTBM;
112
113/***********************************************************************/
114/* Defines the structures used for distributed TBM tables. */
115/***********************************************************************/
116typedef struct _TBMtable *PTBMT;
117
118typedef struct _TBMtable {
119 PTBMT Next; // Points to next data table struct
120 PTABLE Tap; // Points to the sub table
121 PGLOBAL G; // Needed in thread routine
122 bool Complete; // TRUE when all results are read
123 bool Ready; // TRUE when results are there
124 int Rows; // Total number of rows read so far
125 int ProgCur; // Current pos
126 int ProgMax; // Max pos
127 int Rc; // Return code
128 THD *Thd;
129 pthread_attr_t attr; // ???
130 pthread_t Tid; // CheckOpen thread ID
131} TBMT;
132
133/***********************************************************************/
134/* This is the TBM Access Method class declaration. */
135/***********************************************************************/
136class DllExport TDBTBM : public TDBTBL {
137 friend class TBTBLK;
138 public:
139 // Constructor
140 TDBTBM(PTBLDEF tdp = NULL);
141
142 // Methods
143 virtual void ResetDB(void);
144
145 // Database routines
146 virtual int Cardinality(PGLOBAL g) { return 10; }
147 virtual int GetMaxSize(PGLOBAL g) { return 10; } // Temporary
148 virtual int RowNumber(PGLOBAL g, bool b = FALSE);
149 virtual bool OpenDB(PGLOBAL g);
150 virtual int ReadDB(PGLOBAL g);
151
152 protected:
153 // Internal functions
154 bool IsLocal(PTABLE tbp);
155 bool OpenTables(PGLOBAL g);
156 int ReadNextRemote(PGLOBAL g);
157
158 // Members
159 PTBMT Tmp; // To data table TBMT structures
160 PTBMT Cmp; // Current data table PLGF (to move to TDBTBL)
161 PTBMT Bmp; // To bad (unconnected) PLGF structures
162 bool Done; // TRUE after first GetAllResults
163 int Nrc; // Number of remote connections
164 int Nlc; // Number of local connections
165 }; // end of class TDBTBM
166
167pthread_handler_t ThreadOpen(void *p);
168#endif // DEVELOPMENT
169