PostgreSQL Source Code  git master
descriptor.c File Reference
#include "postgres_fe.h"
#include "preproc_extern.h"
Include dependency graph for descriptor.c:

Go to the source code of this file.

Macros

#define MAX_DESCRIPTOR_NAMELEN   128
 

Functions

void push_assignment (char *var, enum ECPGdtype value)
 
static void drop_assignments (void)
 
static void ECPGnumeric_lvalue (char *name)
 
void add_descriptor (char *name, char *connection)
 
void drop_descriptor (char *name, char *connection)
 
struct descriptorlookup_descriptor (char *name, char *connection)
 
void output_get_descr_header (char *desc_name)
 
void output_get_descr (char *desc_name, char *index)
 
void output_set_descr_header (char *desc_name)
 
static const char * descriptor_item_name (enum ECPGdtype itemcode)
 
void output_set_descr (char *desc_name, char *index)
 
struct variabledescriptor_variable (const char *name, int input)
 
struct variablesqlda_variable (const char *name)
 

Variables

static struct assignmentassignments
 
static struct descriptordescriptors
 

Macro Definition Documentation

◆ MAX_DESCRIPTOR_NAMELEN

#define MAX_DESCRIPTOR_NAMELEN   128

Definition at line 336 of file descriptor.c.

Referenced by descriptor_variable().

Function Documentation

◆ add_descriptor()

void add_descriptor ( char *  name,
char *  connection 
)

Definition at line 76 of file descriptor.c.

References connection, descriptors, mm_alloc(), and descriptor::name.

77 {
78  struct descriptor *new;
79 
80  if (name[0] != '"')
81  return;
82 
83  new = (struct descriptor *) mm_alloc(sizeof(struct descriptor));
84 
85  new->next = descriptors;
86  new->name = mm_alloc(strlen(name) + 1);
87  strcpy(new->name, name);
88  if (connection)
89  {
90  new->connection = mm_alloc(strlen(connection) + 1);
91  strcpy(new->connection, connection);
92  }
93  else
94  new->connection = connection;
95  descriptors = new;
96 }
static struct descriptor * descriptors
Definition: descriptor.c:73
const char * name
Definition: encode.c:561
void * mm_alloc(size_t)
Definition: type.c:13
char * connection

◆ descriptor_item_name()

static const char* descriptor_item_name ( enum ECPGdtype  itemcode)
static

Definition at line 234 of file descriptor.c.

References ECPGd_cardinality, ECPGd_count, ECPGd_data, ECPGd_di_code, ECPGd_di_precision, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, and ECPGd_type.

Referenced by output_set_descr().

235 {
236  switch (itemcode)
237  {
238  case ECPGd_cardinality:
239  return "CARDINALITY";
240  case ECPGd_count:
241  return "COUNT";
242  case ECPGd_data:
243  return "DATA";
244  case ECPGd_di_code:
245  return "DATETIME_INTERVAL_CODE";
246  case ECPGd_di_precision:
247  return "DATETIME_INTERVAL_PRECISION";
248  case ECPGd_indicator:
249  return "INDICATOR";
250  case ECPGd_key_member:
251  return "KEY_MEMBER";
252  case ECPGd_length:
253  return "LENGTH";
254  case ECPGd_name:
255  return "NAME";
256  case ECPGd_nullable:
257  return "NULLABLE";
258  case ECPGd_octet:
259  return "OCTET_LENGTH";
260  case ECPGd_precision:
261  return "PRECISION";
262  case ECPGd_ret_length:
263  return "RETURNED_LENGTH";
264  case ECPGd_ret_octet:
265  return "RETURNED_OCTET_LENGTH";
266  case ECPGd_scale:
267  return "SCALE";
268  case ECPGd_type:
269  return "TYPE";
270  default:
271  return NULL;
272  }
273 }

◆ descriptor_variable()

struct variable* descriptor_variable ( const char *  name,
int  input 
)

Definition at line 338 of file descriptor.c.

