1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-04 20:11:56 +03:00

pgindent run over code.

This commit is contained in:
Bruce Momjian
1999-05-25 16:15:34 +00:00
parent 4b04b01aaa
commit 07842084fe
413 changed files with 11723 additions and 10769 deletions

View File

@@ -15,8 +15,8 @@ extern "C"
bool ECPGdisconnect(int, const char *);
bool ECPGprepare(int, char *, char *);
bool ECPGdeallocate(int, char *);
char *ECPGprepared_statement(char *);
char *ECPGprepared_statement(char *);
void ECPGlog(const char *format,...);
#ifdef LIBPQ_FE_H

View File

@@ -52,12 +52,12 @@ struct sqlca sqlca =
static struct connection
{
char *name;
PGconn *connection;
bool committed;
int autocommit;
char *name;
PGconn *connection;
bool committed;
int autocommit;
struct connection *next;
} *all_connections = NULL, *actual_connection = NULL;
} *all_connections = NULL, *actual_connection = NULL;
struct variable
{
@@ -77,7 +77,7 @@ struct variable
struct statement
{
int lineno;
int lineno;
char *command;
struct connection *connection;
struct variable *inlist;
@@ -86,16 +86,16 @@ struct statement
struct prepared_statement
{
char *name;
struct statement *stmt;
struct prepared_statement *next;
} *prep_stmts = NULL;
char *name;
struct statement *stmt;
struct prepared_statement *next;
} *prep_stmts = NULL;
struct auto_mem
{
void *pointer;
void *pointer;
struct auto_mem *next;
} *auto_allocs = NULL;
} *auto_allocs = NULL;
static int simple_debug = 0;
static FILE *debugstream = NULL;
@@ -105,23 +105,23 @@ register_error(long code, char *fmt,...)
{
va_list args;
struct auto_mem *am;
sqlca.sqlcode = code;
va_start(args, fmt);
vsprintf(sqlca.sqlerrm.sqlerrmc, fmt, args);
va_end(args);
sqlca.sqlerrm.sqlerrml = strlen(sqlca.sqlerrm.sqlerrmc);
/* free all memory we have allocated for the user */
for (am = auto_allocs; am;)
{
struct auto_mem *act = am;
am = am->next;
am = am->next;
free(act->pointer);
free(act);
}
auto_allocs = NULL;
}
@@ -129,10 +129,10 @@ static struct connection *
get_connection(const char *connection_name)
{
struct connection *con = all_connections;
if (connection_name == NULL || strcmp(connection_name, "CURRENT") == 0)
return actual_connection;
for (; con && strcmp(connection_name, con->name) != 0; con = con->next);
if (con)
return con;
@@ -161,7 +161,7 @@ ECPGfinish(struct connection * act)
if (actual_connection == act)
actual_connection = all_connections;
free(act->name);
free(act);
}
@@ -180,7 +180,7 @@ ecpg_alloc(long size, int lineno)
register_error(ECPG_OUT_OF_MEMORY, "Out of memory in line %d", lineno);
return NULL;
}
memset(new, '\0', size);
return (new);
}
@@ -204,7 +204,7 @@ static void
add_mem(void *ptr, int lineno)
{
struct auto_mem *am = (struct auto_mem *) ecpg_alloc(sizeof(struct auto_mem), lineno);
am->next = auto_allocs;
auto_allocs = am;
}
@@ -251,7 +251,7 @@ quote_strings(char *arg, int lineno)
char *res = (char *) ecpg_alloc(2 * strlen(arg) + 1, lineno);
int i,
ri;
bool string = false;
bool string = false;
if (!res)
return (res);
@@ -277,7 +277,7 @@ quote_strings(char *arg, int lineno)
}
/*
* create a list of variables
* create a list of variables
* The variables are listed with input variables preceeding outputvariables
* The end of each group is marked by an end marker.
* per variable we list:
@@ -291,11 +291,11 @@ quote_strings(char *arg, int lineno)
* ind_type - type of indicator variable
* ind_value - pointer to indicator variable
* ind_varcharsize - empty
* ind_arraysize - arraysize of indicator array
* ind_arraysize - arraysize of indicator array
* ind_offset - indicator offset
*/
static bool
create_statement(int lineno, struct connection *connection, struct statement ** stmt, char *query, va_list ap)
create_statement(int lineno, struct connection * connection, struct statement ** stmt, char *query, va_list ap)
{
struct variable **list = &((*stmt)->inlist);
enum ECPGttype type;
@@ -325,8 +325,8 @@ create_statement(int lineno, struct connection *connection, struct statement **
var->type = type;
var->pointer = va_arg(ap, void *);
/* if variable is NULL, the statement hasn't been prepared */
/* if variable is NULL, the statement hasn't been prepared */
if (var->pointer == NULL)
{
ECPGlog("create_statement: invalid statement name\n");
@@ -334,16 +334,16 @@ create_statement(int lineno, struct connection *connection, struct statement **
free(var);
return false;
}
var->varcharsize = va_arg(ap, long);
var->arrsize = va_arg(ap, long);
var->offset = va_arg(ap, long);
if (var->arrsize == 0 || var->varcharsize == 0)
var->value = *((void **)(var->pointer));
var->value = *((void **) (var->pointer));
else
var->value = var->pointer;
var->ind_type = va_arg(ap, enum ECPGttype);
var->ind_value = va_arg(ap, void *);
var->ind_varcharsize = va_arg(ap, long);
@@ -366,16 +366,16 @@ create_statement(int lineno, struct connection *connection, struct statement **
}
static void
free_variable(struct variable *var)
free_variable(struct variable * var)
{
struct variable *var_next;
struct variable *var_next;
if( var == (struct variable *)NULL )
return;
if (var == (struct variable *) NULL)
return;
var_next = var->next;
free(var);
while(var_next)
while (var_next)
{
var = var_next;
var_next = var->next;
@@ -384,9 +384,9 @@ free_variable(struct variable *var)
}
static void
free_statement(struct statement *stmt)
free_statement(struct statement * stmt)
{
if( stmt == (struct statement *)NULL )
if (stmt == (struct statement *) NULL)
return;
free_variable(stmt->inlist);
free_variable(stmt->outlist);
@@ -396,20 +396,20 @@ free_statement(struct statement *stmt)
static char *
next_insert(char *text)
{
char *ptr = text;
bool string = false;
char *ptr = text;
bool string = false;
for (; *ptr != '\0' && (*ptr != '?' || string); ptr++)
if (*ptr == '\'')
string = string ? false : true;
return (*ptr == '\0') ? NULL : ptr;
}
static bool
ECPGexecute(struct statement * stmt)
{
bool status = false;
bool status = false;
char *copiedquery;
PGresult *results;
PGnotify *notify;
@@ -626,7 +626,7 @@ ECPGexecute(struct statement * stmt)
strcat(newcopy,
copiedquery
+ (p - newcopy)
+ sizeof("?") - 1 /* don't count the '\0' */);
+ sizeof("?") - 1 /* don't count the '\0' */ );
}
/*
@@ -675,7 +675,7 @@ ECPGexecute(struct statement * stmt)
ECPGlog("ECPGexecute line %d: error: %s", stmt->lineno,
PQerrorMessage(stmt->connection->connection));
register_error(ECPG_PGSQL, "Postgres error: %s line %d.",
PQerrorMessage(stmt->connection->connection), stmt->lineno);
PQerrorMessage(stmt->connection->connection), stmt->lineno);
}
else
{
@@ -729,39 +729,39 @@ ECPGexecute(struct statement * stmt)
/*
* allocate memory for NULL pointers
*/
*/
if ((var->arrsize == 0 || var->varcharsize == 0) && var->value == NULL)
{
int len = 0;
switch(var->type)
{
case ECPGt_char:
case ECPGt_unsigned_char:
var->varcharsize = 0;
/* check strlen for each tuple */
for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
{
int len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
if (len > var->varcharsize)
var->varcharsize = len;
}
var->offset *= var->varcharsize;
len = var->offset * ntuples;
break;
case ECPGt_varchar:
len = ntuples * (var->varcharsize + sizeof (int));
break;
default:
len = var->offset * ntuples;
break;
}
var->value = (void *) ecpg_alloc(len, stmt->lineno);
*((void **) var->pointer) = var->value;
add_mem(var->value, stmt->lineno);
int len = 0;
switch (var->type)
{
case ECPGt_char:
case ECPGt_unsigned_char:
var->varcharsize = 0;
/* check strlen for each tuple */
for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
{
int len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
if (len > var->varcharsize)
var->varcharsize = len;
}
var->offset *= var->varcharsize;
len = var->offset * ntuples;
break;
case ECPGt_varchar:
len = ntuples * (var->varcharsize + sizeof(int));
break;
default:
len = var->offset * ntuples;
break;
}
var->value = (void *) ecpg_alloc(len, stmt->lineno);
*((void **) var->pointer) = var->value;
add_mem(var->value, stmt->lineno);
}
for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)
{
pval = PQgetvalue(results, act_tuple, act_field);
@@ -1034,7 +1034,7 @@ ECPGexecute(struct statement * stmt)
default:
ECPGlog("ECPGexecute line %d: Got something else, postgres error.\n",
stmt->lineno);
register_error(ECPG_PGSQL, "Postgres error: %s line %d.",
register_error(ECPG_PGSQL, "Postgres error: %s line %d.",
PQerrorMessage(stmt->connection->connection), stmt->lineno);
status = false;
break;
@@ -1067,7 +1067,7 @@ ECPGdo(int lineno, const char *connection_name, char *query,...)
register_error(ECPG_NO_CONN, "No such connection %s in line %d.", connection_name ? connection_name : "NULL", lineno);
return (false);
}
va_start(args, query);
if (create_statement(lineno, con, &stmt, query, args) == false)
return (false);
@@ -1096,7 +1096,7 @@ ECPGstatus(int lineno, const char *connection_name)
register_error(ECPG_NO_CONN, "No such connection %s in line %d", connection_name ? connection_name : "NULL", lineno);
return (false);
}
/* are we connected? */
if (con->connection == NULL)
{
@@ -1113,7 +1113,7 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
{
PGresult *res;
struct connection *con = get_connection(connection_name);
if (con == NULL)
{
register_error(ECPG_NO_CONN, "No such connection %s in line %d", connection_name ? connection_name : "NULL", lineno);
@@ -1135,15 +1135,15 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
if (strcmp(transaction, "commit") == 0 || strcmp(transaction, "rollback") == 0)
{
struct prepared_statement *this;
con->committed = true;
/* deallocate all prepared statements */
for (this = prep_stmts; this != NULL; this = this->next)
{
bool b = ECPGdeallocate(lineno, this->name);
if (!b)
bool b = ECPGdeallocate(lineno, this->name);
if (!b)
return false;
}
}
@@ -1193,7 +1193,7 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
register_error(ECPG_NO_CONN, "No such connection %s in line %d", connection_name ? connection_name : "NULL", lineno);
return false;
}
return true;
}
@@ -1251,7 +1251,7 @@ ECPGconnect(int lineno, const char *dbname, const char *user, const char *passwd
register_error(ECPG_CONNECT, "connect: could not open database %s.", dbname ? dbname : "NULL");
return false;
}
this->committed = true;
this->autocommit = autocommit;
@@ -1276,7 +1276,7 @@ ECPGdisconnect(int lineno, const char *connection_name)
else
{
con = get_connection(connection_name);
if (con == NULL)
{
ECPGlog("disconnect: not connected to connection %s\n", connection_name ? connection_name : "NULL");
@@ -1333,27 +1333,27 @@ isvarchar(unsigned char c)
{
if (isalnum(c))
return true;
if (c == '_' || c == '>' || c == '-' || c == '.')
return true;
if (c >= 128)
return true;
return(false);
return (false);
}
static void
replace_variables(char *text)
{
char *ptr = text;
bool string = false;
char *ptr = text;
bool string = false;
for (; *ptr != '\0'; ptr++)
{
if (*ptr == '\'')
string = string ? false : true;
if (!string && *ptr == ':')
{
*ptr = '?';
@@ -1369,21 +1369,21 @@ ECPGprepare(int lineno, char *name, char *variable)
{
struct statement *stmt;
struct prepared_statement *this;
/* check if we already have prepared this statement */
for (this = prep_stmts; this != NULL && strcmp(this->name, name) != 0; this = this->next);
for (this = prep_stmts; this != NULL && strcmp(this->name, name) != 0; this = this->next);
if (this)
{
bool b = ECPGdeallocate(lineno, name);
if (!b)
bool b = ECPGdeallocate(lineno, name);
if (!b)
return false;
}
this = (struct prepared_statement *) ecpg_alloc(sizeof(struct prepared_statement), lineno);
if (!this)
return false;
stmt = (struct statement *) ecpg_alloc(sizeof(struct statement), lineno);
if (!stmt)
{
@@ -1393,13 +1393,13 @@ ECPGprepare(int lineno, char *name, char *variable)
/* create statement */
stmt->lineno = lineno;
stmt->connection = NULL;
stmt->command = ecpg_strdup(variable, lineno);
stmt->inlist = stmt->outlist = NULL;
/* if we have C variables in our statment replace them with '?' */
replace_variables(stmt->command);
stmt->connection = NULL;
stmt->command = ecpg_strdup(variable, lineno);
stmt->inlist = stmt->outlist = NULL;
/* if we have C variables in our statment replace them with '?' */
replace_variables(stmt->command);
/* add prepared statement to our list */
this->name = ecpg_strdup(name, lineno);
this->stmt = stmt;
@@ -1417,10 +1417,11 @@ ECPGprepare(int lineno, char *name, char *variable)
bool
ECPGdeallocate(int lineno, char *name)
{
struct prepared_statement *this, *prev;
struct prepared_statement *this,
*prev;
/* check if we really have prepared this statement */
for (this = prep_stmts, prev = NULL; this != NULL && strcmp(this->name, name) != 0; prev = this, this = this->next);
for (this = prep_stmts, prev = NULL; this != NULL && strcmp(this->name, name) != 0; prev = this, this = this->next);
if (this)
{
/* okay, free all the resources */
@@ -1431,7 +1432,7 @@ ECPGdeallocate(int lineno, char *name)
prev->next = this->next;
else
prep_stmts = this->next;
return true;
}
ECPGlog("deallocate_prepare: invalid statement name %s\n", name);
@@ -1444,8 +1445,7 @@ char *
ECPGprepared_statement(char *name)
{
struct prepared_statement *this;
for (this = prep_stmts; this != NULL && strcmp(this->name, name) != 0; this = this->next);
return (this) ? this->stmt->command : NULL;
}

View File

@@ -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";

View File

@@ -157,12 +157,13 @@ main(int argc, char *const argv[])
struct cursor *ptr;
struct _defines *defptr;
struct typedefs *typeptr;
/* 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->connection);
@@ -191,7 +192,7 @@ main(int argc, char *const argv[])
defptr = defptr->next;
free(this);
}
/* and old typedefs */
for (typeptr = types; typeptr != NULL;)
{
@@ -203,7 +204,7 @@ main(int argc, char *const argv[])
typeptr = typeptr->next;
free(this);
}
/* initialize lex */
lex_init();

View File

@@ -5,8 +5,10 @@
/* variables */
extern int braces_open,
autocommit, struct_level;
extern char *yytext, errortext[128];
autocommit,
struct_level;
extern char *yytext,
errortext[128];
extern int yylineno,
yyleng;
extern FILE *yyin,
@@ -36,9 +38,9 @@ extern void yyerror(char *);
/* return codes */
#define OK 0
#define PARSE_ERROR -1
#define PARSE_ERROR -1
#define ILLEGAL_OPTION -2
#define INDICATOR_NOT_ARRAY -3
#define INDICATOR_NOT_ARRAY -3
#define NO_INCLUDE_FILE ENOENT
#define OUT_OF_MEMORY ENOMEM

View File

@@ -123,7 +123,7 @@ get_type(enum ECPGttype typ)
{
switch (typ)
{
case ECPGt_char:
case ECPGt_char:
return ("ECPGt_char");
break;
case ECPGt_unsigned_char:
@@ -161,14 +161,15 @@ get_type(enum ECPGttype typ)
case ECPGt_NO_INDICATOR: /* no indicator */
return ("ECPGt_NO_INDICATOR");
break;
case ECPGt_char_variable: /* string that should not be quoted */
case ECPGt_char_variable: /* string that should not be
* quoted */
return ("ECPGt_char_variable");
break;
default:
sprintf(errortext, "illegal variable type %d\n", typ);
yyerror(errortext);
}
return NULL;
}
@@ -208,16 +209,16 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * typ, const char *in
switch (typ->u.element->typ)
{
case ECPGt_array:
yyerror("No nested arrays allowed (except strings)"); /* array of array */
yyerror("No nested arrays allowed (except strings)"); /* array of array */
break;
case ECPGt_struct:
case ECPGt_union:
ECPGdump_a_struct(o, name, ind_name, typ->size, typ->u.element, ind_typ->u.element, NULL, prefix, ind_prefix);
ECPGdump_a_struct(o, name, ind_name, typ->size, typ->u.element, ind_typ->u.element, NULL, prefix, ind_prefix);
break;
default:
default:
if (!IS_SIMPLE_TYPE(typ->u.element->typ))
yyerror("Internal error: unknown datatype, please inform pgsql-bugs@postgresql.org");
ECPGdump_a_simple(o, name, typ->u.element->typ,
typ->u.element->size, typ->size, NULL, prefix);
if (ind_typ->typ == ECPGt_NO_INDICATOR)
@@ -227,17 +228,17 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * typ, const char *in
if (ind_typ->typ != ECPGt_array)
{
fprintf(stderr, "Indicator for an array has to be array too.\n");
exit(INDICATOR_NOT_ARRAY);
}
exit(INDICATOR_NOT_ARRAY);
}
ECPGdump_a_simple(o, ind_name, ind_typ->u.element->typ,
ind_typ->u.element->size, ind_typ->size, NULL, prefix);
ind_typ->u.element->size, ind_typ->size, NULL, prefix);
}
}
break;
case ECPGt_struct:
ECPGdump_a_struct(o, name, ind_name, 1, typ, ind_typ, NULL, prefix, ind_prefix);
break;
case ECPGt_union: /* cannot dump a complete union */
case ECPGt_union: /* cannot dump a complete union */
yyerror("Type of union has to be specified");
break;
case ECPGt_char_variable:
@@ -364,12 +365,12 @@ ECPGfree_type(struct ECPGtype * typ)
{
if (!IS_SIMPLE_TYPE(typ->typ))
{
switch(typ->typ)
switch (typ->typ)
{
case ECPGt_array:
case ECPGt_array:
switch (typ->u.element->typ)
{
case ECPGt_array:
case ECPGt_array:
yyerror("internal error, found multi-dimensional array\n");
break;
case ECPGt_struct:
@@ -378,7 +379,7 @@ ECPGfree_type(struct ECPGtype * typ)
ECPGfree_struct_member(typ->u.element->u.members);
free(typ->u.members);
break;
default:
default:
if (!IS_SIMPLE_TYPE(typ->u.element->typ))
yyerror("Internal error: unknown datatype, please inform pgsql-bugs@postgresql.org");

View File

@@ -30,7 +30,7 @@ struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, long);
struct ECPGtype *ECPGmake_varchar_type(enum ECPGttype, long);
struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, long);
struct ECPGtype *ECPGmake_struct_type(struct ECPGstruct_member *, enum ECPGttype type);
struct ECPGstruct_member * ECPGstruct_member_dup(struct ECPGstruct_member *);
struct ECPGstruct_member *ECPGstruct_member_dup(struct ECPGstruct_member *);
/* Frees a type. */
void ECPGfree_struct_member(struct ECPGstruct_member *);
@@ -71,7 +71,7 @@ enum WHEN_TYPE
struct when
{
enum WHEN_TYPE code;
enum WHEN_TYPE code;
char *command;
char *str;
};
@@ -85,10 +85,10 @@ struct index
struct this_type
{
enum ECPGttype type_enum;
char *type_str;
int type_dimension;
int type_index;
enum ECPGttype type_enum;
char *type_str;
int type_dimension;
int type_index;
};
struct _include_path
@@ -109,8 +109,8 @@ struct cursor
struct typedefs
{
char *name;
struct this_type *type;
char *name;
struct this_type *type;
struct ECPGstruct_member *struct_member_list;
struct typedefs *next;
};

View File

@@ -1,15 +1,19 @@
exec sql include sqlca;
exec sql whenever sqlerror do PrintAndStop();
exec sql whenever sqlwarning do warn();
exec sql whenever sqlerror
do
PrintAndStop();
exec sql whenever sqlwarning
do
warn();
void PrintAndStop(void)
void PrintAndStop(void)
{
sqlprint();
exit(-1);
}
void warn(void)
void warn(void)
{
fprintf(stderr, "Warning: At least one column was truncated\n");
}

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.42 1999/05/10 00:46:22 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.43 1999/05/25 16:15:06 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -28,7 +28,7 @@
#define DIGIT(c) ((c) - '0')
/*
* translate_escape()
* translate_escape()
*
* This function performs in-place translation of a single C-style
* escape sequence pointed by p. Curly braces { } and double-quote
@@ -132,7 +132,7 @@ translate_escape(char *p, int isArray)
}
/*
* tcl_value()
* tcl_value()
*
* This function does in-line conversion of a value returned by libpq
* into a tcl string or into a tcl list if the value looks like the
@@ -219,7 +219,7 @@ tcl_value(char *value)
return value;
}
#endif /* TCL_ARRAYS */
#endif /* TCL_ARRAYS */
/**********************************
@@ -241,12 +241,13 @@ Pg_conndefaults(ClientData cData, Tcl_Interp * interp, int argc, char **argv)
{
PQconninfoOption *option;
Tcl_DString result;
char ibuf[32];
char ibuf[32];
Tcl_DStringInit(&result);
for (option = PQconndefaults(); option->keyword != NULL; option++)
{
char * val = option->val ? option->val : "";
char *val = option->val ? option->val : "";
sprintf(ibuf, "%d", option->dispsize);
Tcl_DStringStartSublist(&result);
Tcl_DStringAppendElement(&result, option->keyword);
@@ -359,7 +360,7 @@ Pg_connect(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
}
if (PQstatus(conn) == CONNECTION_OK)
if (PQstatus(conn) == CONNECTION_OK)
{
PgSetConnectionId(interp, conn);
return TCL_OK;
@@ -367,7 +368,7 @@ Pg_connect(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
else
{
Tcl_AppendResult(interp, "Connection to database failed\n",
PQerrorMessage(conn), 0);
PQerrorMessage(conn), 0);
PQfinish(conn);
return TCL_ERROR;
}
@@ -452,6 +453,7 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
int rId = PgSetResultId(interp, argv[1], result);
ExecStatusType rStat = PQresultStatus(result);
if (rStat == PGRES_COPY_IN || rStat == PGRES_COPY_OUT)
{
connid->res_copyStatus = RES_COPY_INPROGRESS;
@@ -473,11 +475,11 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
syntax:
pg_result result ?option?
pg_result result ?option?
the options are:
-status the status of the result
-status the status of the result
-error the error message, if the status indicates error; otherwise
an empty string
@@ -491,11 +493,11 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
-numAttrs returns the number of attributes returned by the query
-assign arrayName
assign the results to an array, using subscripts of the form
(tupno,attributeName)
assign the results to an array, using subscripts of the form
(tupno,attributeName)
-assignbyidx arrayName ?appendstr?
assign the results to an array using the first field's value
assign the results to an array using the first field's value
as a key.
All but the first field of each tuple are stored, using
subscripts of the form (field0value,attributeNameappendstr)
@@ -504,17 +506,17 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
returns the values of the tuple in a list
-tupleArray tupleNumber arrayName
stores the values of the tuple in array arrayName, indexed
stores the values of the tuple in array arrayName, indexed
by the attributes returned
-attributes
returns a list of the name/type pairs of the tuple attributes
returns a list of the name/type pairs of the tuple attributes
-lAttributes
returns a list of the {name type len} entries of the tuple
returns a list of the {name type len} entries of the tuple
attributes
-clear clear the result buffer. Do not reuse after this
-clear clear the result buffer. Do not reuse after this
**********************************/
int
@@ -526,12 +528,12 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
int tupno;
char *arrVar;
char nameBuffer[256];
const char *appendstr;
const char *appendstr;
if (argc < 3 || argc > 5)
{
Tcl_AppendResult(interp, "Wrong # of arguments\n", 0);
goto Pg_result_errReturn; /* append help info */
goto Pg_result_errReturn; /* append help info */
}
result = PgGetResultId(interp, argv[1]);
@@ -550,7 +552,7 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
}
else if (strcmp(opt, "-error") == 0)
{
Tcl_SetResult(interp, (char*) PQresultErrorMessage(result),
Tcl_SetResult(interp, (char *) PQresultErrorMessage(result),
TCL_STATIC);
return TCL_OK;
}
@@ -588,11 +590,10 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
/*
* this assignment assigns the table of result tuples into a giant
* array with the name given in the argument.
* The indices of the array are of the form (tupno,attrName).
* Note we expect field names not to
* exceed a few dozen characters, so truncating to prevent buffer
* overflow shouldn't be a problem.
* array with the name given in the argument. The indices of the
* array are of the form (tupno,attrName). Note we expect field
* names not to exceed a few dozen characters, so truncating to
* prevent buffer overflow shouldn't be a problem.
*/
for (tupno = 0; tupno < PQntuples(result); tupno++)
{
@@ -616,7 +617,7 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
{
if (argc != 4 && argc != 5)
{
Tcl_AppendResult(interp, "-assignbyidx option requires an array name and optionally an append string",0);
Tcl_AppendResult(interp, "-assignbyidx option requires an array name and optionally an append string", 0);
return TCL_ERROR;
}
arrVar = argv[3];
@@ -624,25 +625,27 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
/*
* this assignment assigns the table of result tuples into a giant
* array with the name given in the argument. The indices of the array
* are of the form (field0Value,attrNameappendstr).
* Here, we still assume PQfname won't exceed 200 characters,
* but we dare not make the same assumption about the data in field 0
* nor the append string.
* array with the name given in the argument. The indices of the
* array are of the form (field0Value,attrNameappendstr). Here, we
* still assume PQfname won't exceed 200 characters, but we dare
* not make the same assumption about the data in field 0 nor the
* append string.
*/
for (tupno = 0; tupno < PQntuples(result); tupno++)
{
const char *field0 =
const char *field0 =
#ifdef TCL_ARRAYS
tcl_value(PQgetvalue(result, tupno, 0));
tcl_value(PQgetvalue(result, tupno, 0));
#else
PQgetvalue(result, tupno, 0);
PQgetvalue(result, tupno, 0);
#endif
char *workspace = malloc(strlen(field0) + strlen(appendstr) + 210);
char *workspace = malloc(strlen(field0) + strlen(appendstr) + 210);
for (i = 1; i < PQnfields(result); i++)
{
sprintf(workspace, "%s,%.200s%s", field0, PQfname(result,i),
sprintf(workspace, "%s,%.200s%s", field0, PQfname(result, i),
appendstr);
if (Tcl_SetVar2(interp, arrVar, workspace,
#ifdef TCL_ARRAYS
@@ -676,9 +679,7 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
}
#ifdef TCL_ARRAYS
for (i = 0; i < PQnfields(result); i++)
{
Tcl_AppendElement(interp, tcl_value(PQgetvalue(result, tupno, i)));
}
#else
for (i = 0; i < PQnfields(result); i++)
Tcl_AppendElement(interp, PQgetvalue(result, tupno, i));
@@ -739,7 +740,7 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
else
{
Tcl_AppendResult(interp, "Invalid option\n", 0);
goto Pg_result_errReturn; /* append help info */
goto Pg_result_errReturn; /* append help info */
}
@@ -1298,7 +1299,7 @@ Pg_select(ClientData cData, Tcl_Interp * interp, int argc, char **argv)
if (PQresultStatus(result) != PGRES_TUPLES_OK)
{
/* query failed, or it wasn't SELECT */
Tcl_SetResult(interp, (char*) PQresultErrorMessage(result),
Tcl_SetResult(interp, (char *) PQresultErrorMessage(result),
TCL_VOLATILE);
PQclear(result);
return TCL_ERROR;
@@ -1374,7 +1375,7 @@ Pg_select(ClientData cData, Tcl_Interp * interp, int argc, char **argv)
*/
static int
Pg_have_listener (Pg_ConnectionId *connid, const char * relname)
Pg_have_listener(Pg_ConnectionId * connid, const char *relname)
{
Pg_TclNotifies *notifies;
Tcl_HashEntry *entry;
@@ -1388,7 +1389,7 @@ Pg_have_listener (Pg_ConnectionId *connid, const char * relname)
if (interp == NULL)
continue; /* ignore deleted interpreter */
entry = Tcl_FindHashEntry(&notifies->notify_hash, (char*) relname);
entry = Tcl_FindHashEntry(&notifies->notify_hash, (char *) relname);
if (entry == NULL)
continue; /* no pg_listen in this interpreter */
@@ -1491,14 +1492,15 @@ Pg_listen(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
if (callback)
{
/*
* Create or update a callback for a relation
*/
int alreadyHadListener = Pg_have_listener(connid, caserelname);
int alreadyHadListener = Pg_have_listener(connid, caserelname);
entry = Tcl_CreateHashEntry(&notifies->notify_hash, caserelname, &new);
/* If update, free the old callback string */
if (! new)
if (!new)
ckfree((char *) Tcl_GetHashValue(entry));
/* Store the new callback string */
Tcl_SetHashValue(entry, callback);
@@ -1509,10 +1511,11 @@ Pg_listen(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
/*
* Send a LISTEN command if this is the first listener.
*/
if (! alreadyHadListener)
if (!alreadyHadListener)
{
char *cmd = (char *)
ckalloc((unsigned) (strlen(origrelname) + 8));
char *cmd = (char *)
ckalloc((unsigned) (strlen(origrelname) + 8));
sprintf(cmd, "LISTEN %s", origrelname);
result = PQexec(conn, cmd);
ckfree(cmd);
@@ -1533,6 +1536,7 @@ Pg_listen(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
}
else
{
/*
* Remove a callback for a relation
*/
@@ -1545,15 +1549,17 @@ Pg_listen(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
}
ckfree((char *) Tcl_GetHashValue(entry));
Tcl_DeleteHashEntry(entry);
/*
* Send an UNLISTEN command if that was the last listener.
* Note: we don't attempt to turn off the notify mechanism
* if no LISTENs remain active; not worth the trouble.
* Send an UNLISTEN command if that was the last listener. Note:
* we don't attempt to turn off the notify mechanism if no LISTENs
* remain active; not worth the trouble.
*/
if (! Pg_have_listener(connid, caserelname))
if (!Pg_have_listener(connid, caserelname))
{
char *cmd = (char *)
ckalloc((unsigned) (strlen(origrelname) + 10));
char *cmd = (char *)
ckalloc((unsigned) (strlen(origrelname) + 10));
sprintf(cmd, "UNLISTEN %s", origrelname);
result = PQexec(conn, cmd);
ckfree(cmd);

View File

@@ -5,7 +5,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pgtclCmds.h,v 1.13 1999/02/13 23:22:38 momjian Exp $
* $Id: pgtclCmds.h,v 1.14 1999/05/25 16:15:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -54,7 +54,7 @@ typedef struct Pg_ConnectionId_s
Pg_TclNotifies *notify_list;/* head of list of notify info */
int notifier_running; /* notify event source is live */
int notifier_socket; /* PQsocket on which notifier is listening */
int notifier_socket;/* PQsocket on which notifier is listening */
} Pg_ConnectionId;
/* Values of res_copyStatus */

View File

@@ -12,7 +12,7 @@
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.18 1999/02/13 23:22:38 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.19 1999/05/25 16:15:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -34,7 +34,7 @@ PgEndCopy(Pg_ConnectionId * connid, int *errorCodePtr)
{
PQclear(connid->results[connid->res_copy]);
connid->results[connid->res_copy] =
PQmakeEmptyPGresult(connid->conn, PGRES_BAD_RESPONSE);
PQmakeEmptyPGresult(connid->conn, PGRES_BAD_RESPONSE);
connid->res_copy = -1;
*errorCodePtr = EIO;
return -1;
@@ -43,51 +43,53 @@ PgEndCopy(Pg_ConnectionId * connid, int *errorCodePtr)
{
PQclear(connid->results[connid->res_copy]);
connid->results[connid->res_copy] =
PQmakeEmptyPGresult(connid->conn, PGRES_COMMAND_OK);
PQmakeEmptyPGresult(connid->conn, PGRES_COMMAND_OK);
connid->res_copy = -1;
return 0;
}
}
/*
* Called when reading data (via gets) for a copy <rel> to stdout.
* Called when reading data (via gets) for a copy <rel> to stdout.
*/
int PgInputProc(DRIVER_INPUT_PROTO)
int
PgInputProc(DRIVER_INPUT_PROTO)
{
Pg_ConnectionId *connid;
PGconn *conn;
int avail;
Pg_ConnectionId *connid;
PGconn *conn;
int avail;
connid = (Pg_ConnectionId *)cData;
conn = connid->conn;
connid = (Pg_ConnectionId *) cData;
conn = connid->conn;
if (connid->res_copy < 0 ||
PQresultStatus(connid->results[connid->res_copy]) != PGRES_COPY_OUT)
if (connid->res_copy < 0 ||
PQresultStatus(connid->results[connid->res_copy]) != PGRES_COPY_OUT)
{
*errorCodePtr = EBUSY;
return -1;
}
}
/* Read any newly arrived data into libpq's buffer,
* thereby clearing the socket's read-ready condition.
*/
if (! PQconsumeInput(conn))
/*
* Read any newly arrived data into libpq's buffer, thereby clearing
* the socket's read-ready condition.
*/
if (!PQconsumeInput(conn))
{
*errorCodePtr = EIO;
return -1;
}
}
/* Move data from libpq's buffer to Tcl's. */
/* Move data from libpq's buffer to Tcl's. */
avail = PQgetlineAsync(conn, buf, bufSize);
avail = PQgetlineAsync(conn, buf, bufSize);
if (avail < 0)
if (avail < 0)
{
/* Endmarker detected, change state and return 0 */
return PgEndCopy(connid, errorCodePtr);
}
/* Endmarker detected, change state and return 0 */
return PgEndCopy(connid, errorCodePtr);
}
return avail;
return avail;
}
/*
@@ -103,13 +105,13 @@ PgOutputProc(DRIVER_OUTPUT_PROTO)
conn = connid->conn;
if (connid->res_copy < 0 ||
PQresultStatus(connid->results[connid->res_copy]) != PGRES_COPY_IN)
PQresultStatus(connid->results[connid->res_copy]) != PGRES_COPY_IN)
{
*errorCodePtr = EBUSY;
return -1;
}
if (PQputnbytes(conn, buf, bufSize))
if (PQputnbytes(conn, buf, bufSize))
{
*errorCodePtr = EIO;
return -1;
@@ -358,7 +360,7 @@ getresid(Tcl_Interp * interp, char *id, Pg_ConnectionId ** connid_p)
connid = (Pg_ConnectionId *) Tcl_GetChannelInstanceData(conn_chan);
if (resid < 0 || resid >= connid->res_max || connid->results[resid] == NULL)
if (resid < 0 || resid >= connid->res_max || connid->results[resid] == NULL)
{
Tcl_SetResult(interp, "Invalid result handle", TCL_STATIC);
return -1;
@@ -450,7 +452,7 @@ error_out:
the channel can outlive the interpreter it was created by!)
Upon closure of the channel, we immediately delete the file event handler
for it, which has the effect of disabling any file-ready events that might
be hanging about in the Tcl event queue. But for interpreter deletion,
be hanging about in the Tcl event queue. But for interpreter deletion,
we just set any matching interp pointers in the Pg_TclNotifies list to NULL.
The list item stays around until the connection is deleted. (This avoids
trouble with walking through a list whose members may get deleted under us.)
@@ -459,10 +461,10 @@ error_out:
libpgtcl currently claims to work with Tcl 7.5, 7.6, and 8.0, and each of
'em is different. Worse, the Tcl_File type went away in 8.0, which means
there is no longer any platform-independent way of waiting for file ready.
So we now have to use a Unix-specific interface. Grumble.
So we now have to use a Unix-specific interface. Grumble.
In the current design, Pg_Notify_FileHandler is a file handler that
we establish by calling Tcl_CreateFileHandler(). It gets invoked from
we establish by calling Tcl_CreateFileHandler(). It gets invoked from
the Tcl event loop whenever the underlying PGconn's socket is read-ready.
We suck up any available data (to clear the OS-level read-ready condition)
and then transfer any available PGnotify events into the Tcl event queue.
@@ -473,8 +475,8 @@ error_out:
typedef struct
{
Tcl_Event header; /* Standard Tcl event info */
PGnotify info; /* Notify name from SQL server */
Tcl_Event header; /* Standard Tcl event info */
PGnotify info; /* Notify name from SQL server */
Pg_ConnectionId *connid; /* Connection for server */
} NotifyEvent;
@@ -620,7 +622,7 @@ PgNotifyInterpDelete(ClientData clientData, Tcl_Interp * interp)
* Therefore we daren't tell Tcl_DeleteEvents to actually delete anything!
* We simply use it as a way of scanning the event queue. Events matching
* the about-to-be-deleted connid are marked dead by setting their connid
* fields to NULL. Then Pg_Notify_EventProc will do nothing when those
* fields to NULL. Then Pg_Notify_EventProc will do nothing when those
* events are executed.
*/
static int
@@ -631,6 +633,7 @@ NotifyEventDeleteProc(Tcl_Event * evPtr, ClientData clientData)
if (evPtr->proc == Pg_Notify_EventProc)
{
NotifyEvent *event = (NotifyEvent *) evPtr;
if (event->connid == connid)
event->connid = NULL;
}
@@ -644,13 +647,14 @@ NotifyEventDeleteProc(Tcl_Event * evPtr, ClientData clientData)
*/
static void
Pg_Notify_FileHandler (ClientData clientData, int mask)
Pg_Notify_FileHandler(ClientData clientData, int mask)
{
Pg_ConnectionId *connid = (Pg_ConnectionId *) clientData;
/*
* Consume any data available from the SQL server (this just buffers
* it internally to libpq; but it will clear the read-ready condition).
* it internally to libpq; but it will clear the read-ready
* condition).
*/
PQconsumeInput(connid->conn);
@@ -667,7 +671,7 @@ Pg_Notify_FileHandler (ClientData clientData, int mask)
* notifier is run until the connection is closed.
*
* FIXME: if PQreset is executed on the underlying PGconn, the active
* socket number could change. How and when should we test for this
* socket number could change. How and when should we test for this
* and update the Tcl file handler linkage? (For that matter, we'd
* also have to reissue LISTEN commands for active LISTENs, since the
* new backend won't know about 'em. I'm leaving this problem for
@@ -680,18 +684,20 @@ PgStartNotifyEventSource(Pg_ConnectionId * connid)
/* Start the notify event source if it isn't already running */
if (!connid->notifier_running)
{
int pqsock = PQsocket(connid->conn);
int pqsock = PQsocket(connid->conn);
if (pqsock >= 0)
{
#if TCL_MAJOR_VERSION >= 8
/* In Tcl 8, Tcl_CreateFileHandler takes a socket directly. */
Tcl_CreateFileHandler(pqsock, TCL_READABLE,
Pg_Notify_FileHandler, (ClientData) connid);
Pg_Notify_FileHandler, (ClientData) connid);
#else
/* In Tcl 7.5 and 7.6, we need to gin up a Tcl_File. */
Tcl_File tclfile = Tcl_GetFile((ClientData) pqsock, TCL_UNIX_FD);
Tcl_File tclfile = Tcl_GetFile((ClientData) pqsock, TCL_UNIX_FD);
Tcl_CreateFileHandler(tclfile, TCL_READABLE,
Pg_Notify_FileHandler, (ClientData) connid);
Pg_Notify_FileHandler, (ClientData) connid);
#endif
connid->notifier_running = 1;
connid->notifier_socket = pqsock;
@@ -710,8 +716,9 @@ PgStopNotifyEventSource(Pg_ConnectionId * connid)
Tcl_DeleteFileHandler(connid->notifier_socket);
#else
/* In Tcl 7.5 and 7.6, we need to gin up a Tcl_File. */
Tcl_File tclfile = Tcl_GetFile((ClientData) connid->notifier_socket,
TCL_UNIX_FD);
Tcl_File tclfile = Tcl_GetFile((ClientData) connid->notifier_socket,
TCL_UNIX_FD);
Tcl_DeleteFileHandler(tclfile);
#endif
connid->notifier_running = 0;

View File

@@ -9,7 +9,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pgtclId.h,v 1.10 1999/02/13 23:22:39 momjian Exp $
* $Id: pgtclId.h,v 1.11 1999/05/25 16:15:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -34,7 +34,7 @@ extern void PgSetConnectionId(Tcl_Interp * interp, PGconn *conn);
#endif
extern PGconn *PgGetConnectionId(Tcl_Interp * interp, char *id,
Pg_ConnectionId **);
Pg_ConnectionId **);
extern PgDelConnectionId(DRIVER_DEL_PROTO);
extern int PgOutputProc(DRIVER_OUTPUT_PROTO);
extern PgInputProc(DRIVER_INPUT_PROTO);
@@ -56,6 +56,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;

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.28 1999/05/10 00:46:25 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.29 1999/05/25 16:15:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -92,7 +92,7 @@ static struct authsvc authsvcs[] = {
{"password", STARTUP_PASSWORD_MSG, 0}
};
static int n_authsvcs = sizeof(authsvcs) / sizeof(struct authsvc);
static int n_authsvcs = sizeof(authsvcs) / sizeof(struct authsvc);
#ifdef KRB4
/*----------------------------------------------------------------
@@ -144,8 +144,8 @@ pg_krb4_init()
static char *
pg_krb4_authname(char *PQerrormsg)
{
char instance[INST_SZ+1];
char realm[REALM_SZ+1];
char instance[INST_SZ + 1];
char realm[REALM_SZ + 1];
int status;
static char name[SNAME_SZ + 1] = "";
@@ -299,7 +299,7 @@ pg_krb5_init(void)
if (code = krb5_cc_resolve(tktbuf, &ccache))
{
(void) sprintf(PQerrormsg,
"pg_krb5_init: Kerberos error %d in krb5_cc_resolve\n", code);
"pg_krb5_init: Kerberos error %d in krb5_cc_resolve\n", code);
com_err("pg_krb5_init", code, "in krb5_cc_resolve");
return (krb5_ccache) NULL;
}
@@ -328,14 +328,14 @@ pg_krb5_authname(const char *PQerrormsg)
if (code = krb5_cc_get_principal(ccache, &principal))
{
(void) sprintf(PQerrormsg,
"pg_krb5_authname: Kerberos error %d in krb5_cc_get_principal\n", code);
"pg_krb5_authname: Kerberos error %d in krb5_cc_get_principal\n", code);
com_err("pg_krb5_authname", code, "in krb5_cc_get_principal");
return (char *) NULL;
}
if (code = krb5_unparse_name(principal, &authname))
{
(void) sprintf(PQerrormsg,
"pg_krb5_authname: Kerberos error %d in krb5_unparse_name\n", code);
"pg_krb5_authname: Kerberos error %d in krb5_unparse_name\n", code);
com_err("pg_krb5_authname", code, "in krb5_unparse_name");
krb5_free_principal(principal);
return (char *) NULL;
@@ -384,7 +384,7 @@ pg_krb5_sendauth(const char *PQerrormsg, int sock,
if (code = krb5_cc_get_principal(ccache, &client))
{
(void) sprintf(PQerrormsg,
"pg_krb5_sendauth: Kerberos error %d in krb5_cc_get_principal\n", code);
"pg_krb5_sendauth: Kerberos error %d in krb5_cc_get_principal\n", code);
com_err("pg_krb5_sendauth", code, "in krb5_cc_get_principal");
return STATUS_ERROR;
}
@@ -411,7 +411,7 @@ pg_krb5_sendauth(const char *PQerrormsg, int sock,
if (code = krb5_parse_name(servbuf, &server))
{
(void) sprintf(PQerrormsg,
"pg_krb5_sendauth: Kerberos error %d in krb5_parse_name\n", code);
"pg_krb5_sendauth: Kerberos error %d in krb5_parse_name\n", code);
com_err("pg_krb5_sendauth", code, "in krb5_parse_name");
krb5_free_principal(client);
return STATUS_ERROR;
@@ -443,7 +443,7 @@ pg_krb5_sendauth(const char *PQerrormsg, int sock,
else
{
(void) sprintf(PQerrormsg,
"pg_krb5_sendauth: Kerberos error %d in krb5_sendauth\n", code);
"pg_krb5_sendauth: Kerberos error %d in krb5_sendauth\n", code);
com_err("pg_krb5_sendauth", code, "in krb5_sendauth");
}
}
@@ -544,7 +544,7 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
* Set/return the authentication service currently selected for use by the
* frontend. (You can only use one in the frontend, obviously.)
*/
static int pg_authsvc = -1;
static int pg_authsvc = -1;
void
fe_setauthsvc(const char *name, char *PQerrormsg)
@@ -618,7 +618,7 @@ fe_getauthname(char *PQerrormsg)
default:
(void) sprintf(PQerrormsg,
"fe_getauthname: invalid authentication system: %d\n",
authsvc);
authsvc);
break;
}

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.96 1999/05/03 19:10:40 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.97 1999/05/25 16:15:11 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -503,7 +503,7 @@ connectDB(PGconn *conn)
struct hostent *hp;
StartupPacket sp;
AuthRequest areq;
SOCKET_SIZE_TYPE laddrlen;
SOCKET_SIZE_TYPE laddrlen;
int portno,
family;
char beresp;
@@ -586,7 +586,7 @@ connectDB(PGconn *conn)
strerror(errno),
(family == AF_INET) ? " (with -i)" : "",
conn->pghost ? conn->pghost : "localhost",
(family == AF_INET) ? "TCP/IP port" : "Unix socket",
(family == AF_INET) ? "TCP/IP port" : "Unix socket",
conn->pgport);
goto connect_errReturn;
}

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.79 1999/05/12 04:38:24 tgl Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.80 1999/05/25 16:15:12 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -75,7 +75,7 @@ static int getNotice(PGconn *conn);
* doesn't tell us up front how many tuples will be returned.)
* All other subsidiary storage for a PGresult is kept in PGresult_data blocks
* of size PGRESULT_DATA_BLOCKSIZE. The overhead at the start of each block
* is just a link to the next one, if any. Free-space management info is
* is just a link to the next one, if any. Free-space management info is
* kept in the owning PGresult.
* A query returning a small amount of data will thus require three malloc
* calls: one for the PGresult, one for the tuples pointer array, and one
@@ -90,10 +90,10 @@ static int getNotice(PGconn *conn);
* PGRESULT_DATA_BLOCKSIZE: size of a standard allocation block, in bytes
* PGRESULT_ALIGN_BOUNDARY: assumed alignment requirement for binary data
* PGRESULT_SEP_ALLOC_THRESHOLD: objects bigger than this are given separate
* blocks, instead of being crammed into a regular allocation block.
* blocks, instead of being crammed into a regular allocation block.
* Requirements for correct function are:
* PGRESULT_ALIGN_BOUNDARY must be a multiple of the alignment requirements
* of all machine data types. (Currently this is set from configure
* of all machine data types. (Currently this is set from configure
* tests, so it should be OK automatically.)
* PGRESULT_SEP_ALLOC_THRESHOLD + PGRESULT_BLOCK_OVERHEAD <=
* PGRESULT_DATA_BLOCKSIZE
@@ -110,7 +110,7 @@ static int getNotice(PGconn *conn);
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define PGRESULT_DATA_BLOCKSIZE 2048
#define PGRESULT_ALIGN_BOUNDARY MAXIMUM_ALIGNOF /* from configure */
#define PGRESULT_ALIGN_BOUNDARY MAXIMUM_ALIGNOF /* from configure */
#define PGRESULT_BLOCK_OVERHEAD MAX(sizeof(PGresult_data), PGRESULT_ALIGN_BOUNDARY)
#define PGRESULT_SEP_ALLOC_THRESHOLD (PGRESULT_DATA_BLOCKSIZE / 2)
@@ -126,7 +126,7 @@ static int getNotice(PGconn *conn);
* and the Perl5 interface, so maybe it's not so unreasonable.
*/
PGresult *
PGresult *
PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
{
PGresult *result;
@@ -180,21 +180,23 @@ PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
void *
pqResultAlloc(PGresult *res, int nBytes, int isBinary)
{
char *space;
PGresult_data *block;
char *space;
PGresult_data *block;
if (! res)
if (!res)
return NULL;
if (nBytes <= 0)
return res->null_field;
/* If alignment is needed, round up the current position to an
/*
* If alignment is needed, round up the current position to an
* alignment boundary.
*/
if (isBinary)
{
int offset = res->curOffset % PGRESULT_ALIGN_BOUNDARY;
int offset = res->curOffset % PGRESULT_ALIGN_BOUNDARY;
if (offset)
{
res->curOffset += PGRESULT_ALIGN_BOUNDARY - offset;
@@ -211,20 +213,24 @@ pqResultAlloc(PGresult *res, int nBytes, int isBinary)
return space;
}
/* If the requested object is very large, give it its own block; this
* avoids wasting what might be most of the current block to start a new
* block. (We'd have to special-case requests bigger than the block size
* anyway.) The object is always given binary alignment in this case.
/*
* If the requested object is very large, give it its own block; this
* avoids wasting what might be most of the current block to start a
* new block. (We'd have to special-case requests bigger than the
* block size anyway.) The object is always given binary alignment in
* this case.
*/
if (nBytes >= PGRESULT_SEP_ALLOC_THRESHOLD)
{
block = (PGresult_data *) malloc(nBytes + PGRESULT_BLOCK_OVERHEAD);
if (! block)
if (!block)
return NULL;
space = block->space + PGRESULT_BLOCK_OVERHEAD;
if (res->curBlock)
{
/* Tuck special block below the active block, so that we don't
/*
* Tuck special block below the active block, so that we don't
* have to waste the free space in the active block.
*/
block->next = res->curBlock->next;
@@ -235,14 +241,14 @@ pqResultAlloc(PGresult *res, int nBytes, int isBinary)
/* Must set up the new block as the first active block. */
block->next = NULL;
res->curBlock = block;
res->spaceLeft = 0; /* be sure it's marked full */
res->spaceLeft = 0; /* be sure it's marked full */
}
return space;
}
/* Otherwise, start a new block. */
block = (PGresult_data *) malloc(PGRESULT_DATA_BLOCKSIZE);
if (! block)
if (!block)
return NULL;
block->next = res->curBlock;
res->curBlock = block;
@@ -272,7 +278,8 @@ pqResultAlloc(PGresult *res, int nBytes, int isBinary)
char *
pqResultStrdup(PGresult *res, const char *str)
{
char *space = (char*) pqResultAlloc(res, strlen(str)+1, FALSE);
char *space = (char *) pqResultAlloc(res, strlen(str) + 1, FALSE);
if (space)
strcpy(space, str);
return space;
@@ -300,13 +307,14 @@ pqSetResultError(PGresult *res, const char *msg)
void
PQclear(PGresult *res)
{
PGresult_data *block;
PGresult_data *block;
if (!res)
return;
/* Free all the subsidiary blocks */
while ((block = res->curBlock) != NULL) {
while ((block = res->curBlock) != NULL)
{
res->curBlock = block->next;
free(block);
}
@@ -343,6 +351,7 @@ addTuple(PGresult *res, PGresAttValue *tup)
{
if (res->ntups >= res->tupArrSize)
{
/*
* Try to grow the array.
*
@@ -351,19 +360,19 @@ addTuple(PGresult *res, PGresAttValue *tup)
* While ANSI says that realloc() should act like malloc() in that
* case, some old C libraries (like SunOS 4.1.x) coredump instead.
* On failure realloc is supposed to return NULL without damaging
* the existing allocation.
* Note that the positions beyond res->ntups are garbage, not
* necessarily NULL.
* the existing allocation. Note that the positions beyond
* res->ntups are garbage, not necessarily NULL.
*/
int newSize = (res->tupArrSize > 0) ? res->tupArrSize * 2 : 128;
PGresAttValue ** newTuples;
int newSize = (res->tupArrSize > 0) ? res->tupArrSize * 2 : 128;
PGresAttValue **newTuples;
if (res->tuples == NULL)
newTuples = (PGresAttValue **)
malloc(newSize * sizeof(PGresAttValue *));
else
newTuples = (PGresAttValue **)
realloc(res->tuples, newSize * sizeof(PGresAttValue *));
if (! newTuples)
if (!newTuples)
return FALSE; /* malloc or realloc failed */
res->tupArrSize = newSize;
res->tuples = newTuples;
@@ -537,7 +546,7 @@ parseInput(PGconn *conn)
case 'C': /* command complete */
if (conn->result == NULL)
conn->result = PQmakeEmptyPGresult(conn,
PGRES_COMMAND_OK);
PGRES_COMMAND_OK);
if (pqGets(conn->result->cmdStatus, CMDSTATUS_LEN, conn))
return;
conn->asyncStatus = PGASYNC_READY;
@@ -567,7 +576,7 @@ parseInput(PGconn *conn)
}
if (conn->result == NULL)
conn->result = PQmakeEmptyPGresult(conn,
PGRES_EMPTY_QUERY);
PGRES_EMPTY_QUERY);
conn->asyncStatus = PGASYNC_READY;
break;
case 'K': /* secret key data from the backend */
@@ -653,7 +662,7 @@ parseInput(PGconn *conn)
sprintf(conn->errorMessage,
"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",
"backend sends in response to a query it receives).\n",
id);
/* Discard the unexpected message; good idea?? */
conn->inStart = conn->inEnd;
@@ -724,12 +733,13 @@ getRowDescriptions(PGconn *conn)
PQclear(result);
return EOF;
}
/*
* Since pqGetInt treats 2-byte integers as unsigned, we need to
* coerce the special value "-1" to signed form. (-1 is sent for
* variable-length fields.) Formerly, libpq effectively did a
* sign-extension on the 2-byte value by storing it in a signed short.
* Now we only coerce the single value 65535 == -1; values
* sign-extension on the 2-byte value by storing it in a signed
* short. Now we only coerce the single value 65535 == -1; values
* 32768..65534 are taken as valid field lengths.
*/
if (typlen == 0xFFFF)
@@ -825,7 +835,7 @@ getAnotherTuple(PGconn *conn, int binary)
vlen = 0;
if (tup[i].value == NULL)
{
tup[i].value = (char *) pqResultAlloc(result, vlen+1, binary);
tup[i].value = (char *) pqResultAlloc(result, vlen + 1, binary);
if (tup[i].value == NULL)
goto outOfMemory;
}
@@ -850,7 +860,7 @@ getAnotherTuple(PGconn *conn, int binary)
}
/* Success! Store the completed tuple in the result */
if (! addTuple(result, tup))
if (!addTuple(result, tup))
goto outOfMemory;
/* and reset for a new message */
conn->curTuple = NULL;
@@ -928,23 +938,25 @@ PQgetResult(PGconn *conn)
res = NULL; /* query is complete */
break;
case PGASYNC_READY:
/*
* conn->result is the PGresult to return. If it is NULL
* (which probably shouldn't happen) we assume there is
* an appropriate error message in conn->errorMessage.
* conn->result is the PGresult to return. If it is NULL
* (which probably shouldn't happen) we assume there is an
* appropriate error message in conn->errorMessage.
*/
res = conn->result;
conn->result = NULL; /* handing over ownership to caller */
conn->result = NULL;/* handing over ownership to caller */
conn->curTuple = NULL; /* just in case */
if (!res)
{
res = PQmakeEmptyPGresult(conn, PGRES_FATAL_ERROR);
}
else
{
/* Make sure PQerrorMessage agrees with result; it could be
* that we have done other operations that changed
* errorMessage since the result's error message was saved.
/*
* Make sure PQerrorMessage agrees with result; it could
* be that we have done other operations that changed
* errorMessage since the result's error message was
* saved.
*/
strcpy(conn->errorMessage, PQresultErrorMessage(res));
}
@@ -1186,13 +1198,13 @@ PQgetline(PGconn *conn, char *s, int maxlen)
* then return to normal processing.
*
* RETURNS:
* -1 if the end-of-copy-data marker has been recognized
* 0 if no data is available
* >0 the number of bytes returned.
* -1 if the end-of-copy-data marker has been recognized
* 0 if no data is available
* >0 the number of bytes returned.
* The data returned will not extend beyond a newline character. If possible
* a whole line will be returned at one time. But if the buffer offered by
* the caller is too small to hold a line sent by the backend, then a partial
* data line will be returned. This can be detected by testing whether the
* data line will be returned. This can be detected by testing whether the
* last returned byte is '\n' or not.
* The returned string is *not* null-terminated.
*/
@@ -1200,18 +1212,17 @@ PQgetline(PGconn *conn, char *s, int maxlen)
int
PQgetlineAsync(PGconn *conn, char *buffer, int bufsize)
{
int avail;
int avail;
if (!conn || conn->asyncStatus != PGASYNC_COPY_OUT)
return -1; /* we are not doing a copy... */
/*
* Move data from libpq's buffer to the caller's.
* We want to accept data only in units of whole lines,
* not partial lines. This ensures that we can recognize
* the terminator line "\\.\n". (Otherwise, if it happened
* to cross a packet/buffer boundary, we might hand the first
* one or two characters off to the caller, which we shouldn't.)
* Move data from libpq's buffer to the caller's. We want to accept
* data only in units of whole lines, not partial lines. This ensures
* that we can recognize the terminator line "\\.\n". (Otherwise, if
* it happened to cross a packet/buffer boundary, we might hand the
* first one or two characters off to the caller, which we shouldn't.)
*/
conn->inCursor = conn->inStart;
@@ -1219,7 +1230,8 @@ PQgetlineAsync(PGconn *conn, char *buffer, int bufsize)
avail = bufsize;
while (avail > 0 && conn->inCursor < conn->inEnd)
{
char c = conn->inBuffer[conn->inCursor++];
char c = conn->inBuffer[conn->inCursor++];
*buffer++ = c;
--avail;
if (c == '\n')
@@ -1227,7 +1239,7 @@ PQgetlineAsync(PGconn *conn, char *buffer, int bufsize)
/* Got a complete line; mark the data removed from libpq */
conn->inStart = conn->inCursor;
/* Is it the endmarker line? */
if (bufsize-avail == 3 && buffer[-3] == '\\' && buffer[-2] == '.')
if (bufsize - avail == 3 && buffer[-3] == '\\' && buffer[-2] == '.')
return -1;
/* No, return the data line to the caller */
return bufsize - avail;
@@ -1235,13 +1247,13 @@ PQgetlineAsync(PGconn *conn, char *buffer, int bufsize)
}
/*
* We don't have a complete line.
* We'd prefer to leave it in libpq's buffer until the rest arrives,
* but there is a special case: what if the line is longer than the
* buffer the caller is offering us? In that case we'd better hand over
* a partial line, else we'd get into an infinite loop.
* Do this in a way that ensures we can't misrecognize a terminator
* line later: leave last 3 characters in libpq buffer.
* We don't have a complete line. We'd prefer to leave it in libpq's
* buffer until the rest arrives, but there is a special case: what if
* the line is longer than the buffer the caller is offering us? In
* that case we'd better hand over a partial line, else we'd get into
* an infinite loop. Do this in a way that ensures we can't
* misrecognize a terminator line later: leave last 3 characters in
* libpq buffer.
*/
if (avail == 0 && bufsize > 3)
{
@@ -1737,13 +1749,13 @@ PQoidStatus(PGresult *res)
/*----------
* The cmdStatus string looks like
* INSERT oid count\0
* 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
* INSERT oid count\0oid\0
* ^ our return value points here
* Pretty klugy eh? This routine should've just returned an Oid value.
*----------
*/
@@ -1802,7 +1814,7 @@ PQcmdTuples(PGresult *res)
if (res->conn)
{
sprintf(res->conn->errorMessage,
"PQcmdTuples (INSERT) -- there's no # of tuples\n");
"PQcmdTuples (INSERT) -- there's no # of tuples\n");
DONOTICE(res->conn, res->conn->errorMessage);
}
return "";

View File

@@ -24,7 +24,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.23 1999/02/22 05:26:53 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.24 1999/05/25 16:15:13 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -471,6 +471,7 @@ pqFlush(PGconn *conn)
/* Prevent being SIGPIPEd if backend has closed the connection. */
#ifndef WIN32
pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN);
#endif
int sent = send(conn->sock, ptr, len, 0);
@@ -481,10 +482,11 @@ pqFlush(PGconn *conn)
if (sent < 0)
{
/*
* Anything except EAGAIN or EWOULDBLOCK is trouble.
* If it's EPIPE or ECONNRESET, assume we've lost the
* backend connection permanently.
* Anything except EAGAIN or EWOULDBLOCK is trouble. If it's
* EPIPE or ECONNRESET, assume we've lost the backend
* connection permanently.
*/
switch (errno)
{
@@ -504,7 +506,7 @@ pqFlush(PGconn *conn)
"pqFlush() -- 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 */
conn->status = CONNECTION_BAD; /* No more connection */
#ifdef WIN32
closesocket(conn->sock);
#else
@@ -514,7 +516,7 @@ pqFlush(PGconn *conn)
return EOF;
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));
/* We don't assume it's a fatal error... */
return EOF;

View File

@@ -9,7 +9,7 @@
* didn't really belong there.
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.22 1999/05/03 19:10:41 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.23 1999/05/25 16:15:13 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -520,7 +520,7 @@ PQmblen(unsigned char *s)
return 1;
}
#endif /* MULTIBYTE */
#endif /* MULTIBYTE */
static void
do_field(PQprintOpt *po, PGresult *res,
@@ -556,6 +556,7 @@ do_field(PQprintOpt *po, PGresult *res,
if (!skipit)
{
char ch = 0;
#ifdef MULTIBYTE
int len;
@@ -567,10 +568,11 @@ do_field(PQprintOpt *po, PGresult *res,
#endif
{
ch = *p;
/*
* Consensus on pgsql-interfaces (as of Aug 1998) seems to be that
* the print functions ought not insert backslashes. If you like
* them, you can re-enable this next bit.
* Consensus on pgsql-interfaces (as of Aug 1998) seems to be
* that the print functions ought not insert backslashes. If
* you like them, you can re-enable this next bit.
*/
#ifdef GRATUITOUS_BACKSLASHES
if ((fs_len == 1 && (ch == *(po->fieldSep))) ||
@@ -587,9 +589,10 @@ do_field(PQprintOpt *po, PGresult *res,
fieldNotNum[j] = 1;
}
*o = '\0';
/*
* Above loop will believe E in first column is numeric; also, we
* insist on a digit in the last column for a numeric. This test
* insist on a digit in the last column for a numeric. This test
* is still not bulletproof but it handles most cases.
*/
if (po->align &&

View File

@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: libpq-fe.h,v 1.49 1999/02/13 23:22:42 momjian Exp $
* $Id: libpq-fe.h,v 1.50 1999/05/25 16:15:13 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -36,10 +36,11 @@ extern "C"
typedef enum
{
PGRES_EMPTY_QUERY = 0,
PGRES_COMMAND_OK, /* a query command that doesn't return anything
* was executed properly by the backend */
PGRES_TUPLES_OK, /* a query command that returns tuples
* was executed properly by the backend,
PGRES_COMMAND_OK, /* a query command that doesn't return
* anything was executed properly by the
* backend */
PGRES_TUPLES_OK, /* a query command that returns tuples was
* executed properly by the backend,
* PGresult contains the result tuples */
PGRES_COPY_OUT, /* Copy Out data transfer in progress */
PGRES_COPY_IN, /* Copy In data transfer in progress */
@@ -52,7 +53,7 @@ extern "C"
/* String descriptions of the ExecStatusTypes.
* NB: direct use of this array is now deprecated; call PQresStatus() instead.
*/
extern const char * const pgresStatus[];
extern const char *const pgresStatus[];
/* PGconn encapsulates a connection to the backend.
* The contents of this struct are not supposed to be known to applications.
@@ -76,21 +77,21 @@ extern "C"
{
char relname[NAMEDATALEN]; /* name of relation
* containing data */
int be_pid; /* process id of backend */
int be_pid; /* process id of backend */
} PGnotify;
/* PQnoticeProcessor is the function type for the notice-message callback.
*/
typedef void (*PQnoticeProcessor) (void * arg, const char * message);
typedef void (*PQnoticeProcessor) (void *arg, const char *message);
/* Print options for PQprint() */
/*
* We can't use the conventional "bool", because we are designed to be
* included in a user's program, and user may already have that type
* defined. Pqbool, on the other hand, is unlikely to be used.
*/
typedef char pqbool;
/*
* We can't use the conventional "bool", because we are designed to be
* included in a user's program, and user may already have that type
* defined. Pqbool, on the other hand, is unlikely to be used.
*/
typedef char pqbool;
typedef struct _PQprintOpt
{
@@ -115,16 +116,16 @@ extern "C"
typedef struct _PQconninfoOption
{
char *keyword; /* The keyword of the option */
char *envvar; /* Fallback environment variable name */
char *envvar; /* Fallback environment variable name */
char *compiled; /* Fallback compiled in default value */
char *val; /* Options value */
char *label; /* Label for field in connect dialog */
char *dispchar; /* Character to display for this field */
/* in a connect dialog. Values are: */
/* "" Display entered value as is */
/* "*" Password field - hide value */
/* "D" Debug options - don't */
/* create a field by default */
/* in a connect dialog. Values are: */
/* "" Display entered value as is */
/* "*" Password field - hide value */
/* "D" Debug options - don't */
/* create a field by default */
int dispsize; /* Field size in characters for dialog */
} PQconninfoOption;
@@ -154,8 +155,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)
@@ -193,8 +194,8 @@ extern "C"
/* Override default notice processor */
extern void PQsetNoticeProcessor(PGconn *conn,
PQnoticeProcessor proc,
void *arg);
PQnoticeProcessor proc,
void *arg);
/* === in fe-exec.c === */
@@ -222,12 +223,12 @@ extern "C"
* 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);
@@ -251,39 +252,40 @@ extern "C"
/* Delete a PGresult */
extern void PQclear(PGresult *res);
/* Make an empty PGresult with given status (some apps find this useful).
* If conn is not NULL and status indicates an error, the conn's
* errorMessage is copied.
/*
* Make an empty PGresult with given status (some apps find this
* useful). If conn is not NULL and status indicates an error, the
* conn's errorMessage is copied.
*/
extern PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);
extern PGresult *PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);
/* === in fe-print.c === */
extern void PQprint(FILE *fout, /* output stream */
PGresult *res,
PQprintOpt *ps); /* option structure */
extern void PQprint(FILE *fout, /* output stream */
PGresult *res,
PQprintOpt *ps); /* option structure */
/*
* 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 */
/* Determine length of multibyte encoded char at *s */
extern int PQmblen(unsigned char *s);

View File

@@ -11,7 +11,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: libpq-int.h,v 1.7 1999/05/03 19:10:42 momjian Exp $
* $Id: libpq-int.h,v 1.8 1999/05/25 16:15:14 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -62,23 +62,23 @@
* Note that space[k] refers to the k'th byte starting from the physical
* head of the block.
*/
typedef union pgresult_data PGresult_data;
typedef union pgresult_data PGresult_data;
union pgresult_data
{
PGresult_data *next; /* link to next block, or NULL */
char space[1]; /* dummy for accessing block as bytes */
};
union pgresult_data
{
PGresult_data *next; /* link to next block, or NULL */
char space[1]; /* dummy for accessing block as bytes */
};
/* Data about a single attribute (column) of a query result */
typedef struct pgresAttDesc
{
char *name; /* type name */
Oid typid; /* type id */
int typlen; /* type size */
int atttypmod; /* type-specific modifier info */
} PGresAttDesc;
typedef struct pgresAttDesc
{
char *name; /* type name */
Oid typid; /* type id */
int typlen; /* type size */
int atttypmod; /* type-specific modifier info */
} PGresAttDesc;
/* Data for a single attribute of a single tuple */
@@ -98,123 +98,128 @@
#define NULL_LEN (-1) /* pg_result len for NULL value */
typedef struct pgresAttValue
{
int len; /* length in bytes of the value */
char *value; /* actual value, plus terminating zero byte */
} PGresAttValue;
typedef struct pgresAttValue
{
int len; /* length in bytes of the value */
char *value; /* actual value, plus terminating zero
* byte */
} PGresAttValue;
struct pg_result
{
int ntups;
int numAttributes;
PGresAttDesc *attDescs;
PGresAttValue **tuples; /* each PGresTuple is an array of
struct pg_result
{
int ntups;
int numAttributes;
PGresAttDesc *attDescs;
PGresAttValue **tuples; /* each PGresTuple is an array of
* PGresAttValue's */
int tupArrSize; /* size of tuples array allocated */
ExecStatusType resultStatus;
char cmdStatus[CMDSTATUS_LEN]; /* cmd status from the
int tupArrSize; /* size of tuples array allocated */
ExecStatusType resultStatus;
char cmdStatus[CMDSTATUS_LEN]; /* cmd status from the
* last insert query */
int binary; /* binary tuple values if binary == 1,
int binary; /* binary tuple values if binary == 1,
* otherwise ASCII */
PGconn *conn; /* connection we did the query on, if any */
char *errMsg; /* error message, or NULL if no error */
PGconn *conn; /* connection we did the query on, if any */
char *errMsg; /* error message, or NULL if no error */
/* All NULL attributes in the query result point to this null string */
char null_field[1];
/* All NULL attributes in the query result point to this null string */
char null_field[1];
/* Space management information. Note that attDescs and errMsg,
* if not null, point into allocated blocks. But tuples points
* to a separately malloc'd block, so that we can realloc it.
*/
PGresult_data *curBlock; /* most recently allocated block */
int curOffset; /* start offset of free space in block */
int spaceLeft; /* number of free bytes remaining in block */
};
/*
* Space management information. Note that attDescs and errMsg, if
* not null, point into allocated blocks. But tuples points to a
* separately malloc'd block, so that we can realloc it.
*/
PGresult_data *curBlock; /* most recently allocated block */
int curOffset; /* start offset of free space in block */
int spaceLeft; /* number of free bytes remaining in block */
};
/* PGAsyncStatusType defines the state of the query-execution state machine */
typedef enum
{
PGASYNC_IDLE, /* nothing's happening, dude */
PGASYNC_BUSY, /* query in progress */
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;
typedef enum
{
PGASYNC_IDLE, /* nothing's happening, dude */
PGASYNC_BUSY, /* query in progress */
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;
/* large-object-access data ... allocated only if large-object code is used. */
typedef struct pgLobjfuncs
{
Oid fn_lo_open; /* OID of backend function lo_open */
Oid fn_lo_close;/* OID of backend function lo_close */
Oid fn_lo_creat;/* OID of backend function lo_creat */
Oid fn_lo_unlink; /* OID of backend function
* lo_unlink */
Oid fn_lo_lseek;/* OID of backend function lo_lseek */
Oid fn_lo_tell; /* OID of backend function lo_tell */
Oid fn_lo_read; /* OID of backend function LOread */
Oid fn_lo_write;/* OID of backend function LOwrite */
} PGlobjfuncs;
typedef struct pgLobjfuncs
{
Oid fn_lo_open; /* OID of backend function lo_open */
Oid fn_lo_close; /* OID of backend function lo_close */
Oid fn_lo_creat; /* OID of backend function lo_creat */
Oid fn_lo_unlink; /* OID of backend function lo_unlink */
Oid fn_lo_lseek; /* OID of backend function lo_lseek */
Oid fn_lo_tell; /* OID of backend function lo_tell */
Oid fn_lo_read; /* OID of backend function LOread */
Oid fn_lo_write; /* OID of backend function LOwrite */
} PGlobjfuncs;
/* PGconn stores all the state data associated with a single connection
* to a backend.
*/
struct pg_conn
{
/* Saved values of connection options */
char *pghost; /* the machine on which the server is
struct pg_conn
{
/* Saved values of connection options */
char *pghost; /* the machine on which the server is
* running */
char *pgport; /* the server's communication port */
char *pgtty; /* tty on which the backend messages is
char *pgport; /* the server's communication port */
char *pgtty; /* tty on which the backend messages is
* displayed (NOT ACTUALLY USED???) */
char *pgoptions; /* options to start the backend with */
char *dbName; /* database name */
char *pguser; /* Postgres username and password, if any */
char *pgpass;
char *pgoptions; /* options to start the backend with */
char *dbName; /* database name */
char *pguser; /* Postgres username and password, if any */
char *pgpass;
/* Optional file to write trace info to */
FILE *Pfdebug;
/* Optional file to write trace info to */
FILE *Pfdebug;
/* Callback procedure for notice/error message processing */
PQnoticeProcessor noticeHook;
void *noticeArg;
/* Callback procedure for notice/error message processing */
PQnoticeProcessor noticeHook;
void *noticeArg;
/* Status indicators */
ConnStatusType status;
PGAsyncStatusType asyncStatus;
Dllist *notifyList; /* Notify msgs not yet handed to application */
/* Status indicators */
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 */
SockAddr laddr; /* Local address */
SockAddr raddr; /* Remote address */
int raddr_len; /* Length of remote address */
/* Connection data */
int sock; /* Unix FD for socket, -1 if not connected */
SockAddr laddr; /* Local address */
SockAddr raddr; /* Remote address */
int raddr_len; /* Length of remote address */
/* Miscellaneous stuff */
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 */
/* Miscellaneous stuff */
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 */
/* Buffer for data received from backend and not yet processed */
char *inBuffer; /* currently allocated buffer */
int inBufSize; /* allocated size of 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 */
/* Buffer for data received from backend and not yet processed */
char *inBuffer; /* currently allocated buffer */
int inBufSize; /* allocated size of 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 */
/* Buffer for data not yet sent to backend */
char *outBuffer; /* currently allocated buffer */
int outBufSize; /* allocated size of buffer */
int outCount; /* number of chars waiting in buffer */
/* Buffer for data not yet sent to backend */
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 */
/* Status for asynchronous result construction */
PGresult *result; /* result being constructed */
PGresAttValue *curTuple; /* tuple currently being read */
/* Message space. Placed last for code-size reasons. */
char errorMessage[ERROR_MSG_LENGTH];
};
/* Message space. Placed last for code-size reasons. */
char errorMessage[ERROR_MSG_LENGTH];
};
/* ----------------
* Internal functions of libpq
@@ -232,8 +237,8 @@ extern int pqPacketSend(PGconn *conn, const char *buf, size_t len);
/* === in fe-exec.c === */
extern void pqSetResultError(PGresult *res, const char *msg);
extern void * pqResultAlloc(PGresult *res, int nBytes, int isBinary);
extern char * pqResultStrdup(PGresult *res, const char *str);
extern void *pqResultAlloc(PGresult *res, int nBytes, int isBinary);
extern char *pqResultStrdup(PGresult *res, const char *str);
extern void pqClearAsyncResult(PGconn *conn);
/* === in fe-misc.c === */

View File

@@ -6,13 +6,18 @@ BOOL WINAPI
DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
LPVOID lpReserved)
{
WSADATA wsaData;
switch (fdwReason) {
WSADATA wsaData;
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
if (WSAStartup(MAKEWORD(1,1),&wsaData))
if (WSAStartup(MAKEWORD(1, 1), &wsaData))
{
/* No really good way to do error handling here,
* since we don't know how we were loaded */
/*
* No really good way to do error handling here, since we
* don't know how we were loaded
*/
return FALSE;
}
break;

File diff suppressed because it is too large Load Diff