2001-02-10 03:31:31 +01:00
|
|
|
#include "postgres_fe.h"
|
1998-02-05 16:46:43 +01:00
|
|
|
|
1998-02-27 13:59:33 +01:00
|
|
|
#include "extern.h"
|
1998-02-05 16:46:43 +01:00
|
|
|
|
2001-12-23 13:17:41 +01:00
|
|
|
#define indicator_set ind_type != NULL && ind_type->type != ECPGt_NO_INDICATOR
|
2001-12-09 16:27:49 +01:00
|
|
|
|
2001-12-04 13:33:15 +01:00
|
|
|
struct ECPGstruct_member struct_no_indicator = {"no_indicator", &ecpg_no_indicator, NULL};
|
|
|
|
|
1998-02-17 02:48:12 +01:00
|
|
|
/* malloc + error check */
|
1998-02-26 05:46:47 +01:00
|
|
|
void *
|
|
|
|
mm_alloc(size_t size)
|
1998-02-17 02:48:12 +01:00
|
|
|
{
|
1998-02-26 05:46:47 +01:00
|
|
|
void *ptr = malloc(size);
|
1998-02-17 02:48:12 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
if (ptr == NULL)
|
2001-12-09 16:27:49 +01:00
|
|
|
mmerror(OUT_OF_MEMORY, ET_FATAL, "Out of memory\n");
|
1998-02-17 02:48:12 +01:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return ptr;
|
1998-02-17 02:48:12 +01:00
|
|
|
}
|
|
|
|
|
1998-10-03 04:33:51 +02:00
|
|
|
/* strdup + error check */
|
|
|
|
char *
|
|
|
|
mm_strdup(const char *string)
|
|
|
|
{
|
|
|
|
char *new = strdup(string);
|
|
|
|
|
|
|
|
if (new == NULL)
|
2001-12-09 16:27:49 +01:00
|
|
|
mmerror(OUT_OF_MEMORY, ET_FATAL, "Out of memory\n");
|
2002-09-04 22:31:48 +02:00
|
|
|
|
1998-10-03 04:33:51 +02:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
1998-05-06 15:03:47 +02:00
|
|
|
/* duplicate memberlist */
|
1999-02-20 08:01:08 +01:00
|
|
|
struct ECPGstruct_member *
|
|
|
|
ECPGstruct_member_dup(struct ECPGstruct_member * rm)
|
1998-05-06 15:03:47 +02:00
|
|
|
{
|
1998-09-01 06:40:42 +02:00
|
|
|
struct ECPGstruct_member *new = NULL;
|
|
|
|
|
|
|
|
while (rm)
|
|
|
|
{
|
|
|
|
struct ECPGtype *type;
|
|
|
|
|
2001-12-23 13:17:41 +01:00
|
|
|
switch (rm->type->type)
|
1998-09-01 06:40:42 +02:00
|
|
|
{
|
|
|
|
case ECPGt_struct:
|
1999-02-28 08:25:34 +01:00
|
|
|
case ECPGt_union:
|
2001-12-23 13:17:41 +01:00
|
|
|
type = ECPGmake_struct_type(rm->type->u.members, rm->type->type, rm->type->struct_sizeof);
|
1998-09-01 06:40:42 +02:00
|
|
|
break;
|
|
|
|
case ECPGt_array:
|
2001-12-23 13:17:41 +01:00
|
|
|
type = ECPGmake_array_type(ECPGmake_simple_type(rm->type->u.element->type, rm->type->u.element->size), rm->type->size);
|
1998-09-01 06:40:42 +02:00
|
|
|
break;
|
|
|
|
default:
|
2001-12-23 13:17:41 +01:00
|
|
|
type = ECPGmake_simple_type(rm->type->type, rm->type->size);
|
1998-09-01 06:40:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ECPGmake_struct_member(rm->name, type, &new);
|
|
|
|
|
|
|
|
rm = rm->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (new);
|
1998-05-06 15:03:47 +02:00
|
|
|
}
|
1998-02-05 16:46:43 +01:00
|
|
|
|
|
|
|
/* The NAME argument is copied. The type argument is preserved as a pointer. */
|
1998-05-26 15:43:55 +02:00
|
|
|
void
|
1998-04-27 16:35:58 +02:00
|
|
|
ECPGmake_struct_member(char *name, struct ECPGtype * type, struct ECPGstruct_member ** start)
|
1998-02-05 16:46:43 +01:00
|
|
|
{
|
1998-04-27 16:35:58 +02:00
|
|
|
struct ECPGstruct_member *ptr,
|
1999-02-20 08:01:08 +01:00
|
|
|
*ne =
|
|
|
|
(struct ECPGstruct_member *) mm_alloc(sizeof(struct ECPGstruct_member));
|
1998-02-17 02:48:12 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
ne->name = strdup(name);
|
2001-12-23 13:17:41 +01:00
|
|
|
ne->type = type;
|
1998-02-26 05:46:47 +01:00
|
|
|
ne->next = NULL;
|
1998-02-05 16:46:43 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
for (ptr = *start; ptr && ptr->next; ptr = ptr->next);
|
1998-02-05 16:46:43 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
if (ptr)
|
|
|
|
ptr->next = ne;
|
|
|
|
else
|
|
|
|
*start = ne;
|
1998-02-05 16:46:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ECPGtype *
|
2003-05-14 16:37:36 +02:00
|
|
|
ECPGmake_simple_type(enum ECPGttype type, char *size)
|
1998-02-05 16:46:43 +01:00
|
|
|
{
|
1998-02-26 05:46:47 +01:00
|
|
|
struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
|
1998-02-05 16:46:43 +01:00
|
|
|
|
2001-12-23 13:17:41 +01:00
|
|
|
ne->type = type;
|
|
|
|
ne->size = size;
|
1998-02-26 05:46:47 +01:00
|
|
|
ne->u.element = 0;
|
2001-12-23 13:17:41 +01:00
|
|
|
ne->struct_sizeof = NULL;
|
1998-02-05 16:46:43 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
return ne;
|
1998-02-05 16:46:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ECPGtype *
|
2003-05-14 16:37:36 +02:00
|
|
|
ECPGmake_array_type(struct ECPGtype * type, char *size)
|
1998-02-05 16:46:43 +01:00
|
|
|
{
|
2001-12-23 13:17:41 +01:00
|
|
|
struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, size);
|
1998-02-05 16:46:43 +01:00
|
|
|
|
2001-12-23 13:17:41 +01:00
|
|
|
ne->u.element = type;
|
1998-02-05 16:46:43 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
return ne;
|
1998-02-05 16:46:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ECPGtype *
|
2001-12-23 13:17:41 +01:00
|
|
|
ECPGmake_struct_type(struct ECPGstruct_member * rm, enum ECPGttype type, char *struct_sizeof)
|
1998-02-05 16:46:43 +01:00
|
|
|
{
|
2003-05-14 16:37:36 +02:00
|
|
|
struct ECPGtype *ne = ECPGmake_simple_type(type, make_str("1"));
|
1998-02-05 16:46:43 +01:00
|
|
|
|
1999-02-20 08:01:08 +01:00
|
|
|
ne->u.members = ECPGstruct_member_dup(rm);
|
2001-12-23 13:17:41 +01:00
|
|
|
ne->struct_sizeof = struct_sizeof;
|
1998-02-05 16:46:43 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
return ne;
|
1998-02-05 16:46:43 +01:00
|
|
|
}
|
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
static const char *
|
2001-12-23 13:17:41 +01:00
|
|
|
get_type(enum ECPGttype type)
|
1998-05-06 15:03:47 +02:00
|
|
|
{
|
2001-12-23 13:17:41 +01:00
|
|
|
switch (type)
|
1998-09-01 06:40:42 +02:00
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
case ECPGt_char:
|
1998-09-01 06:40:42 +02:00
|
|
|
return ("ECPGt_char");
|
|
|
|
break;
|
|
|
|
case ECPGt_unsigned_char:
|
|
|
|
return ("ECPGt_unsigned_char");
|
|
|
|
break;
|
|
|
|
case ECPGt_short:
|
|
|
|
return ("ECPGt_short");
|
|
|
|
break;
|
|
|
|
case ECPGt_unsigned_short:
|
|
|
|
return ("ECPGt_unsigned_short");
|
|
|
|
break;
|
|
|
|
case ECPGt_int:
|
|
|
|
return ("ECPGt_int");
|
|
|
|
break;
|
|
|
|
case ECPGt_unsigned_int:
|
|
|
|
return ("ECPGt_unsigned_int");
|
|
|
|
break;
|
|
|
|
case ECPGt_long:
|
|
|
|
return ("ECPGt_long");
|
|
|
|
break;
|
|
|
|
case ECPGt_unsigned_long:
|
2000-09-19 13:47:16 +02:00
|
|
|
return ("ECPGt_unsigned_long");
|
|
|
|
break;
|
|
|
|
case ECPGt_long_long:
|
|
|
|
return ("ECPGt_long_long");
|
|
|
|
break;
|
|
|
|
case ECPGt_unsigned_long_long:
|
|
|
|
return ("ECPGt_unsigned_long_long");
|
1998-09-01 06:40:42 +02:00
|
|
|
break;
|
|
|
|
case ECPGt_float:
|
|
|
|
return ("ECPGt_float");
|
|
|
|
break;
|
|
|
|
case ECPGt_double:
|
|
|
|
return ("ECPGt_double");
|
|
|
|
break;
|
|
|
|
case ECPGt_bool:
|
|
|
|
return ("ECPGt_bool");
|
|
|
|
break;
|
|
|
|
case ECPGt_varchar:
|
|
|
|
return ("ECPGt_varchar");
|
|
|
|
case ECPGt_NO_INDICATOR: /* no indicator */
|
|
|
|
return ("ECPGt_NO_INDICATOR");
|
|
|
|
break;
|
1999-05-25 18:15:34 +02:00
|
|
|
case ECPGt_char_variable: /* string that should not be
|
2000-04-12 19:17:23 +02:00
|
|
|
* quoted */
|
1999-02-20 08:01:08 +01:00
|
|
|
return ("ECPGt_char_variable");
|
|
|
|
break;
|
2003-06-20 14:00:59 +02:00
|
|
|
case ECPGt_const: /* constant string quoted */
|
|
|
|
return ("ECPGt_const");
|
|
|
|
break;
|
2003-03-16 11:42:54 +01:00
|
|
|
case ECPGt_numeric:
|
|
|
|
return ("ECPGt_numeric");
|
|
|
|
break;
|
2003-03-27 15:29:17 +01:00
|
|
|
case ECPGt_interval:
|
|
|
|
return ("ECPGt_interval");
|
|
|
|
break;
|
2001-09-19 16:09:32 +02:00
|
|
|
case ECPGt_descriptor:
|
|
|
|
return ("ECPGt_descriptor");
|
|
|
|
break;
|
2003-03-20 16:56:50 +01:00
|
|
|
case ECPGt_date:
|
|
|
|
return ("ECPGt_date");
|
|
|
|
break;
|
|
|
|
case ECPGt_timestamp:
|
|
|
|
return ("ECPGt_timestamp");
|
|
|
|
break;
|
1998-09-01 06:40:42 +02:00
|
|
|
default:
|
2001-12-23 13:17:41 +01:00
|
|
|
sprintf(errortext, "illegal variable type %d\n", type);
|
1999-02-23 13:57:03 +01:00
|
|
|
yyerror(errortext);
|
1998-09-01 06:40:42 +02:00
|
|
|
}
|
1999-05-25 18:15:34 +02:00
|
|
|
|
1999-02-28 08:25:34 +01:00
|
|
|
return NULL;
|
1998-05-06 15:03:47 +02:00
|
|
|
}
|
1998-02-05 16:46:43 +01:00
|
|
|
|
|
|
|
/* Dump a type.
|
|
|
|
The type is dumped as:
|
1998-02-26 05:46:47 +01:00
|
|
|
type-tag <comma> - enum ECPGttype
|
2002-09-04 22:31:48 +02:00
|
|
|
reference-to-variable <comma> - char *
|
1998-02-26 05:46:47 +01:00
|
|
|
size <comma> - long size of this field (if varchar)
|
|
|
|
arrsize <comma> - long number of elements in the arr
|
|
|
|
offset <comma> - offset to the next element
|
1998-02-05 16:46:43 +01:00
|
|
|
Where:
|
|
|
|
type-tag is one of the simple types or varchar.
|
|
|
|
reference-to-variable can be a reference to a struct element.
|
|
|
|
arrsize is the size of the array in case of array fetches. Otherwise 0.
|
|
|
|
size is the maxsize in case it is a varchar. Otherwise it is the size of
|
1998-04-27 16:35:58 +02:00
|
|
|
the variable (required to do array fetches of structs).
|
1998-02-05 16:46:43 +01:00
|
|
|
*/
|
2001-12-23 13:17:41 +01:00
|
|
|
static void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
|
2003-05-14 16:37:36 +02:00
|
|
|
char *varcharsize,
|
|
|
|
char *arrsiz, const char *siz, const char *prefix);
|
|
|
|
static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz,
|
2001-12-23 13:17:41 +01:00
|
|
|
struct ECPGtype * type, struct ECPGtype * ind_type, const char *offset, const char *prefix, const char *ind_prefix);
|
1998-02-05 16:46:43 +01:00
|
|
|
|
|
|
|
void
|
2003-05-14 16:37:36 +02:00
|
|
|
ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
|
2003-05-29 15:59:26 +02:00
|
|
|
const char *ind_name, struct ECPGtype * ind_type,
|
2003-05-14 16:37:36 +02:00
|
|
|
const char *prefix, const char *ind_prefix,
|
|
|
|
char *arr_str_siz, const char *struct_sizeof,
|
|
|
|
const char *ind_struct_sizeof)
|
1998-02-05 16:46:43 +01:00
|
|
|
{
|
2001-12-23 13:17:41 +01:00
|
|
|
switch (type->type)
|
1998-09-01 06:40:42 +02:00
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
case ECPGt_array:
|
2001-12-23 13:17:41 +01:00
|
|
|
if (indicator_set && ind_type->type != ECPGt_array)
|
2001-12-09 16:27:49 +01:00
|
|
|
mmerror(INDICATOR_NOT_ARRAY, ET_FATAL, "Indicator for array/pointer has to be array/pointer.\n");
|
2001-12-23 13:17:41 +01:00
|
|
|
switch (type->u.element->type)
|
1998-09-01 06:40:42 +02:00
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
case ECPGt_array:
|
2001-12-09 16:27:49 +01:00
|
|
|
mmerror(PARSE_ERROR, ET_ERROR, "No nested arrays allowed (except strings)"); /* array of array */
|
1999-02-28 08:25:34 +01:00
|
|
|
break;
|
|
|
|
case ECPGt_struct:
|
|
|
|
case ECPGt_union:
|
2003-05-29 15:59:26 +02:00
|
|
|
ECPGdump_a_struct(o, name,
|
|
|
|
ind_name,
|
|
|
|
type->size,
|
|
|
|
type->u.element,
|
|
|
|
(ind_type->type == ECPGt_NO_INDICATOR) ? ind_type : ind_type->u.element,
|
|
|
|
NULL, prefix, ind_prefix);
|
1999-02-28 08:25:34 +01:00
|
|
|
break;
|
1999-05-25 18:15:34 +02:00
|
|
|
default:
|
2001-12-23 13:17:41 +01:00
|
|
|
if (!IS_SIMPLE_TYPE(type->u.element->type))
|
1999-02-28 08:25:34 +01:00
|
|
|
yyerror("Internal error: unknown datatype, please inform pgsql-bugs@postgresql.org");
|
1999-05-25 18:15:34 +02:00
|
|
|
|
2003-05-29 15:59:26 +02:00
|
|
|
ECPGdump_a_simple(o, name,
|
|
|
|
type->u.element->type,
|
2002-09-04 22:31:48 +02:00
|
|
|
type->u.element->size, type->size, NULL, prefix);
|
2003-05-23 17:19:36 +02:00
|
|
|
|
2001-12-23 13:17:41 +01:00
|
|
|
if (ind_type != NULL)
|
1999-02-20 08:01:08 +01:00
|
|
|
{
|
2001-12-23 13:17:41 +01:00
|
|
|
if (ind_type->type == ECPGt_NO_INDICATOR)
|
2003-05-14 16:37:36 +02:00
|
|
|
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix);
|
2000-10-16 21:53:04 +02:00
|
|
|
else
|
2003-05-23 17:19:36 +02:00
|
|
|
{
|
2003-05-29 15:59:26 +02:00
|
|
|
ECPGdump_a_simple(o, ind_name, ind_type->u.element->type,
|
|
|
|
ind_type->u.element->size, ind_type->size, NULL, prefix);
|
2003-05-23 17:19:36 +02:00
|
|
|
}
|
1999-02-28 08:25:34 +01:00
|
|
|
}
|
1998-09-01 06:40:42 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ECPGt_struct:
|
2001-12-23 13:17:41 +01:00
|
|
|
if (indicator_set && ind_type->type != ECPGt_struct)
|
2001-12-09 16:27:49 +01:00
|
|
|
mmerror(INDICATOR_NOT_STRUCT, ET_FATAL, "Indicator for struct has to be struct.\n");
|
|
|
|
|
2003-05-14 16:37:36 +02:00
|
|
|
ECPGdump_a_struct(o, name, ind_name, make_str("1"), type, ind_type, NULL, prefix, ind_prefix);
|
1998-09-01 06:40:42 +02:00
|
|
|
break;
|
1999-05-25 18:15:34 +02:00
|
|
|
case ECPGt_union: /* cannot dump a complete union */
|
1999-02-28 08:25:34 +01:00
|
|
|
yyerror("Type of union has to be specified");
|
|
|
|
break;
|
|
|
|
case ECPGt_char_variable:
|
2001-12-23 13:17:41 +01:00
|
|
|
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
|
2001-12-09 16:27:49 +01:00
|
|
|
mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
|
|
|
|
|
2003-05-14 16:37:36 +02:00
|
|
|
ECPGdump_a_simple(o, name, type->type, make_str("1"), (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("1"), struct_sizeof, prefix);
|
|
|
|
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix);
|
1999-02-28 08:25:34 +01:00
|
|
|
break;
|
2001-09-19 16:09:32 +02:00
|
|
|
case ECPGt_descriptor:
|
2001-12-23 13:17:41 +01:00
|
|
|
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
|
2001-12-09 16:27:49 +01:00
|
|
|
mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
|
|
|
|
|
2003-05-14 16:37:36 +02:00
|
|
|
ECPGdump_a_simple(o, name, type->type, 0, make_str("-1"), NULL, prefix);
|
|
|
|
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix);
|
2001-09-19 16:09:32 +02:00
|
|
|
break;
|
1998-09-01 06:40:42 +02:00
|
|
|
default:
|
2001-12-23 13:17:41 +01:00
|
|
|
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
|
2001-12-09 16:27:49 +01:00
|
|
|
mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
|
|
|
|
|
2003-05-14 16:37:36 +02:00
|
|
|
ECPGdump_a_simple(o, name, type->type, type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), struct_sizeof, prefix);
|
2001-12-23 13:17:41 +01:00
|
|
|
if (ind_type != NULL)
|
2003-05-14 16:37:36 +02:00
|
|
|
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix);
|
1998-09-01 06:40:42 +02:00
|
|
|
break;
|
1998-02-26 05:46:47 +01:00
|
|
|
}
|
1998-02-05 16:46:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If siz is NULL, then the offset is 0, if not use siz as a
|
1998-04-27 16:35:58 +02:00
|
|
|
string, it represents the offset needed if we are in an array of structs. */
|
1998-05-18 18:05:05 +02:00
|
|
|
static void
|
2001-12-23 13:17:41 +01:00
|
|
|
ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
|
2003-05-14 16:37:36 +02:00
|
|
|
char *varcharsize,
|
|
|
|
char *arrsize,
|
1998-02-26 05:46:47 +01:00
|
|
|
const char *siz,
|
1998-04-21 15:23:24 +02:00
|
|
|
const char *prefix
|
1998-09-01 06:40:42 +02:00
|
|
|
)
|
1998-02-05 16:46:43 +01:00
|
|
|
{
|
2001-12-23 13:17:41 +01:00
|
|
|
if (type == ECPGt_NO_INDICATOR)
|
1998-09-01 06:40:42 +02:00
|
|
|
fprintf(o, "\n\tECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ");
|
2001-12-23 13:17:41 +01:00
|
|
|
else if (type == ECPGt_descriptor)
|
2001-09-19 16:09:32 +02:00
|
|
|
/* remember that name here already contains quotes (if needed) */
|
|
|
|
fprintf(o, "\n\tECPGt_descriptor, %s, 0L, 0L, 0L, ", name);
|
1998-09-01 06:40:42 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
|
|
|
|
char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1);
|
|
|
|
|
2001-12-23 13:17:41 +01:00
|
|
|
switch (type)
|
1998-09-01 06:40:42 +02:00
|
|
|
{
|
|
|
|
case ECPGt_varchar:
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* we have to use the pointer except for arrays with given
|
|
|
|
* bounds
|
|
|
|
*/
|
2003-05-14 16:37:36 +02:00
|
|
|
if (((atoi(arrsize) > 0) ||
|
2003-05-16 11:42:56 +02:00
|
|
|
(atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0)) &&
|
2003-05-14 16:37:36 +02:00
|
|
|
siz == NULL)
|
2000-04-05 11:05:40 +02:00
|
|
|
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
|
|
|
|
else
|
|
|
|
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
|
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
sprintf(offset, "sizeof(struct varchar_%s)", name);
|
|
|
|
break;
|
|
|
|
case ECPGt_char:
|
|
|
|
case ECPGt_unsigned_char:
|
1999-02-20 08:01:08 +01:00
|
|
|
case ECPGt_char_variable:
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* we have to use the pointer except for arrays with given
|
|
|
|
* bounds
|
|
|
|
*/
|
2003-05-14 16:37:36 +02:00
|
|
|
if ((atoi(varcharsize) > 1 ||
|
|
|
|
(atoi(arrsize) > 0) ||
|
|
|
|
(atoi(varcharsize) == 0 && strcmp(varcharsize, "0") != 0) ||
|
|
|
|
(atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0))
|
|
|
|
&& siz == NULL)
|
2000-04-05 11:05:40 +02:00
|
|
|
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
|
|
|
|
else
|
|
|
|
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
|
|
|
|
|
2003-05-14 16:37:36 +02:00
|
|
|
sprintf(offset, "%s*sizeof(char)", strcmp(varcharsize, "0") == 0 ? "1" : varcharsize);
|
1998-09-01 06:40:42 +02:00
|
|
|
break;
|
2003-03-16 11:42:54 +01:00
|
|
|
case ECPGt_numeric:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we have to use a pointer here
|
|
|
|
*/
|
|
|
|
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
|
2003-03-27 15:29:17 +01:00
|
|
|
sprintf(offset, "sizeof(Numeric)");
|
|
|
|
break;
|
|
|
|
case ECPGt_interval:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we have to use a pointer here
|
|
|
|
*/
|
|
|
|
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
|
|
|
|
sprintf(offset, "sizeof(Interval)");
|
2003-03-16 11:42:54 +01:00
|
|
|
break;
|
2003-03-20 16:56:50 +01:00
|
|
|
case ECPGt_date:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we have to use a pointer and translate the variable type
|
|
|
|
*/
|
|
|
|
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
|
|
|
|
sprintf(offset, "sizeof(Date)");
|
|
|
|
break;
|
|
|
|
case ECPGt_timestamp:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we have to use a pointer and translate the variable type
|
|
|
|
*/
|
|
|
|
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
|
|
|
|
sprintf(offset, "sizeof(Date)");
|
|
|
|
break;
|
2003-06-20 14:00:59 +02:00
|
|
|
case ECPGt_const:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* just dump the const as string
|
|
|
|
*/
|
|
|
|
sprintf(variable, "\"%s\"", name);
|
|
|
|
sprintf(offset, "strlen(\"%s\")", name);
|
|
|
|
break;
|
1998-09-01 06:40:42 +02:00
|
|
|
default:
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* we have to use the pointer except for arrays with given
|
|
|
|
* bounds
|
|
|
|
*/
|
2003-05-14 16:37:36 +02:00
|
|
|
if (((atoi(arrsize) > 0) ||
|
2003-05-16 11:42:56 +02:00
|
|
|
(atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0)) &&
|
2003-05-14 16:37:36 +02:00
|
|
|
siz == NULL)
|
2000-04-05 11:05:40 +02:00
|
|
|
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
|
|
|
|
else
|
|
|
|
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
|
|
|
|
|
2001-12-23 13:17:41 +01:00
|
|
|
sprintf(offset, "sizeof(%s)", ECPGtype_name(type));
|
1998-09-01 06:40:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-05-14 16:37:36 +02:00
|
|
|
if (atoi(arrsize) < 0)
|
|
|
|
strcpy(arrsize, "1");
|
|
|
|
|
|
|
|
if (siz == NULL || strcmp(arrsize, "0") == 0 || strcmp(arrsize, "1") == 0)
|
|
|
|
fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, offset);
|
1998-09-01 06:40:42 +02:00
|
|
|
else
|
2003-05-14 16:37:36 +02:00
|
|
|
fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, siz);
|
1998-09-01 06:40:42 +02:00
|
|
|
|
|
|
|
free(variable);
|
|
|
|
free(offset);
|
1998-02-26 05:46:47 +01:00
|
|
|
}
|
1998-02-05 16:46:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-27 16:35:58 +02:00
|
|
|
/* Penetrate a struct and dump the contents. */
|
1998-05-18 18:05:05 +02:00
|
|
|
static void
|
2003-05-14 16:37:36 +02:00
|
|
|
ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz, struct ECPGtype * type, struct ECPGtype * ind_type, const char *offsetarg, const char *prefix, const char *ind_prefix)
|
1998-02-05 16:46:43 +01:00
|
|
|
{
|
1998-02-26 05:46:47 +01:00
|
|
|
/*
|
|
|
|
* If offset is NULL, then this is the first recursive level. If not
|
1998-04-27 16:35:58 +02:00
|
|
|
* then we are in a struct in a struct and the offset is used as
|
1998-02-26 05:46:47 +01:00
|
|
|
* offset.
|
|
|
|
*/
|
1998-09-01 06:40:42 +02:00
|
|
|
struct ECPGstruct_member *p,
|
|
|
|
*ind_p = NULL;
|
1998-02-26 05:46:47 +01:00
|
|
|
char obuf[BUFSIZ];
|
2001-12-09 16:27:49 +01:00
|
|
|
char pbuf[BUFSIZ],
|
1998-09-01 06:40:42 +02:00
|
|
|
ind_pbuf[BUFSIZ];
|
1998-02-26 05:46:47 +01:00
|
|
|
const char *offset;
|
|
|
|
|
|
|
|
if (offsetarg == NULL)
|
|
|
|
{
|
|
|
|
sprintf(obuf, "sizeof(%s)", name);
|
|
|
|
offset = obuf;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
offset = offsetarg;
|
|
|
|
|
2003-05-14 16:37:36 +02:00
|
|
|
if (atoi(arrsiz) == 1)
|
2001-12-08 21:43:35 +01:00
|
|
|
sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);
|
|
|
|
else
|
|
|
|
sprintf(pbuf, "%s%s->", prefix ? prefix : "", name);
|
2002-09-04 22:31:48 +02:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
prefix = pbuf;
|
1998-09-01 06:40:42 +02:00
|
|
|
|
2001-12-23 13:17:41 +01:00
|
|
|
if (ind_type == &ecpg_no_indicator)
|
2001-12-04 13:33:15 +01:00
|
|
|
ind_p = &struct_no_indicator;
|
2001-12-23 13:17:41 +01:00
|
|
|
else if (ind_type != NULL)
|
2001-12-04 13:33:15 +01:00
|
|
|
{
|
2003-05-14 16:37:36 +02:00
|
|
|
if (atoi(arrsiz) == 1)
|
2001-12-08 21:43:35 +01:00
|
|
|
sprintf(ind_pbuf, "%s%s.", ind_prefix ? ind_prefix : "", ind_name);
|
|
|
|
else
|
|
|
|
sprintf(ind_pbuf, "%s%s->", ind_prefix ? ind_prefix : "", ind_name);
|
2002-09-04 22:31:48 +02:00
|
|
|
|
2001-12-04 13:33:15 +01:00
|
|
|
ind_prefix = ind_pbuf;
|
2001-12-23 13:17:41 +01:00
|
|
|
ind_p = ind_type->u.members;
|
2001-12-04 13:33:15 +01:00
|
|
|
}
|
2002-09-04 22:31:48 +02:00
|
|
|
|
2001-12-23 13:17:41 +01:00
|
|
|
for (p = type->u.members; p; p = p->next)
|
1998-02-26 05:46:47 +01:00
|
|
|
{
|
2003-05-29 15:59:26 +02:00
|
|
|
ECPGdump_a_type(o, p->name, p->type,
|
2003-05-22 09:58:45 +02:00
|
|
|
(ind_p != NULL) ? ind_p->name : NULL,
|
2003-05-29 15:59:26 +02:00
|
|
|
(ind_p != NULL) ? ind_p->type : NULL,
|
2003-05-22 09:58:45 +02:00
|
|
|
prefix, ind_prefix, arrsiz, type->struct_sizeof,
|
|
|
|
(ind_p != NULL) ? ind_type->struct_sizeof : NULL);
|
2001-12-04 13:33:15 +01:00
|
|
|
if (ind_p != NULL && ind_p != &struct_no_indicator)
|
1998-09-01 06:40:42 +02:00
|
|
|
ind_p = ind_p->next;
|
1998-02-26 05:46:47 +01:00
|
|
|
}
|
1998-02-05 16:46:43 +01:00
|
|
|
}
|
|
|
|
|
1998-05-06 15:03:47 +02:00
|
|
|
void
|
1998-04-27 16:35:58 +02:00
|
|
|
ECPGfree_struct_member(struct ECPGstruct_member * rm)
|
1998-02-05 16:46:43 +01:00
|
|
|
{
|
1998-09-01 06:40:42 +02:00
|
|
|
while (rm)
|
|
|
|
{
|
|
|
|
struct ECPGstruct_member *p = rm;
|
|
|
|
|
|
|
|
rm = rm->next;
|
|
|
|
free(p->name);
|
2001-12-23 13:17:41 +01:00
|
|
|
free(p->type);
|
1998-09-01 06:40:42 +02:00
|
|
|
free(p);
|
|
|
|
}
|
1998-05-06 15:03:47 +02:00
|
|
|
}
|
1998-02-05 16:46:43 +01:00
|
|
|
|
|
|
|
void
|
2001-12-23 13:17:41 +01:00
|
|
|
ECPGfree_type(struct ECPGtype * type)
|
1998-02-05 16:46:43 +01:00
|
|
|
{
|
2001-12-23 13:17:41 +01:00
|
|
|
if (!IS_SIMPLE_TYPE(type->type))
|
1998-02-26 05:46:47 +01:00
|
|
|
{
|
2001-12-23 13:17:41 +01:00
|
|
|
switch (type->type)
|
1998-02-26 05:46:47 +01:00
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
case ECPGt_array:
|
2001-12-23 13:17:41 +01:00
|
|
|
switch (type->u.element->type)
|
1999-02-28 08:25:34 +01:00
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
case ECPGt_array:
|
2003-06-25 23:30:34 +02:00
|
|
|
yyerror("internal error, found multi-dimensional array\n");
|
1999-02-28 08:25:34 +01:00
|
|
|
break;
|
|
|
|
case ECPGt_struct:
|
|
|
|
case ECPGt_union:
|
|
|
|
/* Array of structs. */
|
2001-12-23 13:17:41 +01:00
|
|
|
ECPGfree_struct_member(type->u.element->u.members);
|
|
|
|
free(type->u.element);
|
1999-02-28 08:25:34 +01:00
|
|
|
break;
|
1999-05-25 18:15:34 +02:00
|
|
|
default:
|
2001-12-23 13:17:41 +01:00
|
|
|
if (!IS_SIMPLE_TYPE(type->u.element->type))
|
1999-02-28 08:25:34 +01:00
|
|
|
yyerror("Internal error: unknown datatype, please inform pgsql-bugs@postgresql.org");
|
|
|
|
|
2001-12-23 13:17:41 +01:00
|
|
|
free(type->u.element);
|
1999-02-28 08:25:34 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ECPGt_struct:
|
|
|
|
case ECPGt_union:
|
2001-12-23 13:17:41 +01:00
|
|
|
ECPGfree_struct_member(type->u.members);
|
1999-02-28 08:25:34 +01:00
|
|
|
break;
|
|
|
|
default:
|
2001-12-23 13:17:41 +01:00
|
|
|
sprintf(errortext, "illegal variable type %d\n", type->type);
|
1999-02-23 13:57:03 +01:00
|
|
|
yyerror(errortext);
|
1999-02-28 08:25:34 +01:00
|
|
|
break;
|
1999-02-23 13:57:03 +01:00
|
|
|
}
|
1998-02-26 05:46:47 +01:00
|
|
|
}
|
2001-12-23 13:17:41 +01:00
|
|
|
free(type);
|
1998-02-05 16:46:43 +01:00
|
|
|
}
|
2000-02-22 20:57:12 +01:00
|
|
|
|
|
|
|
const char *
|
2001-12-23 13:17:41 +01:00
|
|
|
get_dtype(enum ECPGdtype type)
|
2000-02-22 20:57:12 +01:00
|
|
|
{
|
2001-12-23 13:17:41 +01:00
|
|
|
switch (type)
|
2000-02-22 20:57:12 +01:00
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
case ECPGd_count:
|
2000-02-22 20:57:12 +01:00
|
|
|
return ("ECPGd_countr");
|
|
|
|
break;
|
|
|
|
case ECPGd_data:
|
|
|
|
return ("ECPGd_data");
|
|
|
|
break;
|
|
|
|
case ECPGd_di_code:
|
|
|
|
return ("ECPGd_di_code");
|
|
|
|
break;
|
|
|
|
case ECPGd_di_precision:
|
|
|
|
return ("ECPGd_di_precision");
|
|
|
|
break;
|
|
|
|
case ECPGd_indicator:
|
|
|
|
return ("ECPGd_indicator");
|
|
|
|
break;
|
|
|
|
case ECPGd_key_member:
|
|
|
|
return ("ECPGd_key_member");
|
|
|
|
break;
|
|
|
|
case ECPGd_length:
|
|
|
|
return ("ECPGd_length");
|
|
|
|
break;
|
|
|
|
case ECPGd_name:
|
|
|
|
return ("ECPGd_name");
|
|
|
|
break;
|
|
|
|
case ECPGd_nullable:
|
|
|
|
return ("ECPGd_nullable");
|
|
|
|
break;
|
|
|
|
case ECPGd_octet:
|
|
|
|
return ("ECPGd_octet");
|
|
|
|
break;
|
|
|
|
case ECPGd_precision:
|
|
|
|
return ("ECPGd_precision");
|
|
|
|
break;
|
|
|
|
case ECPGd_ret_length:
|
|
|
|
return ("ECPGd_ret_length");
|
|
|
|
case ECPGd_ret_octet:
|
|
|
|
return ("ECPGd_ret_octet");
|
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
case ECPGd_scale:
|
2000-02-22 20:57:12 +01:00
|
|
|
return ("ECPGd_scale");
|
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
case ECPGd_type:
|
2000-02-22 20:57:12 +01:00
|
|
|
return ("ECPGd_type");
|
|
|
|
break;
|
2001-08-19 11:21:45 +02:00
|
|
|
case ECPGd_cardinality:
|
|
|
|
return ("ECPGd_cardinality");
|
2000-02-22 20:57:12 +01:00
|
|
|
default:
|
2001-12-23 13:17:41 +01:00
|
|
|
sprintf(errortext, "illegal descriptor item %d\n", type);
|
2000-02-22 20:57:12 +01:00
|
|
|
yyerror(errortext);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|