summaryrefslogtreecommitdiff
path: root/storage/connect/tabodbc.h
blob: 70edd337c8c7b37e4dfe1bd3e8d55ef55dd5ad0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*************** Tabodbc H Declares Source Code File (.H) **************/
/*  Name: TABODBC.H   Version 1.5                                      */
/*                                                                     */
/*  (C) Copyright to the author Olivier BERTRAND          2000-2013    */
/*                                                                     */
/*  This file contains the TDBODBC classes declares.                   */
/***********************************************************************/
#include "colblk.h"

typedef class ODBCDEF *PODEF;
typedef class TDBODBC *PTDBODBC;
typedef class ODBCCOL *PODBCCOL;
typedef class TDBOIF  *PTDBOIF;
typedef class OIFCOL  *POIFCOL;

/***********************************************************************/
/*  ODBC table.                                                        */
/***********************************************************************/
class DllExport ODBCDEF : public TABDEF { /* Logical table description */
 public:
  // Constructor
  ODBCDEF(void);

  // Implementation
  virtual const char *GetType(void) {return "ODBC";}
  PSZ  GetConnect(void) {return Connect;}
  PSZ  GetTabname(void) {return Tabname;}
  PSZ  GetTabowner(void) {return Tabowner;}
  PSZ  GetTabqual(void) {return Tabqual;}
  PSZ  GetQchar(void) {return (Qchar && *Qchar) ? Qchar : NULL;} 
  int  GetCatver(void) {return Catver;}
  int  GetOptions(void) {return Options;}

  // Methods
  virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
  virtual PTDB GetTable(PGLOBAL g, MODE m);

 protected:
  // Members
  PSZ     Connect;            /* ODBC connection string                */
  PSZ     Tabname;            /* External table name                   */
  PSZ     Tabowner;           /* External table owner                  */
  PSZ     Tabqual;            /* External table qualifier              */
  PSZ     Qchar;              /* Identifier quoting character          */
  int     Catver;             /* ODBC version for catalog functions    */
  int     Options;            /* Open connection options               */
  bool    Info;               /* true if getting data sources          */
  }; // end of ODBCDEF

#if !defined(NODBC)
#include "odbconn.h"

/***********************************************************************/
/*  This is the ODBC Access Method class declaration for files from    */
/*  other DB drivers to be accessed via ODBC.                          */
/***********************************************************************/
class TDBODBC : public TDBASE {
  friend class ODBCCOL;
  friend class ODBConn;
 public:
  // Constructor
  TDBODBC(PODEF tdp = NULL);
  TDBODBC(PTDBODBC tdbp);

  // Implementation
  virtual AMT  GetAmType(void) {return TYPE_AM_ODBC;}
  virtual PTDB Duplicate(PGLOBAL g)
                {return (PTDB)new(g) TDBODBC(this);}

  // Methods
  virtual PTDB CopyOne(PTABS t);
  virtual int  GetRecpos(void);
  virtual PSZ   GetFile(PGLOBAL g);
  virtual void SetFile(PGLOBAL g, PSZ fn);
  virtual void ResetSize(void);
  virtual int  GetAffectedRows(void) {return AftRows;}

  // Database routines
  virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
  virtual int  GetProgMax(PGLOBAL g);
  virtual int  GetMaxSize(PGLOBAL g);
  virtual bool OpenDB(PGLOBAL g);
  virtual int  ReadDB(PGLOBAL g);
  virtual int  WriteDB(PGLOBAL g);
  virtual int  DeleteDB(PGLOBAL g, int irc);
  virtual void CloseDB(PGLOBAL g);

 protected:
  // Internal functions
  int Decode(char *utf, char *buf, size_t n);
  char *MakeSQL(PGLOBAL g, bool cnt);
//bool  MakeUpdate(PGLOBAL g, PSELECT selist);
//bool  MakeInsert(PGLOBAL g);
//bool  MakeDelete(PGLOBAL g);
//bool  MakeFilter(PGLOBAL g, bool c);
//bool  BindParameters(PGLOBAL g);

