File: tbl.h

package info (click to toggle)
ctn 3.2.0~dfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 16,924 kB
  • sloc: ansic: 179,652; makefile: 7,006; java: 1,863; csh: 1,067; yacc: 523; sh: 424; cpp: 394; sql: 389; lex: 170
file content (337 lines) | stat: -rw-r--r-- 11,521 bytes parent folder | download
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
/*
          Copyright (C) 1993, 1994, RSNA and Washington University

          The software and supporting documentation for the Radiological
          Society of North America (RSNA) 1993, 1994 Digital Imaging and
          Communications in Medicine (DICOM) Demonstration were developed
          at the
                  Electronic Radiology Laboratory
                  Mallinckrodt Institute of Radiology
                  Washington University School of Medicine
                  510 S. Kingshighway Blvd.
                  St. Louis, MO 63110
          as part of the 1993, 1994 DICOM Central Test Node project for, and
          under contract with, the Radiological Society of North America.

          THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND NEITHER RSNA NOR
          WASHINGTON UNIVERSITY MAKE ANY WARRANTY ABOUT THE SOFTWARE, ITS
          PERFORMANCE, ITS MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
          USE, FREEDOM FROM ANY COMPUTER DISEASES OR ITS CONFORMITY TO ANY
          SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND PERFORMANCE OF
          THE SOFTWARE IS WITH THE USER.

          Copyright of the software and supporting documentation is
          jointly owned by RSNA and Washington University, and free access
          is hereby granted as a license to use this software, copy this
          software and prepare derivative works based upon this software.
          However, any distribution of this software source code or
          supporting documentation or derivative works (source code and
          supporting documentation) must include the three paragraphs of
          the copyright notice.
*/
/* Copyright marker.  Copyright will be inserted above.  Do not remove */

/*
**		     Electronic Radiology Laboratory
**		   Mallinckrodt Institute of Radiology
**		Washington University School of Medicine
**
** Module Name(s):
** Author, Date:	Steve Moore, David E. Beecher, January 1994
** Intent:		Define typedefs and function prototypes for
**			TBL facility (for handling table operations).
** Last Update:		$Author: smm $, $Date: 2007-04-09 16:05:42 $
** Source File:		$RCSfile: tbl.h,v $
** Revision:		$Revision: 1.29 $
** Status:		$State: Exp $
*/


#ifndef _TBL_IS_IN
#define _TBL_IS_IN 1

