1998-06-03 22:33:45 +02:00
|
|
|
|
|
|
|
/* Module: columninfo.c
|
|
|
|
*
|
|
|
|
* Description: This module contains routines related to
|
|
|
|
* reading and storing the field information from a query.
|
|
|
|
*
|
|
|
|
* Classes: ColumnInfoClass (Functions prefix: "CI_")
|
|
|
|
*
|
|
|
|
* API functions: none
|
|
|
|
*
|
|
|
|
* Comments: See "notice.txt" for copyright and license information.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "columninfo.h"
|
1998-04-13 17:02:05 +02:00
|
|
|
#include "socket.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <malloc.h>
|
1998-07-23 01:47:48 +02:00
|
|
|
#include <string.h>
|
1998-04-13 17:02:05 +02:00
|
|
|
|
|
|
|
ColumnInfoClass *
|
|
|
|
CI_Constructor()
|
|
|
|
{
|
|
|
|
ColumnInfoClass *rv;
|
|
|
|
|
|
|
|
rv = (ColumnInfoClass *) malloc(sizeof(ColumnInfoClass));
|
|
|
|
|
|
|
|
if (rv) {
|
|
|
|
rv->num_fields = 0;
|
|
|
|
rv->name = NULL;
|
|
|
|
rv->adtid = NULL;
|
|
|
|
rv->adtsize = NULL;
|
1998-06-03 22:33:45 +02:00
|
|
|
rv->display_size = NULL;
|
1998-04-13 17:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CI_Destructor(ColumnInfoClass *self)
|
|
|
|
{
|
|
|
|
CI_free_memory(self);
|
|
|
|
|
|
|
|
free(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in field descriptions.
|
|
|
|
If self is not null, then also store the information.
|
|
|
|
If self is null, then just read, don't store.
|
|
|
|
*/
|
|
|
|
char
|
|
|
|
CI_read_fields(ColumnInfoClass *self, SocketClass *sock)
|
|
|
|
{
|
|
|
|
Int2 lf;
|
|
|
|
int new_num_fields;
|
|
|
|
Oid new_adtid;
|
|
|
|
Int2 new_adtsize;
|
|
|
|
char new_field_name[MAX_MESSAGE_LEN+1];
|
1998-06-03 22:33:45 +02:00
|
|
|
|
1998-04-13 17:02:05 +02:00
|
|
|
|
|
|
|
/* at first read in the number of fields that are in the query */
|
|
|
|
new_num_fields = (Int2) SOCK_get_int(sock, sizeof(Int2));
|
|
|
|
|
|
|
|
mylog("num_fields = %d\n", new_num_fields);
|
|
|
|
|
|
|
|
if (self) { /* according to that allocate memory */
|
|
|
|
CI_set_num_fields(self, new_num_fields);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now read in the descriptions */
|
|
|
|
for(lf = 0; lf < new_num_fields; lf++) {
|
|
|
|
|
|
|
|
SOCK_get_string(sock, new_field_name, MAX_MESSAGE_LEN);
|
|
|
|
new_adtid = (Oid) SOCK_get_int(sock, 4);
|
|
|
|
new_adtsize = (Int2) SOCK_get_int(sock, 2);
|
|
|
|
|
|
|
|
mylog("CI_read_fields: fieldname='%s', adtid=%d, adtsize=%d\n", new_field_name, new_adtid, new_adtsize);
|
|
|
|
|
|
|
|
if (self)
|
|
|
|
CI_set_field_info(self, lf, new_field_name, new_adtid, new_adtsize);
|
|
|
|
}
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return SOCK_get_errcode(sock) == 0;
|
1998-04-13 17:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CI_free_memory(ColumnInfoClass *self)
|
|
|
|
{
|
|
|
|
register Int2 lf;
|
|
|
|
int num_fields = self->num_fields;
|
|
|
|
|
|
|
|
for (lf = 0; lf < num_fields; lf++) {
|
|
|
|
if( self->name[lf])
|
|
|
|
free (self->name[lf]);
|
|
|
|
}
|
1998-06-03 22:33:45 +02:00
|
|
|
|
1998-04-13 17:02:05 +02:00
|
|
|
/* Safe to call even if null */
|
|
|
|
free(self->name);
|
|
|
|
free(self->adtid);
|
|
|
|
free(self->adtsize);
|
1998-06-03 22:33:45 +02:00
|
|
|
free(self->display_size);
|
1998-04-13 17:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CI_set_num_fields(ColumnInfoClass *self, int new_num_fields)
|
|
|
|
{
|
|
|
|
CI_free_memory(self); /* always safe to call */
|
|
|
|
|
|
|
|
self->num_fields = new_num_fields;
|
|
|
|
|
|
|
|
self->name = (char **) malloc (sizeof(char *) * self->num_fields);
|
|
|
|
self->adtid = (Oid *) malloc (sizeof(Oid) * self->num_fields);
|
|
|
|
self->adtsize = (Int2 *) malloc (sizeof(Int2) * self->num_fields);
|
1998-06-03 22:33:45 +02:00
|
|
|
self->display_size = (Int2 *) malloc(sizeof(Int2) * self->num_fields);
|
1998-04-13 17:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
|
|
|
|
Oid new_adtid, Int2 new_adtsize)
|
|
|
|
{
|
|
|
|
|
|
|
|
// check bounds
|
|
|
|
if((field_num < 0) || (field_num >= self->num_fields)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// store the info
|
|
|
|
self->name[field_num] = strdup(new_name);
|
|
|
|
self->adtid[field_num] = new_adtid;
|
|
|
|
self->adtsize[field_num] = new_adtsize;
|
|
|
|
|
1998-06-03 22:33:45 +02:00
|
|
|
self->display_size[field_num] = 0;
|
1998-04-13 17:02:05 +02:00
|
|
|
}
|
|
|
|
|