2 /* Module: columninfo.c
4 * Description: This module contains routines related to
5 * reading and storing the field information from a query.
7 * Classes: ColumnInfoClass (Functions prefix: "CI_")
11 * Comments: See "notice.txt" for copyright and license information.
15 #include "columninfo.h"
26 rv = (ColumnInfoClass *) malloc(sizeof(ColumnInfoClass));
33 rv->display_size = NULL;
40 CI_Destructor(ColumnInfoClass *self)
47 /* Read in field descriptions.
48 If self is not null, then also store the information.
49 If self is null, then just read, don't store.
52 CI_read_fields(ColumnInfoClass *self, SocketClass *sock)
58 char new_field_name[MAX_MESSAGE_LEN+1];
61 /* at first read in the number of fields that are in the query */
62 new_num_fields = (Int2) SOCK_get_int(sock, sizeof(Int2));
64 mylog("num_fields = %d\n", new_num_fields);
66 if (self) { /* according to that allocate memory */
67 CI_set_num_fields(self, new_num_fields);
70 /* now read in the descriptions */
71 for(lf = 0; lf < new_num_fields; lf++) {
73 SOCK_get_string(sock, new_field_name, MAX_MESSAGE_LEN);
74 new_adtid = (Oid) SOCK_get_int(sock, 4);
75 new_adtsize = (Int2) SOCK_get_int(sock, 2);
77 mylog("CI_read_fields: fieldname='%s', adtid=%d, adtsize=%d\n", new_field_name, new_adtid, new_adtsize);
80 CI_set_field_info(self, lf, new_field_name, new_adtid, new_adtsize);
83 return (SOCK_get_errcode(sock) == 0);
89 CI_free_memory(ColumnInfoClass *self)
92 int num_fields = self->num_fields;
94 for (lf = 0; lf < num_fields; lf++) {
96 free (self->name[lf]);
99 /* Safe to call even if null */
103 free(self->display_size);
107 CI_set_num_fields(ColumnInfoClass *self, int new_num_fields)
109 CI_free_memory(self); /* always safe to call */
111 self->num_fields = new_num_fields;
113 self->name = (char **) malloc (sizeof(char *) * self->num_fields);
114 self->adtid = (Oid *) malloc (sizeof(Oid) * self->num_fields);
115 self->adtsize = (Int2 *) malloc (sizeof(Int2) * self->num_fields);
116 self->display_size = (Int2 *) malloc(sizeof(Int2) * self->num_fields);
120 CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
121 Oid new_adtid, Int2 new_adtsize)
125 if((field_num < 0) || (field_num >= self->num_fields)) {
130 self->name[field_num] = strdup(new_name);
131 self->adtid[field_num] = new_adtid;
132 self->adtsize[field_num] = new_adtsize;
134 self->display_size[field_num] = 0;