]>
Commit | Line | Data |
---|---|---|
9fa49beb JB |
1 | --- firebird-1.0.0.796/porting/pyxis/save.c.orig Thu Jan 1 01:00:00 1970 |
2 | +++ firebird-1.0.0.796/porting/pyxis/save.c Wed Dec 4 23:34:54 2002 | |
3 | @@ -0,0 +1,1388 @@ | |
4 | +/*********** Preprocessed module -- do not edit ***************/ | |
5 | +/*********** Preprocessed module -- do not edit ***************/ | |
6 | +/*********** Preprocessed module -- do not edit ***************/ | |
7 | +/*********** Preprocessed module -- do not edit ***************/ | |
8 | +/*********** Preprocessed module -- do not edit ***************/ | |
9 | +/***************** gpre version LI-T6.2.796 Firebird 1.0 **********************/ | |
10 | +/* | |
11 | + * PROGRAM: PYXIS Form Package | |
12 | + * MODULE: save.e | |
13 | + * DESCRIPTION: Form dump/load code. | |
14 | + * | |
15 | + * The contents of this file are subject to the Interbase Public | |
16 | + * License Version 1.0 (the "License"); you may not use this file | |
17 | + * except in compliance with the License. You may obtain a copy | |
18 | + * of the License at http://www.Inprise.com/IPL.html | |
19 | + * | |
20 | + * Software distributed under the License is distributed on an | |
21 | + * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express | |
22 | + * or implied. See the License for the specific language governing | |
23 | + * rights and limitations under the License. | |
24 | + * | |
25 | + * The Original Code was created by Inprise Corporation | |
26 | + * and its predecessors. Portions created by Inprise Corporation are | |
27 | + * Copyright (C) Inprise Corporation. | |
28 | + * | |
29 | + * All Rights Reserved. | |
30 | + * Contributor(s): ______________________________________. | |
31 | + */ | |
32 | + | |
33 | +#include "../jrd/gds.h" | |
34 | +#include "../pyxis/pyxis.h" | |
35 | + | |
36 | +#define HANDLES 10 | |
37 | +#define PYXIS_RELATION "PYXIS$FORMS" | |
38 | +#define BUF_LEN 256 | |
39 | + | |
40 | +extern PIC PICSTR_analyze(); | |
41 | +extern OBJ PYXIS_create_object(), PYXIS_clone(), PYXIS_get_attribute_value(); | |
42 | +extern ATT PYXIS_get_attribute(), PYXIS_put_attribute(), | |
43 | + PYXIS_find_object(); | |
44 | + | |
45 | +/*DATABASE | |
46 | + DB = STATIC "yachts.lnk";*/ | |
47 | +/**** GDS Preprocessor Definitions ****/ | |
48 | +#ifndef _JRD_IBASE_H_ | |
49 | +#include <ibase.h> | |
50 | +#endif | |
51 | + | |
52 | +static ISC_QUAD | |
53 | + isc_blob_null = {0,0}; /* initializer for blobs */ | |
54 | +static long *gds__null = 0; /* dummy status vector */ | |
55 | +static isc_db_handle | |
56 | + DB = 0; /* database handle */ | |
57 | + | |
58 | +static isc_tr_handle | |
59 | + gds__trans = 0; /* default transaction handle */ | |
60 | +static long | |
61 | + isc_status [20], /* status vector */ | |
62 | + isc_status2 [20]; /* status vector */ | |
63 | +static long | |
64 | + isc_array_length, /* array return size */ | |
65 | + SQLCODE; /* SQL status code */ | |
66 | +static char | |
67 | + isc_tpb_0 [4] = {1,9,2,6}; | |
68 | + | |
69 | +static short | |
70 | + isc_1l = 73; | |
71 | +static char | |
72 | + isc_1 [] = { | |
73 | + 4,2,4,0,2,0,9,0,40,32,0,12,0,15,'J',11,'P','Y','X','I','S','$', | |
74 | + 'F','O','R','M','S',0,2,1,25,0,0,0,23,0,10,'P','Y','X','I','S', | |
75 | + '$','F','O','R','M',1,25,0,1,0,23,0,15,'P','Y','X','I','S','$', | |
76 | + 'F','O','R','M','_','N','A','M','E',-1,-1,'L' | |
77 | + }; /* end of blr string for request isc_1 */ | |
78 | + | |
79 | +static short | |
80 | + isc_8l = 161; | |
81 | +static char | |
82 | + isc_8 [] = { | |
83 | + 4,2,4,3,1,0,7,0,4,2,1,0,9,0,4,1,2,0,9,0,7,0,4,0,1,0,40,32,0, | |
84 | + 12,0,2,7,'C',1,'J',11,'P','Y','X','I','S','$','F','O','R','M', | |
85 | + 'S',0,'G',47,23,0,15,'P','Y','X','I','S','$','F','O','R','M', | |
86 | + '_','N','A','M','E',25,0,0,0,-1,2,14,1,2,1,23,0,10,'P','Y','X', | |
87 | + 'I','S','$','F','O','R','M',25,1,0,0,1,21,8,0,1,0,0,0,25,1,1, | |
88 | + 0,-1,17,0,9,13,12,3,18,0,12,2,10,0,1,2,1,25,2,0,0,23,1,10,'P', | |
89 | + 'Y','X','I','S','$','F','O','R','M',-1,-1,-1,14,1,1,21,8,0,0, | |
90 | + 0,0,0,25,1,1,0,-1,-1,'L' | |
91 | + }; /* end of blr string for request isc_8 */ | |
92 | + | |
93 | +static short | |
94 | + isc_21l = 140; | |
95 | +static char | |
96 | + isc_21 [] = { | |
97 | + 4,2,4,0,2,0,40,32,0,7,0,2,7,'C',1,'J',13,'R','D','B','$','R', | |
98 | + 'E','L','A','T','I','O','N','S',0,'G',47,23,0,15,'R','D','B', | |
99 | + '$','S','Y','S','T','E','M','_','F','L','A','G',21,8,0,0,0,0, | |
100 | + 0,'F',1,'H',23,0,17,'R','D','B','$','R','E','L','A','T','I', | |
101 | + 'O','N','_','N','A','M','E',-1,14,0,2,1,23,0,17,'R','D','B', | |
102 | + '$','R','E','L','A','T','I','O','N','_','N','A','M','E',25,0, | |
103 | + 0,0,1,21,8,0,1,0,0,0,25,0,1,0,-1,14,0,1,21,8,0,0,0,0,0,25,0, | |
104 | + 1,0,-1,-1,'L' | |
105 | + }; /* end of blr string for request isc_21 */ | |
106 | + | |
107 | +static short | |
108 | + isc_25l = 358; | |
109 | +static char | |
110 | + isc_25 [] = { | |
111 | + 4,2,4,1,8,0,40,32,0,7,0,40,126,0,40,126,0,7,0,7,0,7,0,7,0,4, | |
112 | + 0,1,0,40,32,0,12,0,2,7,'C',2,'J',19,'R','D','B','$','R','E', | |
113 | + 'L','A','T','I','O','N','_','F','I','E','L','D','S',0,'J',10, | |
114 | + 'R','D','B','$','F','I','E','L','D','S',1,'G',58,47,23,0,17, | |
115 | + 'R','D','B','$','R','E','L','A','T','I','O','N','_','N','A', | |
116 | + 'M','E',25,0,0,0,47,23,0,16,'R','D','B','$','F','I','E','L', | |
117 | + 'D','_','S','O','U','R','C','E',23,1,14,'R','D','B','$','F', | |
118 | + 'I','E','L','D','_','N','A','M','E','F',1,'H',23,0,18,'R','D', | |
119 | + 'B','$','F','I','E','L','D','_','P','O','S','I','T','I','O', | |
120 | + 'N',-1,14,1,2,1,23,0,14,'R','D','B','$','F','I','E','L','D', | |
121 | + '_','N','A','M','E',25,1,0,0,1,21,8,0,1,0,0,0,25,1,1,0,1,23, | |
122 | + 1,15,'R','D','B','$','E','D','I','T','_','S','T','R','I','N', | |
123 | + 'G',25,1,2,0,1,23,0,15,'R','D','B','$','E','D','I','T','_','S', | |
124 | + 'T','R','I','N','G',25,1,3,0,1,23,1,18,'R','D','B','$','S','E', | |
125 | + 'G','M','E','N','T','_','L','E','N','G','T','H',25,1,4,0,1,23, | |
126 | + 1,14,'R','D','B','$','F','I','E','L','D','_','T','Y','P','E', | |
127 | + 25,1,5,0,1,23,1,16,'R','D','B','$','F','I','E','L','D','_','L', | |
128 | + 'E','N','G','T','H',25,1,6,0,1,23,1,15,'R','D','B','$','F','I', | |
129 | + 'E','L','D','_','S','C','A','L','E',25,1,7,0,-1,14,1,1,21,8, | |
130 | + 0,0,0,0,0,25,1,1,0,-1,-1,'L' | |
131 | + }; /* end of blr string for request isc_25 */ | |
132 | + | |
133 | +static short | |
134 | + isc_37l = 113; | |
135 | +static char | |
136 | + isc_37 [] = { | |
137 | + 4,2,4,1,2,0,9,0,7,0,4,0,1,0,40,32,0,12,0,2,7,'C',1,'J',11,'P', | |
138 | + 'Y','X','I','S','$','F','O','R','M','S',0,'G',47,23,0,15,'P', | |
139 | + 'Y','X','I','S','$','F','O','R','M','_','N','A','M','E',25,0, | |
140 | + 0,0,-1,14,1,2,1,23,0,10,'P','Y','X','I','S','$','F','O','R', | |
141 | + 'M',25,1,0,0,1,21,8,0,1,0,0,0,25,1,1,0,-1,14,1,1,21,8,0,0,0, | |
142 | + 0,0,25,1,1,0,-1,-1,'L' | |
143 | + }; /* end of blr string for request isc_37 */ | |
144 | + | |
145 | +static short | |
146 | + isc_46l = 107; | |
147 | +static char | |
148 | + isc_46 [] = { | |
149 | + 4,2,4,0,2,0,40,32,0,7,0,2,7,'C',1,'J',11,'P','Y','X','I','S', | |
150 | + '$','F','O','R','M','S',0,'F',1,'H',23,0,15,'P','Y','X','I', | |
151 | + 'S','$','F','O','R','M','_','N','A','M','E',-1,14,0,2,1,23,0, | |
152 | + 15,'P','Y','X','I','S','$','F','O','R','M','_','N','A','M','E', | |
153 | + 25,0,0,0,1,21,8,0,1,0,0,0,25,0,1,0,-1,14,0,1,21,8,0,0,0,0,0, | |
154 | + 25,0,1,0,-1,-1,'L' | |
155 | + }; /* end of blr string for request isc_46 */ | |
156 | + | |
157 | +static short | |
158 | + isc_50l = 120; | |
159 | +static char | |
160 | + isc_50 [] = { | |
161 | + 4,2,4,3,1,0,7,0,4,2,1,0,7,0,4,1,1,0,7,0,4,0,1,0,40,32,0,12,0, | |
162 | + 2,7,'C',1,'J',11,'P','Y','X','I','S','$','F','O','R','M','S', | |
163 | + 0,'G',47,23,0,15,'P','Y','X','I','S','$','F','O','R','M','_', | |
164 | + 'N','A','M','E',25,0,0,0,-1,2,14,1,2,1,21,8,0,1,0,0,0,25,1,0, | |
165 | + 0,-1,17,0,9,13,12,3,18,0,12,2,5,0,-1,-1,14,1,1,21,8,0,0,0,0, | |
166 | + 0,25,1,0,0,-1,-1,'L' | |
167 | + }; /* end of blr string for request isc_50 */ | |
168 | + | |
169 | +static short | |
170 | + isc_59l = 99; | |
171 | +static char | |
172 | + isc_59 [] = { | |
173 | + 4,2,4,0,1,0,7,0,2,7,'C',1,'J',13,'R','D','B','$','R','E','L', | |
174 | + 'A','T','I','O','N','S',0,'G',47,23,0,17,'R','D','B','$','R', | |
175 | + 'E','L','A','T','I','O','N','_','N','A','M','E',21,14,11,0,'P', | |
176 | + 'Y','X','I','S','$','F','O','R','M','S',-1,14,0,2,1,21,8,0,1, | |
177 | + 0,0,0,25,0,0,0,-1,14,0,1,21,8,0,0,0,0,0,25,0,0,0,-1,-1,'L' | |
178 | + }; /* end of blr string for request isc_59 */ | |
179 | + | |
180 | + | |
181 | +#define gds__blob_null isc_blob_null /* compatibility symbols */ | |
182 | +#define gds__status isc_status | |
183 | +#define gds__status2 isc_status2 | |
184 | +#define gds__array_length isc_array_length | |
185 | +#define gds__count isc_count | |
186 | +#define gds__slack isc_slack | |
187 | +#define gds__utility isc_utility /* end of compatibility symbols */ | |
188 | + | |
189 | +#ifndef isc_version4 | |
190 | + Generate a compile-time error. | |
191 | + Picking up a V3 include file after preprocessing with V4 GPRE. | |
192 | +#endif | |
193 | + | |
194 | +/**** end of GPRE definitions ****/ | |
195 | + | |
196 | + | |
197 | +static SCHAR ddl [] = | |
198 | + { | |
199 | +#include "../pyxis/form_ddl.h" | |
200 | + , 0 }; | |
201 | + | |
202 | +static ATT_N special_attributes [] = | |
203 | + { | |
204 | + att_display_x, | |
205 | + att_display_y, | |
206 | + /* | |
207 | + att_scroll_x, | |
208 | + att_scroll_y, | |
209 | + */ | |
210 | + att_width, | |
211 | + att_height, | |
212 | + att_border, | |
213 | + att_index, | |
214 | + att_inactive, | |
215 | + att_reverse_video, | |
216 | + att_bold, | |
217 | + att_underline, | |
218 | + att_box, | |
219 | + att_blank, | |
220 | + att_insert_right, | |
221 | + att_updatable_flag, | |
222 | + att_wakeup_flag, | |
223 | + att_reverse_for_update, | |
224 | + att_any | |
225 | + }; | |
226 | + | |
227 | +\f | |
228 | +PYXIS_define_forms_relation (dbb) | |
229 | + SLONG **dbb; | |
230 | +{ | |
231 | + struct { | |
232 | + short isc_61; /* isc_utility */ | |
233 | + } isc_60; | |
234 | +/************************************** | |
235 | + * | |
236 | + * P Y X I S _ d e f i n e _ f o r m s _ r e l a t i o n | |
237 | + * | |
238 | + ************************************** | |
239 | + * | |
240 | + * Functional description | |
241 | + * Check for existence of PYXIS$FORMS relation. If it doesn't | |
242 | + * exist, create it. | |
243 | + * | |
244 | + **************************************/ | |
245 | +SLONG *transaction, *handle, success; | |
246 | +STATUS status_vector [20]; | |
247 | + | |
248 | +DB = *dbb; | |
249 | +transaction = handle = NULL; | |
250 | +success = FALSE; | |
251 | + | |
252 | +/*START_TRANSACTION transaction READ_WRITE;*/ | |
253 | +{ | |
254 | +isc_start_transaction ((long*) 0L, &transaction, (short) 1, &DB, (short) 4, isc_tpb_0); | |
255 | +} | |
256 | + | |
257 | +/*FOR (REQUEST_HANDLE handle TRANSACTION_HANDLE transaction) | |
258 | + X IN RDB$RELATIONS WITH X.RDB$RELATION_NAME EQ "PYXIS$FORMS"*/ | |
259 | +{ | |
260 | +if (!handle) | |
261 | + isc_compile_request ((long*) 0L, &DB, &handle, (short) sizeof (isc_59), (char ISC_FAR *) isc_59); | |
262 | +isc_start_request ((long*) 0L, &handle, &transaction, (short) 0); | |
263 | +while (1) | |
264 | + { | |
265 | + isc_receive ((long*) 0L, &handle, (short) 0, (short) 2, &isc_60, (short) 0); | |
266 | + if (!isc_60.isc_61) break; | |
267 | + success = TRUE; | |
268 | +/*END_FOR;*/ | |
269 | + } | |
270 | +} | |
271 | + | |
272 | +gds__release_request (status_vector, GDS_REF (handle)); | |
273 | + | |
274 | +if (!success && gds__ddl (status_vector, | |
275 | + GDS_REF (DB), | |
276 | + GDS_REF (transaction), | |
277 | + sizeof (ddl), | |
278 | + ddl)) | |
279 | + { | |
280 | + gds__print_status (status_vector); | |
281 | + success = FALSE; | |
282 | + /*ROLLBACK transaction;*/ | |
283 | + { | |
284 | + isc_rollback_transaction ((long*) 0L, &transaction); | |
285 | + } | |
286 | + return FALSE; | |
287 | + } | |
288 | + | |
289 | +/*COMMIT transaction;*/ | |
290 | +{ | |
291 | +isc_commit_transaction ((long*) 0L, &transaction); | |
292 | +} | |
293 | + | |
294 | +return success; | |
295 | +} | |
296 | +\f | |
297 | +OBJ PYXIS_delete_form (dbb, transaction, form_name) | |
298 | + SLONG **dbb, **transaction; | |
299 | + TEXT *form_name; | |
300 | +{ | |
301 | + struct { | |
302 | + short isc_58; /* isc_utility */ | |
303 | + } isc_57; | |
304 | + struct { | |
305 | + short isc_56; /* isc_utility */ | |
306 | + } isc_55; | |
307 | + struct { | |
308 | + short isc_54; /* isc_utility */ | |
309 | + } isc_53; | |
310 | + struct { | |
311 | + char isc_52 [32]; /* PYXIS$FORM_NAME */ | |
312 | + } isc_51; | |
313 | +/************************************** | |
314 | + * | |
315 | + * P Y X I S _ d e l e t e _ f o r m | |
316 | + * | |
317 | + ************************************** | |
318 | + * | |
319 | + * Functional description | |
320 | + * Delete a form from a database. | |
321 | + * | |
322 | + **************************************/ | |
323 | +int *handle; | |
324 | + | |
325 | +DB = *dbb; | |
326 | +gds__trans = *transaction; | |
327 | +handle = NULL; | |
328 | + | |
329 | +/*FOR (REQUEST_HANDLE handle) | |
330 | + X IN PYXIS$FORMS WITH X.PYXIS$FORM_NAME EQ form_name*/ | |
331 | +{ | |
332 | +if (!handle) | |
333 | + isc_compile_request ((long*) 0L, &DB, &handle, (short) sizeof (isc_50), (char ISC_FAR *) isc_50); | |
334 | +isc_vtov (form_name, isc_51.isc_52, 32); | |
335 | +isc_start_and_send ((long*) 0L, &handle, &gds__trans, (short) 0, (short) 32, &isc_51, (short) 0); | |
336 | +while (1) | |
337 | + { | |
338 | + isc_receive ((long*) 0L, &handle, (short) 1, (short) 2, &isc_53, (short) 0); | |
339 | + if (!isc_53.isc_54) break; | |
340 | + /*ERASE X;*/ | |
341 | + isc_send ((long*) 0L, &handle, (short) 2, (short) 2, &isc_55, (short) 0); | |
342 | +/*END_FOR;*/ | |
343 | + isc_send ((long*) 0L, &handle, (short) 3, (short) 2, &isc_57, (short) 0); | |
344 | + } | |
345 | +} | |
346 | + | |
347 | +gds__release_request (gds__status, GDS_REF (handle)); | |
348 | + | |
349 | +return NULL; | |
350 | +} | |
351 | +\f | |
352 | +PYXIS_dump (object, ptr) | |
353 | + OBJ object; | |
354 | + TEXT **ptr; | |
355 | +{ | |
356 | +/************************************** | |
357 | + * | |
358 | + * P Y X I S _ d u m p | |
359 | + * | |
360 | + ************************************** | |
361 | + * | |
362 | + * Functional description | |
363 | + * Dump an object into linear form. Assume space is large | |
364 | + * enough. | |
365 | + * | |
366 | + **************************************/ | |
367 | +ATT attribute; | |
368 | +ATT_N *attr_ptr, name; | |
369 | +SLONG value; | |
370 | +TEXT *p, c; | |
371 | + | |
372 | +p = *ptr; | |
373 | + | |
374 | +/* Start by handling ordinary attributes */ | |
375 | + | |
376 | +for (attribute = object->obj_attributes; attribute; | |
377 | + attribute = attribute->att_next) | |
378 | + { | |
379 | + if (attribute->att_type == attype_other) | |
380 | + continue; | |
381 | + sprintf (p, "%d", attribute->att_name); | |
382 | + while (*p) p++; | |
383 | + switch (attribute->att_type) | |
384 | + { | |
385 | + case attype_string: | |
386 | + c = (attribute == object->obj_display_attribute) ? 'D' : 'S'; | |
387 | + sprintf (p, "%c`%s`", c, attribute->att_value); | |
388 | + while (*p) p++; | |
389 | + break; | |
390 | + | |
391 | + case attype_numeric: | |
392 | + sprintf (p, "N%d.", attribute->att_value); | |
393 | + while (*p) p++; | |
394 | + break; | |
395 | + | |
396 | + case attype_object: | |
397 | + *p++ = 'O'; | |
398 | + PYXIS_dump (attribute->att_value, &p); | |
399 | + break; | |
400 | + | |
401 | + default: | |
402 | + BUGCHECK ("DUMP:Unknown attribute type"); | |
403 | + } | |
404 | + } | |
405 | + | |
406 | +/* Next, handle special attributes */ | |
407 | + | |
408 | +for (attr_ptr = special_attributes; *attr_ptr != att_any; attr_ptr++) | |
409 | + if (value = GET_VALUE (object, *attr_ptr)) | |
410 | + { | |
411 | + sprintf (p, "%dN%d.", *attr_ptr, value); | |
412 | + while (*p) p++; | |
413 | + } | |
414 | + | |
415 | +/* Finish up */ | |
416 | + | |
417 | +*p++ = 'E'; | |
418 | +*ptr = p; | |
419 | +} | |
420 | +\f | |
421 | +PYXIS_dump_length (object) | |
422 | + OBJ object; | |
423 | +{ | |
424 | +/************************************** | |
425 | + * | |
426 | + * P Y X I S _ d u m p _ l e n g t h | |
427 | + * | |
428 | + ************************************** | |
429 | + * | |
430 | + * Functional description | |
431 | + * Compute length of object when dumped. | |
432 | + * | |
433 | + **************************************/ | |
434 | +ATT attribute; | |
435 | +ATT_N *attr_ptr; | |
436 | +TEXT buffer [32]; | |
437 | +USHORT n; | |
438 | +SLONG length; | |
439 | +SLONG value; | |
440 | + | |
441 | +length = 1; | |
442 | + | |
443 | +for (attribute = object->obj_attributes; attribute; | |
444 | + attribute = attribute->att_next) | |
445 | + { | |
446 | + if (attribute->att_type == attype_other) | |
447 | + continue; | |
448 | + sprintf (buffer, "%d", attribute->att_name); | |
449 | + length += strlen (buffer); | |
450 | + switch (attribute->att_type) | |
451 | + { | |
452 | + case attype_string: | |
453 | + length += strlen (attribute->att_value) + 3; | |
454 | + break; | |
455 | + | |
456 | + case attype_numeric: | |
457 | + sprintf (buffer, "N%d.", attribute->att_value); | |
458 | + length += strlen (buffer); | |
459 | + break; | |
460 | + | |
461 | + case attype_object: | |
462 | + length += 1 + PYXIS_dump_length (attribute->att_value); | |
463 | + break; | |
464 | + | |
465 | + default: | |
466 | + BUGCHECK ("Unknown attribute type"); | |
467 | + } | |
468 | + } | |
469 | + | |
470 | +/* Next, handle special attributes */ | |
471 | + | |
472 | +for (attr_ptr = special_attributes; *attr_ptr != att_any; attr_ptr++) | |
473 | + if (value = GET_VALUE (object, *attr_ptr)) | |
474 | + { | |
475 | + sprintf (buffer, "%dN%d.", *attr_ptr, value); | |
476 | + length += strlen (buffer); | |
477 | + } | |
478 | + | |
479 | +return length; | |
480 | +} | |
481 | +\f | |
482 | +PYXIS_field_defaults (field) | |
483 | + OBJ field; | |
484 | +{ | |
485 | +/************************************** | |
486 | + * | |
487 | + * P Y X I S _ f i e l d _ d e f a u l t s | |
488 | + * | |
489 | + ************************************** | |
490 | + * | |
491 | + * Functional description | |
492 | + * Supply defaults for missing field characteristics. | |
493 | + * | |
494 | + **************************************/ | |
495 | +ATT attribute; | |
496 | +OBJ prototype; | |
497 | +USHORT length, display_length; | |
498 | +TEXT *p, buffer [256], c, *edit_string; | |
499 | +PIC picture; | |
500 | +DSC desc; | |
501 | +STR string; | |
502 | + | |
503 | +PYXIS_delete_named_attribute (field, att_inactive); | |
504 | +picture = NULL; | |
505 | +desc.dsc_length = desc.dsc_dtype = desc.dsc_scale = 0; | |
506 | + | |
507 | +/* If we have a picture string, analyze it */ | |
508 | + | |
509 | +if (edit_string = GET_STRING (field, att_edit_string)) | |
510 | + { | |
511 | + picture = PICSTR_analyze (edit_string, NULL); | |
512 | + switch (picture->pic_type) | |
513 | + { | |
514 | + case pic_alpha: | |
515 | + case pic_text: | |
516 | + desc.dsc_dtype = dtype_text; | |
517 | + desc.dsc_length = picture->pic_length; | |
518 | + break; | |
519 | + | |
520 | + case pic_numeric: | |
521 | + desc.dsc_dtype = dtype_long; | |
522 | + desc.dsc_scale = -picture->pic_fractions; | |
523 | + break; | |
524 | + | |
525 | + case pic_date: | |
526 | + desc.dsc_dtype = dtype_text; | |
527 | + break; | |
528 | + | |
529 | + case pic_float : | |
530 | + c = 'F'; | |
531 | + desc.dsc_dtype = dtype_double; /* No path to this stmt. */ | |
532 | + break; | |
533 | + } | |
534 | + } | |
535 | + | |
536 | +/* Pick up data type info, if supplied directly */ | |
537 | + | |
538 | +if (GET_ATTRIBUTE (field, att_dtype)) | |
539 | + desc.dsc_dtype = GET_VALUE (field, att_dtype); | |
540 | + | |
541 | +if (GET_ATTRIBUTE (field, att_length)) | |
542 | + desc.dsc_length = GET_VALUE (field, att_length); | |
543 | + | |
544 | +if (GET_ATTRIBUTE (field, att_scale)) | |
545 | + desc.dsc_scale = GET_VALUE (field, att_scale); | |
546 | + | |
547 | +/* Cleanup datatype info, as appropriate */ | |
548 | + | |
549 | +switch (desc.dsc_dtype) | |
550 | + { | |
551 | + case dtype_varying: | |
552 | +/* | |
553 | + desc.dsc_length += 2; | |
554 | +*/ | |
555 | + break; | |
556 | + | |
557 | + case dtype_short: | |
558 | + desc.dsc_length = 2; | |
559 | + break; | |
560 | + | |
561 | + case dtype_long: | |
562 | + desc.dsc_length = 4; | |
563 | + break; | |
564 | + | |
565 | + case dtype_real: | |
566 | + desc.dsc_length = 4; | |
567 | + break; | |
568 | + | |
569 | + case dtype_double: | |
570 | +#ifdef VMS | |
571 | + case dtype_d_float: | |
572 | +#endif | |
573 | + desc.dsc_length = 8; | |
574 | + break; | |
575 | + | |
576 | + case dtype_timestamp: | |
577 | + desc.dsc_length = 8; | |
578 | + break; | |
579 | + | |
580 | + case dtype_sql_date: | |
581 | + desc.dsc_length = 4; | |
582 | + break; | |
583 | + | |
584 | + case dtype_sql_time: | |
585 | + desc.dsc_length = 4; | |
586 | + break; | |
587 | + | |
588 | + case dtype_blob: | |
589 | + if (!(display_length = GET_VALUE (field, att_segment_length))) | |
590 | + display_length = 40; | |
591 | + REPLACE_ATTRIBUTE (field, att_width, attype_numeric, display_length + 2); | |
592 | + REPLACE_ATTRIBUTE (field, att_height, attype_numeric, 6); | |
593 | + if (!GET_VALUE (field, att_prototype)) | |
594 | + { | |
595 | + PYXIS_box (field); | |
596 | + prototype = PYXIS_create_object (NULL_PTR, 0); | |
597 | + REPLACE_ATTRIBUTE (prototype, att_width, attype_numeric, display_length); | |
598 | + REPLACE_ATTRIBUTE (prototype, att_reverse_for_update, attype_numeric, TRUE); | |
599 | + REPLACE_ATTRIBUTE (field, att_prototype, attype_object, prototype); | |
600 | + } | |
601 | + return TRUE; | |
602 | + | |
603 | + case dtype_text: | |
604 | + default: | |
605 | + desc.dsc_dtype = dtype_text; | |
606 | + desc.dsc_scale = 0; | |
607 | + if (!desc.dsc_length && | |
608 | + !(desc.dsc_length = GET_VALUE (field, att_width))) | |
609 | + desc.dsc_length = 10; | |
610 | + break; | |
611 | + } | |
612 | + | |
613 | +REPLACE_ATTRIBUTE (field, att_dtype, attype_numeric, desc.dsc_dtype); | |
614 | +REPLACE_ATTRIBUTE (field, att_length, attype_numeric, desc.dsc_length); | |
615 | +if (desc.dsc_scale) | |
616 | + REPLACE_ATTRIBUTE (field, att_scale, attype_numeric, desc.dsc_scale); | |
617 | + | |
618 | +if (!edit_string) | |
619 | + { | |
620 | + edit_string = (TEXT*) PICSTR_default_edit_string (&desc, buffer); | |
621 | + REPLACE_ATTRIBUTE (field, att_edit_string, attype_string, edit_string); | |
622 | + picture = PICSTR_analyze (edit_string, NULL); | |
623 | + } | |
624 | + | |
625 | +REPLACE_ATTRIBUTE (field, att_width, attype_numeric, picture->pic_length); | |
626 | + | |
627 | +if (!(attribute = GET_ATTRIBUTE (field, att_fill_string))) | |
628 | + { | |
629 | + switch (picture->pic_type) | |
630 | + { | |
631 | + case pic_alpha : c = 'X'; break; | |
632 | + case pic_numeric: c = '9'; break; | |
633 | + case pic_date : c = 'D'; break; | |
634 | + case pic_float : c = 'F'; break; | |
635 | + case pic_text : c = 'T'; break; | |
636 | + } | |
637 | + | |
638 | + /* Make up fill string, possibly laboriously */ | |
639 | + | |
640 | + display_length = picture->pic_length; | |
641 | + string = NULL; | |
642 | + | |
643 | + if (display_length < 255) | |
644 | + p = buffer; | |
645 | + else | |
646 | + { | |
647 | + string = (STR) ALLOCDV (type_str, display_length); | |
648 | + p = string->str_data; | |
649 | + } | |
650 | + | |
651 | + do *p++ = c; while (--display_length); | |
652 | + *p = 0; | |
653 | + | |
654 | + if (string) | |
655 | + { | |
656 | + attribute = PUT_ATTRIBUTE (field, att_fill_string, attype_string, string->str_data); | |
657 | + PYXIS_release (string); | |
658 | + } | |
659 | + else | |
660 | + attribute = PUT_ATTRIBUTE (field, att_fill_string, attype_string, buffer); | |
661 | + } | |
662 | + | |
663 | +PYXIS_set_display_attribute (field, attribute); | |
664 | + | |
665 | +if (picture->pic_type == pic_numeric || picture->pic_type == pic_float) | |
666 | + REPLACE_ATTRIBUTE (field, att_insert_right, attype_numeric, TRUE); | |
667 | + | |
668 | +return TRUE; | |
669 | +} | |
670 | +\f | |
671 | +OBJ PYXIS_forms (dbb, transaction) | |
672 | + SLONG **dbb, **transaction; | |
673 | +{ | |
674 | + struct { | |
675 | + char isc_48 [32]; /* PYXIS$FORM_NAME */ | |
676 | + short isc_49; /* isc_utility */ | |
677 | + } isc_47; | |
678 | +/************************************** | |
679 | + * | |
680 | + * P Y X I S _ f o r m s | |
681 | + * | |
682 | + ************************************** | |
683 | + * | |
684 | + * Functional description | |
685 | + * Get menu all of forms, etc. | |
686 | + * | |
687 | + **************************************/ | |
688 | +OBJ menu, entree; | |
689 | +int *handle; | |
690 | + | |
691 | +DB = *dbb; | |
692 | +gds__trans = *transaction; | |
693 | +menu = PYXIS_create_object (NULL_PTR, 0); | |
694 | +handle = NULL; | |
695 | + | |
696 | +/*FOR (REQUEST_HANDLE handle) | |
697 | + X IN PYXIS$FORMS SORTED BY X.PYXIS$FORM_NAME*/ | |
698 | +{ | |
699 | +if (!handle) | |
700 | + isc_compile_request ((long*) 0L, &DB, &handle, (short) sizeof (isc_46), (char ISC_FAR *) isc_46); | |
701 | +isc_start_request ((long*) 0L, &handle, &gds__trans, (short) 0); | |
702 | +while (1) | |
703 | + { | |
704 | + isc_receive ((long*) 0L, &handle, (short) 0, (short) 34, &isc_47, (short) 0); | |
705 | + if (!isc_47.isc_49) break; | |
706 | + zap_string (/*X.PYXIS$FORM_NAME*/ | |
707 | + isc_47.isc_48); | |
708 | + PYXIS_create_entree (menu, /*X.PYXIS$FORM_NAME*/ | |
709 | + isc_47.isc_48, 0, NULL_PTR); | |
710 | +/*END_FOR;*/ | |
711 | + } | |
712 | +} | |
713 | + | |
714 | +gds__release_request (gds__status, GDS_REF (handle)); | |
715 | + | |
716 | +return menu; | |
717 | +} | |
718 | +\f | |
719 | +OBJ PYXIS_load (ptr) | |
720 | + TEXT **ptr; | |
721 | +{ | |
722 | +/************************************** | |
723 | + * | |
724 | + * P Y X I S _ l o a d | |
725 | + * | |
726 | + ************************************** | |
727 | + * | |
728 | + * Functional description | |
729 | + * Load an object from linear representation. | |
730 | + * | |
731 | + **************************************/ | |
732 | +OBJ object; | |
733 | +ATT attribute; | |
734 | +ATT_T type; | |
735 | +SLONG value, name, n, negate, buf_size; | |
736 | +TEXT *p, c, verb, *s, *string, *new_buf, *buf_end, buffer[1024]; | |
737 | + | |
738 | +p = *ptr; | |
739 | +object = PYXIS_create_object (NULL_PTR, 0); | |
740 | + | |
741 | +for (;;) | |
742 | + { | |
743 | + name = 0; | |
744 | + while (*p >= '0' && *p <= '9') | |
745 | + name = name * 10 + *p++ - '0'; | |
746 | + switch (verb = *p++) | |
747 | + { | |
748 | + case 'D': | |
749 | + case 'S': | |
750 | + c = *p++; | |
751 | + string = buffer; | |
752 | + buf_size = sizeof(buffer); | |
753 | + buf_end = string + buf_size; | |
754 | + s = string; | |
755 | + while (*p != c) | |
756 | + { | |
757 | + *s++ = *p++; | |
758 | + if (s == buf_end) | |
759 | + { | |
760 | + new_buf = (TEXT*) gds__alloc (2 * buf_size); | |
761 | + memcpy (new_buf, string, buf_size); | |
762 | + if (string != buffer) | |
763 | + gds__free (string); | |
764 | + string = new_buf; | |
765 | + s = string + buf_size; | |
766 | + buf_size = 2 * buf_size; | |
767 | + buf_end = string + buf_size; | |
768 | + } | |
769 | + } | |
770 | + *s = 0; | |
771 | + attribute = PUT_ATTRIBUTE (object, name, attype_string, string); | |
772 | + if (verb == 'D') | |
773 | + PYXIS_set_display_attribute (object, attribute); | |
774 | + p++; | |
775 | + if (string != buffer) | |
776 | + gds__free (string); | |
777 | + break; | |
778 | + | |
779 | + case 'N': | |
780 | + type = attype_numeric; | |
781 | + negate = ((*p == '-') ? (++p, TRUE) : (FALSE)); | |
782 | + n = 0; | |
783 | + while ((c = *p++) != '.') | |
784 | + n = n * 10 + c - '0'; | |
785 | + if (negate) | |
786 | + n = -n; | |
787 | + PUT_ATTRIBUTE (object, name, attype_numeric, n); | |
788 | + break; | |
789 | + | |
790 | + case 'O': | |
791 | + PUT_ATTRIBUTE (object, name, attype_object, PYXIS_load (&p)); | |
792 | + break; | |
793 | + | |
794 | + case 'E': | |
795 | + *ptr = p; | |
796 | + return object; | |
797 | + | |
798 | + default: | |
799 | + BUGCHECK ("Bad form definition"); | |
800 | + } | |
801 | + } | |
802 | +} | |
803 | +\f | |
804 | +OBJ PYXIS_load_form (status_vector, dbb, transaction, | |
805 | + form_handle, form_name_length, form_name) | |
806 | + int *status_vector; | |
807 | + SLONG **dbb, **transaction; | |
808 | + OBJ *form_handle; | |
809 | + USHORT *form_name_length; | |
810 | + TEXT *form_name; | |
811 | +{ | |
812 | + struct { | |
813 | + ISC_QUAD isc_41; /* PYXIS$FORM */ | |
814 | + short isc_42; /* isc_utility */ | |
815 | + } isc_40; | |
816 | + struct { | |
817 | + char isc_39 [32]; /* PYXIS$FORM_NAME */ | |
818 | + } isc_38; | |
819 | + isc_blob_handle isc_43; /* blob handle */ | |
820 | + char isc_44 [80]; /* blob segment */ | |
821 | + unsigned short isc_45; /* segment length */ | |
822 | +/************************************** | |
823 | + * | |
824 | + * P Y X I S _ l o a d _ f o r m | |
825 | + * | |
826 | + ************************************** | |
827 | + * | |
828 | + * Functional description | |
829 | + * Load a form from a database. | |
830 | + * If the form doesn't exist, return NULL. | |
831 | + * | |
832 | + **************************************/ | |
833 | +USHORT buf_len, out_size, length; | |
834 | +TEXT *ptr, buffer [4096], *buff, *p; | |
835 | +STATUS code; | |
836 | +SLONG temp_vector [20], handle, seg_count, max_seg; | |
837 | +SLONG size; | |
838 | + | |
839 | +DB = *dbb; | |
840 | +gds__trans = *transaction; | |
841 | +*form_handle = NULL; | |
842 | +handle = NULL; | |
843 | +ptr = NULL; | |
844 | + | |
845 | +/* Unless name is zero terminated, copy and terminate form name */ | |
846 | + | |
847 | +if (form_name_length && (length = *form_name_length)) | |
848 | + { | |
849 | + for (p = buffer; length; --length) | |
850 | + *p++ = *form_name++; | |
851 | + *p = 0; | |
852 | + form_name = buffer; | |
853 | + } | |
854 | + | |
855 | +buff = buffer; | |
856 | +buf_len = sizeof (buffer); | |
857 | + | |
858 | +/* Lookup form */ | |
859 | + | |
860 | +/*FOR (REQUEST_HANDLE handle) | |
861 | + X IN PYXIS$FORMS WITH X.PYXIS$FORM_NAME EQ form_name*/ | |
862 | +{ | |
863 | +if (!handle) | |
864 | + isc_compile_request (isc_status, &DB, &handle, (short) sizeof (isc_37), (char ISC_FAR *) isc_37); | |
865 | +isc_43 = 0; | |
866 | +isc_vtov (form_name, isc_38.isc_39, 32); | |
867 | +if (handle) | |
868 | + isc_start_and_send (isc_status, &handle, &gds__trans, (short) 0, (short) 32, &isc_38, (short) 0); | |
869 | +if (!isc_status [1]) { | |
870 | +while (1) | |
871 | + { | |
872 | + isc_receive (isc_status, &handle, (short) 1, (short) 10, &isc_40, (short) 0); | |
873 | + if (!isc_40.isc_42 || isc_status [1]) break; | |
874 | + /*OPEN_BLOB B IN X.PYXIS$FORM*/ | |
875 | + { | |
876 | + { | |
877 | + isc_open_blob2 (isc_status, &DB, &gds__trans, &isc_43, &isc_40.isc_41, (short) 0, (char*) 0); | |
878 | + }; | |
879 | + /*ON_ERROR*/ | |
880 | + if (isc_status [1]) | |
881 | + { | |
882 | + break; | |
883 | + /*END_ERROR;*/ | |
884 | + } | |
885 | + } | |
886 | + | |
887 | + if (gds__blob_size (&/*B*/ | |
888 | + isc_43, &size, &seg_count, &max_seg)) | |
889 | + if (size > sizeof (buffer)) | |
890 | + buff = ptr = (TEXT *) gds__alloc (size + 2); | |
891 | + | |
892 | + while (size > 0) | |
893 | + { | |
894 | + buf_len = MIN (buf_len, size); | |
895 | + if (code = gds__get_segment (gds__status, | |
896 | + GDS_REF (/*B*/ | |
897 | + isc_43), | |
898 | + GDS_REF (out_size), | |
899 | + buf_len, | |
900 | + GDS_VAL (buff))) | |
901 | + | |
902 | + { | |
903 | + | |
904 | + /* segment and segstr_eof codes are benign; | |
905 | + otherwise, we have an internal error */ | |
906 | + | |
907 | + if (code == gds__segstr_eof) | |
908 | + break; | |
909 | + if (code != gds__segment) | |
910 | + BUGCHECK ("Unable to load form"); | |
911 | + } | |
912 | + | |
913 | + buff += out_size; | |
914 | + size -= out_size; | |
915 | + } | |
916 | + /*CLOSE_BLOB B;*/ | |
917 | + { | |
918 | + isc_close_blob ((long*) 0L, &isc_43); | |
919 | + } | |
920 | + if (!(buff = ptr)) | |
921 | + buff = buffer; | |
922 | + *form_handle = PYXIS_load (&buff); | |
923 | + break; | |
924 | +/*END_FOR*/ | |
925 | + } | |
926 | + }; | |
927 | + /*ON_ERROR*/ | |
928 | + if (isc_status [1]) | |
929 | + { | |
930 | + /*END_ERROR;*/ | |
931 | + } | |
932 | + } | |
933 | + | |
934 | +gds__release_request (temp_vector, GDS_REF (handle)); | |
935 | + | |
936 | +/* If something failed and there isn't a status vector, | |
937 | + blow away user */ | |
938 | + | |
939 | +if (!status_vector && !*form_handle) | |
940 | + { | |
941 | + if (gds__status [1]) | |
942 | + gds__print_status (gds__status); | |
943 | + else | |
944 | + { | |
945 | + sprintf (buffer, "form %s not found\n", form_name); | |
946 | + gds__put_error (buffer); | |
947 | + } | |
948 | + exit (FINI_ERROR); | |
949 | + } | |
950 | + | |
951 | +if (ptr) | |
952 | + gds__free (ptr); | |
953 | + | |
954 | +/* Copy status vector */ | |
955 | + | |
956 | +if (status_vector) | |
957 | + MOVP_fast (gds__status, status_vector, 20 * sizeof (STATUS)); | |
958 | + | |
959 | +return (OBJ) gds__status [1]; | |
960 | +} | |
961 | +\f | |
962 | +OBJ PYXIS_relation_fields (dbb, transaction, relation_name) | |
963 | + SLONG **dbb, **transaction; | |
964 | + TEXT *relation_name; | |
965 | +{ | |
966 | + struct { | |
967 | + char isc_29 [32]; /* RDB$FIELD_NAME */ | |
968 | + short isc_30; /* isc_utility */ | |
969 | + char isc_31 [126]; /* RDB$EDIT_STRING */ | |
970 | + char isc_32 [126]; /* RDB$EDIT_STRING */ | |
971 | + short isc_33; /* RDB$SEGMENT_LENGTH */ | |
972 | + short isc_34; /* RDB$FIELD_TYPE */ | |
973 | + short isc_35; /* RDB$FIELD_LENGTH */ | |
974 | + short isc_36; /* RDB$FIELD_SCALE */ | |
975 | + } isc_28; | |
976 | + struct { | |
977 | + char isc_27 [32]; /* RDB$RELATION_NAME */ | |
978 | + } isc_26; | |
979 | +/************************************** | |
980 | + * | |
981 | + * P Y X I S _ r e l a t i o n _ f i e l d s | |
982 | + * | |
983 | + ************************************** | |
984 | + * | |
985 | + * Functional description | |
986 | + * Create an object containing fields for relation. This is | |
987 | + * NOT formatted as a form. | |
988 | + * | |
989 | + **************************************/ | |
990 | +ATT attribute; | |
991 | +OBJ form, field; | |
992 | +USHORT length, display_length, segment_length; | |
993 | +TEXT *p, c, *edit_string; | |
994 | +int *handle; | |
995 | +DSC desc; | |
996 | + | |
997 | +DB = *dbb; | |
998 | +gds__trans = *transaction; | |
999 | +form = PYXIS_create_object (NULL_PTR, 0); | |
1000 | +handle = NULL; | |
1001 | + | |
1002 | +/*FOR (REQUEST_HANDLE handle) | |
1003 | + RFR IN RDB$RELATION_FIELDS CROSS FLD IN RDB$FIELDS WITH | |
1004 | + RFR.RDB$RELATION_NAME EQ relation_name AND | |
1005 | + RFR.RDB$FIELD_SOURCE EQ FLD.RDB$FIELD_NAME | |
1006 | + SORTED BY RFR.RDB$FIELD_POSITION*/ | |
1007 | +{ | |
1008 | +if (!handle) | |
1009 | + isc_compile_request ((long*) 0L, &DB, &handle, (short) sizeof (isc_25), (char ISC_FAR *) isc_25); | |
1010 | +isc_vtov (relation_name, isc_26.isc_27, 32); | |
1011 | +isc_start_and_send ((long*) 0L, &handle, &gds__trans, (short) 0, (short) 32, &isc_26, (short) 0); | |
1012 | +while (1) | |
1013 | + { | |
1014 | + isc_receive ((long*) 0L, &handle, (short) 1, (short) 294, &isc_28, (short) 0); | |
1015 | + if (!isc_28.isc_30) break; | |
1016 | + | |
1017 | + /* Create field itself */ | |
1018 | + | |
1019 | + zap_string (/*RFR.RDB$FIELD_NAME*/ | |
1020 | + isc_28.isc_29); | |
1021 | + field = PYXIS_create_object (/*RFR.RDB$FIELD_NAME*/ | |
1022 | + isc_28.isc_29, att_field_name); | |
1023 | + | |
1024 | + desc.dsc_scale = /*FLD.RDB$FIELD_SCALE*/ | |
1025 | + isc_28.isc_36; | |
1026 | + desc.dsc_length = /*FLD.RDB$FIELD_LENGTH*/ | |
1027 | + isc_28.isc_35; | |
1028 | + switch (/*FLD.RDB$FIELD_TYPE*/ | |
1029 | + isc_28.isc_34) | |
1030 | + { | |
1031 | + case blr_text: | |
1032 | + desc.dsc_dtype = dtype_text; | |
1033 | + break; | |
1034 | + | |
1035 | + case blr_varying: | |
1036 | + desc.dsc_dtype = dtype_varying; | |
1037 | + desc.dsc_length += 2; | |
1038 | + break; | |
1039 | + | |
1040 | + case blr_short: | |
1041 | + desc.dsc_dtype = dtype_short; | |
1042 | + desc.dsc_length = 2; | |
1043 | + break; | |
1044 | + | |
1045 | + case blr_long: | |
1046 | + desc.dsc_dtype = dtype_long; | |
1047 | + desc.dsc_length = 4; | |
1048 | + break; | |
1049 | + | |
1050 | + case blr_float: | |
1051 | + desc.dsc_dtype = dtype_real; | |
1052 | + desc.dsc_length = 4; | |
1053 | + break; | |
1054 | + | |
1055 | + case blr_double: | |
1056 | +#ifndef VMS | |
1057 | + case blr_d_float: | |
1058 | +#endif | |
1059 | + desc.dsc_dtype = dtype_double; | |
1060 | + desc.dsc_length = 8; | |
1061 | + break; | |
1062 | + | |
1063 | +#ifdef VMS | |
1064 | + case blr_d_float: | |
1065 | + desc.dsc_dtype = dtype_d_float; | |
1066 | + desc.dsc_length = 8; | |
1067 | + break; | |
1068 | +#endif | |
1069 | + | |
1070 | + case blr_timestamp: | |
1071 | + desc.dsc_dtype = dtype_timestamp; | |
1072 | + desc.dsc_length = 8; | |
1073 | + break; | |
1074 | + | |
1075 | + case blr_sql_date: | |
1076 | + desc.dsc_dtype = dtype_sql_date; | |
1077 | + desc.dsc_length = 4; | |
1078 | + break; | |
1079 | + | |
1080 | + case blr_sql_time: | |
1081 | + desc.dsc_dtype = dtype_sql_time; | |
1082 | + desc.dsc_length = 4; | |
1083 | + break; | |
1084 | + | |
1085 | + case blr_blob: | |
1086 | + desc.dsc_dtype = dtype_blob; | |
1087 | + desc.dsc_length = 8; | |
1088 | + if (segment_length = /*FLD.RDB$SEGMENT_LENGTH*/ | |
1089 | + isc_28.isc_33) | |
1090 | + PUT_ATTRIBUTE (field, att_segment_length, attype_numeric, segment_length); | |
1091 | + break; | |
1092 | + } | |
1093 | + | |
1094 | + PYXIS_put_attribute (field, att_dtype, attype_numeric, desc.dsc_dtype); | |
1095 | + PYXIS_put_attribute (field, att_length, attype_numeric, desc.dsc_length); | |
1096 | + if (desc.dsc_scale) | |
1097 | + PYXIS_put_attribute (field, att_scale, attype_numeric, desc.dsc_scale); | |
1098 | + | |
1099 | + if (desc.dsc_dtype != dtype_blob) | |
1100 | + { | |
1101 | + edit_string = /*RFR.RDB$EDIT_STRING*/ | |
1102 | + isc_28.isc_32; | |
1103 | + if (!*edit_string || *edit_string == ' ') | |
1104 | + edit_string = /*FLD.RDB$EDIT_STRING*/ | |
1105 | + isc_28.isc_31; | |
1106 | + if (*edit_string && *edit_string != ' ') | |
1107 | + PUT_ATTRIBUTE (field, att_edit_string, attype_string, edit_string); | |
1108 | + } | |
1109 | + PUT_ATTRIBUTE (field, att_inactive, attype_numeric, TRUE); | |
1110 | + PYXIS_create_entree (form, /*RFR.RDB$FIELD_NAME*/ | |
1111 | + isc_28.isc_29, attype_object, field); | |
1112 | +/*END_FOR;*/ | |
1113 | + } | |
1114 | +} | |
1115 | + | |
1116 | +gds__release_request (gds__status, GDS_REF (handle)); | |
1117 | + | |
1118 | +return form; | |
1119 | +} | |
1120 | + | |
1121 | +\f | |
1122 | +OBJ PYXIS_relation_form (window, fields) | |
1123 | + WIN window; | |
1124 | + OBJ fields; | |
1125 | +{ | |
1126 | +/************************************** | |
1127 | + * | |
1128 | + * P Y X I S _ r e l a t i o n _ f o r m | |
1129 | + * | |
1130 | + ************************************** | |
1131 | + * | |
1132 | + * Functional description | |
1133 | + * Create a form from the fields of a relation. | |
1134 | + * | |
1135 | + **************************************/ | |
1136 | +ATT attribute; | |
1137 | +OBJ form, field, label; | |
1138 | +TEXT *name; | |
1139 | + | |
1140 | +form = PYXIS_create_object (NULL_PTR, 0); | |
1141 | + | |
1142 | +for (attribute = NULL; | |
1143 | + attribute = PYXIS_find_object (fields, attribute, att_entree, TRUE);) | |
1144 | + if (field = GET_OBJECT ((OBJ)attribute->att_value, att_entree_value)) | |
1145 | + { | |
1146 | + field = PYXIS_clone (field); | |
1147 | + if (GET_VALUE (field, att_dtype) != dtype_blob && | |
1148 | + GET_VALUE (field, att_datatype) != blr_blob) | |
1149 | + REPLACE_ATTRIBUTE (field, att_reverse_for_update, attype_numeric, TRUE); | |
1150 | + PYXIS_field_defaults (field); | |
1151 | + name = GET_STRING (field, att_field_name); | |
1152 | + label = PYXIS_create_object (name, att_literal_string); | |
1153 | + PUT_ATTRIBUTE (form, att_label, attype_object, label); | |
1154 | + PUT_ATTRIBUTE (form, att_field, attype_object, field); | |
1155 | + } | |
1156 | + | |
1157 | +PYXIS_format_form (form, window->win_width, window->win_height); | |
1158 | + | |
1159 | +return form; | |
1160 | +} | |
1161 | +\f | |
1162 | +OBJ PYXIS_relations (dbb, transaction) | |
1163 | + SLONG **dbb, **transaction; | |
1164 | +{ | |
1165 | + struct { | |
1166 | + char isc_23 [32]; /* RDB$RELATION_NAME */ | |
1167 | + short isc_24; /* isc_utility */ | |
1168 | + } isc_22; | |
1169 | +/************************************** | |
1170 | + * | |
1171 | + * P Y X I S _ r e l a t i o n s | |
1172 | + * | |
1173 | + ************************************** | |
1174 | + * | |
1175 | + * Functional description | |
1176 | + * Get menu all of relations, etc. | |
1177 | + * | |
1178 | + **************************************/ | |
1179 | +OBJ menu, entree; | |
1180 | +int *handle; | |
1181 | + | |
1182 | +DB = *dbb; | |
1183 | +gds__trans = *transaction; | |
1184 | +menu = PYXIS_create_object (NULL_PTR, 0); | |
1185 | +handle = NULL; | |
1186 | + | |
1187 | +/*FOR (REQUEST_HANDLE handle) | |
1188 | + X IN RDB$RELATIONS WITH X.RDB$SYSTEM_FLAG == 0 SORTED BY X.RDB$RELATION_NAME*/ | |
1189 | +{ | |
1190 | +if (!handle) | |
1191 | + isc_compile_request ((long*) 0L, &DB, &handle, (short) sizeof (isc_21), (char ISC_FAR *) isc_21); | |
1192 | +isc_start_request ((long*) 0L, &handle, &gds__trans, (short) 0); | |
1193 | +while (1) | |
1194 | + { | |
1195 | + isc_receive ((long*) 0L, &handle, (short) 0, (short) 34, &isc_22, (short) 0); | |
1196 | + if (!isc_22.isc_24) break; | |
1197 | + zap_string (/*X.RDB$RELATION_NAME*/ | |
1198 | + isc_22.isc_23); | |
1199 | + PYXIS_create_entree (menu, /*X.RDB$RELATION_NAME*/ | |
1200 | + isc_22.isc_23, 0, NULL_PTR); | |
1201 | +/*END_FOR;*/ | |
1202 | + } | |
1203 | +} | |
1204 | + | |
1205 | +gds__release_request (gds__status, GDS_REF (handle)); | |
1206 | + | |
1207 | +return menu; | |
1208 | +} | |
1209 | + | |
1210 | +\f | |
1211 | +PYXIS_store_form (dbb, transaction, form_name, form) | |
1212 | + SLONG **dbb, **transaction; | |
1213 | + TEXT *form_name; | |
1214 | + OBJ form; | |
1215 | +{ | |
1216 | + struct { | |
1217 | + ISC_QUAD isc_3; /* PYXIS$FORM */ | |
1218 | + char isc_4 [32]; /* PYXIS$FORM_NAME */ | |
1219 | + } isc_2; | |
1220 | + isc_blob_handle isc_5; /* blob handle */ | |
1221 | + char isc_6 [80]; /* blob segment */ | |
1222 | + unsigned short isc_7; /* segment length */ | |
1223 | + struct { | |
1224 | + short isc_17; /* isc_utility */ | |
1225 | + } isc_16; | |
1226 | + struct { | |
1227 | + ISC_QUAD isc_15; /* PYXIS$FORM */ | |
1228 | + } isc_14; | |
1229 | + struct { | |
1230 | + ISC_QUAD isc_12; /* PYXIS$FORM */ | |
1231 | + short isc_13; /* isc_utility */ | |
1232 | + } isc_11; | |
1233 | + struct { | |
1234 | + char isc_10 [32]; /* PYXIS$FORM_NAME */ | |
1235 | + } isc_9; | |
1236 | + isc_blob_handle isc_18; /* blob handle */ | |
1237 | + char isc_19 [80]; /* blob segment */ | |
1238 | + unsigned short isc_20; /* segment length */ | |
1239 | +/************************************** | |
1240 | + * | |
1241 | + * P Y X I S _ s t o r e _ f o r m | |
1242 | + * | |
1243 | + ************************************** | |
1244 | + * | |
1245 | + * Functional description | |
1246 | + * Store a form in a database. If the form already exists, replace it. | |
1247 | + * | |
1248 | + **************************************/ | |
1249 | +SLONG size; | |
1250 | +TEXT *ptr, buffer [4096], *buff, *p; | |
1251 | +int *handle; | |
1252 | +USHORT seg_len; | |
1253 | + | |
1254 | +DB = *dbb; | |
1255 | +gds__trans = *transaction; | |
1256 | +handle = NULL; | |
1257 | +ptr = NULL_PTR; | |
1258 | +seg_len = sizeof (buffer); | |
1259 | + | |
1260 | +/* If local buffer is big enough use it; otherwise allocate buffer big enough */ | |
1261 | + | |
1262 | +size = PYXIS_dump_length (form); | |
1263 | +buff = buffer; | |
1264 | + | |
1265 | +if (size > sizeof (buffer)) | |
1266 | + buff = ptr = (TEXT*) gds__alloc (size); | |
1267 | + | |
1268 | +/* Linearize the form */ | |
1269 | + | |
1270 | +p = buff; | |
1271 | +PYXIS_dump (form, &p); | |
1272 | +size = p - buff; | |
1273 | + | |
1274 | +/* If form exists, modify it */ | |
1275 | + | |
1276 | +/*FOR (REQUEST_HANDLE handle) | |
1277 | + X IN PYXIS$FORMS WITH X.PYXIS$FORM_NAME EQ form_name*/ | |
1278 | +{ | |
1279 | +if (!handle) | |
1280 | + isc_compile_request ((long*) 0L, &DB, &handle, (short) sizeof (isc_8), (char ISC_FAR *) isc_8); | |
1281 | +isc_18 = 0; | |
1282 | +isc_vtov (form_name, isc_9.isc_10, 32); | |
1283 | +isc_start_and_send ((long*) 0L, &handle, &gds__trans, (short) 0, (short) 32, &isc_9, (short) 0); | |
1284 | +while (1) | |
1285 | + { | |
1286 | + isc_receive ((long*) 0L, &handle, (short) 1, (short) 10, &isc_11, (short) 0); | |
1287 | + if (!isc_11.isc_13) break; | |
1288 | + /*MODIFY X USING*/ | |
1289 | + { | |
1290 | + /*CREATE_BLOB B IN X.PYXIS$FORM;*/ | |
1291 | + { | |
1292 | + isc_create_blob2 ((long*) 0L, &DB, &gds__trans, &isc_18, &isc_11.isc_12, (short) 0, (char*) 0); | |
1293 | + } | |
1294 | + while (size > 0) | |
1295 | + { | |
1296 | + seg_len = MIN (seg_len, size); | |
1297 | + if (gds__put_segment (gds__status, | |
1298 | + GDS_REF (/*B*/ | |
1299 | + isc_18), | |
1300 | + seg_len, | |
1301 | + GDS_VAL (buff))) | |
1302 | + break; | |
1303 | + buff += seg_len; | |
1304 | + size -= seg_len; | |
1305 | + } | |
1306 | + if (gds__status[1]) | |
1307 | + gds__print_status (gds__status); | |
1308 | + /*CLOSE_BLOB B;*/ | |
1309 | + { | |
1310 | + isc_close_blob ((long*) 0L, &isc_18); | |
1311 | + } | |
1312 | + /*END_MODIFY;*/ | |
1313 | + isc_14.isc_15 = isc_11.isc_12; | |
1314 | + isc_send ((long*) 0L, &handle, (short) 2, (short) 8, &isc_14, (short) 0); | |
1315 | + } | |
1316 | + if (ptr) | |
1317 | + gds__free (ptr); | |
1318 | + gds__release_request (gds__status, GDS_REF (handle)); | |
1319 | + return SUCCESS; /* gpre generates a gds__send call after this which | |
1320 | + can never be reached; but it's ok */ | |
1321 | +/*END_FOR;*/ | |
1322 | + isc_send ((long*) 0L, &handle, (short) 3, (short) 2, &isc_16, (short) 0); | |
1323 | + } | |
1324 | +} | |
1325 | + | |
1326 | +gds__release_request (gds__status, GDS_REF (handle)); | |
1327 | + | |
1328 | +/* Form doesn't exist -- store a new record */ | |
1329 | + | |
1330 | +/*STORE (REQUEST_HANDLE handle) | |
1331 | + X IN PYXIS$FORMS*/ | |
1332 | +{ | |
1333 | + | |
1334 | +if (!handle) | |
1335 | + isc_compile_request ((long*) 0L, &DB, &handle, (short) sizeof (isc_1), (char ISC_FAR *) isc_1); | |
1336 | +isc_5 = 0; | |
1337 | +isc_2.isc_3 = isc_blob_null; | |
1338 | + strcpy (/*X.PYXIS$FORM_NAME*/ | |
1339 | + isc_2.isc_4, form_name); | |
1340 | + /*CREATE_BLOB B IN X.PYXIS$FORM;*/ | |
1341 | + { | |
1342 | + isc_create_blob2 ((long*) 0L, &DB, &gds__trans, &isc_5, &isc_2.isc_3, (short) 0, (char*) 0); | |
1343 | + } | |
1344 | + while (size > 0) | |
1345 | + { | |
1346 | + seg_len = MIN (seg_len, size); | |
1347 | + if (gds__put_segment (gds__status, | |
1348 | + GDS_REF (/*B*/ | |
1349 | + isc_5), | |
1350 | + seg_len, | |
1351 | + GDS_VAL (buff))) | |
1352 | + break; | |
1353 | + buff += seg_len; | |
1354 | + size -= seg_len; | |
1355 | + } | |
1356 | + if (gds__status[1]) | |
1357 | + gds__print_status (gds__status); | |
1358 | + /*CLOSE_BLOB B;*/ | |
1359 | + { | |
1360 | + isc_close_blob ((long*) 0L, &isc_5); | |
1361 | + } | |
1362 | +/*END_STORE;*/ | |
1363 | + | |
1364 | +isc_start_and_send ((long*) 0L, &handle, &gds__trans, (short) 0, (short) 40, &isc_2, (short) 0); | |
1365 | +} | |
1366 | + | |
1367 | +gds__release_request (gds__status, GDS_REF (handle)); | |
1368 | + | |
1369 | +if (ptr) | |
1370 | + gds__free (ptr); | |
1371 | +} | |
1372 | +\f | |
1373 | +static zap_string (string) | |
1374 | + TEXT *string; | |
1375 | +{ | |
1376 | +/************************************** | |
1377 | + * | |
1378 | + * z a p _ s t r i n g | |
1379 | + * | |
1380 | + ************************************** | |
1381 | + * | |
1382 | + * Functional description | |
1383 | + * Zap trailing blanks in a string. | |
1384 | + * | |
1385 | + **************************************/ | |
1386 | + | |
1387 | +while (*string && *string != ' ') | |
1388 | + string++; | |
1389 | + | |
1390 | +*string = 0; | |
1391 | +} |