References ECPGt_descriptor, MAX_DESCRIPTOR_NAMELEN, and strlcpy().

339 {
340  static char descriptor_names[2][MAX_DESCRIPTOR_NAMELEN];
341  static struct ECPGtype descriptor_type = {ECPGt_descriptor, NULL, NULL, NULL, {NULL}, 0};
342  static struct variable varspace[2] = {
343  {descriptor_names[0], &descriptor_type, 0, NULL},
344  {descriptor_names[1], &descriptor_type, 0, NULL}
345  };
346 
347  strlcpy(descriptor_names[input], name, sizeof(descriptor_names[input]));
348  return &varspace[input];
349 }
Definition: type.h:17
#define MAX_DESCRIPTOR_NAMELEN
Definition: descriptor.c:336
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
const char * name
Definition: encode.c:561

◆ drop_assignments()

static void drop_assignments ( void  )
static

Definition at line 33 of file descriptor.c.

References assignments, free, assignment::next, and assignment::variable.

Referenced by output_get_descr(), output_get_descr_header(), output_set_descr(), and output_set_descr_header().

34 {
35  while (assignments)
36  {
37  struct assignment *old_head = assignments;
38 
39  assignments = old_head->next;
40  free(old_head->variable);
41  free(old_head);
42  }
43 }
static struct assignment * assignments
Definition: descriptor.c:18
struct assignment * next
Definition: type.h:196
char * variable
Definition: type.h:194
#define free(a)
Definition: header.h:65

◆ drop_descriptor()

void drop_descriptor ( char *  name,
char *  connection 
)

Definition at line 99 of file descriptor.c.

References descriptor::connection, descriptors, ET_WARNING, free, i, mmerror(), descriptor::name, descriptor::next, and PARSE_ERROR.

100 {
101  struct descriptor *i;
102  struct descriptor **lastptr = &descriptors;
103 
104  if (name[0] != '"')
105  return;
106 
107  for (i = descriptors; i; lastptr = &i->next, i = i->next)
108  {
109  if (strcmp(name, i->name) == 0)
110  {
111  if ((!connection && !i->connection)
112  || (connection && i->connection
113  && strcmp(connection, i->connection) == 0))
114  {
115  *lastptr = i->next;
116  if (i->connection)
117  free(i->connection);
118  free(i->name);
119  free(i);
120  return;
121  }
122  }
123  }
124  if (connection)
125  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to connection %s does not exist", name, connection);
126  else
127  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to the default connection does not exist", name);
128 }
char * connection
Definition: type.h:188
static struct descriptor * descriptors
Definition: descriptor.c:73
struct descriptor * next
#define PARSE_ERROR
#define free(a)
Definition: header.h:65
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
const char * name
Definition: encode.c:561
int i

◆ ECPGnumeric_lvalue()

static void ECPGnumeric_lvalue ( char *  name)
static

Definition at line 46 of file descriptor.c.

References base_yyout, ECPGt_const, ECPGt_int, ECPGt_long, ECPGt_long_long, ECPGt_short, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, ET_ERROR, find_variable(), mmerror(), PARSE_ERROR, and variable::type.

Referenced by output_get_descr_header(), and output_set_descr_header().

47 {
48  const struct variable *v = find_variable(name);
49 
50  switch (v->type->type)
51  {
52  case ECPGt_short:
53  case ECPGt_int:
54  case ECPGt_long:
55  case ECPGt_long_long:
57  case ECPGt_unsigned_int:
60  case ECPGt_const:
61  fputs(name, base_yyout);
62  break;
63  default:
64  mmerror(PARSE_ERROR, ET_ERROR, "variable \"%s\" must have a numeric type", name);
65  break;
66  }
67 }
Definition: type.h:201
enum ECPGttype type
#define PARSE_ERROR
struct variable * find_variable(char *)
Definition: variable.c:194
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
const char * name
Definition: encode.c:561
FILE * base_yyout

