aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg')
-rw-r--r--src/interfaces/ecpg/include/ecpglib.h32
-rw-r--r--src/interfaces/ecpg/include/ecpgtype.h21
-rw-r--r--src/interfaces/ecpg/include/sqlca.h17
-rw-r--r--src/interfaces/ecpg/lib/ecpglib.c66
-rw-r--r--src/interfaces/ecpg/lib/typename.c42
-rw-r--r--src/interfaces/ecpg/preproc/ecpg.c26
-rw-r--r--src/interfaces/ecpg/preproc/extern.h15
-rw-r--r--src/interfaces/ecpg/preproc/type.c546
-rw-r--r--src/interfaces/ecpg/preproc/type.h85
-rw-r--r--src/interfaces/ecpg/test/Ptest1.c69
-rw-r--r--src/interfaces/ecpg/test/test1.c70
11 files changed, 533 insertions, 456 deletions
diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h
index 4634b695735..a19b1a4f7a1 100644
--- a/src/interfaces/ecpg/include/ecpglib.h
+++ b/src/interfaces/ecpg/include/ecpglib.h
@@ -1,32 +1,34 @@
#include <c.h>
-void ECPGdebug(int, FILE *);
-bool ECPGconnect(const char * dbname);
-bool ECPGdo(int, char *, ...);
-bool ECPGcommit(int);
-bool ECPGrollback(int);
-bool ECPGfinish();
-bool ECPGstatus();
+void ECPGdebug(int, FILE *);
+bool ECPGconnect(const char *dbname);
+bool ECPGdo(int, char *,...);
+bool ECPGcommit(int);
+bool ECPGrollback(int);
+bool ECPGfinish();
+bool ECPGstatus();
-void ECPGlog(const char * format, ...);
+void ECPGlog(const char *format,...);
#ifdef LIBPQ_FE_H
-bool ECPGsetdb(PGconn *);
+bool ECPGsetdb(PGconn *);
+
#endif
/* Here are some methods used by the lib. */
/* Returns a pointer to a string containing a simple type name. */
-const char * ECPGtype_name(enum ECPGttype);
+const char *ECPGtype_name(enum ECPGttype);
/* A generic varchar type. */
-struct ECPGgeneric_varchar {
- int len;
- char arr[1];
+struct ECPGgeneric_varchar
+{
+ int len;
+ char arr[1];
};
/* print an error message */
-void sqlprint(void);
+void sqlprint(void);
/* define this for simplicity as well as compatibility */
-#define SQLCODE sqlca.sqlcode
+#define SQLCODE sqlca.sqlcode
diff --git a/src/interfaces/ecpg/include/ecpgtype.h b/src/interfaces/ecpg/include/ecpgtype.h
index 496c934f4f4..35bac4d0288 100644
--- a/src/interfaces/ecpg/include/ecpgtype.h
+++ b/src/interfaces/ecpg/include/ecpgtype.h
@@ -29,16 +29,17 @@
*/
#include <stdio.h>
-enum ECPGttype {
- ECPGt_char = 1, ECPGt_unsigned_char, ECPGt_short, ECPGt_unsigned_short,
- ECPGt_int, ECPGt_unsigned_int, ECPGt_long, ECPGt_unsigned_long,
- ECPGt_bool,
- ECPGt_float, ECPGt_double,
- ECPGt_varchar, ECPGt_varchar2,
- ECPGt_array,
- ECPGt_record,
- ECPGt_EOIT, /* End of insert types. */
- ECPGt_EORT /* End of result types. */
+enum ECPGttype
+{
+ ECPGt_char = 1, ECPGt_unsigned_char, ECPGt_short, ECPGt_unsigned_short,
+ ECPGt_int, ECPGt_unsigned_int, ECPGt_long, ECPGt_unsigned_long,
+ ECPGt_bool,
+ ECPGt_float, ECPGt_double,
+ ECPGt_varchar, ECPGt_varchar2,
+ ECPGt_array,
+ ECPGt_record,
+ ECPGt_EOIT, /* End of insert types. */
+ ECPGt_EORT /* End of result types. */
};
#define IS_SIMPLE_TYPE(type) ((type) >= ECPGt_char && (type) <= ECPGt_varchar2)
diff --git a/src/interfaces/ecpg/include/sqlca.h b/src/interfaces/ecpg/include/sqlca.h
index 0e7126e7b36..454eba22018 100644
--- a/src/interfaces/ecpg/include/sqlca.h
+++ b/src/interfaces/ecpg/include/sqlca.h
@@ -1,11 +1,14 @@
#ifndef POSTGRES_SQLCA_H
#define POSTGRES_SQLCA_H
-struct sqlca {
- int sqlcode;
- struct {
- int sqlerrml;
- char sqlerrmc[1000];
- } sqlerrm;
-} sqlca;
+struct sqlca
+{
+ int sqlcode;
+ struct
+ {
+ int sqlerrml;
+ char sqlerrmc[1000];
+ } sqlerrm;
+} sqlca;
+
#endif
diff --git a/src/interfaces/ecpg/lib/ecpglib.c b/src/interfaces/ecpg/lib/ecpglib.c
index 823a335c764..f5778f9ac3c 100644
--- a/src/interfaces/ecpg/lib/ecpglib.c
+++ b/src/interfaces/ecpg/lib/ecpglib.c
@@ -45,7 +45,7 @@ register_error(int code, char *fmt,...)
in the argument quoted with \.
*/
static
-char *
+char *
quote_postgres(char *arg)
{
char *res = (char *) malloc(2 * strlen(arg) + 1);
@@ -89,9 +89,10 @@ ECPGdo(int lineno, char *query,...)
type = va_arg(ap, enum ECPGttype);
/*
- * Now, if the type is one of the fill in types then we take the argument
- * and enter that in the string at the first %s position. Then if there
- * are any more fill in types we fill in at the next and so on.
+ * Now, if the type is one of the fill in types then we take the
+ * argument and enter that in the string at the first %s position.
+ * Then if there are any more fill in types we fill in at the next and
+ * so on.
*/
while (type != ECPGt_EOIT)
{
@@ -106,8 +107,11 @@ ECPGdo(int lineno, char *query,...)
char *p;
char buff[20];
- /* Some special treatment is needed for records since we want their
- contents to arrive in a comma-separated list on insert (I think). */
+ /*
+ * Some special treatment is needed for records since we want
+ * their contents to arrive in a comma-separated list on insert (I
+ * think).
+ */
value = va_arg(ap, void *);
varcharsize = va_arg(ap, long);
@@ -157,8 +161,8 @@ ECPGdo(int lineno, char *query,...)
case ECPGt_unsigned_char:
{
/* set slen to string length if type is char * */
- int slen = (varcharsize == 0) ? strlen((char *) value) : varcharsize;
-
+ int slen = (varcharsize == 0) ? strlen((char *) value) : varcharsize;
+
newcopy = (char *) malloc(slen + 1);
strncpy(newcopy, (char *) value, slen);
newcopy[slen] = '\0';
@@ -203,8 +207,9 @@ ECPGdo(int lineno, char *query,...)
break;
}
- /* Now tobeinserted points to an area that is to be inserted at
- the first %s
+ /*
+ * Now tobeinserted points to an area that is to be inserted at
+ * the first %s
*/
newcopy = (char *) malloc(strlen(copiedquery)
+ strlen(tobeinserted)
@@ -212,8 +217,10 @@ ECPGdo(int lineno, char *query,...)
strcpy(newcopy, copiedquery);
if ((p = strstr(newcopy, ";;")) == NULL)
{
- /* We have an argument but we dont have the matched up string
- in the string
+
+ /*
+ * We have an argument but we dont have the matched up string
+ * in the string
*/
register_error(-1, "Too many arguments line %d.", lineno);
return false;
@@ -221,16 +228,20 @@ ECPGdo(int lineno, char *query,...)
else
{
strcpy(p, tobeinserted);
- /* The strange thing in the second argument is the rest of the
- string from the old string */
+
+ /*
+ * The strange thing in the second argument is the rest of the
+ * string from the old string
+ */
strcat(newcopy,
copiedquery
+ (p - newcopy)
+ 2 /* Length of ;; */ );
}
- /* Now everything is safely copied to the newcopy. Lets free the
- oldcopy and let the copiedquery get the value from the newcopy.
+ /*
+ * Now everything is safely copied to the newcopy. Lets free the
+ * oldcopy and let the copiedquery get the value from the newcopy.
*/
if (mallocedval != NULL)
{
@@ -283,9 +294,11 @@ ECPGdo(int lineno, char *query,...)
x;
case PGRES_TUPLES_OK:
- /* XXX Cheap Hack. For now, we see only the last group
- * of tuples. This is clearly not the right
- * way to do things !!
+
+ /*
+ * XXX Cheap Hack. For now, we see only the last group of
+ * tuples. This is clearly not the right way to do things
+ * !!
*/
m = PQnfields(results);
@@ -318,10 +331,10 @@ ECPGdo(int lineno, char *query,...)
char *pval = PQgetvalue(results, 0, x);
- /*long int * res_int;
- char ** res_charstar;
- char * res_char;
- int res_len; */
+ /*
+ * long int * res_int; char ** res_charstar; char *
+ * res_char; int res_len;
+ */
char *scan_length;
ECPGlog("ECPGdo line %d: RESULT: %s\n", lineno, pval ? pval : "");
@@ -476,7 +489,7 @@ ECPGdo(int lineno, char *query,...)
strncpy((char *) value, pval, varcharsize);
}
break;
-
+
case ECPGt_varchar:
{
struct ECPGgeneric_varchar *var =
@@ -673,8 +686,9 @@ ECPGlog(const char *format,...)
}
/* print out an error message */
-void sqlprint(void)
+void
+sqlprint(void)
{
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0';
- printf ("sql error %s\n", sqlca.sqlerrm.sqlerrmc);
+ printf("sql error %s\n", sqlca.sqlerrm.sqlerrmc);
}
diff --git a/src/interfaces/ecpg/lib/typename.c b/src/interfaces/ecpg/lib/typename.c
index 55756037b30..a79fa67202d 100644
--- a/src/interfaces/ecpg/lib/typename.c
+++ b/src/interfaces/ecpg/lib/typename.c
@@ -5,20 +5,30 @@
const char *
ECPGtype_name(enum ECPGttype typ)
{
- switch (typ)
- {
- case ECPGt_char: return "char";
- case ECPGt_unsigned_char: return "unsigned char";
- case ECPGt_short: return "short";
- case ECPGt_unsigned_short: return "unsigned short";
- case ECPGt_int: return "int";
- case ECPGt_unsigned_int: return "unsigned int";
- case ECPGt_long: return "long";
- case ECPGt_unsigned_long: return "unsigned long";
- case ECPGt_float: return "float";
- case ECPGt_double: return "double";
- case ECPGt_bool: return "bool";
- default:
- abort();
- }
+ switch (typ)
+ {
+ case ECPGt_char:return "char";
+ case ECPGt_unsigned_char:
+ return "unsigned char";
+ case ECPGt_short:
+ return "short";
+ case ECPGt_unsigned_short:
+ return "unsigned short";
+ case ECPGt_int:
+ return "int";
+ case ECPGt_unsigned_int:
+ return "unsigned int";
+ case ECPGt_long:
+ return "long";
+ case ECPGt_unsigned_long:
+ return "unsigned long";
+ case ECPGt_float:
+ return "float";
+ case ECPGt_double:
+ return "double";
+ case ECPGt_bool:
+ return "bool";
+ default:
+ abort();
+ }
}
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index 0239ece7d3c..483a7c52fcc 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -6,15 +6,15 @@
#include <stdio.h>
#if HAVE_GETOPT_H
-# include <getopt.h>
+#include <getopt.h>
#else
-# include <unistd.h>
+#include <unistd.h>
#endif
#include <stdlib.h>
#if defined(HAVE_STRING_H)
-# include <string.h>
+#include <string.h>
#else
-# include <strings.h>
+#include <strings.h>
#endif
#include "extern.h"
@@ -29,7 +29,8 @@ usage(char *progname)
int
main(int argc, char *const argv[])
{
- char c, out_option = 0;
+ char c,
+ out_option = 0;
int fnr;
while ((c = getopt(argc, argv, "vdo:")) != EOF)
@@ -52,15 +53,16 @@ main(int argc, char *const argv[])
}
}
- if (optind >= argc) /* no files specified */
+ if (optind >= argc) /* no files specified */
usage(argv[0]);
else
{
/* after the options there must not be anything but filenames */
for (fnr = optind; fnr < argc; fnr++)
{
- char *filename, *ptr2ext;
- int ext = 0;
+ char *filename,
+ *ptr2ext;
+ int ext = 0;
filename = mm_alloc(strlen(argv[fnr]) + 4);
@@ -69,9 +71,9 @@ main(int argc, char *const argv[])
ptr2ext = strrchr(filename, '.');
/* no extension or extension not equal .pgc */
if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0)
- {
+ {
if (ptr2ext == NULL)
- ext = 1; /* we need this information a while later */
+ ext = 1; /* we need this information a while later */
ptr2ext = filename + strlen(filename);
ptr2ext[0] = '.';
}
@@ -80,7 +82,7 @@ main(int argc, char *const argv[])
ptr2ext[1] = 'c';
ptr2ext[2] = '\0';
- if (out_option == 0) /* calculate the output name */
+ if (out_option == 0)/* calculate the output name */
{
yyout = fopen(filename, "w");
if (yyout == NULL)
@@ -91,7 +93,7 @@ main(int argc, char *const argv[])
}
}
- if (ext == 1)
+ if (ext == 1)
{
/* no extension => add .pgc */
ptr2ext = strrchr(filename, '.');
diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h
index 8055e5b07c1..b6166f9bb9f 100644
--- a/src/interfaces/ecpg/preproc/extern.h
+++ b/src/interfaces/ecpg/preproc/extern.h
@@ -1,14 +1,17 @@
/* variables */
-extern int debugging, braces_open;
-extern char * yytext;
-extern int yylineno, yyleng;
-extern FILE *yyin, *yyout;
+extern int debugging,
+ braces_open;
+extern char *yytext;
+extern int yylineno,
+ yyleng;
+extern FILE *yyin,
+ *yyout;
/* functions */
extern void lex_init(void);
-extern char * input_filename;
-extern int yyparse(void);
+extern char *input_filename;
+extern int yyparse(void);
extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);
diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c
index a436997aaa2..f5ff41c8c76 100644
--- a/src/interfaces/ecpg/preproc/type.c
+++ b/src/interfaces/ecpg/preproc/type.c
@@ -5,31 +5,33 @@
#include "type.h"
/* malloc + error check */
-void *mm_alloc(size_t size)
+void *
+mm_alloc(size_t size)
{
- void *ptr = malloc(size);
+ void *ptr = malloc(size);
- if (ptr == NULL)
- {
- fprintf(stderr, "Out of memory\n");
- exit(1);
- }
+ if (ptr == NULL)
+ {
+ fprintf(stderr, "Out of memory\n");
+ exit(1);
+ }
- return (ptr);
+ return (ptr);
}
/* realloc + error check */
-void *mm_realloc(void * ptr, size_t size)
+void *
+mm_realloc(void *ptr, size_t size)
{
- ptr = realloc(ptr, size);
+ ptr = realloc(ptr, size);
- if (ptr == NULL)
- {
- fprintf(stderr, "Out of memory\n");
- exit(1);
- }
+ if (ptr == NULL)
+ {
+ fprintf(stderr, "Out of memory\n");
+ exit(1);
+ }
- return (ptr);
+ return (ptr);
}
/* Constructors
@@ -38,75 +40,76 @@ void *mm_realloc(void * ptr, size_t size)
/* The NAME argument is copied. The type argument is preserved as a pointer. */
struct ECPGrecord_member *
-ECPGmake_record_member(char *name, struct ECPGtype *type, struct ECPGrecord_member **start)
+ECPGmake_record_member(char *name, struct ECPGtype * type, struct ECPGrecord_member ** start)
{
- struct ECPGrecord_member *ptr, *ne =
- (struct ECPGrecord_member *) mm_alloc(sizeof(struct ECPGrecord_member));
+ struct ECPGrecord_member *ptr,
+ *ne =
+ (struct ECPGrecord_member *) mm_alloc(sizeof(struct ECPGrecord_member));
- ne->name = strdup(name);
- ne->typ = type;
- ne->next = NULL;
+ ne->name = strdup(name);
+ ne->typ = type;
+ ne->next = NULL;
- for (ptr = *start; ptr && ptr->next; ptr = ptr->next);
+ for (ptr = *start; ptr && ptr->next; ptr = ptr->next);
- if (ptr)
- ptr->next=ne;
- else
- *start=ne;
- return ne;
+ if (ptr)
+ ptr->next = ne;
+ else
+ *start = ne;
+ return ne;
}
struct ECPGtype *
ECPGmake_simple_type(enum ECPGttype typ, long siz)
{
- struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
+ struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
- ne->typ = typ;
- ne->size = siz;
- ne->u.element = 0;
+ ne->typ = typ;
+ ne->size = siz;
+ ne->u.element = 0;
- return ne;
+ return ne;
}
struct ECPGtype *
ECPGmake_varchar_type(enum ECPGttype typ, long siz)
{
- struct ECPGtype *ne = ECPGmake_simple_type(typ, 1);
+ struct ECPGtype *ne = ECPGmake_simple_type(typ, 1);
- ne->size = siz;
+ ne->size = siz;
- return ne;
+ return ne;
}
struct ECPGtype *
-ECPGmake_array_type(struct ECPGtype *typ, long siz)
+ECPGmake_array_type(struct ECPGtype * typ, long siz)
{
- struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, siz);
+ struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, siz);
- ne->size = siz;
- ne->u.element = typ;
+ ne->size = siz;
+ ne->u.element = typ;
- return ne;
+ return ne;
}
struct ECPGtype *
-ECPGmake_record_type(struct ECPGrecord_member *rm)
+ECPGmake_record_type(struct ECPGrecord_member * rm)
{
- struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_record, 1);
+ struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_record, 1);
- ne->u.members = rm;
+ ne->u.members = rm;
- return ne;
+ return ne;
}
/* Dump a type.
The type is dumped as:
- type-tag <comma> - enum ECPGttype
+ type-tag <comma> - enum ECPGttype
reference-to-variable <comma> - void *
- 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
+ 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
Where:
type-tag is one of the simple types or varchar.
reference-to-variable can be a reference to a struct element.
@@ -114,47 +117,49 @@ ECPGmake_record_type(struct ECPGrecord_member *rm)
size is the maxsize in case it is a varchar. Otherwise it is the size of
the variable (required to do array fetches of records).
*/
-void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
- long varcharsize,
- long arrsiz, const char *siz, const char *prefix);
-void ECPGdump_a_record(FILE *o, const char *name, long arrsiz,
- struct ECPGtype *typ, const char *offset, const char *prefix);
+void
+ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
+ long varcharsize,
+ long arrsiz, const char *siz, const char *prefix);
+void
+ECPGdump_a_record(FILE *o, const char *name, long arrsiz,
+ struct ECPGtype * typ, const char *offset, const char *prefix);
void
-ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *typ, const char *prefix)
+ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * typ, const char *prefix)
{
- if (IS_SIMPLE_TYPE(typ->typ))
- {
- ECPGdump_a_simple(o, name, typ->typ, typ->size, 0, 0, prefix);
- }
- else if (typ->typ == ECPGt_array)
- {
- if (IS_SIMPLE_TYPE(typ->u.element->typ))
- ECPGdump_a_simple(o, name, typ->u.element->typ,
- typ->u.element->size, typ->size, 0, prefix);
- else if (typ->u.element->typ == ECPGt_array)
- {
- abort(); /* Array of array, */
- }
- else if (typ->u.element->typ == ECPGt_record)
- {
- /* Array of records. */
- ECPGdump_a_record(o, name, typ->size, typ->u.element, 0, prefix);
- }
- else
- {
- abort();
- }
- }
- else if (typ->typ == ECPGt_record)
- {
- ECPGdump_a_record(o, name, 0, typ, 0, prefix);
- }
- else
- {
- abort();
- }
+ if (IS_SIMPLE_TYPE(typ->typ))
+ {
+ ECPGdump_a_simple(o, name, typ->typ, typ->size, 0, 0, prefix);
+ }
+ else if (typ->typ == ECPGt_array)
+ {
+ if (IS_SIMPLE_TYPE(typ->u.element->typ))
+ ECPGdump_a_simple(o, name, typ->u.element->typ,
+ typ->u.element->size, typ->size, 0, prefix);
+ else if (typ->u.element->typ == ECPGt_array)
+ {
+ abort(); /* Array of array, */
+ }
+ else if (typ->u.element->typ == ECPGt_record)
+ {
+ /* Array of records. */
+ ECPGdump_a_record(o, name, typ->size, typ->u.element, 0, prefix);
+ }
+ else
+ {
+ abort();
+ }
+ }
+ else if (typ->typ == ECPGt_record)
+ {
+ ECPGdump_a_record(o, name, 0, typ, 0, prefix);
+ }
+ else
+ {
+ abort();
+ }
}
@@ -162,163 +167,170 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *typ, const char *pre
string, it represents the offset needed if we are in an array of records. */
void
ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
- long varcharsize,
- long arrsiz,
- const char *siz,
- const char *prefix)
+ long varcharsize,
+ long arrsiz,
+ const char *siz,
+ const char *prefix)
{
- switch (typ)
- {
- case ECPGt_char:
- if (varcharsize == 0) /* pointer */
- fprintf(o, "\n\tECPGt_char,%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
- siz == NULL ? "sizeof(char)" : siz);
- else
- fprintf(o, "\n\tECPGt_char,&%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
- siz == NULL ? "sizeof(char)" : siz);
- break;
- case ECPGt_unsigned_char:
- if (varcharsize == 0) /* pointer */
- fprintf(o, "\n\tECPGt_unsigned_char,%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
- siz == NULL ? "sizeof(char)" : siz);
- else
- fprintf(o, "\n\tECPGt_unsigned_char,&%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
- siz == NULL ? "sizeof(unsigned char)" : siz);
- break;
- case ECPGt_short:
- fprintf(o, "\n\tECPGt_short,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
- siz == NULL ? "sizeof(short)" : siz);
- break;
- case ECPGt_unsigned_short:
- fprintf(o,
- "\n\tECPGt_unsigned_short,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
- siz == NULL ? "sizeof(unsigned short)" : siz);
- break;
- case ECPGt_int:
- fprintf(o, "\n\tECPGt_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
- siz == NULL ? "sizeof(int)" : siz);
- break;
- case ECPGt_unsigned_int:
- fprintf(o, "\n\tECPGt_unsigned_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
- siz == NULL ? "sizeof(unsigned int)" : siz);
- break;
- case ECPGt_long:
- fprintf(o, "\n\tECPGt_long,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
- siz == NULL ? "sizeof(long)" : siz);
- break;
- case ECPGt_unsigned_long:
- fprintf(o, "\n\tECPGt_unsigned_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
- siz == NULL ? "sizeof(unsigned int)" : siz);
- break;
- case ECPGt_float:
- fprintf(o, "\n\tECPGt_float,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
- siz == NULL ? "sizeof(float)" : siz);
- break;
- case ECPGt_double:
- fprintf(o, "\n\tECPGt_double,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
- siz == NULL ? "sizeof(double)" : siz);
- break;
- case ECPGt_bool:
- fprintf(o, "\n\tECPGt_bool,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
- siz == NULL ? "sizeof(bool)" : siz);
- break;
- case ECPGt_varchar:
- case ECPGt_varchar2:
- if (siz == NULL)
- fprintf(o, "\n\tECPGt_varchar,&%s%s,%ldL,%ldL,sizeof(struct varchar_%s), ",
- prefix ? prefix : "", name,
- varcharsize,
- arrsiz, name);
- else
- fprintf(o, "\n\tECPGt_varchar,&%s%s,%ldL,%ldL,%s, ",
- prefix ? prefix : "", name,
- varcharsize,
- arrsiz, siz);
- break;
- default:
- abort();
- }
+ switch (typ)
+ {
+ case ECPGt_char:
+ if (varcharsize == 0) /* pointer */
+ fprintf(o, "\n\tECPGt_char,%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
+ siz == NULL ? "sizeof(char)" : siz);
+ else
+ fprintf(o, "\n\tECPGt_char,&%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
+ siz == NULL ? "sizeof(char)" : siz);
+ break;
+ case ECPGt_unsigned_char:
+ if (varcharsize == 0) /* pointer */
+ fprintf(o, "\n\tECPGt_unsigned_char,%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
+ siz == NULL ? "sizeof(char)" : siz);
+ else
+ fprintf(o, "\n\tECPGt_unsigned_char,&%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz,
+ siz == NULL ? "sizeof(unsigned char)" : siz);
+ break;
+ case ECPGt_short:
+ fprintf(o, "\n\tECPGt_short,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
+ siz == NULL ? "sizeof(short)" : siz);
+ break;
+ case ECPGt_unsigned_short:
+ fprintf(o,
+ "\n\tECPGt_unsigned_short,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
+ siz == NULL ? "sizeof(unsigned short)" : siz);
+ break;
+ case ECPGt_int:
+ fprintf(o, "\n\tECPGt_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
+ siz == NULL ? "sizeof(int)" : siz);
+ break;
+ case ECPGt_unsigned_int:
+ fprintf(o, "\n\tECPGt_unsigned_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
+ siz == NULL ? "sizeof(unsigned int)" : siz);
+ break;
+ case ECPGt_long:
+ fprintf(o, "\n\tECPGt_long,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
+ siz == NULL ? "sizeof(long)" : siz);
+ break;
+ case ECPGt_unsigned_long:
+ fprintf(o, "\n\tECPGt_unsigned_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
+ siz == NULL ? "sizeof(unsigned int)" : siz);
+ break;
+ case ECPGt_float:
+ fprintf(o, "\n\tECPGt_float,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
+ siz == NULL ? "sizeof(float)" : siz);
+ break;
+ case ECPGt_double:
+ fprintf(o, "\n\tECPGt_double,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
+ siz == NULL ? "sizeof(double)" : siz);
+ break;
+ case ECPGt_bool:
+ fprintf(o, "\n\tECPGt_bool,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz,
+ siz == NULL ? "sizeof(bool)" : siz);
+ break;
+ case ECPGt_varchar:
+ case ECPGt_varchar2:
+ if (siz == NULL)
+ fprintf(o, "\n\tECPGt_varchar,&%s%s,%ldL,%ldL,sizeof(struct varchar_%s), ",
+ prefix ? prefix : "", name,
+ varcharsize,
+ arrsiz, name);
+ else
+ fprintf(o, "\n\tECPGt_varchar,&%s%s,%ldL,%ldL,%s, ",
+ prefix ? prefix : "", name,
+ varcharsize,
+ arrsiz, siz);
+ break;
+ default:
+ abort();
+ }
}
/* Penetrate a record and dump the contents. */
void
-ECPGdump_a_record(FILE *o, const char *name, long arrsiz, struct ECPGtype *typ, const char *offsetarg, const char *prefix)
+ECPGdump_a_record(FILE *o, const char *name, long arrsiz, struct ECPGtype * typ, const char *offsetarg, const char *prefix)
{
- /* If offset is NULL, then this is the first recursive level. If not then
- we are in a record in a record and the offset is used as offset.
- */
- struct ECPGrecord_member *p;
- char obuf[BUFSIZ];
- char pbuf[BUFSIZ];
- const char *offset;
-
- if (offsetarg == NULL)
- {
- sprintf(obuf, "sizeof(%s)", name);
- offset = obuf;
- }
- else
- {
- offset = offsetarg;
- }
-
- sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);
- prefix = pbuf;
-
- for (p = typ->u.members; p; p=p->next)
- {
+
+ /*
+ * If offset is NULL, then this is the first recursive level. If not
+ * then we are in a record in a record and the offset is used as
+ * offset.
+ */
+ struct ECPGrecord_member *p;
+ char obuf[BUFSIZ];
+ char pbuf[BUFSIZ];
+ const char *offset;
+
+ if (offsetarg == NULL)
+ {
+ sprintf(obuf, "sizeof(%s)", name);
+ offset = obuf;
+ }
+ else
+ {
+ offset = offsetarg;
+ }
+
+ sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);
+ prefix = pbuf;
+
+ for (p = typ->u.members; p; p = p->next)
+ {
#if 0
- if (IS_SIMPLE_TYPE(p->typ->typ))
- {
- sprintf(buf, "%s.%s", name, p->name);
- ECPGdump_a_simple(o, buf, p->typ->typ, p->typ->size,
- arrsiz, offset);
- }
- else if (p->typ->typ == ECPGt_array)
- {
- int i;
-
- for (i = 0; i < p->typ->size; i++)
- {
- if (IS_SIMPLE_TYPE(p->typ->u.element->typ))
- {
- /* sprintf(buf, "%s.%s[%d]", name, p->name, i); */
- sprintf(buf, "%s.%s", name, p->name);
- ECPGdump_a_simple(o, buf, p->typ->u.element->typ, p->typ->u.element->size,
- p->typ->u.element->size, offset);
- }
- else if (p->typ->u.element->typ == ECPGt_array)
- {
- /* Array within an array. NOT implemented. */
- abort();
- }
- else if (p->typ->u.element->typ == ECPGt_record)
- {
- /* Record within array within record. NOT implemented yet. */
- abort();
- }
- else
- {
- /* Unknown type */
- abort();
- }
- }
- }
- else if (p->typ->typ == ECPGt_record)
- {
- /* Record within a record */
- sprintf(buf, "%s.%s", name, p->name);
- ECPGdump_a_record(o, buf, arrsiz, p->typ, offset);
- }
- else
- {
- /* Unknown type */
- abort();
- }
+ if (IS_SIMPLE_TYPE(p->typ->typ))
+ {
+ sprintf(buf, "%s.%s", name, p->name);
+ ECPGdump_a_simple(o, buf, p->typ->typ, p->typ->size,
+ arrsiz, offset);
+ }
+ else if (p->typ->typ == ECPGt_array)
+ {
+ int i;
+
+ for (i = 0; i < p->typ->size; i++)
+ {
+ if (IS_SIMPLE_TYPE(p->typ->u.element->typ))
+ {
+ /* sprintf(buf, "%s.%s[%d]", name, p->name, i); */
+ sprintf(buf, "%s.%s", name, p->name);
+ ECPGdump_a_simple(o, buf, p->typ->u.element->typ, p->typ->u.element->size,
+ p->typ->u.element->size, offset);
+ }
+ else if (p->typ->u.element->typ == ECPGt_array)
+ {
+ /* Array within an array. NOT implemented. */
+ abort();
+ }
+ else if (p->typ->u.element->typ == ECPGt_record)
+ {
+
+ /*
+ * Record within array within record. NOT implemented
+ * yet.
+ */
+ abort();
+ }
+ else
+ {
+ /* Unknown type */
+ abort();
+ }
+ }
+ }
+ else if (p->typ->typ == ECPGt_record)
+ {
+ /* Record within a record */
+ sprintf(buf, "%s.%s", name, p->name);
+ ECPGdump_a_record(o, buf, arrsiz, p->typ, offset);
+ }
+ else
+ {
+ /* Unknown type */
+ abort();
+ }
#endif
ECPGdump_a_type(o, p->name, p->typ, prefix);
- }
+ }
}
@@ -326,43 +338,43 @@ ECPGdump_a_record(FILE *o, const char *name, long arrsiz, struct ECPGtype *typ,
anyway. Lets implement that last! */
void
-ECPGfree_record_member(struct ECPGrecord_member *rm)
+ECPGfree_record_member(struct ECPGrecord_member * rm)
{
- while (rm)
- {
- struct ECPGrecord_member *p = rm;
-
- rm = rm->next;
- free(p->name);
- free(p);
- }
+ while (rm)
+ {
+ struct ECPGrecord_member *p = rm;
+
+ rm = rm->next;
+ free(p->name);
+ free(p);
+ }
}
void
-ECPGfree_type(struct ECPGtype *typ)
+ECPGfree_type(struct ECPGtype * typ)
{
- if (!IS_SIMPLE_TYPE(typ->typ))
- {
- if (typ->typ == ECPGt_array)
- {
- if (IS_SIMPLE_TYPE(typ->u.element->typ))
- free(typ->u.element);
- else if (typ->u.element->typ == ECPGt_array)
- abort(); /* Array of array, */
- else if (typ->u.element->typ == ECPGt_record)
- /* Array of records. */
- ECPGfree_record_member(typ->u.members);
- else
- abort();
- }
- else if (typ->typ == ECPGt_record)
- {
- ECPGfree_record_member(typ->u.members);
- }
- else
- {
- abort();
- }
- }
- free(typ);
+ if (!IS_SIMPLE_TYPE(typ->typ))
+ {
+ if (typ->typ == ECPGt_array)
+ {
+ if (IS_SIMPLE_TYPE(typ->u.element->typ))
+ free(typ->u.element);
+ else if (typ->u.element->typ == ECPGt_array)
+ abort(); /* Array of array, */
+ else if (typ->u.element->typ == ECPGt_record)
+ /* Array of records. */
+ ECPGfree_record_member(typ->u.members);
+ else
+ abort();
+ }
+ else if (typ->typ == ECPGt_record)
+ {
+ ECPGfree_record_member(typ->u.members);
+ }
+ else
+ {
+ abort();
+ }
+ }
+ free(typ);
}
diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h
index 8ff6ed1b9c2..69bea16b52d 100644
--- a/src/interfaces/ecpg/preproc/type.h
+++ b/src/interfaces/ecpg/preproc/type.h
@@ -1,36 +1,39 @@
#include <ecpgtype.h>
struct ECPGtype;
-struct ECPGrecord_member {
- char * name;
- struct ECPGtype * typ;
- struct ECPGrecord_member * next;
+struct ECPGrecord_member
+{
+ char *name;
+ struct ECPGtype *typ;
+ struct ECPGrecord_member *next;
};
-struct ECPGtype {
- enum ECPGttype typ;
- long size; /* For array it is the number of elements.
- * For varchar it is the maxsize of the area.
- */
- union {
- struct ECPGtype * element; /* For an array this is the type of the
- * element */
+struct ECPGtype
+{
+ enum ECPGttype typ;
+ long size; /* For array it is the number of elements.
+ * For varchar it is the maxsize of the
+ * area. */
+ union
+ {
+ struct ECPGtype *element; /* For an array this is the type
+ * of the element */
- struct ECPGrecord_member * members;
- /* A pointer to a list of members. */
- } u;
+ struct ECPGrecord_member *members;
+ /* A pointer to a list of members. */
+ } u;
};
/* Everything is malloced. */
-struct ECPGrecord_member * ECPGmake_record_member(char *, struct ECPGtype *, struct ECPGrecord_member **);
-struct ECPGtype * ECPGmake_simple_type(enum ECPGttype, long);
-struct ECPGtype * ECPGmake_varchar_type(enum ECPGttype, long);
-struct ECPGtype * ECPGmake_array_type(struct ECPGtype *, long);
-struct ECPGtype * ECPGmake_record_type(struct ECPGrecord_member *);
+struct ECPGrecord_member *ECPGmake_record_member(char *, struct ECPGtype *, struct ECPGrecord_member **);
+struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, long);
+struct ECPGtype *ECPGmake_varchar_type(enum ECPGttype, long);
+struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, long);
+struct ECPGtype *ECPGmake_record_type(struct ECPGrecord_member *);
/* Frees a type. */
-void ECPGfree_record_member(struct ECPGrecord_member *);
-void ECPGfree_type(struct ECPGtype *);
+void ECPGfree_record_member(struct ECPGrecord_member *);
+void ECPGfree_type(struct ECPGtype *);
/* Dump a type.
The type is dumped as:
@@ -39,32 +42,34 @@ void ECPGfree_type(struct ECPGtype *);
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
- the variable (required to do array fetches of records).
+ size is the maxsize in case it is a varchar. Otherwise it is the size of
+ the variable (required to do array fetches of records).
*/
-void ECPGdump_a_type(FILE *, const char * name, struct ECPGtype *, const char *);
+void ECPGdump_a_type(FILE *, const char *name, struct ECPGtype *, const char *);
/* A simple struct to keep a variable and its type. */
-struct ECPGtemp_type {
- struct ECPGtype * typ;
- const char * name;
+struct ECPGtemp_type
+{
+ struct ECPGtype *typ;
+ const char *name;
};
-extern const char * ECPGtype_name(enum ECPGttype typ);
+extern const char *ECPGtype_name(enum ECPGttype typ);
/* some stuff for whenever statements */
-enum WHEN {
- W_NOTHING,
- W_CONTINUE,
- W_BREAK,
- W_SQLPRINT,
- W_GOTO,
- W_DO,
- W_STOP
+enum WHEN
+{
+ W_NOTHING,
+ W_CONTINUE,
+ W_BREAK,
+ W_SQLPRINT,
+ W_GOTO,
+ W_DO,
+ W_STOP
};
struct when
-{
- enum WHEN code;
- char * str;
+{
+ enum WHEN code;
+ char *str;
};
diff --git a/src/interfaces/ecpg/test/Ptest1.c b/src/interfaces/ecpg/test/Ptest1.c
index 5aee48e7d5c..5418e2c1a40 100644
--- a/src/interfaces/ecpg/test/Ptest1.c
+++ b/src/interfaces/ecpg/test/Ptest1.c
@@ -3,62 +3,75 @@
#include <ecpglib.h>
/* exec sql begin declare section */
- /* VARSIZE */struct varchar_uid { int len; char arr[200]; } uid;
- struct varchar_name { int len; char arr[200]; } name;
- short value;
+ /* VARSIZE */ struct varchar_uid
+{
+ int len;
+ char arr[200];
+} uid;
+struct varchar_name
+{
+ int len;
+ char arr[200];
+} name;
+short value;
+
/* exec sql end declare section */
#include "sqlca.h"
-#define DBCP(x,y) strcpy(x.arr,y);x.len = strlen(x.arr)
-#define LENFIX(x) x.len=strlen(x.arr)
-#define STRFIX(x) x.arr[x.len]='\0'
-#define SQLCODE sqlca.sqlcode
+#define DBCP(x,y) strcpy(x.arr,y);x.len = strlen(x.arr)
+#define LENFIX(x) x.len=strlen(x.arr)
+#define STRFIX(x) x.arr[x.len]='\0'
+#define SQLCODE sqlca.sqlcode
void
-db_error (char *msg)
+db_error(char *msg)
{
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0';
- printf ("%s: db error %s\n", msg, sqlca.sqlerrm.sqlerrmc);
- exit (1);
+ printf("%s: db error %s\n", msg, sqlca.sqlerrm.sqlerrmc);
+ exit(1);
}
int
-main ()
+main()
{
- strcpy (uid.arr, "test/test");
- LENFIX (uid);
+ strcpy(uid.arr, "test/test");
+ LENFIX(uid);
ECPGconnect("kom");
if (SQLCODE)
- db_error ("connect");
+ db_error("connect");
- strcpy (name.arr, "opt1");
- LENFIX (name);
+ strcpy(name.arr, "opt1");
+ LENFIX(name);
+
+ ECPGdo(__LINE__, "declare cur cursor for select name , value from pace_test ", ECPGt_EOIT, ECPGt_EORT);
+ if (SQLCODE)
+ db_error("declare");
- ECPGdo(__LINE__, "declare cur cursor for select name , value from pace_test ", ECPGt_EOIT, ECPGt_EORT );
- if (SQLCODE) db_error ("declare");
-
if (SQLCODE)
- db_error ("open");
+ db_error("open");
- while (1) {
- ECPGdo(__LINE__, "fetch in cur ", ECPGt_EOIT, ECPGt_varchar,&name,200,0,sizeof(struct varchar_name), ECPGt_short,&value,0,0,sizeof(short), ECPGt_EORT );
+ while (1)
+ {
+ ECPGdo(__LINE__, "fetch in cur ", ECPGt_EOIT, ECPGt_varchar, &name, 200, 0, sizeof(struct varchar_name), ECPGt_short, &value, 0, 0, sizeof(short), ECPGt_EORT);
if (SQLCODE)
break;
- STRFIX (name);
- printf ("%s\t%d\n", name.arr, value);
+ STRFIX(name);
+ printf("%s\t%d\n", name.arr, value);
}
if (SQLCODE < 0)
- db_error ("fetch");
+ db_error("fetch");
- ECPGdo(__LINE__, "close cur ", ECPGt_EOIT, ECPGt_EORT );
- if (SQLCODE) db_error ("close");
+ ECPGdo(__LINE__, "close cur ", ECPGt_EOIT, ECPGt_EORT);
+ if (SQLCODE)
+ db_error("close");
ECPGcommit(__LINE__);
- if (SQLCODE) db_error ("commit");
+ if (SQLCODE)
+ db_error("commit");
return (0);
}
diff --git a/src/interfaces/ecpg/test/test1.c b/src/interfaces/ecpg/test/test1.c
index 68d9dd53981..f2533d544d9 100644
--- a/src/interfaces/ecpg/test/test1.c
+++ b/src/interfaces/ecpg/test/test1.c
@@ -1,60 +1,72 @@
exec sql begin declare section;
-VARCHAR uid[200 /* VARSIZE */];
-varchar name[200];
-short value;
+VARCHAR uid[200 /* VARSIZE */ ];
+varchar name[200];
+short value;
exec sql end declare section;
exec sql include sqlca;
-#define DBCP(x,y) strcpy(x.arr,y);x.len = strlen(x.arr)
-#define LENFIX(x) x.len=strlen(x.arr)
-#define STRFIX(x) x.arr[x.len]='\0'
-#define SQLCODE sqlca.sqlcode
+#define DBCP(x,y) strcpy(x.arr,y);x.len = strlen(x.arr)
+#define LENFIX(x) x.len=strlen(x.arr)
+#define STRFIX(x) x.arr[x.len]='\0'
+#define SQLCODE sqlca.sqlcode
void
-db_error (char *msg)
+db_error(char *msg)
{
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0';
- printf ("%s: db error %s\n", msg, sqlca.sqlerrm.sqlerrmc);
- exit (1);
+ printf("%s: db error %s\n", msg, sqlca.sqlerrm.sqlerrmc);
+ exit(1);
}
int
-main ()
+main()
{
- strcpy (uid.arr, "test/test");
- LENFIX (uid);
+ strcpy(uid.arr, "test/test");
+ LENFIX(uid);
+
+ exec sql connect 'kom';
- exec sql connect 'kom';
if (SQLCODE)
- db_error ("connect");
+ db_error("connect");
+
+ strcpy(name.arr, "opt1");
+ LENFIX(name);
- strcpy (name.arr, "opt1");
- LENFIX (name);
+ exec sql declare cur cursor for
+ select name,
+ value from pace_test;
- exec sql declare cur cursor for
- select name, value from pace_test;
- if (SQLCODE) db_error ("declare");
+ if (SQLCODE)
+ db_error("declare");
exec sql open cur;
+
if (SQLCODE)
- db_error ("open");
+ db_error("open");
+
+ while (1)
+ {
+ exec sql fetch in cur into:name,
+ : value;
- while (1) {
- exec sql fetch in cur into :name, :value;
if (SQLCODE)
break;
- STRFIX (name);
- printf ("%s\t%d\n", name.arr, value);
+ STRFIX(name);
+ printf("%s\t%d\n", name.arr, value);
}
if (SQLCODE < 0)
- db_error ("fetch");
+ db_error("fetch");
exec sql close cur;
- if (SQLCODE) db_error ("close");
- exec sql commit;
- if (SQLCODE) db_error ("commit");
+
+ if (SQLCODE)
+ db_error("close");
+ exec sql commit;
+
+ if (SQLCODE)
+ db_error("commit");
return (0);
}