mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
OK, folks, here is the pgindent output.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
/* This is a list of all error codes the embedded SQL program can return */
|
||||
#define ECPG_NO_ERROR 0
|
||||
#define ECPG_NO_ERROR 0
|
||||
#define ECPG_NOT_FOUND 100
|
||||
|
||||
/* system error codes returned by ecpglib get the correct number,
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
/* first we have a set of ecpg messages, they start at 200 */
|
||||
#define ECPG_UNSUPPORTED -200
|
||||
#define ECPG_TOO_MANY_ARGUMENTS -201
|
||||
#define ECPG_TOO_MANY_ARGUMENTS -201
|
||||
#define ECPG_TOO_FEW_ARGUMENTS -202
|
||||
#define ECPG_TOO_MANY_MATCHES -203
|
||||
#define ECPG_INT_FORMAT -204
|
||||
@@ -33,4 +33,4 @@
|
||||
#define ECPG_TRANS -401
|
||||
#define ECPG_CONNECT -402
|
||||
|
||||
#endif /* !_ECPG_ERROR_H */
|
||||
#endif /* !_ECPG_ERROR_H */
|
||||
|
||||
@@ -1,43 +1,46 @@
|
||||
#include <c.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void ECPGdebug(int, FILE *);
|
||||
bool ECPGsetconn(int, const char *);
|
||||
bool ECPGconnect(int, const char *, const char *, const char *, const char *);
|
||||
bool ECPGdo(int, char *,...);
|
||||
bool ECPGtrans(int, const char *);
|
||||
bool ECPGdisconnect(int, const char *);
|
||||
void ECPGdebug(int, FILE *);
|
||||
bool ECPGsetconn(int, const char *);
|
||||
bool ECPGconnect(int, const char *, const char *, const char *, const char *);
|
||||
bool ECPGdo(int, char *,...);
|
||||
bool ECPGtrans(int, const char *);
|
||||
bool ECPGdisconnect(int, const char *);
|
||||
|
||||
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);
|
||||
|
||||
struct cursor { const char *name;
|
||||
char *command;
|
||||
struct cursor
|
||||
{
|
||||
const char *name;
|
||||
char *command;
|
||||
struct cursor *next;
|
||||
};
|
||||
};
|
||||
|
||||
extern int no_auto_trans;
|
||||
extern int no_auto_trans;
|
||||
|
||||
/* define this for simplicity as well as compatibility */
|
||||
|
||||
@@ -45,6 +48,7 @@ extern int no_auto_trans;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#include <ecpgerrno.h>
|
||||
|
||||
@@ -30,27 +30,29 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
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_struct,
|
||||
ECPGt_EOIT, /* End of insert types. */
|
||||
ECPGt_EORT, /* End of result types. */
|
||||
ECPGt_NO_INDICATOR /* no indicator */
|
||||
};
|
||||
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_struct,
|
||||
ECPGt_EOIT, /* End of insert types. */
|
||||
ECPGt_EORT, /* End of result types. */
|
||||
ECPGt_NO_INDICATOR /* no indicator */
|
||||
};
|
||||
|
||||
#define IS_SIMPLE_TYPE(type) ((type) >= ECPGt_char && (type) <= ECPGt_varchar2)
|
||||
|
||||
const char * ECPGtype_name(enum ECPGttype);
|
||||
const char *ECPGtype_name(enum ECPGttype);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,49 +2,50 @@
|
||||
#define POSTGRES_SQLCA_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct sqlca
|
||||
{
|
||||
char sqlcaid[8];
|
||||
long sqlabc;
|
||||
long sqlcode;
|
||||
struct
|
||||
struct sqlca
|
||||
{
|
||||
int sqlerrml;
|
||||
char sqlerrmc[70];
|
||||
} sqlerrm;
|
||||
char sqlerrp[8];
|
||||
long sqlerrd[6];
|
||||
/* Element 0: empty */
|
||||
/* 1: empty */
|
||||
/* 2: number of rows processed */
|
||||
/* after an INSERT, UPDATE or*/
|
||||
/* DELETE statement */
|
||||
/* 3: empty */
|
||||
/* 4: empty */
|
||||
/* 5: empty */
|
||||
char sqlwarn[8];
|
||||
char sqlcaid[8];
|
||||
long sqlabc;
|
||||
long sqlcode;
|
||||
struct
|
||||
{
|
||||
int sqlerrml;
|
||||
char sqlerrmc[70];
|
||||
} sqlerrm;
|
||||
char sqlerrp[8];
|
||||
long sqlerrd[6];
|
||||
/* Element 0: empty */
|
||||
/* 1: empty */
|
||||
/* 2: number of rows processed */
|
||||
/* after an INSERT, UPDATE or */
|
||||
/* DELETE statement */
|
||||
/* 3: empty */
|
||||
/* 4: empty */
|
||||
/* 5: empty */
|
||||
char sqlwarn[8];
|
||||
/* Element 0: set to 'W' if at least one other is 'W' */
|
||||
/* 1: if 'W' at least one character string */
|
||||
/* value was truncated when it was */
|
||||
/* stored into a host variable. */
|
||||
/* 2: empty */
|
||||
/* 3: empty */
|
||||
/* 4: empty */
|
||||
/* 5: empty */
|
||||
/* 6: empty */
|
||||
/* 7: empty */
|
||||
|
||||
char sqlext[8];
|
||||
};
|
||||
/* 1: if 'W' at least one character string */
|
||||
/* value was truncated when it was */
|
||||
/* stored into a host variable. */
|
||||
/* 2: empty */
|
||||
/* 3: empty */
|
||||
/* 4: empty */
|
||||
/* 5: empty */
|
||||
/* 6: empty */
|
||||
/* 7: empty */
|
||||
|
||||
char sqlext[8];
|
||||
};
|
||||
|
||||
extern struct sqlca sqlca;
|
||||
|
||||
extern struct sqlca sqlca;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@ ECPGtype_name(enum ECPGttype typ)
|
||||
{
|
||||
switch (typ)
|
||||
{
|
||||
case ECPGt_char:
|
||||
case ECPGt_char:
|
||||
return "char";
|
||||
case ECPGt_unsigned_char:
|
||||
return "unsigned char";
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
#include <getopt.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
extern int optind;
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#if defined(HAVE_STRING_H)
|
||||
@@ -22,7 +23,7 @@ extern char *optarg;
|
||||
#include "extern.h"
|
||||
|
||||
struct _include_path *include_paths;
|
||||
int no_auto_trans = 0;
|
||||
int no_auto_trans = 0;
|
||||
struct cursor *cur = NULL;
|
||||
|
||||
static void
|
||||
@@ -33,22 +34,24 @@ usage(char *progname)
|
||||
}
|
||||
|
||||
static void
|
||||
add_include_path(char * path)
|
||||
add_include_path(char *path)
|
||||
{
|
||||
struct _include_path *ip = include_paths;
|
||||
|
||||
include_paths = mm_alloc(sizeof(struct _include_path));
|
||||
include_paths->path = path;
|
||||
include_paths->next = ip;
|
||||
|
||||
include_paths = mm_alloc(sizeof(struct _include_path));
|
||||
include_paths->path = path;
|
||||
include_paths->next = ip;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *const argv[])
|
||||
{
|
||||
int fnr, c, out_option = 0;
|
||||
struct _include_path *ip;
|
||||
|
||||
add_include_path("/usr/include");
|
||||
int fnr,
|
||||
c,
|
||||
out_option = 0;
|
||||
struct _include_path *ip;
|
||||
|
||||
add_include_path("/usr/include");
|
||||
add_include_path(INCLUDE_PATH);
|
||||
add_include_path("/usr/local/include");
|
||||
add_include_path(".");
|
||||
@@ -66,10 +69,10 @@ main(int argc, char *const argv[])
|
||||
break;
|
||||
case 'I':
|
||||
add_include_path(optarg);
|
||||
break;
|
||||
case 't':
|
||||
no_auto_trans = 1;
|
||||
break;
|
||||
break;
|
||||
case 't':
|
||||
no_auto_trans = 1;
|
||||
break;
|
||||
case 'v':
|
||||
fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
|
||||
fprintf(stderr, "exec sql include ... search starts here:\n");
|
||||
@@ -86,14 +89,15 @@ main(int argc, char *const argv[])
|
||||
if (optind >= argc) /* no files specified */
|
||||
{
|
||||
usage(argv[0]);
|
||||
return(ILLEGAL_OPTION);
|
||||
return (ILLEGAL_OPTION);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* after the options there must not be anything but filenames */
|
||||
for (fnr = optind; fnr < argc; fnr++)
|
||||
{
|
||||
char *output_filename = NULL, *ptr2ext;
|
||||
char *output_filename = NULL,
|
||||
*ptr2ext;
|
||||
|
||||
input_filename = mm_alloc(strlen(argv[fnr]) + 5);
|
||||
|
||||
@@ -104,7 +108,7 @@ main(int argc, char *const argv[])
|
||||
if (ptr2ext == NULL)
|
||||
{
|
||||
ptr2ext = input_filename + strlen(input_filename);
|
||||
|
||||
|
||||
/* no extension => add .pgc */
|
||||
ptr2ext[0] = '.';
|
||||
ptr2ext[1] = 'p';
|
||||
@@ -116,12 +120,12 @@ main(int argc, char *const argv[])
|
||||
if (out_option == 0)/* calculate the output name */
|
||||
{
|
||||
output_filename = strdup(input_filename);
|
||||
|
||||
|
||||
ptr2ext = strrchr(output_filename, '.');
|
||||
/* make extension = .c */
|
||||
ptr2ext[1] = 'c';
|
||||
ptr2ext[2] = '\0';
|
||||
|
||||
|
||||
yyout = fopen(output_filename, "w");
|
||||
if (yyout == NULL)
|
||||
{
|
||||
@@ -139,13 +143,14 @@ main(int argc, char *const argv[])
|
||||
{
|
||||
struct cursor *ptr;
|
||||
struct _defines *defptr;
|
||||
|
||||
|
||||
/* remove old cursor definitions if any are still there */
|
||||
for (ptr = cur; ptr != NULL;)
|
||||
{
|
||||
struct cursor *this = ptr;
|
||||
struct arguments *l1, *l2;
|
||||
|
||||
struct arguments *l1,
|
||||
*l2;
|
||||
|
||||
free(ptr->command);
|
||||
free(ptr->name);
|
||||
for (l1 = argsinsert; l1; l1 = l2)
|
||||
@@ -161,20 +166,21 @@ main(int argc, char *const argv[])
|
||||
ptr = ptr->next;
|
||||
free(this);
|
||||
}
|
||||
|
||||
|
||||
/* remove old defines as well */
|
||||
for (defptr = defines; defptr != NULL;)
|
||||
{
|
||||
struct _defines *this = defptr;
|
||||
|
||||
free(defptr->new);
|
||||
free(defptr->old);
|
||||
defptr = defptr->next;
|
||||
free(this);
|
||||
}
|
||||
|
||||
|
||||
/* initialize lex */
|
||||
lex_init();
|
||||
|
||||
|
||||
/* we need two includes and a constant */
|
||||
fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n/* These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
|
||||
|
||||
@@ -189,7 +195,7 @@ main(int argc, char *const argv[])
|
||||
|
||||
if (output_filename)
|
||||
free(output_filename);
|
||||
|
||||
|
||||
free(input_filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ static ScanKeyword ScanKeywords[] = {
|
||||
{"found", SQL_FOUND},
|
||||
{"go", SQL_GO},
|
||||
{"goto", SQL_GOTO},
|
||||
{"identified", SQL_IDENTIFIED},
|
||||
{"immediate", SQL_IMMEDIATE},
|
||||
{"identified", SQL_IDENTIFIED},
|
||||
{"immediate", SQL_IMMEDIATE},
|
||||
{"indicator", SQL_INDICATOR},
|
||||
{"open", SQL_OPEN},
|
||||
{"release", SQL_RELEASE},
|
||||
|
||||
@@ -3,55 +3,63 @@
|
||||
|
||||
/* variables */
|
||||
|
||||
extern int braces_open, no_auto_trans;
|
||||
extern int braces_open,
|
||||
no_auto_trans;
|
||||
extern char *yytext;
|
||||
extern int yylineno,
|
||||
yyleng;
|
||||
extern FILE *yyin,
|
||||
*yyout;
|
||||
|
||||
struct _include_path { char * path;
|
||||
struct _include_path * next;
|
||||
};
|
||||
struct _include_path
|
||||
{
|
||||
char *path;
|
||||
struct _include_path *next;
|
||||
};
|
||||
|
||||
extern struct _include_path *include_paths;
|
||||
|
||||
struct cursor { char *name;
|
||||
char *command;
|
||||
struct arguments * argsinsert;
|
||||
struct arguments * argsresult;
|
||||
struct cursor *next;
|
||||
};
|
||||
|
||||
struct cursor
|
||||
{
|
||||
char *name;
|
||||
char *command;
|
||||
struct arguments *argsinsert;
|
||||
struct arguments *argsresult;
|
||||
struct cursor *next;
|
||||
};
|
||||
|
||||
extern struct cursor *cur;
|
||||
|
||||
struct _defines { char *old;
|
||||
char *new;
|
||||
struct _defines *next;
|
||||
};
|
||||
struct _defines
|
||||
{
|
||||
char *old;
|
||||
char *new;
|
||||
struct _defines *next;
|
||||
};
|
||||
|
||||
extern struct _defines *defines;
|
||||
|
||||
|
||||
/* This is a linked list of the variable names and types. */
|
||||
struct variable
|
||||
{
|
||||
char * name;
|
||||
struct ECPGtype * type;
|
||||
int brace_level;
|
||||
struct variable * next;
|
||||
char *name;
|
||||
struct ECPGtype *type;
|
||||
int brace_level;
|
||||
struct variable *next;
|
||||
};
|
||||
|
||||
|
||||
extern struct ECPGtype ecpg_no_indicator;
|
||||
extern struct variable no_indicator;
|
||||
|
||||
struct arguments {
|
||||
struct variable * variable;
|
||||
struct variable * indicator;
|
||||
struct arguments * next;
|
||||
struct arguments
|
||||
{
|
||||
struct variable *variable;
|
||||
struct variable *indicator;
|
||||
struct arguments *next;
|
||||
};
|
||||
|
||||
extern struct arguments * argsinsert;
|
||||
extern struct arguments * argsresult;
|
||||
extern struct arguments *argsinsert;
|
||||
extern struct arguments *argsresult;
|
||||
|
||||
/* functions */
|
||||
|
||||
@@ -59,15 +67,15 @@ extern void lex_init(void);
|
||||
extern char *input_filename;
|
||||
extern int yyparse(void);
|
||||
extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);
|
||||
ScanKeyword * ScanECPGKeywordLookup(char *);
|
||||
ScanKeyword * ScanCKeywordLookup(char *);
|
||||
ScanKeyword *ScanECPGKeywordLookup(char *);
|
||||
ScanKeyword *ScanCKeywordLookup(char *);
|
||||
extern void yyerror(char *);
|
||||
|
||||
/* return codes */
|
||||
|
||||
#define OK 0
|
||||
#define PARSE_ERROR -1
|
||||
#define PARSE_ERROR -1
|
||||
#define ILLEGAL_OPTION -2
|
||||
|
||||
#define NO_INCLUDE_FILE ENOENT
|
||||
#define NO_INCLUDE_FILE ENOENT
|
||||
#define OUT_OF_MEMORY ENOMEM
|
||||
|
||||
@@ -24,31 +24,31 @@ mm_alloc(size_t size)
|
||||
static struct ECPGstruct_member *
|
||||
struct_member_dup(struct ECPGstruct_member * rm)
|
||||
{
|
||||
struct ECPGstruct_member *new = NULL;
|
||||
struct ECPGstruct_member *new = NULL;
|
||||
|
||||
while (rm)
|
||||
{
|
||||
struct ECPGtype *type;
|
||||
|
||||
switch(rm->typ->typ)
|
||||
{
|
||||
case ECPGt_struct:
|
||||
type = ECPGmake_struct_type(rm->typ->u.members);
|
||||
break;
|
||||
case ECPGt_array:
|
||||
type = ECPGmake_array_type(ECPGmake_simple_type(rm->typ->u.element->typ, rm->typ->u.element->size), rm->typ->size);
|
||||
break;
|
||||
default:
|
||||
type = ECPGmake_simple_type(rm->typ->typ, rm->typ->size);
|
||||
break;
|
||||
}
|
||||
|
||||
ECPGmake_struct_member(rm->name, type, &new);
|
||||
|
||||
rm = rm->next;
|
||||
}
|
||||
while (rm)
|
||||
{
|
||||
struct ECPGtype *type;
|
||||
|
||||
return(new);
|
||||
switch (rm->typ->typ)
|
||||
{
|
||||
case ECPGt_struct:
|
||||
type = ECPGmake_struct_type(rm->typ->u.members);
|
||||
break;
|
||||
case ECPGt_array:
|
||||
type = ECPGmake_array_type(ECPGmake_simple_type(rm->typ->u.element->typ, rm->typ->u.element->size), rm->typ->size);
|
||||
break;
|
||||
default:
|
||||
type = ECPGmake_simple_type(rm->typ->typ, rm->typ->size);
|
||||
break;
|
||||
}
|
||||
|
||||
ECPGmake_struct_member(rm->name, type, &new);
|
||||
|
||||
rm = rm->next;
|
||||
}
|
||||
|
||||
return (new);
|
||||
}
|
||||
|
||||
/* The NAME argument is copied. The type argument is preserved as a pointer. */
|
||||
@@ -103,51 +103,52 @@ ECPGmake_struct_type(struct ECPGstruct_member * rm)
|
||||
return ne;
|
||||
}
|
||||
|
||||
static const char *get_type(enum ECPGttype typ)
|
||||
static const char *
|
||||
get_type(enum ECPGttype typ)
|
||||
{
|
||||
switch (typ)
|
||||
{
|
||||
case ECPGt_char:
|
||||
return("ECPGt_char");
|
||||
break;
|
||||
case ECPGt_unsigned_char:
|
||||
return("ECPGt_unsigned_char");
|
||||
break;
|
||||
case ECPGt_short:
|
||||
return("ECPGt_short");
|
||||
break;
|
||||
case ECPGt_unsigned_short:
|
||||
return("ECPGt_unsigned_short");
|
||||
break;
|
||||
case ECPGt_int:
|
||||
return("ECPGt_int");
|
||||
break;
|
||||
case ECPGt_unsigned_int:
|
||||
return("ECPGt_unsigned_int");
|
||||
break;
|
||||
case ECPGt_long:
|
||||
return("ECPGt_long");
|
||||
break;
|
||||
case ECPGt_unsigned_long:
|
||||
return("ECPGt_unsigned_int");
|
||||
break;
|
||||
case ECPGt_float:
|
||||
return("ECPGt_float");
|
||||
break;
|
||||
case ECPGt_double:
|
||||
return("ECPGt_double");
|
||||
break;
|
||||
case ECPGt_bool:
|
||||
return("ECPGt_bool");
|
||||
break;
|
||||
case ECPGt_varchar:
|
||||
return("ECPGt_varchar");
|
||||
case ECPGt_NO_INDICATOR: /* no indicator */
|
||||
return("ECPGt_NO_INDICATOR");
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
switch (typ)
|
||||
{
|
||||
case ECPGt_char:
|
||||
return ("ECPGt_char");
|
||||
break;
|
||||
case ECPGt_unsigned_char:
|
||||
return ("ECPGt_unsigned_char");
|
||||
break;
|
||||
case ECPGt_short:
|
||||
return ("ECPGt_short");
|
||||
break;
|
||||
case ECPGt_unsigned_short:
|
||||
return ("ECPGt_unsigned_short");
|
||||
break;
|
||||
case ECPGt_int:
|
||||
return ("ECPGt_int");
|
||||
break;
|
||||
case ECPGt_unsigned_int:
|
||||
return ("ECPGt_unsigned_int");
|
||||
break;
|
||||
case ECPGt_long:
|
||||
return ("ECPGt_long");
|
||||
break;
|
||||
case ECPGt_unsigned_long:
|
||||
return ("ECPGt_unsigned_int");
|
||||
break;
|
||||
case ECPGt_float:
|
||||
return ("ECPGt_float");
|
||||
break;
|
||||
case ECPGt_double:
|
||||
return ("ECPGt_double");
|
||||
break;
|
||||
case ECPGt_bool:
|
||||
return ("ECPGt_bool");
|
||||
break;
|
||||
case ECPGt_varchar:
|
||||
return ("ECPGt_varchar");
|
||||
case ECPGt_NO_INDICATOR: /* no indicator */
|
||||
return ("ECPGt_NO_INDICATOR");
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
/* Dump a type.
|
||||
@@ -164,13 +165,11 @@ static const char *get_type(enum ECPGttype typ)
|
||||
size is the maxsize in case it is a varchar. Otherwise it is the size of
|
||||
the variable (required to do array fetches of structs).
|
||||
*/
|
||||
static void
|
||||
ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
|
||||
static void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
|
||||
long varcharsize,
|
||||
long arrsiz, const char *siz, const char *prefix);
|
||||
static void
|
||||
ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz,
|
||||
struct ECPGtype * typ, struct ECPGtype * ind_typ, const char *offset, const char *prefix, const char * ind_prefix);
|
||||
static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz,
|
||||
struct ECPGtype * typ, struct ECPGtype * ind_typ, const char *offset, const char *prefix, const char *ind_prefix);
|
||||
|
||||
|
||||
void
|
||||
@@ -181,41 +180,39 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * typ, const char *in
|
||||
ind_typ = &ecpg_no_indicator;
|
||||
ind_name = "no_indicator";
|
||||
}
|
||||
|
||||
switch(typ->typ)
|
||||
{
|
||||
case 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, NULL, prefix);
|
||||
if (ind_typ == &ecpg_no_indicator)
|
||||
ECPGdump_a_simple(o, ind_name, ind_typ->typ, ind_typ->size, -1, NULL, ind_prefix);
|
||||
else
|
||||
ECPGdump_a_simple(o, ind_name, ind_typ->u.element->typ,
|
||||
ind_typ->u.element->size, ind_typ->size, NULL, prefix);
|
||||
}
|
||||
else if (typ->u.element->typ == ECPGt_array)
|
||||
{
|
||||
yyerror("No nested arrays allowed (except strings)"); /* Array of array, */
|
||||
}
|
||||
else if (typ->u.element->typ == ECPGt_struct)
|
||||
{
|
||||
/* Array of structs. */
|
||||
ECPGdump_a_struct(o, name, ind_name, typ->size, typ->u.element, ind_typ->u.element, NULL, prefix, ind_prefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
yyerror("Internal error: unknown datatype, pleqase inform pgsql-bugs@postgresql.org");
|
||||
}
|
||||
break;
|
||||
case ECPGt_struct:
|
||||
ECPGdump_a_struct(o, name, ind_name, 1, typ, ind_typ, NULL, prefix, ind_prefix);
|
||||
break;
|
||||
default:
|
||||
ECPGdump_a_simple(o, name, typ->typ, typ->size, -1, NULL, prefix);
|
||||
ECPGdump_a_simple(o, ind_name, ind_typ->typ, ind_typ->size, -1, NULL, ind_prefix);
|
||||
break;
|
||||
|
||||
switch (typ->typ)
|
||||
{
|
||||
case 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, NULL, prefix);
|
||||
if (ind_typ == &ecpg_no_indicator)
|
||||
ECPGdump_a_simple(o, ind_name, ind_typ->typ, ind_typ->size, -1, NULL, ind_prefix);
|
||||
else
|
||||
ECPGdump_a_simple(o, ind_name, ind_typ->u.element->typ,
|
||||
ind_typ->u.element->size, ind_typ->size, NULL, prefix);
|
||||
}
|
||||
else if (typ->u.element->typ == ECPGt_array)
|
||||
{
|
||||
yyerror("No nested arrays allowed (except strings)"); /* Array of array, */
|
||||
}
|
||||
else if (typ->u.element->typ == ECPGt_struct)
|
||||
{
|
||||
/* Array of structs. */
|
||||
ECPGdump_a_struct(o, name, ind_name, typ->size, typ->u.element, ind_typ->u.element, NULL, prefix, ind_prefix);
|
||||
}
|
||||
else
|
||||
yyerror("Internal error: unknown datatype, pleqase inform pgsql-bugs@postgresql.org");
|
||||
break;
|
||||
case ECPGt_struct:
|
||||
ECPGdump_a_struct(o, name, ind_name, 1, typ, ind_typ, NULL, prefix, ind_prefix);
|
||||
break;
|
||||
default:
|
||||
ECPGdump_a_simple(o, name, typ->typ, typ->size, -1, NULL, prefix);
|
||||
ECPGdump_a_simple(o, ind_name, ind_typ->typ, ind_typ->size, -1, NULL, ind_prefix);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,51 +225,51 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
|
||||
long arrsize,
|
||||
const char *siz,
|
||||
const char *prefix
|
||||
)
|
||||
)
|
||||
{
|
||||
if (typ == ECPGt_NO_INDICATOR)
|
||||
fprintf(o, "\n\tECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ");
|
||||
else
|
||||
{
|
||||
char *variable = (char *)mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
|
||||
char *offset = (char *)mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1);
|
||||
if (typ == ECPGt_NO_INDICATOR)
|
||||
fprintf(o, "\n\tECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ");
|
||||
else
|
||||
{
|
||||
char *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
|
||||
char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1);
|
||||
|
||||
if (varcharsize == 0 || arrsize >= 0)
|
||||
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
|
||||
else
|
||||
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
|
||||
if (varcharsize == 0 || arrsize >= 0)
|
||||
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
|
||||
else
|
||||
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
|
||||
|
||||
switch (typ)
|
||||
{
|
||||
case ECPGt_varchar:
|
||||
sprintf(offset, "sizeof(struct varchar_%s)", name);
|
||||
break;
|
||||
case ECPGt_char:
|
||||
case ECPGt_unsigned_char:
|
||||
sprintf(offset, "%ld*sizeof(char)", varcharsize);
|
||||
break;
|
||||
default:
|
||||
sprintf(offset, "sizeof(%s)", ECPGtype_name(typ));
|
||||
break;
|
||||
switch (typ)
|
||||
{
|
||||
case ECPGt_varchar:
|
||||
sprintf(offset, "sizeof(struct varchar_%s)", name);
|
||||
break;
|
||||
case ECPGt_char:
|
||||
case ECPGt_unsigned_char:
|
||||
sprintf(offset, "%ld*sizeof(char)", varcharsize);
|
||||
break;
|
||||
default:
|
||||
sprintf(offset, "sizeof(%s)", ECPGtype_name(typ));
|
||||
break;
|
||||
}
|
||||
|
||||
if (arrsize < 0)
|
||||
arrsize = 1;
|
||||
|
||||
if (siz == NULL)
|
||||
fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(typ), variable, varcharsize, arrsize, offset);
|
||||
else
|
||||
fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(typ), variable, varcharsize, arrsize, siz);
|
||||
|
||||
free(variable);
|
||||
free(offset);
|
||||
}
|
||||
|
||||
if (arrsize < 0)
|
||||
arrsize = 1;
|
||||
|
||||
if (siz == NULL)
|
||||
fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(typ), variable, varcharsize, arrsize, offset);
|
||||
else
|
||||
fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(typ), variable, varcharsize, arrsize, siz);
|
||||
|
||||
free(variable);
|
||||
free(offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Penetrate a struct and dump the contents. */
|
||||
static void
|
||||
ECPGdump_a_struct(FILE *o, const char *name, const char * ind_name, long arrsiz, struct ECPGtype * typ, struct ECPGtype * ind_typ, const char *offsetarg, const char *prefix, const char *ind_prefix)
|
||||
ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz, struct ECPGtype * typ, struct ECPGtype * ind_typ, const char *offsetarg, const char *prefix, const char *ind_prefix)
|
||||
{
|
||||
|
||||
/*
|
||||
@@ -280,9 +277,11 @@ ECPGdump_a_struct(FILE *o, const char *name, const char * ind_name, long arrsiz,
|
||||
* then we are in a struct in a struct and the offset is used as
|
||||
* offset.
|
||||
*/
|
||||
struct ECPGstruct_member *p, *ind_p = NULL;
|
||||
struct ECPGstruct_member *p,
|
||||
*ind_p = NULL;
|
||||
char obuf[BUFSIZ];
|
||||
char pbuf[BUFSIZ], ind_pbuf[BUFSIZ];
|
||||
char pbuf[BUFSIZ],
|
||||
ind_pbuf[BUFSIZ];
|
||||
const char *offset;
|
||||
|
||||
if (offsetarg == NULL)
|
||||
@@ -291,36 +290,36 @@ ECPGdump_a_struct(FILE *o, const char *name, const char * ind_name, long arrsiz,
|
||||
offset = obuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = offsetarg;
|
||||
}
|
||||
|
||||
sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);
|
||||
prefix = pbuf;
|
||||
|
||||
|
||||
sprintf(ind_pbuf, "%s%s.", ind_prefix ? ind_prefix : "", ind_name);
|
||||
ind_prefix = ind_pbuf;
|
||||
|
||||
if (ind_typ != NULL) ind_p = ind_typ->u.members;
|
||||
if (ind_typ != NULL)
|
||||
ind_p = ind_typ->u.members;
|
||||
for (p = typ->u.members; p; p = p->next)
|
||||
{
|
||||
ECPGdump_a_type(o, p->name, p->typ, (ind_p != NULL) ? ind_p->name : NULL, (ind_p != NULL) ? ind_p->typ : NULL, prefix, ind_prefix);
|
||||
if (ind_p != NULL) ind_p = ind_p->next;
|
||||
if (ind_p != NULL)
|
||||
ind_p = ind_p->next;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ECPGfree_struct_member(struct ECPGstruct_member * rm)
|
||||
{
|
||||
while (rm)
|
||||
{
|
||||
struct ECPGstruct_member *p = rm;
|
||||
|
||||
rm = rm->next;
|
||||
free(p->name);
|
||||
free(p->typ);
|
||||
free(p);
|
||||
}
|
||||
while (rm)
|
||||
{
|
||||
struct ECPGstruct_member *p = rm;
|
||||
|
||||
rm = rm->next;
|
||||
free(p->name);
|
||||
free(p->typ);
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -337,7 +336,7 @@ ECPGfree_type(struct ECPGtype * typ)
|
||||
else if (typ->u.element->typ == ECPGt_struct)
|
||||
{
|
||||
/* Array of structs. */
|
||||
ECPGfree_struct_member(typ->u.element->u.members);
|
||||
ECPGfree_struct_member(typ->u.element->u.members);
|
||||
free(typ->u.members);
|
||||
}
|
||||
else
|
||||
@@ -345,13 +344,11 @@ ECPGfree_type(struct ECPGtype * typ)
|
||||
}
|
||||
else if (typ->typ == ECPGt_struct)
|
||||
{
|
||||
ECPGfree_struct_member(typ->u.members);
|
||||
ECPGfree_struct_member(typ->u.members);
|
||||
free(typ->u.members);
|
||||
}
|
||||
else
|
||||
{
|
||||
abort();
|
||||
}
|
||||
}
|
||||
free(typ);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ struct ECPGtype
|
||||
};
|
||||
|
||||
/* Everything is malloced. */
|
||||
void ECPGmake_struct_member(char *, struct ECPGtype *, struct ECPGstruct_member **);
|
||||
void ECPGmake_struct_member(char *, struct ECPGtype *, struct ECPGstruct_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);
|
||||
@@ -45,7 +45,7 @@ void ECPGfree_type(struct ECPGtype *);
|
||||
size is the maxsize in case it is a varchar. Otherwise it is the size of
|
||||
the variable (required to do array fetches of structs).
|
||||
*/
|
||||
void ECPGdump_a_type(FILE *, const char *, struct ECPGtype *, const char *, struct ECPGtype *, const char *, const char *);
|
||||
void ECPGdump_a_type(FILE *, const char *, struct ECPGtype *, const char *, struct ECPGtype *, const char *, const char *);
|
||||
|
||||
/* A simple struct to keep a variable and its type. */
|
||||
struct ECPGtemp_type
|
||||
@@ -71,19 +71,19 @@ enum WHEN
|
||||
struct when
|
||||
{
|
||||
enum WHEN code;
|
||||
char *command;
|
||||
char *str;
|
||||
char *command;
|
||||
char *str;
|
||||
};
|
||||
|
||||
struct index
|
||||
{
|
||||
int index1;
|
||||
int index2;
|
||||
char *str;
|
||||
int index1;
|
||||
int index2;
|
||||
char *str;
|
||||
};
|
||||
|
||||
struct this_type
|
||||
{
|
||||
enum ECPGttype type_enum;
|
||||
char *type_str;
|
||||
enum ECPGttype type_enum;
|
||||
char *type_str;
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: libpgtcl.h,v 1.4 1997/09/08 02:40:03 momjian Exp $
|
||||
* $Id: libpgtcl.h,v 1.5 1998/09/01 04:39:53 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -19,4 +19,4 @@
|
||||
extern int Pgtcl_Init(Tcl_Interp * interp);
|
||||
extern int Pgtcl_SafeInit(Tcl_Interp * interp);
|
||||
|
||||
#endif /* LIBPGTCL_H */
|
||||
#endif /* LIBPGTCL_H */
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.11 1998/06/16 04:10:15 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.12 1998/09/01 04:39:55 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -23,117 +23,118 @@
|
||||
#include "pgtclId.h"
|
||||
|
||||
/*
|
||||
* Pgtcl_Init
|
||||
* initialization package for the PGLITE Tcl package
|
||||
* Pgtcl_Init
|
||||
* initialization package for the PGLITE Tcl package
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
Pgtcl_Init (Tcl_Interp *interp)
|
||||
Pgtcl_Init(Tcl_Interp * interp)
|
||||
{
|
||||
|
||||
/* finish off the ChannelType struct. Much easier to do it here then
|
||||
* to guess where it might be by position in the struct. This is needed
|
||||
* for Tcl7.6 and beyond, which have the getfileproc.
|
||||
*/
|
||||
/*
|
||||
* finish off the ChannelType struct. Much easier to do it here then
|
||||
* to guess where it might be by position in the struct. This is
|
||||
* needed for Tcl7.6 and beyond, which have the getfileproc.
|
||||
*/
|
||||
#if HAVE_TCL_GETFILEPROC
|
||||
Pg_ConnType.getFileProc = PgGetFileProc;
|
||||
Pg_ConnType.getFileProc = PgGetFileProc;
|
||||
#endif
|
||||
|
||||
/* register all pgtcl commands */
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_conndefaults",
|
||||
Pg_conndefaults,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
/* register all pgtcl commands */
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_conndefaults",
|
||||
Pg_conndefaults,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_connect",
|
||||
Pg_connect,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_connect",
|
||||
Pg_connect,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_disconnect",
|
||||
Pg_disconnect,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_exec",
|
||||
Pg_exec,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_select",
|
||||
Pg_select,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_result",
|
||||
Pg_result,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_open",
|
||||
Pg_lo_open,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_close",
|
||||
Pg_lo_close,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_disconnect",
|
||||
Pg_disconnect,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_read",
|
||||
Pg_lo_read,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_exec",
|
||||
Pg_exec,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_write",
|
||||
Pg_lo_write,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_select",
|
||||
Pg_select,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_lseek",
|
||||
Pg_lo_lseek,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_result",
|
||||
Pg_result,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_creat",
|
||||
Pg_lo_creat,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_open",
|
||||
Pg_lo_open,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_tell",
|
||||
Pg_lo_tell,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_close",
|
||||
Pg_lo_close,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_unlink",
|
||||
Pg_lo_unlink,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_read",
|
||||
Pg_lo_read,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_import",
|
||||
Pg_lo_import,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_export",
|
||||
Pg_lo_export,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_listen",
|
||||
Pg_listen,
|
||||
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_write",
|
||||
Pg_lo_write,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_PkgProvide(interp, "Pgtcl", "1.2");
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_lseek",
|
||||
Pg_lo_lseek,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
return TCL_OK;
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_creat",
|
||||
Pg_lo_creat,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_tell",
|
||||
Pg_lo_tell,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_unlink",
|
||||
Pg_lo_unlink,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_import",
|
||||
Pg_lo_import,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_export",
|
||||
Pg_lo_export,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_listen",
|
||||
Pg_listen,
|
||||
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_PkgProvide(interp, "Pgtcl", "1.2");
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
Pgtcl_SafeInit (Tcl_Interp *interp)
|
||||
Pgtcl_SafeInit(Tcl_Interp * interp)
|
||||
{
|
||||
return Pgtcl_Init(interp);
|
||||
return Pgtcl_Init(interp);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pgtclCmds.h,v 1.10 1998/06/16 04:10:17 momjian Exp $
|
||||
* $Id: pgtclCmds.h,v 1.11 1998/09/01 04:39:57 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -28,33 +28,37 @@
|
||||
* name. (All their callbacks will be called, but in an unspecified order.)
|
||||
*/
|
||||
|
||||
typedef struct Pg_TclNotifies_s {
|
||||
struct Pg_TclNotifies_s *next; /* list link */
|
||||
Tcl_Interp *interp; /* This Tcl interpreter */
|
||||
/* NB: if interp == NULL, the interpreter is gone but we haven't
|
||||
* yet got round to deleting the Pg_TclNotifies structure.
|
||||
*/
|
||||
Tcl_HashTable notify_hash; /* Active pg_listen requests */
|
||||
} Pg_TclNotifies;
|
||||
typedef struct Pg_TclNotifies_s
|
||||
{
|
||||
struct Pg_TclNotifies_s *next; /* list link */
|
||||
Tcl_Interp *interp; /* This Tcl interpreter */
|
||||
|
||||
typedef struct Pg_ConnectionId_s {
|
||||
char id[32];
|
||||
PGconn *conn;
|
||||
int res_max; /* Max number of results allocated */
|
||||
int res_hardmax; /* Absolute max to allow */
|
||||
int res_count; /* Current count of active results */
|
||||
int res_last; /* Optimize where to start looking */
|
||||
int res_copy; /* Query result with active copy */
|
||||
int res_copyStatus; /* Copying status */
|
||||
PGresult **results; /* The results */
|
||||
/*
|
||||
* NB: if interp == NULL, the interpreter is gone but we haven't yet
|
||||
* got round to deleting the Pg_TclNotifies structure.
|
||||
*/
|
||||
Tcl_HashTable notify_hash; /* Active pg_listen requests */
|
||||
} Pg_TclNotifies;
|
||||
|
||||
Pg_TclNotifies *notify_list; /* head of list of notify info */
|
||||
int notifier_running; /* notify event source is live */
|
||||
typedef struct Pg_ConnectionId_s
|
||||
{
|
||||
char id[32];
|
||||
PGconn *conn;
|
||||
int res_max; /* Max number of results allocated */
|
||||
int res_hardmax; /* Absolute max to allow */
|
||||
int res_count; /* Current count of active results */
|
||||
int res_last; /* Optimize where to start looking */
|
||||
int res_copy; /* Query result with active copy */
|
||||
int res_copyStatus; /* Copying status */
|
||||
PGresult **results; /* The results */
|
||||
|
||||
} Pg_ConnectionId;
|
||||
Pg_TclNotifies *notify_list;/* head of list of notify info */
|
||||
int notifier_running; /* notify event source is live */
|
||||
|
||||
} Pg_ConnectionId;
|
||||
|
||||
#define RES_COPY_NONE 0
|
||||
#define RES_COPY_INPROGRESS 1
|
||||
#define RES_COPY_INPROGRESS 1
|
||||
#define RES_COPY_FIN 2
|
||||
|
||||
|
||||
@@ -62,38 +66,38 @@ typedef struct Pg_ConnectionId_s {
|
||||
/* registered Tcl functions */
|
||||
/* **************************/
|
||||
extern int Pg_conndefaults(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_connect(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_disconnect(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_exec(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_select(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_result(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_lo_open(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_lo_close(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_lo_read(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_lo_write(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_lo_lseek(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_lo_creat(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_lo_tell(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_lo_unlink(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_lo_import(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_lo_export(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int Pg_listen(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
|
||||
#endif /*PGTCLCMDS_H*/
|
||||
#endif /* PGTCLCMDS_H */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,50 +1,50 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pgtclId.h--
|
||||
* useful routines to convert between strings and pointers
|
||||
* useful routines to convert between strings and pointers
|
||||
* Needed because everything in tcl is a string, but often, pointers
|
||||
* to data structures are needed.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pgtclId.h,v 1.7 1998/06/16 04:10:17 momjian Exp $
|
||||
* $Id: pgtclId.h,v 1.8 1998/09/01 04:39:59 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
extern void PgSetConnectionId(Tcl_Interp *interp, PGconn *conn);
|
||||
|
||||
extern void PgSetConnectionId(Tcl_Interp * interp, PGconn *conn);
|
||||
|
||||
#if TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION == 5
|
||||
/* Only Tcl 7.5 had drivers with this signature */
|
||||
# define DRIVER_DEL_PROTO ClientData cData, Tcl_Interp *interp, \
|
||||
Tcl_File inFile, Tcl_File outFile
|
||||
# define DRIVER_OUTPUT_PROTO ClientData cData, Tcl_File outFile, char *buf, \
|
||||
#define DRIVER_DEL_PROTO ClientData cData, Tcl_Interp *interp, \
|
||||
Tcl_File inFile, Tcl_File outFile
|
||||
#define DRIVER_OUTPUT_PROTO ClientData cData, Tcl_File outFile, char *buf, \
|
||||
int bufSize, int *errorCodePtr
|
||||
# define DRIVER_INPUT_PROTO ClientData cData, Tcl_File inFile, char *buf, \
|
||||
#define DRIVER_INPUT_PROTO ClientData cData, Tcl_File inFile, char *buf, \
|
||||
int bufSize, int *errorCodePtr
|
||||
#else
|
||||
/* Tcl 7.6 and beyond use this signature */
|
||||
# define DRIVER_OUTPUT_PROTO ClientData cData, char *buf, int bufSize, \
|
||||
#define DRIVER_OUTPUT_PROTO ClientData cData, char *buf, int bufSize, \
|
||||
int *errorCodePtr
|
||||
# define DRIVER_INPUT_PROTO ClientData cData, char *buf, int bufSize, \
|
||||
#define DRIVER_INPUT_PROTO ClientData cData, char *buf, int bufSize, \
|
||||
int *errorCodePtr
|
||||
# define DRIVER_DEL_PROTO ClientData cData, Tcl_Interp *interp
|
||||
#define DRIVER_DEL_PROTO ClientData cData, Tcl_Interp *interp
|
||||
#endif
|
||||
|
||||
extern PGconn *PgGetConnectionId(Tcl_Interp *interp, char *id, \
|
||||
Pg_ConnectionId **);
|
||||
extern PgDelConnectionId(DRIVER_DEL_PROTO);
|
||||
extern int PgOutputProc(DRIVER_OUTPUT_PROTO);
|
||||
extern PgInputProc(DRIVER_INPUT_PROTO);
|
||||
extern int PgSetResultId(Tcl_Interp *interp, char *connid, PGresult *res);
|
||||
extern PGresult *PgGetResultId(Tcl_Interp *interp, char *id);
|
||||
extern void PgDelResultId(Tcl_Interp *interp, char *id);
|
||||
extern int PgGetConnByResultId(Tcl_Interp *interp, char *resid);
|
||||
extern void PgStartNotifyEventSource(Pg_ConnectionId *connid);
|
||||
extern void PgStopNotifyEventSource(Pg_ConnectionId *connid);
|
||||
extern void PgNotifyTransferEvents(Pg_ConnectionId *connid);
|
||||
extern void PgNotifyInterpDelete(ClientData clientData, Tcl_Interp *interp);
|
||||
extern PGconn *PgGetConnectionId(Tcl_Interp * interp, char *id, \
|
||||
Pg_ConnectionId **);
|
||||
extern PgDelConnectionId(DRIVER_DEL_PROTO);
|
||||
extern int PgOutputProc(DRIVER_OUTPUT_PROTO);
|
||||
extern PgInputProc(DRIVER_INPUT_PROTO);
|
||||
extern int PgSetResultId(Tcl_Interp * interp, char *connid, PGresult *res);
|
||||
extern PGresult *PgGetResultId(Tcl_Interp * interp, char *id);
|
||||
extern void PgDelResultId(Tcl_Interp * interp, char *id);
|
||||
extern int PgGetConnByResultId(Tcl_Interp * interp, char *resid);
|
||||
extern void PgStartNotifyEventSource(Pg_ConnectionId * connid);
|
||||
extern void PgStopNotifyEventSource(Pg_ConnectionId * connid);
|
||||
extern void PgNotifyTransferEvents(Pg_ConnectionId * connid);
|
||||
extern void PgNotifyInterpDelete(ClientData clientData, Tcl_Interp * interp);
|
||||
|
||||
/* GetFileProc is needed in Tcl 7.6 and later */
|
||||
#if (TCL_MAJOR_VERSION * 100 + TCL_MINOR_VERSION) >= 706
|
||||
@@ -55,6 +55,7 @@ extern void PgNotifyInterpDelete(ClientData clientData, Tcl_Interp *interp);
|
||||
|
||||
#if HAVE_TCL_GETFILEPROC
|
||||
extern Tcl_File PgGetFileProc(ClientData cData, int direction);
|
||||
|
||||
#endif
|
||||
|
||||
extern Tcl_ChannelType Pg_ConnType;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.23 1998/09/01 03:28:50 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.24 1998/09/01 04:40:01 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -42,7 +42,7 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <pwd.h>
|
||||
#endif /* WIN32 */
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef HAVE_CRYPT_H
|
||||
#include <crypt.h>
|
||||
@@ -56,7 +56,8 @@
|
||||
|
||||
struct authsvc
|
||||
{
|
||||
char name[NAMEDATALEN]; /* service nickname (for command line) */
|
||||
char name[NAMEDATALEN]; /* service nickname (for command
|
||||
* line) */
|
||||
MsgType msgtype; /* startup packet header type */
|
||||
int allowed; /* initially allowed (before command line
|
||||
* option parsing)? */
|
||||
@@ -76,17 +77,17 @@ static struct authsvc authsvcs[] = {
|
||||
#ifdef KRB4
|
||||
{"krb4", STARTUP_KRB4_MSG, 1},
|
||||
{"kerberos", STARTUP_KRB4_MSG, 1},
|
||||
#endif /* KRB4 */
|
||||
#endif /* KRB4 */
|
||||
#ifdef KRB5
|
||||
{"krb5", STARTUP_KRB5_MSG, 1},
|
||||
{"kerberos", STARTUP_KRB5_MSG, 1},
|
||||
#endif /* KRB5 */
|
||||
#endif /* KRB5 */
|
||||
{UNAUTHNAME, STARTUP_MSG,
|
||||
#if defined(KRB4) || defined(KRB5)
|
||||
0
|
||||
#else /* !(KRB4 || KRB5) */
|
||||
1
|
||||
#endif /* !(KRB4 || KRB5) */
|
||||
#endif /* !(KRB4 || KRB5) */
|
||||
},
|
||||
{"password", STARTUP_PASSWORD_MSG, 0}
|
||||
};
|
||||
@@ -223,7 +224,7 @@ pg_krb4_sendauth(const char *PQerrormsg, int sock,
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
#endif /* KRB4 */
|
||||
#endif /* KRB4 */
|
||||
|
||||
#ifdef KRB5
|
||||
/*----------------------------------------------------------------
|
||||
@@ -457,7 +458,7 @@ pg_krb5_sendauth(const char *PQerrormsg, int sock,
|
||||
return code ? STATUS_ERROR : STATUS_OK;
|
||||
}
|
||||
|
||||
#endif /* KRB5 */
|
||||
#endif /* KRB5 */
|
||||
|
||||
static int
|
||||
pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
|
||||
@@ -521,7 +522,7 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
|
||||
if (password == NULL || *password == '\0')
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_sendauth: no password supplied\n");
|
||||
"fe_sendauth: no password supplied\n");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if (pg_password_sendauth(conn, password, areq) != STATUS_OK)
|
||||
@@ -607,10 +608,10 @@ fe_getauthname(char *PQerrormsg)
|
||||
case STARTUP_MSG:
|
||||
{
|
||||
#ifdef WIN32
|
||||
char username[128];
|
||||
DWORD namesize = sizeof(username) - 1;
|
||||
char username[128];
|
||||
DWORD namesize = sizeof(username) - 1;
|
||||
|
||||
if (GetUserName(username,&namesize))
|
||||
if (GetUserName(username, &namesize))
|
||||
name = username;
|
||||
#else
|
||||
struct passwd *pw = getpwuid(geteuid());
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: fe-auth.h,v 1.9 1998/08/17 03:50:33 scrappy Exp $
|
||||
* $Id: fe-auth.h,v 1.10 1998/09/01 04:40:03 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -30,10 +30,9 @@
|
||||
#define DEFAULT_CLIENT_AUTHSVC UNAUTHNAME
|
||||
#else /* KRB4 || KRB5 */
|
||||
#define DEFAULT_CLIENT_AUTHSVC "kerberos"
|
||||
#endif /* KRB4 || KRB5 */
|
||||
#endif /* KRB4 || KRB5 */
|
||||
|
||||
extern int
|
||||
fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
|
||||
extern int fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
|
||||
const char *password, char *PQerrormsg);
|
||||
extern MsgType fe_getauthsvc(char *PQerrormsg);
|
||||
extern void fe_setauthsvc(const char *name, char *PQerrormsg);
|
||||
@@ -42,4 +41,4 @@ extern char *fe_getauthname(char *PQerrormsg);
|
||||
#define PG_KRB4_VERSION "PGVER4.1" /* at most KRB_SENDAUTH_VLEN chars */
|
||||
#define PG_KRB5_VERSION "PGVER5.1"
|
||||
|
||||
#endif /* FE_AUTH_H */
|
||||
#endif /* FE_AUTH_H */
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.79 1998/08/17 03:50:34 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.80 1998/09/01 04:40:04 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -50,7 +50,8 @@ 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);
|
||||
static void defaultNoticeProcessor(void * arg, const char * message);
|
||||
static void defaultNoticeProcessor(void *arg, const char *message);
|
||||
|
||||
/* XXX Why is this not static? */
|
||||
void PQsetenv(PGconn *conn);
|
||||
|
||||
@@ -282,8 +283,10 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, cons
|
||||
{
|
||||
PGconn *conn;
|
||||
char *tmp;
|
||||
|
||||
/* An error message from some service we call. */
|
||||
bool error = FALSE;
|
||||
|
||||
/* We encountered an error that prevents successful completion */
|
||||
int i;
|
||||
|
||||
@@ -359,9 +362,10 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, cons
|
||||
|
||||
if (conn->dbName)
|
||||
{
|
||||
|
||||
/*
|
||||
* 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 == '"')
|
||||
{
|
||||
@@ -370,8 +374,8 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, cons
|
||||
}
|
||||
else
|
||||
for (i = 0; conn->dbName[i]; i++)
|
||||
if (isascii((unsigned char)conn->dbName[i]) &&
|
||||
isupper(conn->dbName[i]))
|
||||
if (isascii((unsigned char) conn->dbName[i]) &&
|
||||
isupper(conn->dbName[i]))
|
||||
conn->dbName[i] = tolower(conn->dbName[i]);
|
||||
}
|
||||
|
||||
@@ -392,57 +396,63 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, cons
|
||||
static int
|
||||
update_db_info(PGconn *conn)
|
||||
{
|
||||
char *tmp, *old = conn->dbName;
|
||||
|
||||
char *tmp,
|
||||
*old = conn->dbName;
|
||||
|
||||
if (strchr(conn->dbName, '@') != NULL)
|
||||
{
|
||||
/* old style: dbname[@server][:port] */
|
||||
tmp = strrchr(conn->dbName, ':');
|
||||
if (tmp != NULL) /* port number given */
|
||||
if (tmp != NULL) /* port number given */
|
||||
{
|
||||
conn->pgport = strdup(tmp + 1);
|
||||
conn->pgport = strdup(tmp + 1);
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
|
||||
tmp = strrchr(conn->dbName, '@');
|
||||
if (tmp != NULL) /* host name given */
|
||||
if (tmp != NULL) /* host name given */
|
||||
{
|
||||
conn->pghost = strdup(tmp + 1);
|
||||
conn->pghost = strdup(tmp + 1);
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
|
||||
conn->dbName = strdup(old);
|
||||
free(old);
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset;
|
||||
|
||||
int offset;
|
||||
|
||||
/*
|
||||
* only allow protocols tcp and unix
|
||||
*/
|
||||
* only allow protocols tcp and unix
|
||||
*/
|
||||
if (strncmp(conn->dbName, "tcp:", 4) == 0)
|
||||
offset = 4;
|
||||
else if (strncmp(conn->dbName, "unix:", 5) == 0)
|
||||
offset = 5;
|
||||
else return 0;
|
||||
|
||||
else
|
||||
return 0;
|
||||
|
||||
if (strncmp(conn->dbName + offset, "postgresql://", strlen("postgresql://")) == 0)
|
||||
{
|
||||
/* new style: <tcp|unix>:postgresql://server[:port][/dbname][?options] */
|
||||
|
||||
/*
|
||||
* new style:
|
||||
* <tcp|unix>:postgresql://server[:port][/dbname][?options]
|
||||
*/
|
||||
offset += strlen("postgresql://");
|
||||
|
||||
|
||||
tmp = strrchr(conn->dbName + offset, '?');
|
||||
if (tmp != NULL) /* options given */
|
||||
if (tmp != NULL) /* options given */
|
||||
{
|
||||
conn->pgoptions = strdup(tmp + 1);
|
||||
conn->pgoptions = strdup(tmp + 1);
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
|
||||
tmp = strrchr(conn->dbName + offset, '/');
|
||||
if (tmp != NULL) /* database name given */
|
||||
if (tmp != NULL) /* database name given */
|
||||
{
|
||||
conn->dbName = strdup(tmp + 1);
|
||||
conn->dbName = strdup(tmp + 1);
|
||||
*tmp = '\0';
|
||||
}
|
||||
else
|
||||
@@ -452,30 +462,31 @@ update_db_info(PGconn *conn)
|
||||
else if (conn->pguser)
|
||||
conn->dbName = strdup(conn->pguser);
|
||||
}
|
||||
|
||||
|
||||
tmp = strrchr(old + offset, ':');
|
||||
if (tmp != NULL) /* port number given */
|
||||
if (tmp != NULL) /* port number given */
|
||||
{
|
||||
conn->pgport = strdup(tmp + 1);
|
||||
conn->pgport = strdup(tmp + 1);
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
|
||||
if (strncmp(old, "unix:", 5) == 0)
|
||||
{
|
||||
conn->pghost = NULL;
|
||||
if (strcmp(old + offset, "localhost") != 0)
|
||||
{
|
||||
(void) sprintf(conn->errorMessage,
|
||||
"connectDB() -- non-tcp access only possible on localhost\n");
|
||||
return 1;
|
||||
"connectDB() -- non-tcp access only possible on localhost\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else conn->pghost = strdup(old + offset);
|
||||
|
||||
else
|
||||
conn->pghost = strdup(old + offset);
|
||||
|
||||
free(old);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -498,12 +509,12 @@ connectDB(PGconn *conn)
|
||||
char beresp;
|
||||
int on = 1;
|
||||
|
||||
/*
|
||||
* parse dbName to get all additional info in it, if any
|
||||
*/
|
||||
/*
|
||||
* parse dbName to get all additional info in it, if any
|
||||
*/
|
||||
if (update_db_info(conn) != 0)
|
||||
goto connect_errReturn;
|
||||
|
||||
|
||||
/*
|
||||
* Initialize the startup packet.
|
||||
*/
|
||||
@@ -535,7 +546,8 @@ connectDB(PGconn *conn)
|
||||
}
|
||||
family = AF_INET;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
hp = NULL;
|
||||
family = AF_UNIX;
|
||||
}
|
||||
@@ -556,7 +568,7 @@ connectDB(PGconn *conn)
|
||||
else
|
||||
conn->raddr_len = UNIXSOCK_PATH(conn->raddr.un, portno);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Connect to the server */
|
||||
if ((conn->sock = socket(family, SOCK_STREAM, 0)) < 0)
|
||||
@@ -577,14 +589,14 @@ connectDB(PGconn *conn)
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the right options.
|
||||
* We need nonblocking I/O, and we don't want delay of outgoing data.
|
||||
* Set the right options. We need nonblocking I/O, and we don't want
|
||||
* delay of outgoing data.
|
||||
*/
|
||||
|
||||
#ifndef WIN32
|
||||
if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
|
||||
#else
|
||||
if (ioctlsocket(conn->sock,FIONBIO, &on) != 0)
|
||||
if (ioctlsocket(conn->sock, FIONBIO, &on) != 0)
|
||||
#endif
|
||||
{
|
||||
(void) sprintf(conn->errorMessage,
|
||||
@@ -606,16 +618,16 @@ connectDB(PGconn *conn)
|
||||
}
|
||||
if (setsockopt(conn->sock, pe->p_proto, TCP_NODELAY,
|
||||
#ifdef WIN32
|
||||
(char *)
|
||||
(char *)
|
||||
#endif
|
||||
&on,
|
||||
&on,
|
||||
sizeof(on)) < 0)
|
||||
{
|
||||
(void) sprintf(conn->errorMessage,
|
||||
"connectDB() -- setsockopt failed: errno=%d\n%s\n",
|
||||
"connectDB() -- setsockopt failed: errno=%d\n%s\n",
|
||||
errno, strerror(errno));
|
||||
#ifdef WIN32
|
||||
printf("Winsock error: %i\n",WSAGetLastError());
|
||||
printf("Winsock error: %i\n", WSAGetLastError());
|
||||
#endif
|
||||
goto connect_errReturn;
|
||||
}
|
||||
@@ -626,7 +638,7 @@ connectDB(PGconn *conn)
|
||||
if (getsockname(conn->sock, &conn->laddr.sa, &laddrlen) < 0)
|
||||
{
|
||||
(void) sprintf(conn->errorMessage,
|
||||
"connectDB() -- getsockname() failed: errno=%d\n%s\n",
|
||||
"connectDB() -- getsockname() failed: errno=%d\n%s\n",
|
||||
errno, strerror(errno));
|
||||
goto connect_errReturn;
|
||||
}
|
||||
@@ -640,15 +652,15 @@ connectDB(PGconn *conn)
|
||||
if (pqPacketSend(conn, (char *) &sp, sizeof(StartupPacket)) != STATUS_OK)
|
||||
{
|
||||
sprintf(conn->errorMessage,
|
||||
"connectDB() -- couldn't send startup packet: errno=%d\n%s\n",
|
||||
"connectDB() -- couldn't send startup packet: errno=%d\n%s\n",
|
||||
errno, strerror(errno));
|
||||
goto connect_errReturn;
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform the authentication exchange:
|
||||
* wait for backend messages and respond as necessary.
|
||||
* We fall out of this loop when done talking to the postmaster.
|
||||
* Perform the authentication exchange: wait for backend messages and
|
||||
* respond as necessary. We fall out of this loop when done talking to
|
||||
* the postmaster.
|
||||
*/
|
||||
|
||||
for (;;)
|
||||
@@ -659,8 +671,10 @@ connectDB(PGconn *conn)
|
||||
/* Load data, or detect EOF */
|
||||
if (pqReadData(conn) < 0)
|
||||
goto connect_errReturn;
|
||||
/* Scan the message.
|
||||
* If we run out of data, loop around to try again.
|
||||
|
||||
/*
|
||||
* Scan the message. If we run out of data, loop around to try
|
||||
* again.
|
||||
*/
|
||||
conn->inCursor = conn->inStart;
|
||||
|
||||
@@ -679,7 +693,7 @@ connectDB(PGconn *conn)
|
||||
if (beresp != 'R')
|
||||
{
|
||||
(void) sprintf(conn->errorMessage,
|
||||
"connectDB() -- expected authentication request\n");
|
||||
"connectDB() -- expected authentication request\n");
|
||||
goto connect_errReturn;
|
||||
}
|
||||
|
||||
@@ -710,20 +724,21 @@ connectDB(PGconn *conn)
|
||||
}
|
||||
|
||||
/*
|
||||
* Now we expect to hear from the backend.
|
||||
* A ReadyForQuery message indicates that startup is successful,
|
||||
* but we might also get an Error message indicating failure.
|
||||
* (Notice messages indicating nonfatal warnings are also allowed
|
||||
* by the protocol, as is a BackendKeyData message.)
|
||||
* Easiest way to handle this is to let PQgetResult() read the messages.
|
||||
* We just have to fake it out about the state of the connection.
|
||||
* Now we expect to hear from the backend. A ReadyForQuery message
|
||||
* indicates that startup is successful, but we might also get an
|
||||
* Error message indicating failure. (Notice messages indicating
|
||||
* nonfatal warnings are also allowed by the protocol, as is a
|
||||
* BackendKeyData message.) Easiest way to handle this is to let
|
||||
* PQgetResult() read the messages. We just have to fake it out about
|
||||
* the state of the connection.
|
||||
*/
|
||||
|
||||
conn->status = CONNECTION_OK;
|
||||
conn->asyncStatus = PGASYNC_BUSY;
|
||||
res = PQgetResult(conn);
|
||||
/* NULL return indicating we have gone to IDLE state is expected */
|
||||
if (res) {
|
||||
if (res)
|
||||
{
|
||||
if (res->resultStatus != PGRES_FATAL_ERROR)
|
||||
sprintf(conn->errorMessage,
|
||||
"connectDB() -- unexpected message during startup\n");
|
||||
@@ -731,16 +746,17 @@ connectDB(PGconn *conn)
|
||||
goto connect_errReturn;
|
||||
}
|
||||
|
||||
/* Given the new protocol that sends a ReadyForQuery message
|
||||
* after successful backend startup, it should no longer be
|
||||
* necessary to send an empty query to test for startup.
|
||||
/*
|
||||
* Given the new protocol that sends a ReadyForQuery message after
|
||||
* successful backend startup, it should no longer be necessary to
|
||||
* send an empty query to test for startup.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
|
||||
/*
|
||||
* Send a blank query to make sure everything works; in
|
||||
* particular, that the database exists.
|
||||
* Send a blank query to make sure everything works; in particular,
|
||||
* that the database exists.
|
||||
*/
|
||||
res = PQexec(conn, " ");
|
||||
if (res == NULL || res->resultStatus != PGRES_EMPTY_QUERY)
|
||||
@@ -754,8 +770,8 @@ connectDB(PGconn *conn)
|
||||
|
||||
#endif
|
||||
|
||||
/* Post-connection housekeeping.
|
||||
* Send environment variables to server
|
||||
/*
|
||||
* Post-connection housekeeping. Send environment variables to server
|
||||
*/
|
||||
|
||||
PQsetenv(conn);
|
||||
@@ -781,32 +797,38 @@ PQsetenv(PGconn *conn)
|
||||
{
|
||||
struct EnvironmentOptions *eo;
|
||||
char setQuery[80]; /* mjl: size okay? XXX */
|
||||
|
||||
#ifdef MULTIBYTE
|
||||
char *envname = "PGCLIENTENCODING";
|
||||
static char envbuf[64]; /* big enough? */
|
||||
char *env;
|
||||
char *encoding = 0;
|
||||
char *envname = "PGCLIENTENCODING";
|
||||
static char envbuf[64]; /* big enough? */
|
||||
char *env;
|
||||
char *encoding = 0;
|
||||
PGresult *rtn;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef MULTIBYTE
|
||||
/* query server encoding */
|
||||
env = getenv(envname);
|
||||
if (!env) {
|
||||
rtn = PQexec(conn, "select getdatabaseencoding()");
|
||||
if (rtn && PQresultStatus(rtn) == PGRES_TUPLES_OK) {
|
||||
encoding = PQgetvalue(rtn,0,0);
|
||||
if (encoding) {
|
||||
/* set client encoding */
|
||||
sprintf(envbuf,"%s=%s",envname,encoding);
|
||||
putenv(envbuf);
|
||||
}
|
||||
PQclear(rtn);
|
||||
}
|
||||
if (!encoding) { /* this should not happen */
|
||||
sprintf(envbuf,"%s=%s",envname,pg_encoding_to_char(MULTIBYTE));
|
||||
putenv(envbuf);
|
||||
}
|
||||
if (!env)
|
||||
{
|
||||
rtn = PQexec(conn, "select getdatabaseencoding()");
|
||||
if (rtn && PQresultStatus(rtn) == PGRES_TUPLES_OK)
|
||||
{
|
||||
encoding = PQgetvalue(rtn, 0, 0);
|
||||
if (encoding)
|
||||
{
|
||||
/* set client encoding */
|
||||
sprintf(envbuf, "%s=%s", envname, encoding);
|
||||
putenv(envbuf);
|
||||
}
|
||||
PQclear(rtn);
|
||||
}
|
||||
if (!encoding)
|
||||
{ /* this should not happen */
|
||||
sprintf(envbuf, "%s=%s", envname, pg_encoding_to_char(MULTIBYTE));
|
||||
putenv(envbuf);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -833,12 +855,13 @@ PQsetenv(PGconn *conn)
|
||||
|
||||
/*
|
||||
* makeEmptyPGconn
|
||||
* - create a PGconn data structure with (as yet) no interesting data
|
||||
* - create a PGconn data structure with (as yet) no interesting data
|
||||
*/
|
||||
static PGconn *
|
||||
makeEmptyPGconn(void)
|
||||
{
|
||||
PGconn *conn = (PGconn *) malloc(sizeof(PGconn));
|
||||
PGconn *conn = (PGconn *) malloc(sizeof(PGconn));
|
||||
|
||||
if (conn == NULL)
|
||||
return conn;
|
||||
|
||||
@@ -914,11 +937,11 @@ closePGconn(PGconn *conn)
|
||||
{
|
||||
if (conn->sock >= 0)
|
||||
{
|
||||
|
||||
/*
|
||||
* Try to send "close connection" message to backend.
|
||||
* Ignore any error.
|
||||
* Note: this routine used to go to substantial lengths to avoid
|
||||
* getting SIGPIPE'd if the connection were already closed.
|
||||
* Try to send "close connection" message to backend. Ignore any
|
||||
* error. Note: this routine used to go to substantial lengths to
|
||||
* avoid getting SIGPIPE'd if the connection were already closed.
|
||||
* Now we rely on pqFlush to avoid the signal.
|
||||
*/
|
||||
(void) pqPuts("X", conn);
|
||||
@@ -998,9 +1021,10 @@ int
|
||||
PQrequestCancel(PGconn *conn)
|
||||
{
|
||||
int tmpsock = -1;
|
||||
struct {
|
||||
uint32 packetlen;
|
||||
CancelRequestPacket cp;
|
||||
struct
|
||||
{
|
||||
uint32 packetlen;
|
||||
CancelRequestPacket cp;
|
||||
} crp;
|
||||
|
||||
/* Check we have an open connection */
|
||||
@@ -1015,9 +1039,8 @@ PQrequestCancel(PGconn *conn)
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to open a temporary connection to the postmaster.
|
||||
* Use the information saved by connectDB to do this with
|
||||
* only kernel calls.
|
||||
* We need to open a temporary connection to the postmaster. Use the
|
||||
* information saved by connectDB to do this with only kernel calls.
|
||||
*/
|
||||
if ((tmpsock = socket(conn->raddr.sa.sa_family, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
@@ -1029,6 +1052,7 @@ PQrequestCancel(PGconn *conn)
|
||||
strcpy(conn->errorMessage, "PQrequestCancel() -- connect() failed: ");
|
||||
goto cancel_errReturn;
|
||||
}
|
||||
|
||||
/*
|
||||
* We needn't set nonblocking I/O or NODELAY options here.
|
||||
*/
|
||||
@@ -1040,7 +1064,7 @@ PQrequestCancel(PGconn *conn)
|
||||
crp.cp.backendPID = htonl(conn->be_pid);
|
||||
crp.cp.cancelAuthCode = htonl(conn->be_key);
|
||||
|
||||
if (send(tmpsock, (char*) &crp, sizeof(crp), 0) != (int) sizeof(crp))
|
||||
if (send(tmpsock, (char *) &crp, sizeof(crp), 0) != (int) sizeof(crp))
|
||||
{
|
||||
strcpy(conn->errorMessage, "PQrequestCancel() -- send() failed: ");
|
||||
goto cancel_errReturn;
|
||||
@@ -1404,6 +1428,7 @@ char *
|
||||
PQerrorMessage(PGconn *conn)
|
||||
{
|
||||
static char noConn[] = "PQerrorMessage: conn pointer is NULL\n";
|
||||
|
||||
if (!conn)
|
||||
return noConn;
|
||||
return conn->errorMessage;
|
||||
@@ -1441,7 +1466,7 @@ PQuntrace(PGconn *conn)
|
||||
}
|
||||
|
||||
void
|
||||
PQsetNoticeProcessor (PGconn *conn, PQnoticeProcessor proc, void *arg)
|
||||
PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
|
||||
{
|
||||
if (conn == NULL)
|
||||
return;
|
||||
@@ -1457,7 +1482,7 @@ PQsetNoticeProcessor (PGconn *conn, PQnoticeProcessor proc, void *arg)
|
||||
*/
|
||||
|
||||
static void
|
||||
defaultNoticeProcessor(void * arg, const char * message)
|
||||
defaultNoticeProcessor(void *arg, const char *message)
|
||||
{
|
||||
/* Note: we expect the supplied string to end with a newline already. */
|
||||
fprintf(stderr, "%s", message);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.64 1998/09/01 03:28:51 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.65 1998/09/01 04:40:05 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -33,11 +33,11 @@
|
||||
#define TUPARR_GROW_BY 100
|
||||
|
||||
/* keep this in same order as ExecStatusType in libpq-fe.h */
|
||||
const char * const pgresStatus[] = {
|
||||
const char *const pgresStatus[] = {
|
||||
"PGRES_EMPTY_QUERY",
|
||||
"PGRES_COMMAND_OK",
|
||||
"PGRES_TUPLES_OK",
|
||||
"PGRES_COPY_OUT",
|
||||
"PGRES_COPY_OUT",
|
||||
"PGRES_COPY_IN",
|
||||
"PGRES_BAD_RESPONSE",
|
||||
"PGRES_NONFATAL_ERROR",
|
||||
@@ -53,10 +53,10 @@ static PGresult *makeEmptyPGresult(PGconn *conn, ExecStatusType status);
|
||||
static void freeTuple(PGresAttValue *tuple, int numAttributes);
|
||||
static void addTuple(PGresult *res, PGresAttValue *tup);
|
||||
static void parseInput(PGconn *conn);
|
||||
static int getRowDescriptions(PGconn *conn);
|
||||
static int getAnotherTuple(PGconn *conn, int binary);
|
||||
static int getNotify(PGconn *conn);
|
||||
static int getNotice(PGconn *conn);
|
||||
static int getRowDescriptions(PGconn *conn);
|
||||
static int getAnotherTuple(PGconn *conn, int binary);
|
||||
static int getNotify(PGconn *conn);
|
||||
static int getNotice(PGconn *conn);
|
||||
|
||||
|
||||
/*
|
||||
@@ -127,7 +127,7 @@ PQclear(PGresult *res)
|
||||
static void
|
||||
freeTuple(PGresAttValue *tuple, int numAttributes)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
if (tuple)
|
||||
{
|
||||
@@ -170,12 +170,13 @@ addTuple(PGresult *res, PGresAttValue *tup)
|
||||
{
|
||||
/* grow the array */
|
||||
res->tupArrSize += TUPARR_GROW_BY;
|
||||
|
||||
/*
|
||||
* we can use realloc because shallow copying of the structure
|
||||
* is okay. Note that the first time through, res->tuples is NULL.
|
||||
* realloc is supposed to do the right thing in that case.
|
||||
* Also note that the positions beyond res->ntups are garbage,
|
||||
* not necessarily NULL.
|
||||
* we can use realloc because shallow copying of the structure is
|
||||
* okay. Note that the first time through, res->tuples is NULL.
|
||||
* realloc is supposed to do the right thing in that case. Also
|
||||
* note that the positions beyond res->ntups are garbage, not
|
||||
* necessarily NULL.
|
||||
*/
|
||||
res->tuples = (PGresAttValue **)
|
||||
realloc(res->tuples, res->tupArrSize * sizeof(PGresAttValue *));
|
||||
@@ -187,10 +188,10 @@ addTuple(PGresult *res, PGresAttValue *tup)
|
||||
|
||||
/*
|
||||
* PQsendQuery
|
||||
* Submit a query, but don't wait for it to finish
|
||||
* Submit a query, but don't wait for it to finish
|
||||
*
|
||||
* Returns: 1 if successfully submitted
|
||||
* 0 if error (conn->errorMessage is set)
|
||||
* 0 if error (conn->errorMessage is set)
|
||||
*/
|
||||
|
||||
int
|
||||
@@ -204,7 +205,7 @@ PQsendQuery(PGconn *conn, const char *query)
|
||||
return 0;
|
||||
}
|
||||
/* check to see if the query string is too long */
|
||||
if (strlen(query) > MAX_MESSAGE_LEN-2)
|
||||
if (strlen(query) > MAX_MESSAGE_LEN - 2)
|
||||
{
|
||||
sprintf(conn->errorMessage, "PQsendQuery() -- query is too long. "
|
||||
"Maximum length is %d\n", MAX_MESSAGE_LEN - 2);
|
||||
@@ -259,11 +260,11 @@ PQconsumeInput(PGconn *conn)
|
||||
if (!conn)
|
||||
return;
|
||||
|
||||
/* Load more data, if available.
|
||||
* We do this no matter what state we are in, since we are probably
|
||||
* getting called because the application wants to get rid
|
||||
* of a read-select condition.
|
||||
* Note that we will NOT block waiting for more input.
|
||||
/*
|
||||
* Load more data, if available. We do this no matter what state we
|
||||
* are in, since we are probably getting called because the
|
||||
* application wants to get rid of a read-select condition. Note that
|
||||
* we will NOT block waiting for more input.
|
||||
*/
|
||||
if (pqReadData(conn) < 0)
|
||||
strcpy(conn->asyncErrorMessage, conn->errorMessage);
|
||||
@@ -280,30 +281,34 @@ PQconsumeInput(PGconn *conn)
|
||||
static void
|
||||
parseInput(PGconn *conn)
|
||||
{
|
||||
char id;
|
||||
char id;
|
||||
|
||||
/*
|
||||
/*
|
||||
* Loop to parse successive complete messages available in the buffer.
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
/*
|
||||
* Quit if in COPY_OUT state: we expect raw data from the server until
|
||||
* PQendcopy is called. Don't try to parse it according to the normal
|
||||
* protocol. (This is bogus. The data lines ought to be part of the
|
||||
* protocol and have identifying leading characters.)
|
||||
|
||||
/*
|
||||
* Quit if in COPY_OUT state: we expect raw data from the server
|
||||
* until PQendcopy is called. Don't try to parse it according to
|
||||
* the normal protocol. (This is bogus. The data lines ought to
|
||||
* be part of the protocol and have identifying leading
|
||||
* characters.)
|
||||
*/
|
||||
if (conn->asyncStatus == PGASYNC_COPY_OUT)
|
||||
return;
|
||||
|
||||
/*
|
||||
* OK to try to read a message type code.
|
||||
*/
|
||||
conn->inCursor = conn->inStart;
|
||||
if (pqGetc(&id, conn))
|
||||
return;
|
||||
|
||||
/*
|
||||
* NOTIFY and NOTICE messages can happen in any state besides COPY OUT;
|
||||
* always process them right away.
|
||||
* NOTIFY and NOTICE messages can happen in any state besides COPY
|
||||
* OUT; always process them right away.
|
||||
*/
|
||||
if (id == 'A')
|
||||
{
|
||||
@@ -317,18 +322,19 @@ parseInput(PGconn *conn)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
* Other messages should only be processed while in BUSY state.
|
||||
* (In particular, in READY state we hold off further parsing
|
||||
* until the application collects the current PGresult.)
|
||||
* If the state is IDLE then we got trouble.
|
||||
* Other messages should only be processed while in BUSY
|
||||
* state. (In particular, in READY state we hold off further
|
||||
* parsing until the application collects the current
|
||||
* PGresult.) If the state is IDLE then we got trouble.
|
||||
*/
|
||||
if (conn->asyncStatus != PGASYNC_BUSY)
|
||||
{
|
||||
if (conn->asyncStatus == PGASYNC_IDLE)
|
||||
{
|
||||
sprintf(conn->errorMessage,
|
||||
"Backend message type 0x%02x arrived while idle\n",
|
||||
"Backend message type 0x%02x arrived while idle\n",
|
||||
id);
|
||||
DONOTICE(conn, conn->errorMessage);
|
||||
/* Discard the unexpected message; good idea?? */
|
||||
@@ -341,18 +347,21 @@ parseInput(PGconn *conn)
|
||||
case 'C': /* command complete */
|
||||
if (conn->result == NULL)
|
||||
conn->result = makeEmptyPGresult(conn,
|
||||
PGRES_COMMAND_OK);
|
||||
PGRES_COMMAND_OK);
|
||||
if (pqGets(conn->result->cmdStatus, CMDSTATUS_LEN, conn))
|
||||
return;
|
||||
conn->asyncStatus = PGASYNC_READY;
|
||||
break;
|
||||
case 'E': /* error return */
|
||||
if (pqGets(conn->asyncErrorMessage,ERROR_MSG_LENGTH,conn))
|
||||
if (pqGets(conn->asyncErrorMessage, ERROR_MSG_LENGTH, conn))
|
||||
return;
|
||||
/* delete any partially constructed result */
|
||||
pqClearAsyncResult(conn);
|
||||
/* we leave result NULL while setting asyncStatus=READY;
|
||||
* this signals an error condition to PQgetResult.
|
||||
|
||||
/*
|
||||
* we leave result NULL while setting
|
||||
* asyncStatus=READY; this signals an error condition
|
||||
* to PQgetResult.
|
||||
*/
|
||||
conn->asyncStatus = PGASYNC_READY;
|
||||
break;
|
||||
@@ -366,18 +375,20 @@ parseInput(PGconn *conn)
|
||||
if (id != '\0')
|
||||
{
|
||||
sprintf(conn->errorMessage,
|
||||
"unexpected character %c following 'I'\n", id);
|
||||
"unexpected character %c following 'I'\n", id);
|
||||
DONOTICE(conn, conn->errorMessage);
|
||||
}
|
||||
if (conn->result == NULL)
|
||||
conn->result = makeEmptyPGresult(conn,
|
||||
PGRES_EMPTY_QUERY);
|
||||
PGRES_EMPTY_QUERY);
|
||||
conn->asyncStatus = PGASYNC_READY;
|
||||
break;
|
||||
case 'K': /* secret key data from the backend */
|
||||
/* This is expected only during backend startup,
|
||||
* but it's just as easy to handle it as part of the
|
||||
* main loop. Save the data and continue processing.
|
||||
|
||||
/*
|
||||
* This is expected only during backend startup, but
|
||||
* it's just as easy to handle it as part of the main
|
||||
* loop. Save the data and continue processing.
|
||||
*/
|
||||
if (pqGetInt(&(conn->be_pid), 4, conn))
|
||||
return;
|
||||
@@ -389,7 +400,8 @@ parseInput(PGconn *conn)
|
||||
return;
|
||||
/* We pretty much ignore this message type... */
|
||||
break;
|
||||
case 'T': /* row descriptions (start of query results) */
|
||||
case 'T': /* row descriptions (start of query
|
||||
* results) */
|
||||
if (conn->result == NULL)
|
||||
{
|
||||
/* First 'T' in a query sequence */
|
||||
@@ -398,7 +410,9 @@ parseInput(PGconn *conn)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* A new 'T' message is treated as the start of
|
||||
|
||||
/*
|
||||
* A new 'T' message is treated as the start of
|
||||
* another PGresult. (It is not clear that this
|
||||
* is really possible with the current backend.)
|
||||
* We stop parsing until the application accepts
|
||||
@@ -418,7 +432,7 @@ parseInput(PGconn *conn)
|
||||
else
|
||||
{
|
||||
sprintf(conn->errorMessage,
|
||||
"Backend sent D message without prior T\n");
|
||||
"Backend sent D message without prior T\n");
|
||||
DONOTICE(conn, conn->errorMessage);
|
||||
/* Discard the unexpected message; good idea?? */
|
||||
conn->inStart = conn->inEnd;
|
||||
@@ -435,7 +449,7 @@ parseInput(PGconn *conn)
|
||||
else
|
||||
{
|
||||
sprintf(conn->errorMessage,
|
||||
"Backend sent B message without prior T\n");
|
||||
"Backend sent B message without prior T\n");
|
||||
DONOTICE(conn, conn->errorMessage);
|
||||
/* Discard the unexpected message; good idea?? */
|
||||
conn->inStart = conn->inEnd;
|
||||
@@ -450,8 +464,8 @@ parseInput(PGconn *conn)
|
||||
break;
|
||||
default:
|
||||
sprintf(conn->asyncErrorMessage,
|
||||
"unknown protocol character '%c' read from backend. "
|
||||
"(The protocol character is the first character the "
|
||||
"unknown protocol character '%c' read from backend. "
|
||||
"(The protocol character is the first character the "
|
||||
"backend sends in response to a query it receives).\n",
|
||||
id);
|
||||
/* Discard the unexpected message; good idea?? */
|
||||
@@ -567,7 +581,7 @@ getAnotherTuple(PGconn *conn, int binary)
|
||||
tup = conn->curTuple;
|
||||
|
||||
/* Get the null-value bitmap */
|
||||
nbytes = (nfields + BYTELEN-1) / BYTELEN;
|
||||
nbytes = (nfields + BYTELEN - 1) / BYTELEN;
|
||||
if (nbytes >= MAX_FIELDS)
|
||||
{
|
||||
sprintf(conn->asyncErrorMessage,
|
||||
@@ -637,7 +651,7 @@ getAnotherTuple(PGconn *conn, int binary)
|
||||
|
||||
/*
|
||||
* PQisBusy
|
||||
* Return TRUE if PQgetResult would block waiting for input.
|
||||
* Return TRUE if PQgetResult would block waiting for input.
|
||||
*/
|
||||
|
||||
int
|
||||
@@ -656,14 +670,14 @@ PQisBusy(PGconn *conn)
|
||||
|
||||
/*
|
||||
* PQgetResult
|
||||
* Get the next PGresult produced by a query.
|
||||
* Returns NULL if and only if no query work remains.
|
||||
* Get the next PGresult produced by a query.
|
||||
* Returns NULL if and only if no query work remains.
|
||||
*/
|
||||
|
||||
PGresult *
|
||||
PGresult *
|
||||
PQgetResult(PGconn *conn)
|
||||
{
|
||||
PGresult *res;
|
||||
PGresult *res;
|
||||
|
||||
if (!conn)
|
||||
return NULL;
|
||||
@@ -694,16 +708,16 @@ PQgetResult(PGconn *conn)
|
||||
res = NULL; /* query is complete */
|
||||
break;
|
||||
case PGASYNC_READY:
|
||||
|
||||
/*
|
||||
* conn->result is the PGresult to return, or possibly NULL
|
||||
* indicating an error.
|
||||
* conn->asyncErrorMessage holds the errorMessage to return.
|
||||
* (We keep it stashed there so that other user calls can't
|
||||
* overwrite it prematurely.)
|
||||
* indicating an error. conn->asyncErrorMessage holds the
|
||||
* errorMessage to return. (We keep it stashed there so that
|
||||
* other user calls can't overwrite it prematurely.)
|
||||
*/
|
||||
res = conn->result;
|
||||
conn->result = NULL; /* handing over ownership to caller */
|
||||
conn->curTuple = NULL; /* just in case */
|
||||
conn->result = NULL;/* handing over ownership to caller */
|
||||
conn->curTuple = NULL; /* just in case */
|
||||
if (!res)
|
||||
res = makeEmptyPGresult(conn, PGRES_FATAL_ERROR);
|
||||
strcpy(conn->errorMessage, conn->asyncErrorMessage);
|
||||
@@ -742,11 +756,13 @@ PQgetResult(PGconn *conn)
|
||||
PGresult *
|
||||
PQexec(PGconn *conn, const char *query)
|
||||
{
|
||||
PGresult *result;
|
||||
PGresult *lastResult;
|
||||
PGresult *result;
|
||||
PGresult *lastResult;
|
||||
|
||||
/* Silently discard any prior query result that application didn't eat.
|
||||
* This is probably poor design, but it's here for backward compatibility.
|
||||
/*
|
||||
* Silently discard any prior query result that application didn't
|
||||
* eat. This is probably poor design, but it's here for backward
|
||||
* compatibility.
|
||||
*/
|
||||
while ((result = PQgetResult(conn)) != NULL)
|
||||
{
|
||||
@@ -755,19 +771,20 @@ PQexec(PGconn *conn, const char *query)
|
||||
{
|
||||
PQclear(result);
|
||||
sprintf(conn->errorMessage,
|
||||
"PQexec: you gotta get out of a COPY state yourself.\n");
|
||||
"PQexec: you gotta get out of a COPY state yourself.\n");
|
||||
return NULL;
|
||||
}
|
||||
PQclear(result);
|
||||
}
|
||||
|
||||
/* OK to send the message */
|
||||
if (! PQsendQuery(conn, query))
|
||||
if (!PQsendQuery(conn, query))
|
||||
return NULL;
|
||||
|
||||
/* For backwards compatibility, return the last result if there are
|
||||
* more than one. We have to stop if we see copy in/out, however.
|
||||
* We will resume parsing when application calls PQendcopy.
|
||||
/*
|
||||
* For backwards compatibility, return the last result if there are
|
||||
* more than one. We have to stop if we see copy in/out, however. We
|
||||
* will resume parsing when application calls PQendcopy.
|
||||
*/
|
||||
lastResult = NULL;
|
||||
while ((result = PQgetResult(conn)) != NULL)
|
||||
@@ -788,7 +805,7 @@ PQexec(PGconn *conn, const char *query)
|
||||
* This is possible in several places, so we break it out as a subroutine.
|
||||
* Entry: 'N' flag character has already been consumed.
|
||||
* Exit: returns 0 if successfully consumed Notice message.
|
||||
* returns EOF if not enough data.
|
||||
* returns EOF if not enough data.
|
||||
*/
|
||||
static int
|
||||
getNotice(PGconn *conn)
|
||||
@@ -804,12 +821,12 @@ getNotice(PGconn *conn)
|
||||
* This is possible in several places, so we break it out as a subroutine.
|
||||
* Entry: 'A' flag character has already been consumed.
|
||||
* Exit: returns 0 if successfully consumed Notify message.
|
||||
* returns EOF if not enough data.
|
||||
* returns EOF if not enough data.
|
||||
*/
|
||||
static int
|
||||
getNotify(PGconn *conn)
|
||||
{
|
||||
PGnotify tempNotify;
|
||||
PGnotify tempNotify;
|
||||
PGnotify *newNotify;
|
||||
|
||||
if (pqGetInt(&(tempNotify.be_pid), 4, conn))
|
||||
@@ -885,14 +902,16 @@ PQgetline(PGconn *conn, char *s, int maxlen)
|
||||
return EOF;
|
||||
}
|
||||
|
||||
/* Since this is a purely synchronous routine, we don't bother to
|
||||
/*
|
||||
* Since this is a purely synchronous routine, we don't bother to
|
||||
* maintain conn->inCursor; there is no need to back up.
|
||||
*/
|
||||
while (maxlen > 1)
|
||||
{
|
||||
if (conn->inStart < conn->inEnd)
|
||||
{
|
||||
char c = conn->inBuffer[conn->inStart++];
|
||||
char c = conn->inBuffer[conn->inStart++];
|
||||
|
||||
if (c == '\n')
|
||||
{
|
||||
result = 0; /* success exit */
|
||||
@@ -951,7 +970,7 @@ PQputnbytes(PGconn *conn, const char *buffer, int nbytes)
|
||||
int
|
||||
PQendcopy(PGconn *conn)
|
||||
{
|
||||
PGresult *result;
|
||||
PGresult *result;
|
||||
|
||||
if (!conn)
|
||||
return 0;
|
||||
@@ -960,7 +979,7 @@ PQendcopy(PGconn *conn)
|
||||
conn->asyncStatus != PGASYNC_COPY_OUT)
|
||||
{
|
||||
sprintf(conn->errorMessage,
|
||||
"PQendcopy() -- I don't think there's a copy in progress.");
|
||||
"PQendcopy() -- I don't think there's a copy in progress.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -980,10 +999,10 @@ PQendcopy(PGconn *conn)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Trouble.
|
||||
* The worst case is that we've lost sync with the backend entirely
|
||||
* due to application screwup of the copy in/out protocol.
|
||||
* To recover, reset the connection (talk about using a sledgehammer...)
|
||||
/*
|
||||
* Trouble. The worst case is that we've lost sync with the backend
|
||||
* entirely due to application screwup of the copy in/out protocol. To
|
||||
* recover, reset the connection (talk about using a sledgehammer...)
|
||||
*/
|
||||
PQclear(result);
|
||||
|
||||
@@ -1014,9 +1033,9 @@ PQendcopy(PGconn *conn)
|
||||
* nargs : # of arguments in args array.
|
||||
*
|
||||
* RETURNS
|
||||
* PGresult with status = PGRES_COMMAND_OK if successful.
|
||||
* PGresult with status = PGRES_COMMAND_OK if successful.
|
||||
* *actual_result_len is > 0 if there is a return value, 0 if not.
|
||||
* PGresult with status = PGRES_FATAL_ERROR if backend returns an error.
|
||||
* PGresult with status = PGRES_FATAL_ERROR if backend returns an error.
|
||||
* NULL on communications failure. conn->errorMessage will be set.
|
||||
* ----------------
|
||||
*/
|
||||
@@ -1031,7 +1050,7 @@ PQfn(PGconn *conn,
|
||||
int nargs)
|
||||
{
|
||||
bool needInput = false;
|
||||
ExecStatusType status = PGRES_FATAL_ERROR;
|
||||
ExecStatusType status = PGRES_FATAL_ERROR;
|
||||
char id;
|
||||
int i;
|
||||
|
||||
@@ -1051,9 +1070,9 @@ PQfn(PGconn *conn,
|
||||
|
||||
if (pqPuts("F ", conn)) /* function */
|
||||
return NULL;
|
||||
if (pqPutInt(fnid, 4, conn)) /* function id */
|
||||
if (pqPutInt(fnid, 4, conn))/* function id */
|
||||
return NULL;
|
||||
if (pqPutInt(nargs, 4, conn)) /* # of args */
|
||||
if (pqPutInt(nargs, 4, conn)) /* # of args */
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < nargs; ++i)
|
||||
@@ -1084,8 +1103,10 @@ PQfn(PGconn *conn,
|
||||
pqReadData(conn) < 0)
|
||||
break;
|
||||
}
|
||||
/* Scan the message.
|
||||
* If we run out of data, loop around to try again.
|
||||
|
||||
/*
|
||||
* Scan the message. If we run out of data, loop around to try
|
||||
* again.
|
||||
*/
|
||||
conn->inCursor = conn->inStart;
|
||||
needInput = true;
|
||||
@@ -1093,9 +1114,10 @@ PQfn(PGconn *conn,
|
||||
if (pqGetc(&id, conn))
|
||||
continue;
|
||||
|
||||
/* We should see V or E response to the command,
|
||||
* but might get N and/or A notices first.
|
||||
* We also need to swallow the final Z before returning.
|
||||
/*
|
||||
* We should see V or E response to the command, but might get N
|
||||
* and/or A notices first. We also need to swallow the final Z
|
||||
* before returning.
|
||||
*/
|
||||
switch (id)
|
||||
{
|
||||
@@ -1119,7 +1141,7 @@ PQfn(PGconn *conn,
|
||||
conn))
|
||||
continue;
|
||||
}
|
||||
if (pqGetc(&id, conn)) /* get the last '0' */
|
||||
if (pqGetc(&id, conn)) /* get the last '0' */
|
||||
continue;
|
||||
}
|
||||
if (id == '0')
|
||||
@@ -1127,7 +1149,8 @@ PQfn(PGconn *conn,
|
||||
/* correctly finished function result message */
|
||||
status = PGRES_COMMAND_OK;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
/* The backend violates the protocol. */
|
||||
sprintf(conn->errorMessage,
|
||||
"FATAL: PQfn: protocol error: id=%x\n", id);
|
||||
@@ -1249,7 +1272,7 @@ check_tuple_field_number(const char *routineName, PGresult *res,
|
||||
char *
|
||||
PQfname(PGresult *res, int field_num)
|
||||
{
|
||||
if (! check_field_number("PQfname", res, field_num))
|
||||
if (!check_field_number("PQfname", res, field_num))
|
||||
return NULL;
|
||||
if (res->attDescs)
|
||||
return res->attDescs[field_num].name;
|
||||
@@ -1282,8 +1305,8 @@ PQfnumber(PGresult *res, const char *field_name)
|
||||
}
|
||||
else
|
||||
for (i = 0; field_case[i]; i++)
|
||||
if (isascii((unsigned char)field_case[i]) &&
|
||||
isupper(field_case[i]))
|
||||
if (isascii((unsigned char) field_case[i]) &&
|
||||
isupper(field_case[i]))
|
||||
field_case[i] = tolower(field_case[i]);
|
||||
|
||||
for (i = 0; i < res->numAttributes; i++)
|
||||
@@ -1301,7 +1324,7 @@ PQfnumber(PGresult *res, const char *field_name)
|
||||
Oid
|
||||
PQftype(PGresult *res, int field_num)
|
||||
{
|
||||
if (! check_field_number("PQftype", res, field_num))
|
||||
if (!check_field_number("PQftype", res, field_num))
|
||||
return InvalidOid;
|
||||
if (res->attDescs)
|
||||
return res->attDescs[field_num].typid;
|
||||
@@ -1312,7 +1335,7 @@ PQftype(PGresult *res, int field_num)
|
||||
short
|
||||
PQfsize(PGresult *res, int field_num)
|
||||
{
|
||||
if (! check_field_number("PQfsize", res, field_num))
|
||||
if (!check_field_number("PQfsize", res, field_num))
|
||||
return 0;
|
||||
if (res->attDescs)
|
||||
return res->attDescs[field_num].typlen;
|
||||
@@ -1323,7 +1346,7 @@ PQfsize(PGresult *res, int field_num)
|
||||
int
|
||||
PQfmod(PGresult *res, int field_num)
|
||||
{
|
||||
if (! check_field_number("PQfmod", res, field_num))
|
||||
if (!check_field_number("PQfmod", res, field_num))
|
||||
return 0;
|
||||
if (res->attDescs)
|
||||
return res->attDescs[field_num].atttypmod;
|
||||
@@ -1347,8 +1370,11 @@ PQcmdStatus(PGresult *res)
|
||||
const char *
|
||||
PQoidStatus(PGresult *res)
|
||||
{
|
||||
char *p, *e, *scan;
|
||||
int slen, olen;
|
||||
char *p,
|
||||
*e,
|
||||
*scan;
|
||||
int slen,
|
||||
olen;
|
||||
|
||||
if (!res)
|
||||
return "";
|
||||
@@ -1356,22 +1382,20 @@ PQoidStatus(PGresult *res)
|
||||
if (strncmp(res->cmdStatus, "INSERT ", 7) != 0)
|
||||
return "";
|
||||
|
||||
/* The cmdStatus string looks like
|
||||
* INSERT oid count\0
|
||||
* In order to be able to return an ordinary C string without
|
||||
* damaging the result for PQcmdStatus or PQcmdTuples, we copy
|
||||
* the oid part of the string to just after the null, so that
|
||||
* cmdStatus looks like
|
||||
* INSERT oid count\0oid\0
|
||||
* ^ our return value points here
|
||||
* Pretty klugy eh? This routine should've just returned an Oid value.
|
||||
/*
|
||||
* The cmdStatus string looks like INSERT oid count\0 In order to be
|
||||
* able to return an ordinary C string without damaging the result for
|
||||
* PQcmdStatus or PQcmdTuples, we copy the oid part of the string to
|
||||
* just after the null, so that cmdStatus looks like INSERT oid
|
||||
* count\0oid\0 ^ our return value points here Pretty klugy eh? This
|
||||
* routine should've just returned an Oid value.
|
||||
*/
|
||||
|
||||
slen = strlen(res->cmdStatus);
|
||||
p = res->cmdStatus + 7; /* where oid is now */
|
||||
e = res->cmdStatus + slen + 1; /* where to put the oid string */
|
||||
p = res->cmdStatus + 7; /* where oid is now */
|
||||
e = res->cmdStatus + slen + 1; /* where to put the oid string */
|
||||
|
||||
for (scan = p; *scan && *scan != ' '; )
|
||||
for (scan = p; *scan && *scan != ' ';)
|
||||
scan++;
|
||||
olen = scan - p;
|
||||
if (slen + olen + 2 > sizeof(res->cmdStatus))
|
||||
@@ -1439,7 +1463,7 @@ PQcmdTuples(PGresult *res)
|
||||
char *
|
||||
PQgetvalue(PGresult *res, int tup_num, int field_num)
|
||||
{
|
||||
if (! check_tuple_field_number("PQgetvalue", res, tup_num, field_num))
|
||||
if (!check_tuple_field_number("PQgetvalue", res, tup_num, field_num))
|
||||
return NULL;
|
||||
return res->tuples[tup_num][field_num].value;
|
||||
}
|
||||
@@ -1452,7 +1476,7 @@ PQgetvalue(PGresult *res, int tup_num, int field_num)
|
||||
int
|
||||
PQgetlength(PGresult *res, int tup_num, int field_num)
|
||||
{
|
||||
if (! check_tuple_field_number("PQgetlength", res, tup_num, field_num))
|
||||
if (!check_tuple_field_number("PQgetlength", res, tup_num, field_num))
|
||||
return 0;
|
||||
if (res->tuples[tup_num][field_num].len != NULL_LEN)
|
||||
return res->tuples[tup_num][field_num].len;
|
||||
@@ -1466,7 +1490,7 @@ PQgetlength(PGresult *res, int tup_num, int field_num)
|
||||
int
|
||||
PQgetisnull(PGresult *res, int tup_num, int field_num)
|
||||
{
|
||||
if (! check_tuple_field_number("PQgetisnull", res, tup_num, field_num))
|
||||
if (!check_tuple_field_number("PQgetisnull", res, tup_num, field_num))
|
||||
return 1; /* pretend it is null */
|
||||
if (res->tuples[tup_num][field_num].len == NULL_LEN)
|
||||
return 1;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.15 1998/08/17 03:50:37 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.16 1998/09/01 04:40:07 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "libpq/libpq-fs.h" /* must come after sys/stat.h */
|
||||
#include "libpq/libpq-fs.h" /* must come after sys/stat.h */
|
||||
|
||||
|
||||
#define LO_BUFSIZE 1024
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.19 1998/08/29 02:09:25 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.20 1998/09/01 04:40:08 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -46,7 +46,7 @@
|
||||
#if !defined(NO_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#endif /* WIN32 */
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
@@ -87,7 +87,7 @@ pqGetc(char *result, PGconn *conn)
|
||||
static int
|
||||
pqPutBytes(const char *s, int nbytes, PGconn *conn)
|
||||
{
|
||||
int avail = conn->outBufSize - conn->outCount;
|
||||
int avail = conn->outBufSize - conn->outCount;
|
||||
|
||||
while (nbytes > avail)
|
||||
{
|
||||
@@ -117,10 +117,10 @@ int
|
||||
pqGets(char *s, int maxlen, PGconn *conn)
|
||||
{
|
||||
/* Copy conn data to locals for faster search loop */
|
||||
char *inBuffer = conn->inBuffer;
|
||||
int inCursor = conn->inCursor;
|
||||
int inEnd = conn->inEnd;
|
||||
int slen;
|
||||
char *inBuffer = conn->inBuffer;
|
||||
int inCursor = conn->inCursor;
|
||||
int inEnd = conn->inEnd;
|
||||
int slen;
|
||||
|
||||
while (inCursor < inEnd && inBuffer[inCursor])
|
||||
inCursor++;
|
||||
@@ -133,8 +133,8 @@ pqGets(char *s, int maxlen, PGconn *conn)
|
||||
strcpy(s, inBuffer + conn->inCursor);
|
||||
else
|
||||
{
|
||||
strncpy(s, inBuffer + conn->inCursor, maxlen-1);
|
||||
s[maxlen-1] = '\0';
|
||||
strncpy(s, inBuffer + conn->inCursor, maxlen - 1);
|
||||
s[maxlen - 1] = '\0';
|
||||
}
|
||||
|
||||
conn->inCursor = ++inCursor;
|
||||
@@ -149,7 +149,7 @@ pqGets(char *s, int maxlen, PGconn *conn)
|
||||
int
|
||||
pqPuts(const char *s, PGconn *conn)
|
||||
{
|
||||
if (pqPutBytes(s, strlen(s)+1, conn))
|
||||
if (pqPutBytes(s, strlen(s) + 1, conn))
|
||||
return EOF;
|
||||
|
||||
if (conn->Pfdebug)
|
||||
@@ -170,7 +170,7 @@ pqGetnchar(char *s, int len, PGconn *conn)
|
||||
|
||||
memcpy(s, conn->inBuffer + conn->inCursor, len);
|
||||
/* no terminating null */
|
||||
|
||||
|
||||
conn->inCursor += len;
|
||||
|
||||
if (conn->Pfdebug)
|
||||
@@ -204,8 +204,8 @@ pqPutnchar(const char *s, int len, PGconn *conn)
|
||||
int
|
||||
pqGetInt(int *result, int bytes, PGconn *conn)
|
||||
{
|
||||
uint16 tmp2;
|
||||
uint32 tmp4;
|
||||
uint16 tmp2;
|
||||
uint32 tmp4;
|
||||
|
||||
switch (bytes)
|
||||
{
|
||||
@@ -244,19 +244,19 @@ pqGetInt(int *result, int bytes, PGconn *conn)
|
||||
int
|
||||
pqPutInt(int value, int bytes, PGconn *conn)
|
||||
{
|
||||
uint16 tmp2;
|
||||
uint32 tmp4;
|
||||
uint16 tmp2;
|
||||
uint32 tmp4;
|
||||
|
||||
switch (bytes)
|
||||
{
|
||||
case 2:
|
||||
tmp2 = htons((uint16) value);
|
||||
if (pqPutBytes((const char*) &tmp2, 2, conn))
|
||||
if (pqPutBytes((const char *) &tmp2, 2, conn))
|
||||
return EOF;
|
||||
break;
|
||||
case 4:
|
||||
tmp4 = htonl((uint32) value);
|
||||
if (pqPutBytes((const char*) &tmp4, 4, conn))
|
||||
if (pqPutBytes((const char *) &tmp4, 4, conn))
|
||||
return EOF;
|
||||
break;
|
||||
default:
|
||||
@@ -278,8 +278,8 @@ pqPutInt(int value, int bytes, PGconn *conn)
|
||||
static int
|
||||
pqReadReady(PGconn *conn)
|
||||
{
|
||||
fd_set input_mask;
|
||||
struct timeval timeout;
|
||||
fd_set input_mask;
|
||||
struct timeval timeout;
|
||||
|
||||
if (conn->sock < 0)
|
||||
return 0;
|
||||
@@ -288,7 +288,7 @@ pqReadReady(PGconn *conn)
|
||||
FD_SET(conn->sock, &input_mask);
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 0;
|
||||
if (select(conn->sock+1, &input_mask, (fd_set *) NULL, (fd_set *) NULL,
|
||||
if (select(conn->sock + 1, &input_mask, (fd_set *) NULL, (fd_set *) NULL,
|
||||
&timeout) < 0)
|
||||
{
|
||||
sprintf(conn->errorMessage,
|
||||
@@ -302,17 +302,17 @@ pqReadReady(PGconn *conn)
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* pqReadData: read more data, if any is available
|
||||
* Possible return values:
|
||||
* 1: successfully loaded at least one more byte
|
||||
* 0: no data is presently available, but no error detected
|
||||
* -1: error detected (including EOF = connection closure);
|
||||
* conn->errorMessage set
|
||||
* 1: successfully loaded at least one more byte
|
||||
* 0: no data is presently available, but no error detected
|
||||
* -1: error detected (including EOF = connection closure);
|
||||
* conn->errorMessage set
|
||||
* NOTE: callers must not assume that pointers or indexes into conn->inBuffer
|
||||
* remain valid across this call!
|
||||
*/
|
||||
int
|
||||
pqReadData(PGconn *conn)
|
||||
{
|
||||
int nread;
|
||||
int nread;
|
||||
|
||||
if (conn->sock < 0)
|
||||
{
|
||||
@@ -331,16 +331,19 @@ pqReadData(PGconn *conn)
|
||||
}
|
||||
else
|
||||
conn->inStart = conn->inCursor = conn->inEnd = 0;
|
||||
/* If the buffer is fairly full, enlarge it.
|
||||
* We need to be able to enlarge the buffer in case a single message
|
||||
* exceeds the initial buffer size. We enlarge before filling the
|
||||
* buffer entirely so as to avoid asking the kernel for a partial packet.
|
||||
* The magic constant here should be at least one TCP packet.
|
||||
|
||||
/*
|
||||
* If the buffer is fairly full, enlarge it. We need to be able to
|
||||
* enlarge the buffer in case a single message exceeds the initial
|
||||
* buffer size. We enlarge before filling the buffer entirely so as
|
||||
* to avoid asking the kernel for a partial packet. The magic constant
|
||||
* here should be at least one TCP packet.
|
||||
*/
|
||||
if (conn->inBufSize - conn->inEnd < 2000)
|
||||
{
|
||||
int newSize = conn->inBufSize * 2;
|
||||
char * newBuf = (char *) realloc(conn->inBuffer, newSize);
|
||||
int newSize = conn->inBufSize * 2;
|
||||
char *newBuf = (char *) realloc(conn->inBuffer, newSize);
|
||||
|
||||
if (newBuf)
|
||||
{
|
||||
conn->inBuffer = newBuf;
|
||||
@@ -350,7 +353,7 @@ pqReadData(PGconn *conn)
|
||||
|
||||
/* OK, try to read some data */
|
||||
tryAgain:
|
||||
nread = recv(conn->sock, conn->inBuffer + conn->inEnd,
|
||||
nread = recv(conn->sock, conn->inBuffer + conn->inEnd,
|
||||
conn->inBufSize - conn->inEnd, 0);
|
||||
if (nread < 0)
|
||||
{
|
||||
@@ -376,22 +379,24 @@ tryAgain:
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* A return value of 0 could mean just that no data is now available,
|
||||
* or it could mean EOF --- that is, the server has closed the connection.
|
||||
* Since we have the socket in nonblock mode, the only way to tell the
|
||||
* difference is to see if select() is saying that the file is ready.
|
||||
* Grumble. Fortunately, we don't expect this path to be taken much,
|
||||
* since in normal practice we should not be trying to read data unless
|
||||
* the file selected for reading already.
|
||||
/*
|
||||
* A return value of 0 could mean just that no data is now available,
|
||||
* or it could mean EOF --- that is, the server has closed the
|
||||
* connection. Since we have the socket in nonblock mode, the only way
|
||||
* to tell the difference is to see if select() is saying that the
|
||||
* file is ready. Grumble. Fortunately, we don't expect this path to
|
||||
* be taken much, since in normal practice we should not be trying to
|
||||
* read data unless the file selected for reading already.
|
||||
*/
|
||||
if (! pqReadReady(conn))
|
||||
if (!pqReadReady(conn))
|
||||
return 0; /* definitely no data available */
|
||||
|
||||
/* Still not sure that it's EOF,
|
||||
* because some data could have just arrived.
|
||||
/*
|
||||
* Still not sure that it's EOF, because some data could have just
|
||||
* arrived.
|
||||
*/
|
||||
tryAgain2:
|
||||
nread = recv(conn->sock, conn->inBuffer + conn->inEnd,
|
||||
nread = recv(conn->sock, conn->inBuffer + conn->inEnd,
|
||||
conn->inBufSize - conn->inEnd, 0);
|
||||
if (nread < 0)
|
||||
{
|
||||
@@ -417,22 +422,22 @@ tryAgain2:
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* OK, we are getting a zero read even though select() says ready.
|
||||
/*
|
||||
* OK, we are getting a zero read even though select() says ready.
|
||||
* This means the connection has been closed. Cope.
|
||||
*/
|
||||
sprintf(conn->errorMessage,
|
||||
"pqReadData() -- backend closed the channel unexpectedly.\n"
|
||||
"\tThis probably means the backend terminated abnormally"
|
||||
" before or while processing the request.\n");
|
||||
conn->status = CONNECTION_BAD; /* No more connection to
|
||||
* backend */
|
||||
conn->status = CONNECTION_BAD; /* No more connection to backend */
|
||||
#ifdef WIN32
|
||||
closesocket(conn->sock);
|
||||
#else
|
||||
close(conn->sock);
|
||||
#endif
|
||||
conn->sock = -1;
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -442,8 +447,8 @@ tryAgain2:
|
||||
int
|
||||
pqFlush(PGconn *conn)
|
||||
{
|
||||
char * ptr = conn->outBuffer;
|
||||
int len = conn->outCount;
|
||||
char *ptr = conn->outBuffer;
|
||||
int len = conn->outCount;
|
||||
|
||||
if (conn->sock < 0)
|
||||
{
|
||||
@@ -455,10 +460,11 @@ pqFlush(PGconn *conn)
|
||||
{
|
||||
/* Prevent being SIGPIPEd if backend has closed the connection. */
|
||||
#ifndef WIN32
|
||||
pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN);
|
||||
pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN);
|
||||
|
||||
#endif
|
||||
|
||||
int sent = send(conn->sock, ptr, len, 0);
|
||||
int sent = send(conn->sock, ptr, len, 0);
|
||||
|
||||
#ifndef WIN32
|
||||
pqsignal(SIGPIPE, oldsighandler);
|
||||
@@ -479,7 +485,7 @@ pqFlush(PGconn *conn)
|
||||
#endif
|
||||
default:
|
||||
sprintf(conn->errorMessage,
|
||||
"pqFlush() -- couldn't send data: errno=%d\n%s\n",
|
||||
"pqFlush() -- couldn't send data: errno=%d\n%s\n",
|
||||
errno, strerror(errno));
|
||||
return EOF;
|
||||
}
|
||||
@@ -511,8 +517,8 @@ pqFlush(PGconn *conn)
|
||||
int
|
||||
pqWait(int forRead, int forWrite, PGconn *conn)
|
||||
{
|
||||
fd_set input_mask;
|
||||
fd_set output_mask;
|
||||
fd_set input_mask;
|
||||
fd_set output_mask;
|
||||
|
||||
if (conn->sock < 0)
|
||||
{
|
||||
@@ -521,14 +527,15 @@ pqWait(int forRead, int forWrite, PGconn *conn)
|
||||
}
|
||||
|
||||
/* loop in case select returns EINTR */
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
FD_ZERO(&input_mask);
|
||||
FD_ZERO(&output_mask);
|
||||
if (forRead)
|
||||
FD_SET(conn->sock, &input_mask);
|
||||
if (forWrite)
|
||||
FD_SET(conn->sock, &output_mask);
|
||||
if (select(conn->sock+1, &input_mask, &output_mask, (fd_set *) NULL,
|
||||
if (select(conn->sock + 1, &input_mask, &output_mask, (fd_set *) NULL,
|
||||
(struct timeval *) NULL) < 0)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* didn't really belong there.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.11 1998/09/01 03:28:54 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.12 1998/09/01 04:40:09 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -30,7 +30,7 @@
|
||||
#else
|
||||
#include <termios.h>
|
||||
#endif
|
||||
#endif /* WIN32 */
|
||||
#endif /* WIN32 */
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
@@ -52,19 +52,16 @@ static struct winsize
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
do_field(PQprintOpt *po, PGresult *res,
|
||||
static void do_field(PQprintOpt *po, PGresult *res,
|
||||
const int i, const int j, char *buf, const int fs_len,
|
||||
char **fields,
|
||||
const int nFields, char **fieldNames,
|
||||
unsigned char *fieldNotNum, int *fieldMax,
|
||||
const int fieldMaxLen, FILE *fout);
|
||||
static char *
|
||||
do_header(FILE *fout, PQprintOpt *po, const int nFields,
|
||||
static char *do_header(FILE *fout, PQprintOpt *po, const int nFields,
|
||||
int *fieldMax, char **fieldNames, unsigned char *fieldNotNum,
|
||||
const int fs_len, PGresult *res);
|
||||
static void
|
||||
output_row(FILE *fout, PQprintOpt *po, const int nFields, char **fields,
|
||||
static void output_row(FILE *fout, PQprintOpt *po, const int nFields, char **fields,
|
||||
unsigned char *fieldNotNum, int *fieldMax, char *border,
|
||||
const int row_index);
|
||||
static void fill(int length, int max, char filler, FILE *fp);
|
||||
@@ -150,7 +147,7 @@ PQprint(FILE *fout,
|
||||
|
||||
if (fout == NULL)
|
||||
fout = stdout;
|
||||
if (po->pager && fout == stdout
|
||||
if (po->pager && fout == stdout
|
||||
#ifndef WIN32
|
||||
&&
|
||||
isatty(fileno(stdin)) &&
|
||||
@@ -502,20 +499,20 @@ PQprintTuples(PGresult *res,
|
||||
* if this variable is not defined, the same encoding as
|
||||
* the backend is assumed.
|
||||
*/
|
||||
int PQmblen(unsigned char *s)
|
||||
int
|
||||
PQmblen(unsigned char *s)
|
||||
{
|
||||
char *str;
|
||||
int encoding = -1;
|
||||
char *str;
|
||||
int encoding = -1;
|
||||
|
||||
str = getenv("PGCLIENTENCODING");
|
||||
if (str) {
|
||||
encoding = pg_char_to_encoding(str);
|
||||
}
|
||||
if (encoding < 0) {
|
||||
encoding = MULTIBYTE;
|
||||
}
|
||||
return(pg_encoding_mblen(encoding, s));
|
||||
str = getenv("PGCLIENTENCODING");
|
||||
if (str)
|
||||
encoding = pg_char_to_encoding(str);
|
||||
if (encoding < 0)
|
||||
encoding = MULTIBYTE;
|
||||
return (pg_encoding_mblen(encoding, s));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void
|
||||
@@ -552,11 +549,11 @@ do_field(PQprintOpt *po, PGresult *res,
|
||||
if (!skipit)
|
||||
{
|
||||
#ifdef MULTIBYTE
|
||||
int len;
|
||||
int len;
|
||||
|
||||
for (p = pval, o = buf; *p;
|
||||
len = PQmblen(p),memcpy(o,p,len),
|
||||
o+=len, p+=len)
|
||||
for (p = pval, o = buf; *p;
|
||||
len = PQmblen(p), memcpy(o, p, len),
|
||||
o += len, p += len)
|
||||
#else
|
||||
for (p = pval, o = buf; *p; *(o++) = *(p++))
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: libpq-fe.h,v 1.39 1998/08/29 04:05:45 momjian Exp $
|
||||
* $Id: libpq-fe.h,v 1.40 1998/09/01 04:40:10 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -60,7 +60,7 @@ extern "C"
|
||||
} ExecStatusType;
|
||||
|
||||
/* string descriptions of the ExecStatusTypes */
|
||||
extern const char * const pgresStatus[];
|
||||
extern const char *const pgresStatus[];
|
||||
|
||||
/*
|
||||
* POSTGRES backend dependent Constants.
|
||||
@@ -127,7 +127,7 @@ extern "C"
|
||||
} PGnotify;
|
||||
|
||||
/* PQnoticeProcessor is a typedef for a callback function type */
|
||||
typedef void (*PQnoticeProcessor) (void * arg, const char * message);
|
||||
typedef void (*PQnoticeProcessor) (void *arg, const char *message);
|
||||
|
||||
/* PGAsyncStatusType is private to libpq, really shouldn't be seen by users */
|
||||
typedef enum
|
||||
@@ -137,7 +137,7 @@ extern "C"
|
||||
PGASYNC_READY, /* result ready for PQgetResult */
|
||||
PGASYNC_COPY_IN, /* Copy In data transfer in progress */
|
||||
PGASYNC_COPY_OUT /* Copy Out data transfer in progress */
|
||||
} PGAsyncStatusType;
|
||||
} PGAsyncStatusType;
|
||||
|
||||
/* generic socket address type for PGconn connection information.
|
||||
* Really shouldn't be visible to users */
|
||||
@@ -148,7 +148,7 @@ extern "C"
|
||||
#ifndef WIN32
|
||||
struct sockaddr_un un;
|
||||
#endif
|
||||
} PGSockAddr;
|
||||
} PGSockAddr;
|
||||
|
||||
/* large-object-access data ... allocated only if large-object code is used.
|
||||
* Really shouldn't be visible to users */
|
||||
@@ -187,13 +187,14 @@ extern "C"
|
||||
FILE *Pfdebug;
|
||||
|
||||
/* Callback procedure for notice/error message processing */
|
||||
PQnoticeProcessor noticeHook;
|
||||
PQnoticeProcessor noticeHook;
|
||||
void *noticeArg;
|
||||
|
||||
/* Status indicators */
|
||||
ConnStatusType status;
|
||||
PGAsyncStatusType asyncStatus;
|
||||
Dllist *notifyList; /* Notify msgs not yet handed to application */
|
||||
ConnStatusType status;
|
||||
PGAsyncStatusType asyncStatus;
|
||||
Dllist *notifyList; /* Notify msgs not yet handed to
|
||||
* application */
|
||||
|
||||
/* Connection data */
|
||||
int sock; /* Unix FD for socket, -1 if not connected */
|
||||
@@ -205,28 +206,33 @@ extern "C"
|
||||
int be_pid; /* PID of backend --- needed for cancels */
|
||||
int be_key; /* key of backend --- needed for cancels */
|
||||
char salt[2]; /* password salt received from backend */
|
||||
PGlobjfuncs *lobjfuncs; /* private state for large-object access fns */
|
||||
PGlobjfuncs *lobjfuncs; /* private state for large-object access
|
||||
* fns */
|
||||
|
||||
/* Buffer for data received from backend and not yet processed */
|
||||
char *inBuffer; /* currently allocated buffer */
|
||||
char *inBuffer; /* currently allocated buffer */
|
||||
int inBufSize; /* allocated size of buffer */
|
||||
int inStart; /* offset to first unconsumed data in buffer */
|
||||
int inStart; /* offset to first unconsumed data in
|
||||
* buffer */
|
||||
int inCursor; /* next byte to tentatively consume */
|
||||
int inEnd; /* offset to first position after avail data */
|
||||
int inEnd; /* offset to first position after avail
|
||||
* data */
|
||||
|
||||
/* Buffer for data not yet sent to backend */
|
||||
char *outBuffer; /* currently allocated buffer */
|
||||
int outBufSize; /* allocated size of buffer */
|
||||
char *outBuffer; /* currently allocated buffer */
|
||||
int outBufSize; /* allocated size of buffer */
|
||||
int outCount; /* number of chars waiting in buffer */
|
||||
|
||||
/* Status for asynchronous result construction */
|
||||
PGresult *result; /* result being constructed */
|
||||
PGresAttValue *curTuple; /* tuple currently being read */
|
||||
PGresult *result; /* result being constructed */
|
||||
PGresAttValue *curTuple;/* tuple currently being read */
|
||||
|
||||
/* Message space. Placed last for code-size reasons.
|
||||
* errorMessage is the message last returned to the application.
|
||||
* When asyncStatus=READY, asyncErrorMessage is the pending message
|
||||
* that will be put in errorMessage by PQgetResult. */
|
||||
/*
|
||||
* Message space. Placed last for code-size reasons. errorMessage
|
||||
* is the message last returned to the application. When
|
||||
* asyncStatus=READY, asyncErrorMessage is the pending message
|
||||
* that will be put in errorMessage by PQgetResult.
|
||||
*/
|
||||
char errorMessage[ERROR_MSG_LENGTH];
|
||||
char asyncErrorMessage[ERROR_MSG_LENGTH];
|
||||
} PGconn;
|
||||
@@ -303,8 +309,8 @@ extern "C"
|
||||
extern PGconn *PQconnectdb(const char *conninfo);
|
||||
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 *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)
|
||||
|
||||
@@ -313,6 +319,7 @@ extern "C"
|
||||
|
||||
/* close the current connection and free the PGconn data structure */
|
||||
extern void PQfinish(PGconn *conn);
|
||||
|
||||
/*
|
||||
* close the current connection and restablish a new one with the same
|
||||
* parameters
|
||||
@@ -331,16 +338,16 @@ extern "C"
|
||||
extern char *PQtty(PGconn *conn);
|
||||
extern ConnStatusType PQstatus(PGconn *conn);
|
||||
extern char *PQerrorMessage(PGconn *conn);
|
||||
extern int PQsocket(PGconn *conn);
|
||||
extern int PQsocket(PGconn *conn);
|
||||
|
||||
/* Enable/disable tracing */
|
||||
extern void PQtrace(PGconn *conn, FILE *debug_port);
|
||||
extern void PQuntrace(PGconn *conn);
|
||||
|
||||
/* Override default notice processor */
|
||||
extern void PQsetNoticeProcessor (PGconn *conn,
|
||||
PQnoticeProcessor proc,
|
||||
void *arg);
|
||||
extern void PQsetNoticeProcessor(PGconn *conn,
|
||||
PQnoticeProcessor proc,
|
||||
void *arg);
|
||||
|
||||
/* === in fe-exec.c === */
|
||||
|
||||
@@ -349,7 +356,7 @@ extern "C"
|
||||
extern PGnotify *PQnotifies(PGconn *conn);
|
||||
|
||||
/* Interface for multiple-result or asynchronous queries */
|
||||
extern int PQsendQuery(PGconn *conn, const char *query);
|
||||
extern int PQsendQuery(PGconn *conn, const char *query);
|
||||
extern PGresult *PQgetResult(PGconn *conn);
|
||||
|
||||
/* Routines for managing an asychronous query */
|
||||
@@ -362,14 +369,17 @@ extern "C"
|
||||
extern void PQputnbytes(PGconn *conn, const char *buffer, int nbytes);
|
||||
extern int PQendcopy(PGconn *conn);
|
||||
|
||||
/* "Fast path" interface --- not really recommended for application use */
|
||||
/*
|
||||
* "Fast path" interface --- not really recommended for application
|
||||
* use
|
||||
*/
|
||||
extern PGresult *PQfn(PGconn *conn,
|
||||
int fnid,
|
||||
int *result_buf,
|
||||
int *result_len,
|
||||
int result_is_int,
|
||||
PQArgBlock *args,
|
||||
int nargs);
|
||||
int fnid,
|
||||
int *result_buf,
|
||||
int *result_len,
|
||||
int result_is_int,
|
||||
PQArgBlock *args,
|
||||
int nargs);
|
||||
|
||||
/* Accessor functions for PGresult objects */
|
||||
extern ExecStatusType PQresultStatus(PGresult *res);
|
||||
@@ -393,31 +403,32 @@ extern "C"
|
||||
/* === in fe-print.c === */
|
||||
|
||||
extern void PQprint(FILE *fout, /* output stream */
|
||||
PGresult *res,
|
||||
PQprintOpt *ps); /* option structure */
|
||||
PGresult *res,
|
||||
PQprintOpt *ps); /* option structure */
|
||||
|
||||
/* PQdisplayTuples() is a better version of PQprintTuples(),
|
||||
* but both are obsoleted by PQprint().
|
||||
/*
|
||||
* PQdisplayTuples() is a better version of PQprintTuples(), but both
|
||||
* are obsoleted by PQprint().
|
||||
*/
|
||||
extern void PQdisplayTuples(PGresult *res,
|
||||
FILE *fp, /* where to send the
|
||||
* output */
|
||||
int fillAlign, /* pad the fields with
|
||||
* spaces */
|
||||
const char *fieldSep, /* field separator */
|
||||
int printHeader, /* display headers? */
|
||||
int quiet);
|
||||
FILE *fp, /* where to send the
|
||||
* output */
|
||||
int fillAlign, /* pad the fields with
|
||||
* spaces */
|
||||
const char *fieldSep, /* field separator */
|
||||
int printHeader, /* display headers? */
|
||||
int quiet);
|
||||
extern void PQprintTuples(PGresult *res,
|
||||
FILE *fout, /* output stream */
|
||||
int printAttName, /* print attribute names
|
||||
* or not */
|
||||
int terseOutput, /* delimiter bars or
|
||||
* not? */
|
||||
int width); /* width of column, if
|
||||
* 0, use variable width */
|
||||
FILE *fout, /* output stream */
|
||||
int printAttName, /* print attribute names
|
||||
* or not */
|
||||
int terseOutput, /* delimiter bars or
|
||||
* not? */
|
||||
int width); /* width of column, if
|
||||
* 0, use variable width */
|
||||
|
||||
#ifdef MULTIBYTE
|
||||
extern int PQmblen(unsigned char *s);
|
||||
extern int PQmblen(unsigned char *s);
|
||||
#endif
|
||||
|
||||
/* === in fe-lobj.c === */
|
||||
@@ -436,6 +447,7 @@ extern "C"
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* LIBPQ_FE_H */
|
||||
#endif /* LIBPQ_FE_H */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: libpq-int.h,v 1.1 1998/08/17 03:52:36 scrappy Exp $
|
||||
* $Id: libpq-int.h,v 1.2 1998/09/01 04:40:12 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -27,7 +27,7 @@
|
||||
* NB: we used to use PG_PROTOCOL_LATEST from the backend pqcomm.h file,
|
||||
* but that's not really the right thing: just recompiling libpq
|
||||
* against a more recent backend isn't going to magically update it
|
||||
* for most sorts of protocol changes. So, when you change libpq
|
||||
* for most sorts of protocol changes. So, when you change libpq
|
||||
* to support a different protocol revision, you have to change this
|
||||
* constant too. PG_PROTOCOL_EARLIEST and PG_PROTOCOL_LATEST in
|
||||
* pqcomm.h describe what the backend knows, not what libpq knows.
|
||||
@@ -46,28 +46,29 @@
|
||||
|
||||
/* === in fe-connect.c === */
|
||||
|
||||
extern int pqPacketSend(PGconn *conn, const char *buf, size_t len);
|
||||
extern int pqPacketSend(PGconn *conn, const char *buf, size_t len);
|
||||
|
||||
/* === in fe-exec.c === */
|
||||
|
||||
extern void pqClearAsyncResult(PGconn *conn);
|
||||
extern void pqClearAsyncResult(PGconn *conn);
|
||||
|
||||
/* === in fe-misc.c === */
|
||||
|
||||
/* "Get" and "Put" routines return 0 if successful, EOF if not.
|
||||
* Note that for Get, EOF merely means the buffer is exhausted,
|
||||
* not that there is necessarily any error.
|
||||
*/
|
||||
extern int pqGetc(char *result, PGconn *conn);
|
||||
extern int pqGets(char *s, int maxlen, PGconn *conn);
|
||||
extern int pqPuts(const char *s, PGconn *conn);
|
||||
extern int pqGetnchar(char *s, int len, PGconn *conn);
|
||||
extern int pqPutnchar(const char *s, int len, PGconn *conn);
|
||||
extern int pqGetInt(int *result, int bytes, PGconn *conn);
|
||||
extern int pqPutInt(int value, int bytes, PGconn *conn);
|
||||
extern int pqReadData(PGconn *conn);
|
||||
extern int pqFlush(PGconn *conn);
|
||||
extern int pqWait(int forRead, int forWrite, PGconn *conn);
|
||||
/*
|
||||
* "Get" and "Put" routines return 0 if successful, EOF if not. Note that
|
||||
* for Get, EOF merely means the buffer is exhausted, not that there is
|
||||
* necessarily any error.
|
||||
*/
|
||||
extern int pqGetc(char *result, PGconn *conn);
|
||||
extern int pqGets(char *s, int maxlen, PGconn *conn);
|
||||
extern int pqPuts(const char *s, PGconn *conn);
|
||||
extern int pqGetnchar(char *s, int len, PGconn *conn);
|
||||
extern int pqPutnchar(const char *s, int len, PGconn *conn);
|
||||
extern int pqGetInt(int *result, int bytes, PGconn *conn);
|
||||
extern int pqPutInt(int value, int bytes, PGconn *conn);
|
||||
extern int pqReadData(PGconn *conn);
|
||||
extern int pqFlush(PGconn *conn);
|
||||
extern int pqWait(int forRead, int forWrite, PGconn *conn);
|
||||
|
||||
/* max length of message to send */
|
||||
#define MAX_MESSAGE_LEN 8193
|
||||
@@ -90,8 +91,9 @@
|
||||
#ifndef strerror
|
||||
#if defined(sun) && defined(sparc) && !defined(__SVR4)
|
||||
extern char *sys_errlist[];
|
||||
#define strerror(A) (sys_errlist[(A)])
|
||||
#endif /* sunos4 */
|
||||
#endif /* !strerror */
|
||||
|
||||
#endif /* LIBPQ_INT_H */
|
||||
#define strerror(A) (sys_errlist[(A)])
|
||||
#endif /* sunos4 */
|
||||
#endif /* !strerror */
|
||||
|
||||
#endif /* LIBPQ_INT_H */
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason,
|
||||
LPVOID lpReserved ){
|
||||
BOOL WINAPI
|
||||
DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
|
||||
LPVOID lpReserved)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/pqsignal.c,v 1.8 1998/09/01 03:28:56 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/pqsignal.c,v 1.9 1998/09/01 04:40:14 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This shouldn't be in libpq, but the monitor and some other
|
||||
@@ -38,5 +38,5 @@ pqsignal(int signo, pqsigfunc func)
|
||||
if (sigaction(signo, &act, &oact) < 0)
|
||||
return SIG_ERR;
|
||||
return oact.sa_handler;
|
||||
#endif /* !USE_POSIX_SIGNALS */
|
||||
#endif /* !USE_POSIX_SIGNALS */
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pqsignal.h,v 1.4 1997/09/08 02:40:38 momjian Exp $
|
||||
* $Id: pqsignal.h,v 1.5 1998/09/01 04:40:15 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This shouldn't be in libpq, but the monitor and some other
|
||||
@@ -23,4 +23,4 @@ typedef void (*pqsigfunc) (int);
|
||||
|
||||
extern pqsigfunc pqsignal(int signo, pqsigfunc func);
|
||||
|
||||
#endif /* PQSIGNAL_H */
|
||||
#endif /* PQSIGNAL_H */
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
|
||||
/*
|
||||
* Some compat functions
|
||||
* Some compat functions
|
||||
*/
|
||||
#define open(a,b,c) _open(a,b,c)
|
||||
#define read(a,b,c) _read(a,b,c)
|
||||
|
||||
@@ -43,15 +43,15 @@ static PyObject *PGError;
|
||||
|
||||
#ifndef NO_DIRECT
|
||||
#define DIRECT_ACCESS 1 /* enables direct access functions */
|
||||
#endif /* NO_DIRECT */
|
||||
#endif /* NO_DIRECT */
|
||||
|
||||
#ifndef NO_LARGE
|
||||
#define LARGE_OBJECTS 1 /* enables large objects support */
|
||||
#endif /* NO_LARGE */
|
||||
#endif /* NO_LARGE */
|
||||
|
||||
#ifndef NO_DEF_VAR
|
||||
#define DEFAULT_VARS 1 /* enables default variables use */
|
||||
#endif /* NO_DEF_VAR */
|
||||
#endif /* NO_DEF_VAR */
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@@ -65,7 +65,7 @@ PyObject *pg_default_opt; /* default connection options */
|
||||
PyObject *pg_default_tty; /* default debug tty */
|
||||
PyObject *pg_default_port; /* default connection port */
|
||||
|
||||
#endif /* DEFAULT_VARS */
|
||||
#endif /* DEFAULT_VARS */
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@@ -110,7 +110,7 @@ typedef struct
|
||||
staticforward PyTypeObject PglargeType;
|
||||
|
||||
#define is_pglargeobject(v) ((v)->ob_type == &PglargeType)
|
||||
#endif /* LARGE_OBJECTS */
|
||||
#endif /* LARGE_OBJECTS */
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@@ -148,7 +148,7 @@ check_lo(pglargeobject * self, int level)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* LARGE_OBJECTS */
|
||||
#endif /* LARGE_OBJECTS */
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@@ -649,7 +649,7 @@ staticforward PyTypeObject PglargeType = {
|
||||
0, /* tp_hash */
|
||||
};
|
||||
|
||||
#endif /* LARGE_OBJECTS */
|
||||
#endif /* LARGE_OBJECTS */
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@@ -823,7 +823,7 @@ pgconnect(pgobject * self, PyObject * args, PyObject * dict)
|
||||
|
||||
if ((!pgdbname) && (pg_default_base != Py_None))
|
||||
pgdbname = PyString_AsString(pg_default_base);
|
||||
#endif /* DEFAULT_VARS */
|
||||
#endif /* DEFAULT_VARS */
|
||||
|
||||
if ((npgobj = PyObject_NEW(pgobject, &PgType)) == NULL)
|
||||
return NULL;
|
||||
@@ -1213,7 +1213,7 @@ pg_endcopy(pgobject * self, PyObject * args)
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
#endif /* DIRECT_ACCESS */
|
||||
#endif /* DIRECT_ACCESS */
|
||||
|
||||
|
||||
static PyObject *
|
||||
@@ -1381,13 +1381,13 @@ static struct PyMethodDef pgobj_methods[] = {
|
||||
{"putline", (PyCFunction) pg_putline, 1}, /* direct access: putline */
|
||||
{"getline", (PyCFunction) pg_getline, 1}, /* direct access: getline */
|
||||
{"endcopy", (PyCFunction) pg_endcopy, 1}, /* direct access: endcopy */
|
||||
#endif /* DIRECT_ACCESS */
|
||||
#endif /* DIRECT_ACCESS */
|
||||
|
||||
#ifdef LARGE_OBJECTS
|
||||
{"locreate", (PyCFunction) pg_locreate, 1}, /* creates large object */
|
||||
{"getlo", (PyCFunction) pg_getlo, 1}, /* get lo from oid */
|
||||
{"loimport", (PyCFunction) pg_loimport, 1}, /* imports lo from file */
|
||||
#endif /* LARGE_OBJECTS */
|
||||
#endif /* LARGE_OBJECTS */
|
||||
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
@@ -1747,7 +1747,7 @@ pgsetdefport(PyObject * self, PyObject * args)
|
||||
return old;
|
||||
}
|
||||
|
||||
#endif /* DEFAULT_VARS */
|
||||
#endif /* DEFAULT_VARS */
|
||||
|
||||
/* List of functions defined in the module */
|
||||
|
||||
@@ -1765,7 +1765,7 @@ static struct PyMethodDef pg_methods[] = {
|
||||
{"set_deftty", pgsetdeftty, 1}, /* sets default debug tty */
|
||||
{"get_defport", pggetdefport, 1}, /* gets default port */
|
||||
{"set_defport", pgsetdefport, 1}, /* sets default port */
|
||||
#endif /* DEFAULT_VARS */
|
||||
#endif /* DEFAULT_VARS */
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
@@ -1796,7 +1796,7 @@ initpg(void)
|
||||
PyDict_SetItemString(dict, "SEEK_SET", PyInt_FromLong(SEEK_SET));
|
||||
PyDict_SetItemString(dict, "SEEK_CUR", PyInt_FromLong(SEEK_CUR));
|
||||
PyDict_SetItemString(dict, "SEEK_END", PyInt_FromLong(SEEK_END));
|
||||
#endif /* LARGE_OBJECTS */
|
||||
#endif /* LARGE_OBJECTS */
|
||||
|
||||
#ifdef DEFAULT_VARS
|
||||
/* prepares default values */
|
||||
@@ -1810,7 +1810,7 @@ initpg(void)
|
||||
pg_default_port = Py_None;
|
||||
Py_INCREF(Py_None);
|
||||
pg_default_tty = Py_None;
|
||||
#endif /* DEFAULT_VARS */
|
||||
#endif /* DEFAULT_VARS */
|
||||
|
||||
/* Check for errors */
|
||||
if (PyErr_Occurred())
|
||||
|
||||
Reference in New Issue
Block a user