◆ lookup_descriptor()

struct descriptor* lookup_descriptor ( char *  name,
char *  connection 
)

Definition at line 132 of file descriptor.c.

References descriptor::connection, ET_WARNING, i, mm_strdup(), mmerror(), descriptor::name, descriptor::next, and PARSE_ERROR.

133 {
134  struct descriptor *i;
135 
136  if (name[0] != '"')
137  return NULL;
138 
139  for (i = descriptors; i; i = i->next)
140  {
141  if (strcmp(name, i->name) == 0)
142  {
143  if ((!connection && !i->connection)
144  || (connection && i->connection
145  && strcmp(connection, i->connection) == 0))
146  return i;
147  if (connection && !i->connection)
148  {
149  /* overwrite descriptor's connection */
151  return i;
152  }
153  }
154  }
155  if (connection)
156  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to connection %s does not exist", name, connection);
157  else
158  mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to the default connection does not exist", name);
159  return NULL;
160 }
char * connection
Definition: type.h:188
static struct descriptor * descriptors
Definition: descriptor.c:73
char * mm_strdup(const char *)
Definition: type.c:25
struct descriptor * next
#define PARSE_ERROR
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
const char * name
Definition: encode.c:561
int i

◆ output_get_descr()

void output_get_descr ( char *  desc_name,
char *  index 
)

Definition at line 182 of file descriptor.c.

References base_yyout, variable::brace_level, drop_assignments(), ECPGd_key_member, ECPGd_nullable, ECPGdump_a_type(), ET_WARNING, find_variable(), fprintf, free, get_dtype(), mm_strdup(), mmerror(), variable::name, assignment::next, PARSE_ERROR, variable::type, assignment::value, assignment::variable, and whenever_action().

183 {
184  struct assignment *results;
185 
186  fprintf(base_yyout, "{ ECPGget_desc(__LINE__, %s, %s,", desc_name, index);
187  for (results = assignments; results != NULL; results = results->next)
188  {
189  const struct variable *v = find_variable(results->variable);
190  char *str_zero = mm_strdup("0");
191 
192  switch (results->value)
193  {
194  case ECPGd_nullable:
195  mmerror(PARSE_ERROR, ET_WARNING, "nullable is always 1");
196  break;
197  case ECPGd_key_member:
198  mmerror(PARSE_ERROR, ET_WARNING, "key_member is always 0");
199  break;
200  default:
201  break;
202  }
203  fprintf(base_yyout, "%s,", get_dtype(results->value));
205  NULL, NULL, -1, NULL, NULL, str_zero, NULL, NULL);
206  free(str_zero);
207  }
209  fputs("ECPGd_EODT);\n", base_yyout);
210 
211  whenever_action(2 | 1);
212 }
int brace_level
Definition: type.h:174
static struct assignment * assignments
Definition: descriptor.c:18
static void drop_assignments(void)
Definition: descriptor.c:33
enum ECPGttype type
#define fprintf
Definition: port.h:221
char * mm_strdup(const char *)
Definition: type.c:25
void whenever_action(int mode)
Definition: output.c:66
void ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *type, const int brace_level, const char *ind_name, struct ECPGtype *ind_type, const int ind_brace_level, const char *prefix, const char *ind_prefix, char *arr_str_size, const char *struct_sizeof, const char *ind_struct_sizeof)
Definition: type.c:241
Definition: type.h:89
const char * get_dtype(enum ECPGdtype)
Definition: type.c:693
#define PARSE_ERROR
struct assignment * next
Definition: type.h:196
char * variable
Definition: type.h:194
struct variable * find_variable(char *)
Definition: variable.c:194
#define free(a)
Definition: header.h:65
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
enum ECPGdtype value
Definition: type.h:195
char * name
Definition: type.h:172
FILE * base_yyout

◆ output_get_descr_header()

void output_get_descr_header ( char *  desc_name)

Definition at line 163 of file descriptor.c.

