mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
pgindent run before 6.3 release, with Thomas' requested changes.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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, '.');
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
/*
|
||||
* 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;
|
||||
|
||||
for (p = typ->u.members; p; p=p->next)
|
||||
{
|
||||
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;
|
||||
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();
|
||||
}
|
||||
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;
|
||||
while (rm)
|
||||
{
|
||||
struct ECPGrecord_member *p = rm;
|
||||
|
||||
rm = rm->next;
|
||||
free(p->name);
|
||||
free(p);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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 ("open");
|
||||
db_error("declare");
|
||||
|
||||
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)
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
if (SQLCODE) db_error ("declare");
|
||||
exec sql declare cur cursor for
|
||||
select name,
|
||||
value from pace_test;
|
||||
|
||||
if (SQLCODE)
|
||||
db_error("declare");
|
||||
|
||||
exec sql open cur;
|
||||
if (SQLCODE)
|
||||
db_error ("open");
|
||||
|
||||
while (1) {
|
||||
exec sql fetch in cur into :name, :value;
|
||||
if (SQLCODE)
|
||||
db_error("open");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.20 1998/02/11 19:13:54 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.21 1998/02/26 04:44:48 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -41,7 +41,7 @@
|
||||
static inline char *
|
||||
translate_escape(char *p, int isArray)
|
||||
{
|
||||
char c,
|
||||
char c,
|
||||
*q,
|
||||
*s;
|
||||
|
||||
@@ -155,7 +155,7 @@ tcl_value(char *value)
|
||||
{
|
||||
int literal,
|
||||
last;
|
||||
char *p;
|
||||
char *p;
|
||||
|
||||
if (!value)
|
||||
{
|
||||
@@ -645,7 +645,7 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
|
||||
#ifdef TCL_ARRAYS
|
||||
for (i = 0; i < PQnfields(result); i++)
|
||||
{
|
||||
Tcl_AppendElement(interp, PQgetvalue(result,tupno,i));
|
||||
Tcl_AppendElement(interp, PQgetvalue(result, tupno, i));
|
||||
}
|
||||
#else
|
||||
/* Tcl_AppendResult(interp, PQgetvalue(result,tupno,0),NULL); */
|
||||
@@ -1323,17 +1323,24 @@ Pg_select(ClientData cData, Tcl_Interp * interp, int argc, char **argv)
|
||||
|
||||
for (column = 0; column < ncols; column++)
|
||||
{
|
||||
Tcl_SetVar2(interp, argv[3], info[column].cname,
|
||||
PQgetvalue(result, tupno, column), 0);
|
||||
Tcl_SetVar2(interp, argv[3], info[column].cname,
|
||||
PQgetvalue(result, tupno, column), 0);
|
||||
}
|
||||
|
||||
Tcl_SetVar2(interp, argv[3], ".command", "update", 0);
|
||||
|
||||
if ((r = Tcl_Eval(interp, argv[4])) != TCL_OK && r != TCL_CONTINUE)
|
||||
{
|
||||
if (r == TCL_BREAK) {
|
||||
/* I suppose that memory used by info and result must be released */
|
||||
free(info); PQclear(result);Tcl_UnsetVar(interp, argv[3], 0);
|
||||
if (r == TCL_BREAK)
|
||||
{
|
||||
|
||||
/*
|
||||
* I suppose that memory used by info and result must be
|
||||
* released
|
||||
*/
|
||||
free(info);
|
||||
PQclear(result);
|
||||
Tcl_UnsetVar(interp, argv[3], 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
if (r == TCL_ERROR)
|
||||
@@ -1345,7 +1352,9 @@ Pg_select(ClientData cData, Tcl_Interp * interp, int argc, char **argv)
|
||||
Tcl_AddErrorInfo(interp, msg);
|
||||
}
|
||||
/* also, releasing memory used by info and result */
|
||||
free(info); PQclear(result);Tcl_UnsetVar(interp, argv[3], 0);
|
||||
free(info);
|
||||
PQclear(result);
|
||||
Tcl_UnsetVar(interp, argv[3], 0);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.6 1997/09/08 21:55:24 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.7 1998/02/26 04:44:53 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -49,7 +49,7 @@ PgSetConnectionId(Pg_clientData * cd, char *id, PGconn *conn)
|
||||
/*
|
||||
* Get back the connection from the Id
|
||||
*/
|
||||
PGconn *
|
||||
PGconn *
|
||||
PgGetConnectionId(Pg_clientData * cd, char *id)
|
||||
{
|
||||
Tcl_HashEntry *hent;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.14 1998/01/29 03:24:03 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.15 1998/02/26 04:44:56 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -477,14 +477,14 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
|
||||
*/
|
||||
int
|
||||
fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
|
||||
const char *password, char *PQerrormsg)
|
||||
const char *password, char *PQerrormsg)
|
||||
{
|
||||
switch (areq)
|
||||
{
|
||||
case AUTH_REQ_OK:
|
||||
break;
|
||||
case AUTH_REQ_OK:
|
||||
break;
|
||||
|
||||
case AUTH_REQ_KRB4:
|
||||
case AUTH_REQ_KRB4:
|
||||
#ifdef KRB4
|
||||
if (pg_krb4_sendauth(PQerrormsg, conn->sock, &conn->laddr.in,
|
||||
&conn->raddr.in,
|
||||
@@ -496,12 +496,12 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
|
||||
}
|
||||
break;
|
||||
#else
|
||||
(void)sprintf(PQerrormsg,
|
||||
"fe_sendauth: krb4 authentication not supported\n");
|
||||
return (STATUS_ERROR);
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_sendauth: krb4 authentication not supported\n");
|
||||
return (STATUS_ERROR);
|
||||
#endif
|
||||
|
||||
case AUTH_REQ_KRB5:
|
||||
case AUTH_REQ_KRB5:
|
||||
#ifdef KRB5
|
||||
if (pg_krb5_sendauth(PQerrormsg, conn->sock, &conn->laddr.in,
|
||||
&conn->raddr.in,
|
||||
@@ -513,27 +513,27 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
|
||||
}
|
||||
break;
|
||||
#else
|
||||
(void)sprintf(PQerrormsg,
|
||||
"fe_sendauth: krb5 authentication not supported\n");
|
||||
return (STATUS_ERROR);
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_sendauth: krb5 authentication not supported\n");
|
||||
return (STATUS_ERROR);
|
||||
#endif
|
||||
|
||||
case AUTH_REQ_PASSWORD:
|
||||
case AUTH_REQ_CRYPT:
|
||||
if (pg_password_sendauth(conn, password, areq) != STATUS_OK)
|
||||
{
|
||||
(void)sprintf(PQerrormsg,
|
||||
"fe_sendauth: error sending password authentication\n");
|
||||
case AUTH_REQ_PASSWORD:
|
||||
case AUTH_REQ_CRYPT:
|
||||
if (pg_password_sendauth(conn, password, areq) != STATUS_OK)
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_sendauth: error sending password authentication\n");
|
||||
return (STATUS_ERROR);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_sendauth: authentication type %u not supported\n", areq);
|
||||
return (STATUS_ERROR);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
(void)sprintf(PQerrormsg,
|
||||
"fe_sendauth: authentication type %u not supported\n",areq);
|
||||
return (STATUS_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
return (STATUS_OK);
|
||||
}
|
||||
@@ -580,7 +580,7 @@ fe_getauthsvc(char *PQerrormsg)
|
||||
* name the user has authenticated to the system
|
||||
* if there is an error, return the error message in PQerrormsg
|
||||
*/
|
||||
char *
|
||||
char *
|
||||
fe_getauthname(char *PQerrormsg)
|
||||
{
|
||||
char *name = (char *) NULL;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.62 1998/01/31 21:27:28 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.63 1998/02/26 04:44:59 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -49,7 +49,7 @@ static void closePGconn(PGconn *conn);
|
||||
static int conninfo_parse(const char *conninfo, char *errorMessage);
|
||||
static char *conninfo_getval(char *keyword);
|
||||
static void conninfo_free(void);
|
||||
void PQsetenv(PGconn *conn);
|
||||
void PQsetenv(PGconn *conn);
|
||||
|
||||
#define NOTIFYLIST_INITIAL_SIZE 10
|
||||
#define NOTIFYLIST_GROWBY 10
|
||||
@@ -114,15 +114,29 @@ struct EnvironmentOptions
|
||||
|
||||
{
|
||||
/* common user-interface settings */
|
||||
{ "PGDATESTYLE", "datestyle" },
|
||||
{ "PGTZ", "timezone" },
|
||||
{
|
||||
"PGDATESTYLE", "datestyle"
|
||||
},
|
||||
{
|
||||
"PGTZ", "timezone"
|
||||
},
|
||||
|
||||
/* internal performance-related settings */
|
||||
{ "PGCOSTHEAP", "cost_heap" },
|
||||
{ "PGCOSTINDEX", "cost_index" },
|
||||
{ "PGRPLANS", "r_plans" },
|
||||
{ "PGGEQO", "geqo" },
|
||||
{ NULL }
|
||||
{
|
||||
"PGCOSTHEAP", "cost_heap"
|
||||
},
|
||||
{
|
||||
"PGCOSTINDEX", "cost_index"
|
||||
},
|
||||
{
|
||||
"PGRPLANS", "r_plans"
|
||||
},
|
||||
{
|
||||
"PGGEQO", "geqo"
|
||||
},
|
||||
{
|
||||
NULL
|
||||
}
|
||||
};
|
||||
|
||||
/* ----------------
|
||||
@@ -149,7 +163,8 @@ PQconnectdb(const char *conninfo)
|
||||
{
|
||||
PGconn *conn;
|
||||
char errorMessage[ERROR_MSG_LENGTH];
|
||||
char* tmp;
|
||||
char *tmp;
|
||||
|
||||
/* ----------
|
||||
* Allocate memory for the conn structure
|
||||
* ----------
|
||||
@@ -190,7 +205,7 @@ PQconnectdb(const char *conninfo)
|
||||
tmp = conninfo_getval("port");
|
||||
conn->pgport = tmp ? strdup(tmp) : NULL;
|
||||
tmp = conninfo_getval("tty");
|
||||
conn->pgtty = tmp ? strdup(tmp) : NULL;
|
||||
conn->pgtty = tmp ? strdup(tmp) : NULL;
|
||||
tmp = conninfo_getval("options");
|
||||
conn->pgoptions = tmp ? strdup(tmp) : NULL;
|
||||
tmp = conninfo_getval("user");
|
||||
@@ -291,7 +306,7 @@ PQconndefaults(void)
|
||||
*
|
||||
* ----------------
|
||||
*/
|
||||
PGconn *
|
||||
PGconn *
|
||||
PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, const char *pgtty, const char *dbName, const char *login, const char *pwd)
|
||||
{
|
||||
PGconn *conn;
|
||||
@@ -399,8 +414,8 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, cons
|
||||
conn->dbName = strdup(conn->pguser);
|
||||
|
||||
/*
|
||||
* if the database name is surrounded by double-quotes,
|
||||
* then don't convert case
|
||||
* if the database name is surrounded by double-quotes, then
|
||||
* don't convert case
|
||||
*/
|
||||
if (*conn->dbName == '"')
|
||||
{
|
||||
@@ -455,8 +470,8 @@ connectDB(PGconn *conn)
|
||||
{
|
||||
struct hostent *hp;
|
||||
|
||||
StartupPacket sp;
|
||||
AuthRequest areq;
|
||||
StartupPacket sp;
|
||||
AuthRequest areq;
|
||||
int laddrlen = sizeof(SockAddr);
|
||||
int portno,
|
||||
family,
|
||||
@@ -466,9 +481,9 @@ connectDB(PGconn *conn)
|
||||
* Initialize the startup packet.
|
||||
*/
|
||||
|
||||
MemSet((char *)&sp, 0, sizeof (StartupPacket));
|
||||
MemSet((char *) &sp, 0, sizeof(StartupPacket));
|
||||
|
||||
sp.protoVersion = (ProtocolVersion)htonl(PG_PROTOCOL_LATEST);
|
||||
sp.protoVersion = (ProtocolVersion) htonl(PG_PROTOCOL_LATEST);
|
||||
|
||||
strncpy(sp.user, conn->pguser, SM_USER);
|
||||
strncpy(sp.database, conn->dbName, SM_DATABASE);
|
||||
@@ -491,7 +506,8 @@ connectDB(PGconn *conn)
|
||||
conn->pghost);
|
||||
goto connect_errReturn;
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
hp = NULL;
|
||||
|
||||
#if FALSE
|
||||
@@ -572,7 +588,7 @@ connectDB(PGconn *conn)
|
||||
|
||||
/* Send the startup packet. */
|
||||
|
||||
if (packetSend(conn, (char *)&sp, sizeof(StartupPacket)) != STATUS_OK)
|
||||
if (packetSend(conn, (char *) &sp, sizeof(StartupPacket)) != STATUS_OK)
|
||||
{
|
||||
sprintf(conn->errorMessage,
|
||||
"connectDB() -- couldn't send complete packet: errno=%d\n%s\n", errno, strerror(errno));
|
||||
@@ -586,12 +602,12 @@ connectDB(PGconn *conn)
|
||||
|
||||
do
|
||||
{
|
||||
int beresp;
|
||||
int beresp;
|
||||
|
||||
if ((beresp = pqGetc(conn->Pfin, conn->Pfdebug)) == EOF)
|
||||
{
|
||||
(void)sprintf(conn->errorMessage,
|
||||
"connectDB() -- error getting authentication request\n");
|
||||
(void) sprintf(conn->errorMessage,
|
||||
"connectDB() -- error getting authentication request\n");
|
||||
|
||||
goto connect_errReturn;
|
||||
}
|
||||
@@ -600,8 +616,8 @@ connectDB(PGconn *conn)
|
||||
|
||||
if (beresp == 'E')
|
||||
{
|
||||
pqGets(conn->errorMessage, sizeof (conn->errorMessage),
|
||||
conn->Pfin, conn->Pfdebug);
|
||||
pqGets(conn->errorMessage, sizeof(conn->errorMessage),
|
||||
conn->Pfin, conn->Pfdebug);
|
||||
|
||||
goto connect_errReturn;
|
||||
}
|
||||
@@ -610,18 +626,18 @@ connectDB(PGconn *conn)
|
||||
|
||||
if (beresp != 'R')
|
||||
{
|
||||
(void)sprintf(conn->errorMessage,
|
||||
"connectDB() -- expected authentication request\n");
|
||||
(void) sprintf(conn->errorMessage,
|
||||
"connectDB() -- expected authentication request\n");
|
||||
|
||||
goto connect_errReturn;
|
||||
}
|
||||
|
||||
/* Get the type of request. */
|
||||
|
||||
if (pqGetInt((int *)&areq, 4, conn->Pfin, conn->Pfdebug))
|
||||
if (pqGetInt((int *) &areq, 4, conn->Pfin, conn->Pfdebug))
|
||||
{
|
||||
(void)sprintf(conn->errorMessage,
|
||||
"connectDB() -- error getting authentication request type\n");
|
||||
(void) sprintf(conn->errorMessage,
|
||||
"connectDB() -- error getting authentication request type\n");
|
||||
|
||||
goto connect_errReturn;
|
||||
}
|
||||
@@ -629,11 +645,11 @@ connectDB(PGconn *conn)
|
||||
/* Get the password salt if there is one. */
|
||||
|
||||
if (areq == AUTH_REQ_CRYPT &&
|
||||
pqGetnchar(conn->salt, sizeof (conn->salt),
|
||||
conn->Pfin, conn->Pfdebug))
|
||||
pqGetnchar(conn->salt, sizeof(conn->salt),
|
||||
conn->Pfin, conn->Pfdebug))
|
||||
{
|
||||
(void)sprintf(conn->errorMessage,
|
||||
"connectDB() -- error getting password salt\n");
|
||||
(void) sprintf(conn->errorMessage,
|
||||
"connectDB() -- error getting password salt\n");
|
||||
|
||||
goto connect_errReturn;
|
||||
}
|
||||
@@ -642,7 +658,7 @@ connectDB(PGconn *conn)
|
||||
/* Respond to the request. */
|
||||
|
||||
if (fe_sendauth(areq, conn, conn->pghost, conn->pgpass,
|
||||
conn->errorMessage) != STATUS_OK)
|
||||
conn->errorMessage) != STATUS_OK)
|
||||
goto connect_errReturn;
|
||||
}
|
||||
while (areq != AUTH_REQ_OK);
|
||||
@@ -664,7 +680,7 @@ void
|
||||
PQsetenv(PGconn *conn)
|
||||
{
|
||||
struct EnvironmentOptions *eo;
|
||||
char setQuery[80]; /* mjl: size okay? XXX */
|
||||
char setQuery[80]; /* mjl: size okay? XXX */
|
||||
|
||||
for (eo = EnvironmentOptions; eo->envName; eo++)
|
||||
{
|
||||
@@ -679,13 +695,13 @@ PQsetenv(PGconn *conn)
|
||||
else
|
||||
sprintf(setQuery, "SET %s = '%.60s'", eo->pgName, val);
|
||||
#ifdef CONNECTDEBUG
|
||||
printf("Use environment variable %s to send %s\n", eo->envName, setQuery);
|
||||
printf("Use environment variable %s to send %s\n", eo->envName, setQuery);
|
||||
#endif
|
||||
res = PQexec(conn, setQuery);
|
||||
PQclear(res); /* Don't care? */
|
||||
PQclear(res); /* Don't care? */
|
||||
}
|
||||
}
|
||||
} /* PQsetenv() */
|
||||
} /* PQsetenv() */
|
||||
|
||||
/*
|
||||
* freePGconn
|
||||
@@ -1095,7 +1111,7 @@ conninfo_free()
|
||||
}
|
||||
|
||||
/* =========== accessor functions for PGconn ========= */
|
||||
char *
|
||||
char *
|
||||
PQdb(PGconn *conn)
|
||||
{
|
||||
if (!conn)
|
||||
@@ -1106,7 +1122,7 @@ PQdb(PGconn *conn)
|
||||
return conn->dbName;
|
||||
}
|
||||
|
||||
char *
|
||||
char *
|
||||
PQuser(PGconn *conn)
|
||||
{
|
||||
if (!conn)
|
||||
@@ -1117,7 +1133,7 @@ PQuser(PGconn *conn)
|
||||
return conn->pguser;
|
||||
}
|
||||
|
||||
char *
|
||||
char *
|
||||
PQhost(PGconn *conn)
|
||||
{
|
||||
if (!conn)
|
||||
@@ -1129,7 +1145,7 @@ PQhost(PGconn *conn)
|
||||
return conn->pghost;
|
||||
}
|
||||
|
||||
char *
|
||||
char *
|
||||
PQoptions(PGconn *conn)
|
||||
{
|
||||
if (!conn)
|
||||
@@ -1140,7 +1156,7 @@ PQoptions(PGconn *conn)
|
||||
return conn->pgoptions;
|
||||
}
|
||||
|
||||
char *
|
||||
char *
|
||||
PQtty(PGconn *conn)
|
||||
{
|
||||
if (!conn)
|
||||
@@ -1151,7 +1167,7 @@ PQtty(PGconn *conn)
|
||||
return conn->pgtty;
|
||||
}
|
||||
|
||||
char *
|
||||
char *
|
||||
PQport(PGconn *conn)
|
||||
{
|
||||
if (!conn)
|
||||
@@ -1173,7 +1189,7 @@ PQstatus(PGconn *conn)
|
||||
return conn->status;
|
||||
}
|
||||
|
||||
char *
|
||||
char *
|
||||
PQerrorMessage(PGconn *conn)
|
||||
{
|
||||
if (!conn)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: fe-connect.h,v 1.7 1998/01/29 03:24:36 scrappy Exp $
|
||||
* $Id: fe-connect.h,v 1.8 1998/02/26 04:45:02 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -23,6 +23,6 @@
|
||||
*----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int packetSend(PGconn *conn, const char *buf, size_t len);
|
||||
int packetSend(PGconn *conn, const char *buf, size_t len);
|
||||
|
||||
#endif /* FE_CONNECT_H */
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.46 1998/01/26 01:42:35 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.47 1998/02/26 04:45:07 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -457,10 +457,11 @@ process_response_from_backend(FILE *pfin, FILE *pfout, FILE *pfdebug,
|
||||
{
|
||||
/* hmm, no response from the backend-end, that's bad */
|
||||
(void) sprintf(reason, "PQexec() -- Request was sent to backend"
|
||||
", but backend closed the channel before responding."
|
||||
"\n\tThis probably means the backend terminated abnormally"
|
||||
" before or while processing the request.\n");
|
||||
conn->status = CONNECTION_BAD; /* No more connection to backend */
|
||||
", but backend closed the channel before responding."
|
||||
"\n\tThis probably means the backend terminated abnormally"
|
||||
" before or while processing the request.\n");
|
||||
conn->status = CONNECTION_BAD; /* No more connection to
|
||||
* backend */
|
||||
*result_p = (PGresult *) NULL;
|
||||
done = true;
|
||||
}
|
||||
@@ -1643,7 +1644,7 @@ PQnfields(PGresult *res)
|
||||
/*
|
||||
returns NULL if the field_num is invalid
|
||||
*/
|
||||
char *
|
||||
char *
|
||||
PQfname(PGresult *res, int field_num)
|
||||
{
|
||||
if (!res)
|
||||
@@ -1756,7 +1757,7 @@ PQfsize(PGresult *res, int field_num)
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
char *
|
||||
PQcmdStatus(PGresult *res)
|
||||
{
|
||||
if (!res)
|
||||
@@ -1853,7 +1854,7 @@ PQcmdTuples(PGresult *res)
|
||||
|
||||
if res is not binary, a null-terminated ASCII string is returned.
|
||||
*/
|
||||
char *
|
||||
char *
|
||||
PQgetvalue(PGresult *res, int tup_num, int field_num)
|
||||
{
|
||||
if (!res)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.9 1998/01/26 01:42:36 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.10 1998/02/26 04:45:09 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -65,7 +65,7 @@ pqPutnchar(const char *s, int len, FILE *f, FILE *debug)
|
||||
int
|
||||
pqGetnchar(char *s, int len, FILE *f, FILE *debug)
|
||||
{
|
||||
int status;
|
||||
int status;
|
||||
|
||||
status = pqGetNBytes(s, len, f);
|
||||
|
||||
@@ -82,7 +82,7 @@ pqGetnchar(char *s, int len, FILE *f, FILE *debug)
|
||||
int
|
||||
pqGets(char *s, int len, FILE *f, FILE *debug)
|
||||
{
|
||||
int status;
|
||||
int status;
|
||||
|
||||
status = pqGetString(s, len, f);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: libpq-fe.h,v 1.26 1998/02/24 06:04:55 scrappy Exp $
|
||||
* $Id: libpq-fe.h,v 1.27 1998/02/26 04:45:15 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -138,10 +138,10 @@ extern "C"
|
||||
FILE *Pfin;
|
||||
FILE *Pfout;
|
||||
FILE *Pfdebug;
|
||||
int sock; /* The socket */
|
||||
SockAddr laddr; /* Local address */
|
||||
SockAddr raddr; /* Remote address */
|
||||
char salt[2];
|
||||
int sock; /* The socket */
|
||||
SockAddr laddr; /* Local address */
|
||||
SockAddr raddr; /* Remote address */
|
||||
char salt[2];
|
||||
int asyncNotifyWaiting;
|
||||
Dllist *notifyList;
|
||||
char *pguser; /* Postgres username of user who is
|
||||
@@ -224,7 +224,7 @@ extern "C"
|
||||
extern PGconn *PQconnectdb(const char *conninfo);
|
||||
extern PQconninfoOption *PQconndefaults(void);
|
||||
extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
|
||||
const char *pgtty, const char *dbName, const char *login, const char *pwd);
|
||||
const char *pgtty, const char *dbName, const char *login, const char *pwd);
|
||||
#define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME) PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL)
|
||||
/* close the current connection and free the PGconn data structure */
|
||||
extern void PQfinish(PGconn *conn);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user