-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbtrieve.h
390 lines (353 loc) · 11.8 KB
/
btrieve.h
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#if !defined(__BTRIEVE_H)
#define __BTRIEVE_H
/*************************************************************
Constants
*************************************************************/
#define BTR_CONST_MAXKEYSIZE 255
#define BTR_CONST_MAXSEGNUM 119
#define BTR_CONST_POSLEN 128
#define BTR_CONST_NOKEY -1
#define BTR_CONST_ACSSIZE 265
#define BTR_CONST_NAMELEN 20
#define BTR_CONST_FLDNAMELEN 20
#define BTR_CONST_FILENAMELEN 256
#define BTR_CONST_MAXINFO 5
/*************************************************************
Types
*************************************************************/
#define BTR_TYPE_STRING 0
#define BTR_TYPE_INTEGER 1
#define BTR_TYPE_FLOAT 2
#define BTR_TYPE_DATE 3
#define BTR_TYPE_TIME 4
#define BTR_TYPE_DECIMAL 5
#define BTR_TYPE_MONEY 6
#define BTR_TYPE_LOGICAL 7
#define BTR_TYPE_NUMERIC 8
#define BTR_TYPE_BFLOAT 9
#define BTR_TYPE_LSTRING 10
#define BTR_TYPE_ZSTRING 11
#define BTR_TYPE_MEMO 12
//#define BTR_TYPE_13 13
#define BTR_TYPE_UNSIGNED 14
#define BTR_TYPE_AUTOINC 15
//#define BTR_TYPE_16 16
#define BTR_TYPE_STS 17
#define BTR_TYPE_UNKNOWN -1
/*************************************************************
Operations
*************************************************************/
#define BTR_OP_OPEN 0
#define BTR_OP_CLOSE 1
#define BTR_OP_INSERT 2
#define BTR_OP_UPDATE 3
#define BTR_OP_DELETE 4
#define BTR_OP_GET_E 5
#define BTR_OP_GET_NEXT 6
#define BTR_OP_GET_PREV 7
#define BTR_OP_GET_G 8
#define BTR_OP_GET_GE 9
#define BTR_OP_GET_L 10
#define BTR_OP_GET_LE 11
#define BTR_OP_GET_FIRST 12
#define BTR_OP_GET_LAST 13
#define BTR_OP_CREATE 14
#define BTR_OP_STATUS 15
#define BTR_OP_EXTEND 16
#define BTR_OP_SET_DIR 17
#define BTR_OP_GET_DIR 18
#define BTR_OP_BEGIN_TRAN 19
#define BTR_OP_END_TRAN 20
#define BTR_OP_ABORT_TRAN 21
#define BTR_OP_GET_POS 22
#define BTR_OP_GET_DIRECT 23
#define BTR_OP_STEP_NEXT 24
#define BTR_OP_STOP 25
#define BTR_OP_VERSION 26
#define BTR_OP_UNLOCK 27
#define BTR_OP_RESET 28
#define BTR_OP_SET_OWNER 29
#define BTR_OP_CLEAR_OWNER 30
#define BTR_OP_CREATE_INDEX 31
#define BTR_OP_DROP_INDEX 32
#define BTR_OP_STEP_FIRST 33
#define BTR_OP_STEP_LAST 34
#define BTR_OP_STEP_PREV 35
#define BTR_OP_GET_NEXT_EXT 36
#define BTR_OP_GET_PREV_EXT 37
#define BTR_OP_STEP_NEXT_EXT 38
#define BTR_OP_STEP_PREV_EXT 39
#define BTR_OP_INSERT_EXT 40
/*************************************************************
File flags
*************************************************************/
#define BTR_FILE_VAR 0x0001
#define BTR_FILE_COMPRESS 0x0002
#define BTR_FILE_PREALLOC 0x0004
//#define BTR_FILE_ODBC 0x10
#define BTR_FILE_BALANCED 0x0020
#define BTR_FILE_0100 0x0100
/*************************************************************
Key flags
*************************************************************/
#define BTR_KEY_DUP 0x0001
#define BTR_KEY_MOD 0x0002
#define BTR_KEY_BIN 0x0004
#define BTR_KEY_NUL 0x0008
#define BTR_KEY_SEG 0x0010
#define BTR_KEY_ALT 0x0020
#define BTR_KEY_DESC 0x0040
#define BTR_KEY_REP 0x0080
#define BTR_KEY_EXT 0x0100
#define BTR_KEY_MAN 0x0200
#define BTR_KEY_NOCASE 0x0400
#define BTR_KEY_ACSNAME 0x0800
#define BTR_KEY_KEYONLY 0x4000
#define BTR_KEY_PENDING 0x8000
/*************************************************************
Errors
*************************************************************/
#define BTR_ERR_KEYNOTFOUND 4
#define BTR_ERR_INVALIDKEY 6
#define BTR_ERR_EOF 9
#define BTR_ERR_CANTFIND 12
#define BTR_ERR_NOTLOADED 20
#define BTR_ERR_CANTCREATE 25
#define BTR_ERR_UNKNOWN 5000
#define BTR_ERR_NOMEMORY 5001
/*************************************************************
Data types
*************************************************************/
typedef void BTR_VOID;
typedef char BTR_CHAR;
typedef char BTR_BOOL;
typedef unsigned char BTR_BYTE;
typedef short BTR_SINT;
typedef unsigned short BTR_WORD;
typedef long BTR_LONG;
typedef unsigned long BTR_DWORD;
typedef double BTR_DOUBLE;
#ifdef __WIN32__
#pragma pack(push,1)
#endif
struct BTR_VERSION
{
BTR_SINT Version;
BTR_SINT Revision;
BTR_CHAR MKDEId;
};
struct BTR_FILE
{
BTR_WORD recLen; // Record length
BTR_WORD pageSize; // Page size
BTR_WORD keyNum; // Number of keys
BTR_DWORD recNum; // Number of records
BTR_WORD flags; // File flags
BTR_BYTE dupPointers; // ???
BTR_BYTE reserved; // ???
BTR_WORD allocations; // ???
};
struct BTR_SEG
{
BTR_WORD position; // Key position in record buffer
BTR_WORD length; // Key length
BTR_WORD flags; // Key flags
BTR_DWORD keyNum; // Number of keys
BTR_BYTE type; // Key type
BTR_WORD nulval; // Null value
BTR_BYTE unknown1; // ???
BTR_BYTE unknown2; // ???
BTR_BYTE acs; // ACS Number
};
struct BTR_STATUS
{
BTR_FILE file;
BTR_SEG seg[BTR_CONST_MAXSEGNUM];
BTR_CHAR acs[BTR_CONST_ACSSIZE]; // Add space if ACS
};
#ifdef __WIN32__
#pragma pack(pop)
#endif
/*************************************************************
BTRV
*************************************************************/
extern BTR_SINT BTRV(BTR_WORD operation,
BTR_VOID *posBlock,
BTR_VOID *dataBuffer,
BTR_WORD *dataLength,
BTR_VOID *keyBuffer,
BTR_SINT keyNumber);
/*************************************************************
FIELDINFO
*************************************************************/
struct FIELDINFO
{
// BTR_CHAR name[BTR_CONST_FLDNAMELEN+1];
BTR_CHAR *name;
BTR_SINT type;
BTR_WORD length;
BTR_WORD dec;
};
/*************************************************************
KEYINFO
*************************************************************/
struct KEYINFO
{
BTR_CHAR *name;
};
struct FIELD;
/*************************************************************
SEG
*************************************************************/
struct SEG
{
BTR_WORD key;
BTR_WORD position;
BTR_WORD length;
BTR_SINT type;
BTR_WORD flags;
BTR_WORD nulval;
BTR_WORD acs;
FIELD *field;
};
/*************************************************************
FIELD
*************************************************************/
struct FIELD
{
// BTR_CHAR name[BTR_CONST_FLDNAMELEN+1];
BTR_CHAR *name;
BTR_WORD position;
BTR_WORD length;
BTR_WORD dec;
BTR_SINT type;
};
/*************************************************************
Btrieve
*************************************************************/
class Btrieve
{
public:
static BTR_WORD infoNum;
static FIELDINFO *info[BTR_CONST_MAXINFO];
static BTR_WORD defPageSize;
static BTR_WORD defFlags;
public:
Btrieve(BTR_VOID);
~Btrieve(BTR_VOID);
static BTR_BOOL isLoaded;
static BTR_SINT debug;
static BTR_BOOL loaded(BTR_VOID) {return isLoaded;};
static BTR_VOID debugView(BTR_SINT l,BTR_CHAR *s,...);
static BTR_VOID CreateDDF(BTR_CHAR *path);
static BTR_VOID AddToDDF(BTR_CHAR *path,BTR_CHAR *name,BTR_CHAR *loc,
FIELDINFO *field,KEYINFO *key,BTR_WORD aFlags=0);
static FIELDINFO *loadField(BTR_CHAR *ddfpath,BTR_CHAR *name);
static BTR_SINT create(BTR_CHAR *name,
FIELDINFO *field,
KEYINFO *key,
BTR_VOID *acs=0);
static BTR_SINT BeginTransaction(BTR_VOID);
static BTR_SINT EndTransaction(BTR_VOID);
static BTR_SINT AbortTransaction(BTR_VOID);
static BTR_CHAR *type(BTR_SINT type);
};
/*************************************************************
DAT
*************************************************************/
class DAT
{
public:
BTR_CHAR *fileName;
BTR_CHAR pos[BTR_CONST_POSLEN];
BTR_BOOL isOpened;
BTR_WORD segNum;
BTR_WORD keyNum;
BTR_WORD fieldNum;
SEG *seg;
FIELD *field;
BTR_BOOL isEof;
BTR_SINT currentKey;
BTR_CHAR *recBuf;
BTR_CHAR *keyBuf;
BTR_WORD recLen;
BTR_WORD recBufLen;
BTR_WORD recVarLen;
BTR_WORD pageSize;
BTR_WORD flags;
BTR_DWORD recNum;
DAT(BTR_VOID);
DAT(BTR_CHAR *name,BTR_CHAR *owner=0);
~DAT(BTR_VOID);
BTR_VOID init(BTR_VOID);
BTR_SINT open(BTR_CHAR *name,BTR_CHAR *owner=0);
BTR_SINT close(BTR_VOID);
BTR_SINT status(BTR_VOID);
BTR_SINT setField(FIELDINFO *info);
BTR_SINT loadField(BTR_CHAR *path,BTR_CHAR *aname=0);
BTR_VOID keySelect(BTR_SINT key);
BTR_VOID keySelect(BTR_CHAR *name);
BTR_VOID viewFile(BTR_VOID);
BTR_VOID viewHeader(BTR_VOID);
BTR_VOID viewFields(BTR_VOID);
BTR_VOID viewKeys(BTR_VOID);
BTR_VOID viewSegs(BTR_VOID);
BTR_VOID viewRecord(BTR_VOID);
BTR_VOID viewField(BTR_CHAR *name);
BTR_BOOL eof(BTR_VOID);
BTR_BOOL opened(BTR_VOID);
BTR_WORD fieldOffset(BTR_CHAR *name);
BTR_VOID *fieldPtr(BTR_CHAR *name);
BTR_CHAR *fieldString(BTR_CHAR *name);
BTR_WORD fieldLen(BTR_CHAR *name);
BTR_WORD fieldMemoLen(BTR_CHAR *name,BTR_WORD offset=0,BTR_WORD len=0);
BTR_WORD fieldDec(BTR_CHAR *name);
BTR_SINT fieldType(BTR_CHAR *name);
BTR_CHAR *fieldName(BTR_CHAR *name);
BTR_CHAR *fieldZString(BTR_CHAR *name);
BTR_CHAR *fieldZMemo(BTR_CHAR *name,BTR_WORD offset=0,BTR_WORD len=0);
BTR_SINT fieldChar(BTR_CHAR *name);
BTR_SINT fieldInt(BTR_CHAR *name);
BTR_LONG fieldLong(BTR_CHAR *name);
BTR_DOUBLE fieldDouble(BTR_CHAR *name);
BTR_DOUBLE fieldDecimal(BTR_CHAR *name);
BTR_VOID clear(BTR_VOID);
BTR_SINT assignString(BTR_CHAR *name,BTR_CHAR *value);
BTR_SINT assignChar(BTR_CHAR *name,BTR_SINT value);
BTR_SINT assignInt(BTR_CHAR *name,BTR_SINT value);
BTR_SINT assignLong(BTR_CHAR *name,BTR_LONG value);
BTR_SINT assignDouble(BTR_CHAR *name,BTR_DOUBLE value);
BTR_SINT assignDecimal(BTR_CHAR *name,BTR_DOUBLE value);
BTR_VOID rec2key(BTR_SINT key);
BTR_SINT getFirst(BTR_SINT key=BTR_CONST_NOKEY);
BTR_SINT getLast(BTR_SINT key=BTR_CONST_NOKEY);
BTR_SINT getNext(BTR_SINT key=BTR_CONST_NOKEY);
BTR_SINT getE(BTR_SINT key=BTR_CONST_NOKEY);
BTR_SINT getL(BTR_SINT key=BTR_CONST_NOKEY);
BTR_SINT getGE(BTR_SINT key=BTR_CONST_NOKEY);
BTR_SINT stepFirst(BTR_VOID);
BTR_SINT stepNext(BTR_VOID);
BTR_SINT stepLast(BTR_VOID);
BTR_SINT insert(BTR_SINT key=BTR_CONST_NOKEY);
BTR_SINT update(BTR_SINT key=BTR_CONST_NOKEY);
BTR_SINT del(BTR_SINT key=BTR_CONST_NOKEY);
};
extern FIELDINFO file_field[];
extern FIELDINFO field_field[];
extern FIELDINFO index_field[];
extern FIELDINFO comment_field[];
extern KEYINFO file_key[];
extern KEYINFO field_key[];
extern KEYINFO index_key[];
extern KEYINFO comment_key[];
#if !defined(__WIN32__)
#define TYPE_INTEGER BTR_TYPE_INTEGER
#define TYPE_STRING BTR_TYPE_STRING
#define TYPE_UNKNOWN BTR_TYPE_UNKNOWN
#define TYPE_UNSIGNED BTR_TYPE_UNSIGNED
#define TYPE_FLOAT BTR_TYPE_FLOAT
#define SIZE_INT 2
#define SIZE_LONG 4
typedef FIELDINFO FIELD_INFO;
#endif
#endif