References base_yyout, drop_assignments(), ECPGd_count, ECPGnumeric_lvalue(), ET_WARNING, fprintf, mmerror(), assignment::next, PARSE_ERROR, assignment::value, assignment::variable, and whenever_action().

164 {
165  struct assignment *results;
166 
167  fprintf(base_yyout, "{ ECPGget_desc_header(__LINE__, %s, &(", desc_name);
168  for (results = assignments; results != NULL; results = results->next)
169  {
170  if (results->value == ECPGd_count)
171  ECPGnumeric_lvalue(results->variable);
172  else
173  mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
174  }
175 
177  fprintf(base_yyout, "));\n");
178  whenever_action(3);
179 }
static struct assignment * assignments
Definition: descriptor.c:18
static void drop_assignments(void)
Definition: descriptor.c:33
#define fprintf
Definition: port.h:221
void whenever_action(int mode)
Definition: output.c:66
static void ECPGnumeric_lvalue(char *name)
Definition: descriptor.c:46
#define PARSE_ERROR
struct assignment * next
Definition: type.h:196
char * variable
Definition: type.h:194
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
enum ECPGdtype value
Definition: type.h:195
FILE * base_yyout

◆ output_set_descr()

void output_set_descr ( char *  desc_name,
char *  index 
)

Definition at line 276 of file descriptor.c.

References base_yyout, variable::brace_level, descriptor_item_name(), drop_assignments(), ECPGd_cardinality, ECPGd_data, ECPGd_di_code, ECPGd_di_precision, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, ECPGd_type, ECPGdump_a_type(), find_variable(), fprintf, free, get_dtype(), mm_strdup(), mmfatal(), variable::name, assignment::next, PARSE_ERROR, variable::type, assignment::value, assignment::variable, and whenever_action().

277 {
278  struct assignment *results;
279 
280  fprintf(base_yyout, "{ ECPGset_desc(__LINE__, %s, %s,", desc_name, index);
281  for (results = assignments; results != NULL; results = results->next)
282  {
283  const struct variable *v = find_variable(results->variable);
284 
285  switch (results->value)
286  {
287  case ECPGd_cardinality:
288  case ECPGd_di_code:
289  case ECPGd_di_precision:
290  case ECPGd_precision:
291  case ECPGd_scale:
292  mmfatal(PARSE_ERROR, "descriptor item \"%s\" is not implemented",
293  descriptor_item_name(results->value));
294  break;
295 
296  case ECPGd_key_member:
297  case ECPGd_name:
298  case ECPGd_nullable:
299  case ECPGd_octet:
300  case ECPGd_ret_length:
301  case ECPGd_ret_octet:
302  mmfatal(PARSE_ERROR, "descriptor item \"%s\" cannot be set",
303  descriptor_item_name(results->value));
304  break;
305 
306  case ECPGd_data:
307  case ECPGd_indicator:
308  case ECPGd_length:
309  case ECPGd_type:
310  {
311  char *str_zero = mm_strdup("0");
312 
313  fprintf(base_yyout, "%s,", get_dtype(results->value));
315  NULL, NULL, -1, NULL, NULL, str_zero, NULL, NULL);
316  free(str_zero);
317  }
318  break;
319 
320  default:
321  ;
322  }
323  }
325  fputs("ECPGd_EODT);\n", base_yyout);
326 
327  whenever_action(2 | 1);
328 }
int brace_level
Definition: type.h:174
void void mmfatal(int errorcode, const char *error,...) pg_attribute_printf(2
static struct assignment * assignments
Definition: descriptor.c:18
static void drop_assignments(void)
Definition: descriptor.c:33
enum ECPGttype type
#define fprintf
Definition: port.h:221
char * mm_strdup(const char *)
Definition: type.c:25
void whenever_action(int mode)
Definition: output.c:66
void ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *type, const int brace_level, const char *ind_name, struct ECPGtype *ind_type, const int ind_brace_level, const char *prefix, const char *ind_prefix, char *arr_str_size, const char *struct_sizeof, const char *ind_struct_sizeof)
Definition: type.c:241
Definition: type.h:89
const char * get_dtype(enum ECPGdtype)
Definition: type.c:693
#define PARSE_ERROR
struct assignment * next
Definition: type.h:196
char * variable
Definition: type.h:194
struct variable * find_variable(char *)
Definition: variable.c:194
#define free(a)
Definition: header.h:65
static const char * descriptor_item_name(enum ECPGdtype itemcode)
Definition: descriptor.c:234
enum ECPGdtype value
Definition: type.h:195
char * name
Definition: type.h:172
FILE * base_yyout

