7 static char *rcsid_tst_c = "$Header$";
10 /************************************************************************/
14 /* A test program for the client library interface.
16 /* Author: Noah Mendelsohn
18 /* Copyright: 1986 MIT Project Athena
20 /************************************************************************/
25 char *field_names[] = {"desc",
30 FIELD_TYPE field_types[] = {STRING_T, /* desc */
34 INTEGER_T}; /* count */
44 \f /************************************************************
46 ************************************************************/
49 * Declare the names of fields to be retrieved and their types
55 * The following defines are for convenience in addressing
66 * Declare the relation and related data structures for
67 * storing the retrieved data.
70 TUPLE_DESCRIPTOR tuple_desc;
71 RELATION retrieved_data, decoded_rel;
74 * Declarations for misc. variables
77 TUPLE t; /* next tuple to print */
81 int rc; /* A return code */
83 \f /************************************************************
84 * EXECUTION BEGINS HERE *
85 ************************************************************/
88 * Build the descriptor describing the layout of the tuples
89 * to be retrieved, and create an empty relation into which
90 * the retrieval will be done.
93 gdb_init(); /* initialize the global */
94 /* database facility */
96 printf("tst.c: attempting to create tuple descriptor\n");
98 tuple_desc = create_tuple_descriptor(field_count, field_names,
101 printf("tst.c: tuple desc created.. attempting to create relation\n");
102 retrieved_data = create_relation(tuple_desc);
104 printf("tst.c: relation created, formatting descriptor\n");
107 print_tuple_descriptor("Test Tuple Descriptor", tuple_desc);
109 printf("tst.c: descriptor formatted, formatting relation\n");
111 print_relation("Test Relation", retrieved_data);
113 printf("Creating tuples\n");
115 for (i=0; i<3; i++) {
116 t = create_tuple(tuple_desc);
120 fprintf(stderr, "Following tuple should contain null fields:\n\n");
122 print_tuple("A NULL TUPLE", t);
124 *(int *)FIELD_FROM_TUPLE(t, CODE) = i+1;
126 *(double *)FIELD_FROM_TUPLE(t, COST) = 12.34 * (i+1);
127 string_alloc((STRING *)FIELD_FROM_TUPLE(t,MAN), 20);
128 strcpy(STRING_DATA(*((STRING *)FIELD_FROM_TUPLE(t,MAN))),
129 "Manager field data");
130 ADD_TUPLE_TO_RELATION(retrieved_data, t);
134 printf("tst.c: relation initialized, formatting relation\n");
136 print_relation("Test Relation", retrieved_data);
140 * Try to encode the entire relation!!
143 printf("Attempting to encode the relation\n");
145 coded_len = FCN_PROPERTY(RELATION_T, CODED_LENGTH_PROPERTY)
146 (&retrieved_data, NULL);
148 coded_dat = (char *)malloc(coded_len);
150 FCN_PROPERTY(RELATION_T, ENCODE_PROPERTY)
151 (&retrieved_data, NULL, coded_dat);
153 printf("Relation encoding complete, writing file \n\n");
155 coded_file = fopen("coded.dat", "w");
157 fwrite(coded_dat, 1, coded_len, coded_file);
161 printf("File written\n");
163 printf("Decoding relation\n\n");
165 FCN_PROPERTY(RELATION_T, DECODE_PROPERTY)
166 (&decoded_rel, NULL, coded_dat);
168 printf("Relation decoded!! Printing it\n\n");
170 print_relation("Decoded Relation", decoded_rel);
173 printf("tst.c: exit\n");