  // Members
  ODBConn *Ocp;               // Points to an ODBC connection class
  ODBCCOL *Cnp;                // Points to count(*) column
  char    *Connect;           // Points to connection string
  char    *TableName;         // Points to EOM table name
  char    *Owner;             // Points to EOM table Owner
  char    *Qualifier;         // Points to EOM table Qualifier
  char    *Query;             // Points to SQL statement
  char    *Count;             // Points to count(*) SQL statement
//char    *Where;             // Points to local where clause
  char    *Quote;             // The identifier quoting character
  char    *MulConn;            // Used for multiple ODBC tables
  char    *DBQ;                // The address part of Connect string
  int      Options;           // Connect options
  int      Fpos;              // Position of last read record
  int      AftRows;            // The number of affected rows
  int      Rows;              // Rowset size
  int      Catver;            // Catalog ODBC version
  int      CurNum;            // Current buffer line number
  int      Rbuf;              // Number of lines read in buffer
  int      BufSize;           // Size of connect string buffer
  int       Nparm;              // The number of statement parameters
  }; // end of class TDBODBC

/***********************************************************************/
/*  Class ODBCCOL: DOS access method column descriptor.                */
/*  This A.M. is used for ODBC tables.                                 */
/***********************************************************************/
class ODBCCOL : public COLBLK {
  friend class TDBODBC;
 public:
  // Constructors
  ODBCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am = "ODBC");
  ODBCCOL(ODBCCOL *colp, PTDB tdbp); // Constructor used in copy process

  // Implementation
  virtual int     GetAmType(void) {return TYPE_AM_ODBC;}
          SQLLEN *GetStrLen(void) {return StrLen;}
          int     GetRank(void) {return Rank;}
//        PVBLK   GetBlkp(void) {return Blkp;}

  // Methods
//virtual bool   CheckLocal(PTDB tdbp);
  virtual bool   SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check);
  virtual void   ReadColumn(PGLOBAL g);
  virtual void   WriteColumn(PGLOBAL g);
          void   AllocateBuffers(PGLOBAL g, int rows);
          void  *GetBuffer(DWORD rows);
          SWORD  GetBuflen(void);
//        void   Print(PGLOBAL g, FILE *, uint);

 protected:
  // Constructor used by GetMaxSize
  ODBCCOL(void);

  // Members
  TIMESTAMP_STRUCT *Sqlbuf;     // To get SQL_TIMESTAMP's
  void   *Bufp;                 // To extended buffer
  PVBLK   Blkp;                // To Value Block
//char    F_Date[12];          // Internal Date format
  PVAL    To_Val;              // To value used for Insert
  SQLLEN *StrLen;              // As returned by ODBC
  SQLLEN  Slen;                 // Used with Fetch
  int     Rank;                 // Rank (position) number in the query
  }; // end of class ODBCCOL

/***********************************************************************/
/*  This is the class declaration for the ODBC info table.             */
/***********************************************************************/
class TDBOIF : public TDBASE {
  friend class OIFCOL;
 public:
  // Constructor
  TDBOIF(PODEF tdp);

  // Implementation
  virtual AMT  GetAmType(void) {return TYPE_AM_ODBC;}

  // Methods
  virtual int  GetRecpos(void) {return N;}
  virtual int  GetProgCur(void) {return N;}
  virtual int  RowNumber(PGLOBAL g, bool b = false) {return N + 1;}

  // Database routines
  virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
  virtual int  GetMaxSize(PGLOBAL g);
  virtual bool OpenDB(PGLOBAL g);
  virtual int  ReadDB(PGLOBAL g);
  virtual int  WriteDB(PGLOBAL g);
  virtual int  DeleteDB(PGLOBAL g, int irc);
  virtual void CloseDB(PGLOBAL g);

 protected:
  // Specific routines
          bool Initialize(PGLOBAL g);
          bool InitCol(PGLOBAL g);

  // Members
  PQRYRES Qrp;           
  int     N;                  // Row number
  bool    Init;          
  }; // end of class TDBOIF

/***********************************************************************/
/*  Class OIFCOL: ODBC info column.                                    */
/***********************************************************************/
class OIFCOL : public COLBLK {
  friend class TDBOIF;
 public:
  // Constructors
  OIFCOL(PCOLDEF cdp, PTDB tdbp, int n);

  // Implementation
  virtual int  GetAmType(void) {return TYPE_AM_ODBC;}

  // Methods
  virtual void ReadColumn(PGLOBAL g);

 protected:
  OIFCOL(void) {}              // Default constructor not to be used

  // Members
  PTDBOIF Tdbp;                // Points to ODBC table block
  PCOLRES Crp;                // The column data array
  int     Flag;
  }; // end of class OIFCOL
#endif  // !NODBC