◆ output_set_descr_header()

void output_set_descr_header ( char *  desc_name)

Definition at line 215 of file descriptor.c.

References base_yyout, drop_assignments(), ECPGd_count, ECPGnumeric_lvalue(), ET_WARNING, fprintf, mmerror(), assignment::next, PARSE_ERROR, assignment::value, assignment::variable, and whenever_action().

216 {
217  struct assignment *results;
218 
219  fprintf(base_yyout, "{ ECPGset_desc_header(__LINE__, %s, (int)(", desc_name);
220  for (results = assignments; results != NULL; results = results->next)
221  {
222  if (results->value == ECPGd_count)
223  ECPGnumeric_lvalue(results->variable);
224  else
225  mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
226  }
227 
229  fprintf(base_yyout, "));\n");
230  whenever_action(3);
231 }
static struct assignment * assignments
Definition: descriptor.c:18
static void drop_assignments(void)
Definition: descriptor.c:33
#define fprintf
Definition: port.h:221
void whenever_action(int mode)
Definition: output.c:66
static void ECPGnumeric_lvalue(char *name)
Definition: descriptor.c:46
#define PARSE_ERROR
struct assignment * next
Definition: type.h:196
char * variable
Definition: type.h:194
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
enum ECPGdtype value
Definition: type.h:195
FILE * base_yyout

◆ push_assignment()

void push_assignment ( char *  var,
enum ECPGdtype  value 
)

Definition at line 21 of file descriptor.c.

References assignments, mm_alloc(), value, and assignment::variable.

22 {
23  struct assignment *new = (struct assignment *) mm_alloc(sizeof(struct assignment));
24 
25  new->next = assignments;
26  new->variable = mm_alloc(strlen(var) + 1);
27  strcpy(new->variable, var);
28  new->value = value;
29  assignments = new;
30 }
static struct assignment * assignments
Definition: descriptor.c:18
char * variable
Definition: type.h:194
static struct @143 value
void * mm_alloc(size_t)
Definition: type.c:13

◆ sqlda_variable()

struct variable* sqlda_variable ( const char *  name)

Definition at line 352 of file descriptor.c.

References variable::brace_level, ECPGt_sqlda, mm_alloc(), mm_strdup(), variable::name, variable::next, and variable::type.

353 {
354  struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable));
355 
356  p->name = mm_strdup(name);
357  p->type = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
358  p->type->type = ECPGt_sqlda;
359  p->type->size = NULL;
360  p->type->struct_sizeof = NULL;
361  p->type->u.element = NULL;
362  p->type->counter = 0;
363  p->brace_level = 0;
364  p->next = NULL;
365 
366  return p;
367 }
int brace_level
Definition: type.h:174
enum ECPGttype type
struct variable * next
Definition: type.h:17
char * mm_strdup(const char *)
Definition: type.c:25
const char * name
Definition: encode.c:561
void * mm_alloc(size_t)
Definition: type.c:13
char * name
Definition: type.h:172

Variable Documentation

◆ assignments

struct assignment* assignments
static

Definition at line 18 of file descriptor.c.

Referenced by drop_assignments(), and push_assignment().

◆ descriptors

struct descriptor* descriptors
static

Definition at line 73 of file descriptor.c.

Referenced by add_descriptor(), and drop_descriptor().