#ifdef  __cplusplus
extern "C" {
#endif

#include <string.h>

typedef void TBL_HANDLE;

typedef enum {
    TBL_OTHER,
    TBL_UNSIGNED2, TBL_UNSIGNED4,
    TBL_SIGNED2, TBL_SIGNED4,
    TBL_FLOAT4, TBL_FLOAT8,
    TBL_STRING, TBL_TEXT,
    TBL_BINARYDATA, TBL_MBSTRING
}   TBL_DATATYPE;

typedef struct {
    TBL_DATATYPE Type;
    int AllocatedSize;
    int Size;
    int IsNull;
    union {
	void *Other;
	short *Signed2;
	int *Signed4;
	unsigned short *Unsigned2;
	unsigned int *Unsigned4;
	float *Float4;
	double *Float8;
	char *String;
	char *Text;
	void *BinaryData;
    }   Value;
}   TBL_VALUE;

typedef enum {
    TBL_NULL, TBL_NOT_NULL, TBL_EQUAL, TBL_NOT_EQUAL,
    TBL_GREATER, TBL_GREATER_EQUAL,
    TBL_LESS, TBL_LESS_EQUAL, TBL_LIKE,
    TBL_NOP
}   TBL_OPERATOR;

typedef enum {
    TBL_SET, TBL_INCREMENT, TBL_DECREMENT, TBL_ZERO,
    TBL_ADD, TBL_SUBTRACT
}   TBL_FUNCTION;

typedef struct {
    char *FieldName;
    TBL_OPERATOR Operator;
    TBL_VALUE Value;
}   TBL_CRITERIA;

typedef struct {
    char *FieldName;
    TBL_VALUE Value;
}   TBL_FIELD;

typedef struct {
    char *FieldName;
    TBL_FUNCTION Function;
    TBL_VALUE Value;
}   TBL_UPDATE;

typedef struct _TBL_CONTEXT {
    int refCount;
    char
       *databaseName,
       *tableName;
    void *dbSpecific;
    struct _TBL_CONTEXT
       *next;
}   TBL_CONTEXT;

#define TBL_LOAD_STRING(v, s)	(v)->Type = TBL_STRING; \
	(v)->Size = strlen((s)); \
	(v)->AllocatedSize = (v)->Size + 1; \
	(v)->IsNull = 0; \
	(v)->Value.String = (s);

#define	TBL_EXISTING_STRING(v, s) (v)->Type = TBL_STRING; \
	(v)->AllocatedSize = sizeof((s)); \
	(v)->Size = 0; \
	(v)->IsNull = 1; \
	(v)->Value.String = (s);

#define	TBL_FIELD_DECLARE_STRING(v, fname, str, siz) (v).FieldName = fname; \
	(v).Value.Type =TBL_STRING; \
	(v).Value.AllocatedSize = (siz); \
	(v).Value.Size = 0; \
	(v).Value.IsNull = 1; \
	(v).Value.Value.String = (str);

#define	TBL_FIELD_DECLARE_NUM(v, fname, type, d, siz) (v).FieldName = fname; \
	(v).Value.Type = (type); \
	(v).Value.AllocatedSize = (siz); \
	(v).Value.Size = 0; \
	(v).Value.IsNull = 1; \
	if (type == TBL_SIGNED4) \
		(v).Value.Value.Signed4 = (int *)&(d); \
	else if (type == TBL_FLOAT4) \
		(v).Value.Value.Float4 = (float *)&(d); \
	else if (type == TBL_FLOAT8) \
		(v).Value.Value.Float8 = (double *)&(d);

#define TBL_CRITERIA_LOAD_BYTE(v,fname,s,type,operator)  	\
        (v).FieldName = fname;			\
        (v).Operator = (TBL_OPERATOR)operator;	\
        (v).Value.Type = (TBL_DATATYPE)type;	\
        (v).Value.IsNull = 0;			\
        if( type == TBL_STRING ){		\
            (v).Value.Size=strlen((s));		\
            (v).Value.AllocatedSize=strlen((s))+1;\
            (v).Value.Value.String=(s);		\
	}

#define TBL_FIELD_LOAD_BYTE(v,fname,s,type)  	\
        (v).FieldName = fname;			\
        (v).Value.Type = (TBL_DATATYPE)type;	\
        (v).Value.IsNull = 0;			\
        if( type == TBL_STRING ){		\
            (v).Value.Size=strlen((s));		\
            (v).Value.AllocatedSize=strlen((s))+1;\
            (v).Value.Value.String=(s);		\
	}else if( type == TBL_TEXT){		\
            (v).Value.Size=strlen((s));		\
            (v).Value.AllocatedSize=strlen((s))+1;\
            (v).Value.Value.Text=(s);		\
	}

#define TBL_UPDATE_LOAD_BYTE(v,fname,s,type,f) 	\
        (v).FieldName = fname;			\
	(v).Function = f;			\
        (v).Value.Type = (TBL_DATATYPE)type;	\
        (v).Value.IsNull = 0;			\
        if( type == TBL_STRING ){		\
            (v).Value.Size=strlen((s));		\
            (v).Value.AllocatedSize=strlen((s))+1;\
            (v).Value.Value.String=(s);		\
	} else if (type == TBL_TEXT) {		\
            (v).Value.Size=strlen((s));		\
            (v).Value.AllocatedSize=strlen((s))+1;\
            (v).Value.Value.Text=(s);		\
	}

#define TBL_CRITERIA_LOAD_NUM(v,fname,s,type,operator)  	\
        (v).FieldName = fname;			\
        (v).Operator = (TBL_OPERATOR) operator;	\
        (v).Value.Type = (TBL_DATATYPE) type;	\
        (v).Value.IsNull = 0;			\
        if( type == TBL_SIGNED4 ){		\
            (v).Value.Size=4;			\
            (v).Value.AllocatedSize=4;		\
            (v).Value.Value.Signed4=(int *)&(s);\
        }else if( type == TBL_FLOAT4 ){		\
            (v).Value.Size=4;			\
            (v).Value.AllocatedSize=4;		\
            (v).Value.Value.Float4=(float *)&(s);\
        }else if( type == TBL_FLOAT8 ){		\
            (v).Value.Size=8;			\
            (v).Value.AllocatedSize=8;		\
            (v).Value.Value.Float8=(double *)&(s);\
        }

#define TBL_FIELD_LOAD_NUM(v,fname,s,type)  	\
        (v).FieldName = fname;			\
        (v).Value.Type = type;			\
        (v).Value.IsNull = 0;			\
        if( type == TBL_SIGNED4 ){		\
            (v).Value.Size=4;			\
            (v).Value.AllocatedSize=4;		\
            (v).Value.Value.Signed4=(int *)&(s);\
        }else if( type == TBL_FLOAT4 ){		\
            (v).Value.Size=4;			\
            (v).Value.AllocatedSize=4;		\
            (v).Value.Value.Float4=(float *)&(s);\
        }else if( type == TBL_FLOAT8 ){		\
            (v).Value.Size=8;			\
            (v).Value.AllocatedSize=8;		\
            (v).Value.Value.Float8=(double *)&(s);\
        }

#define TBL_UPDATE_LOAD_NUM(v,fname,s,type,f)  	\
        (v).FieldName = fname;			\
        (v).Function = f;			\
        (v).Value.Type = type;			\
        (v).Value.IsNull = 0;			\
        if( type == TBL_SIGNED4 ){		\
            (v).Value.Size=4;			\
            (v).Value.AllocatedSize=4;		\
            (v).Value.Value.Signed4=(int *)&(s);\
        }else if( type == TBL_FLOAT4 ){		\
            (v).Value.Size=4;			\
            (v).Value.AllocatedSize=4;		\
            (v).Value.Value.Float4=(float *)&(s);\
        }else if( type == TBL_FLOAT8 ){		\
            (v).Value.Size=8;			\
            (v).Value.AllocatedSize=8;		\
            (v).Value.Value.Float8=(double *)&(s);\
        }

#define	TBL_FIELD_STRING(name, string) (name), TBL_STRING, \
sizeof((string)), 0, 1, (void *)(string)

/* Define the function prototypes for this facility. */

CONDITION TBL_Open(const char *databaseName, const char *tableName, TBL_HANDLE ** handle);
CONDITION TBL_OpenDB(const char *databaseName, TBL_HANDLE ** handle);
CONDITION TBL_Close(TBL_HANDLE ** handle);
CONDITION TBL_CloseDB();

CONDITION
TBL_Select(TBL_HANDLE ** handle, const TBL_CRITERIA * criteriaList,
    TBL_FIELD * fieldList, long *count, CONDITION(*callback) (TBL_FIELD*, long, void*), void *ctx);
CONDITION
TBL_SelectTable(TBL_HANDLE ** handle, const TBL_CRITERIA * criteriaList,
    TBL_FIELD * fieldList, long *count, CONDITION(*callback) (TBL_FIELD*, long, void*), void *ctx, const char* tableName);
CONDITION
TBL_Update(TBL_HANDLE ** handle, const TBL_CRITERIA * criteriaList, TBL_UPDATE * updateList);
CONDITION
TBL_UpdateTable(TBL_HANDLE ** handle, const TBL_CRITERIA * criteriaList,
	TBL_UPDATE * updateList, const char* tableName);
CONDITION
TBL_Insert(TBL_HANDLE ** handle, TBL_FIELD * fieldList);
CONDITION
TBL_InsertTable(TBL_HANDLE ** handle, TBL_FIELD * fieldList,
		const char* tablename);
CONDITION
TBL_Delete(TBL_HANDLE ** handle, const TBL_CRITERIA * criteriaList);
CONDITION
TBL_DeleteTable(TBL_HANDLE ** handle, const TBL_CRITERIA * criteriaList,
	const char* tableName);
CONDITION
TBL_Layout(char *databaseName, char *tableName, CONDITION(*callback) (), void *ctx);
CONDITION
TBL_NextUnique(TBL_HANDLE ** handle, char *name, int *unique);
CONDITION
TBL_NextSequence(TBL_HANDLE ** handle, char *name, long *unique);
CONDITION
TBL_Debug(CTNBOOLEAN flag);
int
    TBL_HasViews(void);
int TBL_HasUpdateIncrement(void);

char *TBL_Message(CONDITION condition);

void TBL_BeginInsertTransaction(void);
void TBL_CommitInsertTransaction(void);
void TBL_RollbackInsertTransaction(void);

CONDITION TBL_SetOption(const char* string);

/* Define condition values */

#define	TBL_NORMAL		FORM_COND(FAC_TBL, SEV_SUCC, 1)
#define	TBL_UNIMPLEMENTED	FORM_COND(FAC_TBL, SEV_ERROR, 2)
#define	TBL_MALLOCFAILURE	FORM_COND(FAC_TBL, SEV_ERROR, 3)
#define	TBL_OPENFAILED		FORM_COND(FAC_TBL, SEV_ERROR, 4)
#define	TBL_FILEOPENFAILED	FORM_COND(FAC_TBL, SEV_ERROR, 5)
#define	TBL_ILLEGALFORMAT	FORM_COND(FAC_TBL, SEV_ERROR, 6)
#define	TBL_LISTCREATEFAILURE	FORM_COND(FAC_TBL, SEV_ERROR, 7)
#define	TBL_LISTFAILURE		FORM_COND(FAC_TBL, SEV_ERROR, 8)
#define	TBL_ALREADYOPENED	FORM_COND(FAC_TBL, SEV_ERROR, 9)
#define	TBL_DBNOEXIST		FORM_COND(FAC_TBL, SEV_ERROR, 10)
#define	TBL_TBLNOEXIST		FORM_COND(FAC_TBL, SEV_ERROR, 11)
#define	TBL_NOMEMORY		FORM_COND(FAC_TBL, SEV_ERROR, 12)
#define	TBL_CLOSERROR		FORM_COND(FAC_TBL, SEV_ERROR, 13)
#define	TBL_BADHANDLE		FORM_COND(FAC_TBL, SEV_ERROR, 14)
#define	TBL_NOFIELDLIST		FORM_COND(FAC_TBL, SEV_ERROR, 15)
#define	TBL_SELECTFAILED	FORM_COND(FAC_TBL, SEV_ERROR, 16)
#define	TBL_EARLYEXIT		FORM_COND(FAC_TBL, SEV_ERROR, 17)
#define	TBL_DELETEFAILED	FORM_COND(FAC_TBL, SEV_ERROR, 18)
#define	TBL_INSERTFAILED	FORM_COND(FAC_TBL, SEV_ERROR, 18)
#define	TBL_UPDATEFAILED	FORM_COND(FAC_TBL, SEV_ERROR, 19)
#define	TBL_DBINITFAILED	FORM_COND(FAC_TBL, SEV_ERROR, 20)
#define	TBL_NOCOLUMNS		FORM_COND(FAC_TBL, SEV_ERROR, 21)
#define	TBL_NOCALLBACK		FORM_COND(FAC_TBL, SEV_ERROR, 22)
#define	TBL_DBSPECIFIC		FORM_COND(FAC_TBL, SEV_ERROR, 23)

#ifdef  __cplusplus
}
#endif

#endif