summaryrefslogtreecommitdiff
path: root/src/interfaces
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces')
-rw-r--r--src/interfaces/ecpg/include/ecpglib.h4
-rw-r--r--src/interfaces/ecpg/lib/ecpglib.c226
-rw-r--r--src/interfaces/ecpg/lib/typename.c2
-rw-r--r--src/interfaces/ecpg/preproc/ecpg.c9
-rw-r--r--src/interfaces/ecpg/preproc/extern.h10
-rw-r--r--src/interfaces/ecpg/preproc/type.c31
-rw-r--r--src/interfaces/ecpg/preproc/type.h16
-rw-r--r--src/interfaces/ecpg/test/header_test.h12
-rw-r--r--src/interfaces/libpgtcl/pgtclCmds.c112
-rw-r--r--src/interfaces/libpgtcl/pgtclCmds.h4
-rw-r--r--src/interfaces/libpgtcl/pgtclId.c93
-rw-r--r--src/interfaces/libpgtcl/pgtclId.h5
-rw-r--r--src/interfaces/libpq/fe-auth.c24
-rw-r--r--src/interfaces/libpq/fe-connect.c6
-rw-r--r--src/interfaces/libpq/fe-exec.c148
-rw-r--r--src/interfaces/libpq/fe-misc.c14
-rw-r--r--src/interfaces/libpq/fe-print.c15
-rw-r--r--src/interfaces/libpq/libpq-fe.h106
-rw-r--r--src/interfaces/libpq/libpq-int.h245
-rw-r--r--src/interfaces/libpq/libpqdll.c15
-rw-r--r--src/interfaces/python/pgmodule.c833
21 files changed, 1016 insertions, 914 deletions
diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h
index bac46c849b..9ceb691695 100644
--- a/src/interfaces/ecpg/include/ecpglib.h
+++ b/src/interfaces/ecpg/include/ecpglib.h
@@ -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
diff --git a/src/interfaces/ecpg/lib/ecpglib.c b/src/interfaces/ecpg/lib/ecpglib.c
index 5314a0a90d..88c3057d9a 100644
--- a/src/interfaces/ecpg/lib/ecpglib.c
+++ b/src/interfaces/ecpg/lib/ecpglib.c
@@ -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;
}
-
diff --git a/src/interfaces/ecpg/lib/typename.c b/src/interfaces/ecpg/lib/typename.c
index af87b160aa..8a9923d940 100644
--- a/src/interfaces/ecpg/lib/typename.c
+++ b/src/interfaces/ecpg/lib/typename.c
@@ -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";
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index b385b2a197..aa6c2c274b 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -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();
diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h
index 3892014ed3..52a3896f53 100644
--- a/src/interfaces/ecpg/preproc/extern.h
+++ b/src/interfaces/ecpg/preproc/extern.h
@@ -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
diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c
index 3c5d2f3ed0..30580a775c 100644
--- a/src/interfaces/ecpg/preproc/type.c
+++ b/src/interfaces/ecpg/preproc/type.c
@@ -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");
diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h
index ed97b2e667..7cdc476e83 100644
--- a/src/interfaces/ecpg/preproc/type.h
+++ b/src/interfaces/ecpg/preproc/type.h
@@ -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;
};
diff --git a/src/interfaces/ecpg/test/header_test.h b/src/interfaces/ecpg/test/header_test.h
index d6a84322b1..b93221c339 100644
--- a/src/interfaces/ecpg/test/header_test.h
+++ b/src/interfaces/ecpg/test/header_test.h
@@ -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");
}
diff --git a/src/interfaces/libpgtcl/pgtclCmds.c b/src/interfaces/libpgtcl/pgtclCmds.c
index 99b6f925e6..0c2b184ed6 100644
--- a/src/interfaces/libpgtcl/pgtclCmds.c
+++ b/src/interfaces/libpgtcl/pgtclCmds.c
@@ -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);
diff --git a/src/interfaces/libpgtcl/pgtclCmds.h b/src/interfaces/libpgtcl/pgtclCmds.h
index 767c266b05..495bf19e33 100644
--- a/src/interfaces/libpgtcl/pgtclCmds.h
+++ b/src/interfaces/libpgtcl/pgtclCmds.h
@@ -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 */
diff --git a/src/interfaces/libpgtcl/pgtclId.c b/src/interfaces/libpgtcl/pgtclId.c
index ae5e9ba1b9..b8d30ce4f4 100644
--- a/src/interfaces/libpgtcl/pgtclId.c
+++ b/src/interfaces/libpgtcl/pgtclId.c
@@ -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;
diff --git a/src/interfaces/libpgtcl/pgtclId.h b/src/interfaces/libpgtcl/pgtclId.h
index f2877b8059..046ab39a08 100644
--- a/src/interfaces/libpgtcl/pgtclId.h
+++ b/src/interfaces/libpgtcl/pgtclId.h
@@ -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;
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
index 5ecb4f517a..534e8eda58 100644
--- a/src/interfaces/libpq/fe-auth.c
+++ b/src/interfaces/libpq/fe-auth.c
@@ -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;
}
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index fb78b1ee37..92e2a46434 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -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;
}
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 7c1540ae15..475a51bc4a 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -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 "";
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index 726279291a..fd33052f7c 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -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;
diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c
index 25e58bc950..d5793af085 100644
--- a/src/interfaces/libpq/fe-print.c
+++ b/src/interfaces/libpq/fe-print.c
@@ -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 &&
diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h
index 6655592d67..acbf539cd7 100644
--- a/src/interfaces/libpq/libpq-fe.h
+++ b/src/interfaces/libpq/libpq-fe.h
@@ -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);
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index aaeffa3459..351d9fac2b 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -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;
-
- struct pg_result
- {
- int ntups;
- int numAttributes;
- PGresAttDesc *attDescs;
- PGresAttValue **tuples; /* each PGresTuple is an array of
+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
* 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 */
-
- /* 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 */
- };
+ 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];
+
+ /*
+ * 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;
-
- /* Optional file to write trace info to */
- FILE *Pfdebug;
-
- /* 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 */
-
- /* 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 */
-
- /* 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 */
-
- /* 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];
- };
+ 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;
+
+ /* 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 */
+
+ /* 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 */
+
+ /* 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 */
+
+ /* 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];
+};
/* ----------------
* 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 === */
diff --git a/src/interfaces/libpq/libpqdll.c b/src/interfaces/libpq/libpqdll.c
index 5407c54e40..f0241acf78 100644
--- a/src/interfaces/libpq/libpqdll.c
+++ b/src/interfaces/libpq/libpqdll.c
@@ -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;
diff --git a/src/interfaces/python/pgmodule.c b/src/interfaces/python/pgmodule.c
index 17be50889a..254fb1e798 100644
--- a/src/interfaces/python/pgmodule.c
+++ b/src/interfaces/python/pgmodule.c
@@ -3,27 +3,27 @@
* D'Arcy J.M. Cain, (darcy@druid.net). Based heavily on code written by
* Pascal Andre, andre@chimay.via.ecp.fr. Copyright (c) 1995, Pascal Andre
* (andre@via.ecp.fr).
- *
+ *
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without a written
* agreement is hereby granted, provided that the above copyright notice and
* this paragraph and the following two paragraphs appear in all copies or in
* any new file that contains a substantial portion of this file.
- *
+ *
* IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
* SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE
* AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
* AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS.
- *
+ *
* Further modifications copyright 1997, 1998, 1999 by D'Arcy J.M. Cain
* (darcy@druid.net) subject to the same terms and conditions as above.
- *
+ *
*/
#include <Python.h>
@@ -36,22 +36,22 @@
/* really bad stuff here - I'm so naughty */
/* If you need to you can run mkdefines to get */
/* current defines but it should not have changed */
-#define INT2OID 21
-#define INT4OID 23
-#define OIDOID 26
-#define FLOAT4OID 700
-#define FLOAT8OID 701
-#define CASHOID 790
+#define INT2OID 21
+#define INT4OID 23
+#define OIDOID 26
+#define FLOAT4OID 700
+#define FLOAT8OID 701
+#define CASHOID 790
-static PyObject *PGError;
-static const char *PyPgVersion = "3.0 beta";
+static PyObject *PGError;
+static const char *PyPgVersion = "3.0 beta";
/* taken from fileobject.c */
#define BUF(v) PyString_AS_STRING((PyStringObject *)(v))
/* default values */
-#define MODULE_NAME "pgsql"
-#define ARRAYSIZE 1
+#define MODULE_NAME "pgsql"
+#define ARRAYSIZE 1
/* flags for object validity checks */
#define CHECK_OPEN 1
@@ -63,16 +63,16 @@ static const char *PyPgVersion = "3.0 beta";
#define MAX_BUFFER_SIZE 8192 /* maximum transaction size */
#ifndef NO_DIRECT
-#define DIRECT_ACCESS 1 /* enables direct access functions */
-#endif /* NO_DIRECT */
+#define DIRECT_ACCESS 1 /* enables direct access functions */
+#endif /* NO_DIRECT */
#ifndef NO_LARGE
-#define LARGE_OBJECTS 1 /* enables large objects support */
-#endif /* NO_LARGE */
+#define LARGE_OBJECTS 1 /* enables large objects support */
+#endif /* NO_LARGE */
#ifndef NO_DEF_VAR
-#define DEFAULT_VARS 1 /* enables default variables use */
-#endif /* NO_DEF_VAR */
+#define DEFAULT_VARS 1 /* enables default variables use */
+#endif /* NO_DEF_VAR */
/* --------------------------------------------------------------------- */
@@ -80,15 +80,15 @@ static const char *PyPgVersion = "3.0 beta";
#ifdef DEFAULT_VARS
-static PyObject *pg_default_host; /* default database host */
-static PyObject *pg_default_base; /* default database name */
-static PyObject *pg_default_opt; /* default connection options */
-static PyObject *pg_default_tty; /* default debug tty */
-static PyObject *pg_default_port; /* default connection port */
-static PyObject *pg_default_user; /* default username */
-static PyObject *pg_default_passwd; /* default password */
+static PyObject *pg_default_host; /* default database host */
+static PyObject *pg_default_base; /* default database name */
+static PyObject *pg_default_opt;/* default connection options */
+static PyObject *pg_default_tty;/* default debug tty */
+static PyObject *pg_default_port; /* default connection port */
+static PyObject *pg_default_user; /* default username */
+static PyObject *pg_default_passwd; /* default password */
-#endif /* DEFAULT_VARS */
+#endif /* DEFAULT_VARS */
/* --------------------------------------------------------------------- */
/* OBJECTS DECLARATION */
@@ -98,9 +98,9 @@ static PyObject *pg_default_passwd; /* default password */
typedef struct
{
PyObject_HEAD
- int valid; /* validity flag */
- PGconn *cnx; /* PostGres connection handle */
-} pgobject;
+ int valid; /* validity flag */
+ PGconn *cnx; /* PostGres connection handle */
+} pgobject;
staticforward PyTypeObject PgType;
@@ -111,8 +111,8 @@ staticforward PyTypeObject PgType;
typedef struct
{
PyObject_HEAD
- PGresult *last_result; /* last result content */
-} pgqueryobject;
+ PGresult *last_result; /* last result content */
+} pgqueryobject;
staticforward PyTypeObject PgQueryType;
@@ -124,15 +124,15 @@ staticforward PyTypeObject PgQueryType;
typedef struct
{
PyObject_HEAD
- pgobject *pgcnx; /* parent connection object */
- Oid lo_oid; /* large object oid */
- int lo_fd; /* large object fd */
-} pglargeobject;
+ pgobject * pgcnx; /* parent connection object */
+ Oid lo_oid; /* large object oid */
+ int lo_fd; /* large object fd */
+} pglargeobject;
staticforward PyTypeObject PglargeType;
#define is_pglargeobject(v) ((v)->ob_type == &PglargeType)
-#endif /* LARGE_OBJECTS */
+#endif /* LARGE_OBJECTS */
/* --------------------------------------------------------------------- */
/* INTERNAL FUNCTIONS */
@@ -141,7 +141,8 @@ staticforward PyTypeObject PglargeType;
static int
check_cnx_obj(pgobject * self)
{
- if (!self->valid) {
+ if (!self->valid)
+ {
PyErr_SetString(PGError, "connection has been closed");
return 0;
}
@@ -183,7 +184,7 @@ check_lo_obj(pglargeobject * self, int level)
return 1;
}
-#endif /* LARGE_OBJECTS */
+#endif /* LARGE_OBJECTS */
/* --------------------------------------------------------------------- */
/* PG CONNECTION OBJECT IMPLEMENTATION */
@@ -194,17 +195,17 @@ check_lo_obj(pglargeobject * self, int level)
static pglargeobject *
pglarge_new(pgobject * pgcnx, Oid oid)
{
- pglargeobject * npglo;
+ pglargeobject *npglo;
if ((npglo = PyObject_NEW(pglargeobject, &PglargeType)) == NULL)
- return NULL;
-
+ return NULL;
+
Py_XINCREF(pgcnx);
npglo->pgcnx = pgcnx;
npglo->lo_fd = -1;
npglo->lo_oid = oid;
- return npglo;
+ return npglo;
}
/* destructor */
@@ -220,13 +221,14 @@ pglarge_dealloc(pglargeobject * self)
/* opens large object */
static char pglarge_open__doc__[] =
- "open(mode) -- open access to large object with specified mode "
- "(INV_READ, INV_WRITE constants defined by module).";
+"open(mode) -- open access to large object with specified mode "
+"(INV_READ, INV_WRITE constants defined by module).";
static PyObject *
pglarge_open(pglargeobject * self, PyObject * args)
{
- int mode, fd;
+ int mode,
+ fd;
/* check validity */
if (!check_lo_obj(self, CHECK_CLOSE))
@@ -254,8 +256,8 @@ pglarge_open(pglargeobject * self, PyObject * args)
/* close large object */
static char pglarge_close__doc__[] =
- "close() -- close access to large object data.";
-
+"close() -- close access to large object data.";
+
static PyObject *
pglarge_close(pglargeobject * self, PyObject * args)
{
@@ -263,7 +265,7 @@ pglarge_close(pglargeobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method close() takes no parameters.");
+ "method close() takes no parameters.");
return NULL;
}
@@ -286,14 +288,14 @@ pglarge_close(pglargeobject * self, PyObject * args)
/* reads from large object */
static char pglarge_read__doc__[] =
- "read(integer) -- read from large object to sized string. "
- "Object must be opened in read mode before calling this method.";
+"read(integer) -- read from large object to sized string. "
+"Object must be opened in read mode before calling this method.";
static PyObject *
pglarge_read(pglargeobject * self, PyObject * args)
{
- int size;
- PyObject *buffer;
+ int size;
+ PyObject *buffer;
/* checks validity */
if (!check_lo_obj(self, CHECK_OPEN))
@@ -329,14 +331,14 @@ pglarge_read(pglargeobject * self, PyObject * args)
/* write to large object */
static char pglarge_write__doc__[] =
- "write(string) -- write sized string to large object. "
- "Object must be opened in read mode before calling this method.";
-
+"write(string) -- write sized string to large object. "
+"Object must be opened in read mode before calling this method.";
+
static PyObject *
pglarge_write(pglargeobject * self, PyObject * args)
{
- char *buffer;
- int size;
+ char *buffer;
+ int size;
/* checks validity */
if (!check_lo_obj(self, CHECK_OPEN))
@@ -346,13 +348,13 @@ pglarge_write(pglargeobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, "s", &buffer))
{
PyErr_SetString(PyExc_TypeError,
- "write(buffer), with buffer (sized string).");
+ "write(buffer), with buffer (sized string).");
return NULL;
}
/* sends query */
if ((size = lo_write(self->pgcnx->cnx, self->lo_fd, buffer,
- strlen(buffer))) < strlen(buffer))
+ strlen(buffer))) < strlen(buffer))
{
PyErr_SetString(PyExc_IOError, "buffer truncated during write.");
return NULL;
@@ -365,15 +367,17 @@ pglarge_write(pglargeobject * self, PyObject * args)
/* go to position in large object */
static char pglarge_seek__doc__[] =
- "seek(off, whence) -- move to specified position. Object must be opened "
- "before calling this method. whence can be SEEK_SET, SEEK_CUR or SEEK_END, "
- "constants defined by module.";
+"seek(off, whence) -- move to specified position. Object must be opened "
+"before calling this method. whence can be SEEK_SET, SEEK_CUR or SEEK_END, "
+"constants defined by module.";
static PyObject *
pglarge_lseek(pglargeobject * self, PyObject * args)
{
/* offset and whence are initialized to keep compiler happy */
- int ret, offset = 0, whence = 0;
+ int ret,
+ offset = 0,
+ whence = 0;
/* checks validity */
if (!check_lo_obj(self, CHECK_OPEN))
@@ -383,7 +387,7 @@ pglarge_lseek(pglargeobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, "ii", &offset, &whence))
{
PyErr_SetString(PyExc_TypeError,
- "lseek(offset, whence), with offset and whence (integers).");
+ "lseek(offset, whence), with offset and whence (integers).");
return NULL;
}
@@ -400,19 +404,20 @@ pglarge_lseek(pglargeobject * self, PyObject * args)
/* gets large object size */
static char pglarge_size__doc__[] =
- "size() -- return large object size. "
- "Object must be opened before calling this method.";
+"size() -- return large object size. "
+"Object must be opened before calling this method.";
static PyObject *
pglarge_size(pglargeobject * self, PyObject * args)
{
- int start, end;
+ int start,
+ end;
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method size() takes no parameters.");
+ "method size() takes no parameters.");
return NULL;
}
@@ -435,10 +440,10 @@ pglarge_size(pglargeobject * self, PyObject * args)
}
/* move back to start position */
- if ((start = lo_lseek(self->pgcnx->cnx,self->lo_fd,start,SEEK_SET)) == -1)
+ if ((start = lo_lseek(self->pgcnx->cnx, self->lo_fd, start, SEEK_SET)) == -1)
{
PyErr_SetString(PyExc_IOError,
- "error while moving back to first position.");
+ "error while moving back to first position.");
return NULL;
}
@@ -448,19 +453,19 @@ pglarge_size(pglargeobject * self, PyObject * args)
/* gets large object cursor position */
static char pglarge_tell__doc__[] =
- "tell() -- give current position in large object. "
- "Object must be opened before calling this method.";
+"tell() -- give current position in large object. "
+"Object must be opened before calling this method.";
static PyObject *
pglarge_tell(pglargeobject * self, PyObject * args)
{
- int start;
+ int start;
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method tell() takes no parameters.");
+ "method tell() takes no parameters.");
return NULL;
}
@@ -481,13 +486,13 @@ pglarge_tell(pglargeobject * self, PyObject * args)
/* exports large object as unix file */
static char pglarge_export__doc__[] =
- "export(string) -- export large object data to specified file. "
- "Object must be closed when calling this method.";
+"export(string) -- export large object data to specified file. "
+"Object must be closed when calling this method.";
static PyObject *
pglarge_export(pglargeobject * self, PyObject * args)
{
- char *name;
+ char *name;
/* checks validity */
if (!check_lo_obj(self, CHECK_CLOSE))
@@ -497,7 +502,7 @@ pglarge_export(pglargeobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, "s", &name))
{
PyErr_SetString(PyExc_TypeError,
- "export(filename), with filename (string).");
+ "export(filename), with filename (string).");
return NULL;
}
@@ -514,8 +519,8 @@ pglarge_export(pglargeobject * self, PyObject * args)
/* deletes a large object */
static char pglarge_unlink__doc__[] =
- "unlink() -- destroy large object. "
- "Object must be closed when calling this method.";
+"unlink() -- destroy large object. "
+"Object must be closed when calling this method.";
static PyObject *
pglarge_unlink(pglargeobject * self, PyObject * args)
@@ -524,7 +529,7 @@ pglarge_unlink(pglargeobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method unlink() takes no parameters.");
+ "method unlink() takes no parameters.");
return NULL;
}
@@ -546,15 +551,15 @@ pglarge_unlink(pglargeobject * self, PyObject * args)
/* large object methods */
static struct PyMethodDef pglarge_methods[] = {
- {"open", (PyCFunction) pglarge_open, 1, pglarge_open__doc__ },
- {"close", (PyCFunction) pglarge_close, 1, pglarge_close__doc__ },
- {"read", (PyCFunction) pglarge_read, 1, pglarge_read__doc__ },
- {"write", (PyCFunction) pglarge_write, 1, pglarge_write__doc__ },
- {"seek", (PyCFunction) pglarge_lseek, 1, pglarge_seek__doc__ },
- {"size", (PyCFunction) pglarge_size, 1, pglarge_size__doc__ },
- {"tell", (PyCFunction) pglarge_tell, 1, pglarge_tell__doc__ },
- {"export", (PyCFunction) pglarge_export, 1, pglarge_export__doc__ },
- {"unlink", (PyCFunction) pglarge_unlink, 1, pglarge_unlink__doc__ },
+ {"open", (PyCFunction) pglarge_open, 1, pglarge_open__doc__},
+ {"close", (PyCFunction) pglarge_close, 1, pglarge_close__doc__},
+ {"read", (PyCFunction) pglarge_read, 1, pglarge_read__doc__},
+ {"write", (PyCFunction) pglarge_write, 1, pglarge_write__doc__},
+ {"seek", (PyCFunction) pglarge_lseek, 1, pglarge_seek__doc__},
+ {"size", (PyCFunction) pglarge_size, 1, pglarge_size__doc__},
+ {"tell", (PyCFunction) pglarge_tell, 1, pglarge_tell__doc__},
+ {"export", (PyCFunction) pglarge_export, 1, pglarge_export__doc__},
+ {"unlink", (PyCFunction) pglarge_unlink, 1, pglarge_unlink__doc__},
{NULL, NULL}
};
@@ -594,7 +599,7 @@ pglarge_getattr(pglargeobject * self, char *name)
/* attributes list */
if (!strcmp(name, "__members__"))
{
- PyObject *list = PyList_New(3);
+ PyObject *list = PyList_New(3);
if (list)
{
@@ -608,11 +613,11 @@ pglarge_getattr(pglargeobject * self, char *name)
/* module name */
if (!strcmp(name, "__module__"))
- return PyString_FromString(MODULE_NAME);
+ return PyString_FromString(MODULE_NAME);
/* class name */
if (!strcmp(name, "__class__"))
- return PyString_FromString("pglarge");
+ return PyString_FromString("pglarge");
/* seeks name in methods (fallback) */
return Py_FindMethod(pglarge_methods, (PyObject *) self, name);
@@ -622,18 +627,18 @@ pglarge_getattr(pglargeobject * self, char *name)
static int
pglarge_print(pglargeobject * self, FILE *fp, int flags)
{
- char print_buffer[128];
+ char print_buffer[128];
- if (self->lo_fd >= 0)
+ if (self->lo_fd >= 0)
{
- snprintf(print_buffer, sizeof(print_buffer),
- "Opened large object, oid %ld", (long)self->lo_oid);
+ snprintf(print_buffer, sizeof(print_buffer),
+ "Opened large object, oid %ld", (long) self->lo_oid);
fputs(print_buffer, fp);
- }
- else
+ }
+ else
{
- snprintf(print_buffer, sizeof(print_buffer),
- "Closed large object, oid %ld", (long)self->lo_oid);
+ snprintf(print_buffer, sizeof(print_buffer),
+ "Closed large object, oid %ld", (long) self->lo_oid);
fputs(print_buffer, fp);
}
@@ -643,25 +648,25 @@ pglarge_print(pglargeobject * self, FILE *fp, int flags)
/* object type definition */
staticforward PyTypeObject PglargeType = {
PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "pglarge", /* tp_name */
- sizeof(pglargeobject), /* tp_basicsize */
- 0, /* tp_itemsize */
+ 0, /* ob_size */
+ "pglarge", /* tp_name */
+ sizeof(pglargeobject), /* tp_basicsize */
+ 0, /* tp_itemsize */
/* methods */
- (destructor) pglarge_dealloc, /* tp_dealloc */
- (printfunc) pglarge_print, /* tp_print */
- (getattrfunc) pglarge_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
+ (destructor) pglarge_dealloc, /* tp_dealloc */
+ (printfunc) pglarge_print, /* tp_print */
+ (getattrfunc) pglarge_getattr, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
};
-#endif /* LARGE_OBJECTS */
+#endif /* LARGE_OBJECTS */
/* --------------------------------------------------------------------- */
@@ -669,29 +674,35 @@ staticforward PyTypeObject PglargeType = {
/* connects to a database */
static char connect__doc__[] =
- "connect(dbname, host, port, opt, tty) -- connect to a PostgreSQL database "
- "using specified parameters (optionals, keywords aware).";
+"connect(dbname, host, port, opt, tty) -- connect to a PostgreSQL database "
+"using specified parameters (optionals, keywords aware).";
static PyObject *
-pgconnect(pgobject *self, PyObject *args, PyObject *dict)
+pgconnect(pgobject * self, PyObject * args, PyObject * dict)
{
- static const char *kwlist[] = { "dbname", "host", "port", "opt",
- "tty", "user", "passwd" , NULL };
- char *pghost, *pgopt, *pgtty, *pgdbname, *pguser, *pgpasswd;
- int pgport;
- char port_buffer[20];
- pgobject *npgobj;
+ static const char *kwlist[] = {"dbname", "host", "port", "opt",
+ "tty", "user", "passwd", NULL};
+ char *pghost,
+ *pgopt,
+ *pgtty,
+ *pgdbname,
+ *pguser,
+ *pgpasswd;
+ int pgport;
+ char port_buffer[20];
+ pgobject *npgobj;
pghost = pgopt = pgtty = pgdbname = pguser = pgpasswd = NULL;
pgport = -1;
- /* parses standard arguments
- * With the right compiler warnings, this will issue a diagnostic.
- * There is really no way around it. If I don't declare kwlist as
- * const char *kwlist[] then it complains when I try to assign all
- * those constant strings to it. */
+ /*
+ * parses standard arguments With the right compiler warnings, this
+ * will issue a diagnostic. There is really no way around it. If I
+ * don't declare kwlist as const char *kwlist[] then it complains when
+ * I try to assign all those constant strings to it.
+ */
if (!PyArg_ParseTupleAndKeywords(args, dict, "|zzlzzzz", kwlist,
- &pgdbname, &pghost, &pgport, &pgopt, &pgtty, &pguser, &pgpasswd))
+ &pgdbname, &pghost, &pgport, &pgopt, &pgtty, &pguser, &pgpasswd))
return NULL;
#ifdef DEFAULT_VARS
@@ -716,7 +727,7 @@ pgconnect(pgobject *self, PyObject *args, PyObject *dict)
if ((!pgpasswd) && (pg_default_passwd != Py_None))
pgpasswd = PyString_AsString(pg_default_passwd);
-#endif /* DEFAULT_VARS */
+#endif /* DEFAULT_VARS */
if ((npgobj = PyObject_NEW(pgobject, &PgType)) == NULL)
return NULL;
@@ -726,11 +737,11 @@ pgconnect(pgobject *self, PyObject *args, PyObject *dict)
bzero(port_buffer, sizeof(port_buffer));
sprintf(port_buffer, "%d", pgport);
npgobj->cnx = PQsetdbLogin(pghost, port_buffer, pgopt, pgtty, pgdbname,
- pguser, pgpasswd);
+ pguser, pgpasswd);
}
else
npgobj->cnx = PQsetdbLogin(pghost, NULL, pgopt, pgtty, pgdbname,
- pguser, pgpasswd);
+ pguser, pgpasswd);
if (PQstatus(npgobj->cnx) == CONNECTION_BAD)
{
@@ -755,13 +766,13 @@ pg_dealloc(pgobject * self)
}
/* close without deleting */
-static char pg_close__doc__[] =
- "close() -- close connection. All instances of the connection object and "
- "derived objects (queries and large objects) can no longer be used after "
- "this call.";
+static char pg_close__doc__[] =
+"close() -- close connection. All instances of the connection object and "
+"derived objects (queries and large objects) can no longer be used after "
+"this call.";
static PyObject *
-pg_close(pgobject *self, PyObject *args)
+pg_close(pgobject * self, PyObject * args)
{
/* gets args */
if (!PyArg_ParseTuple(args, ""))
@@ -776,7 +787,7 @@ pg_close(pgobject *self, PyObject *args)
self->cnx = NULL;
Py_INCREF(Py_None);
return Py_None;
-}
+}
static void
pgquery_dealloc(pgqueryobject * self)
@@ -788,10 +799,10 @@ pgquery_dealloc(pgqueryobject * self)
}
/* resets connection */
-static char pg_reset__doc__[] =
- "reset() -- reset connection with current parameters. All derived queries "
- "and large objects derived from this connection will not be usable after "
- "this call.";
+static char pg_reset__doc__[] =
+"reset() -- reset connection with current parameters. All derived queries "
+"and large objects derived from this connection will not be usable after "
+"this call.";
static PyObject *
pg_reset(pgobject * self, PyObject * args)
@@ -806,7 +817,7 @@ pg_reset(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method reset() takes no parameters.");
+ "method reset() takes no parameters.");
return NULL;
}
@@ -817,8 +828,8 @@ pg_reset(pgobject * self, PyObject * args)
}
/* get connection socket */
-static char pg_fileno__doc__[] =
- "fileno() -- return database connection socket file handle.";
+static char pg_fileno__doc__[] =
+"fileno() -- return database connection socket file handle.";
static PyObject *
pg_fileno(pgobject * self, PyObject * args)
@@ -833,7 +844,7 @@ pg_fileno(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method fileno() takes no parameters.");
+ "method fileno() takes no parameters.");
return NULL;
}
@@ -846,7 +857,7 @@ pg_fileno(pgobject * self, PyObject * args)
/* get number of rows */
static char pgquery_ntuples__doc__[] =
- "ntuples() -- returns number of tuples returned by query.";
+"ntuples() -- returns number of tuples returned by query.";
static PyObject *
pgquery_ntuples(pgqueryobject * self, PyObject * args)
@@ -855,29 +866,31 @@ pgquery_ntuples(pgqueryobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method ntuples() takes no parameters.");
+ "method ntuples() takes no parameters.");
return NULL;
}
return PyInt_FromLong((long) PQntuples(self->last_result));
-}
+}
/* list fields names from query result */
static char pgquery_listfields__doc__[] =
- "listfields() -- Lists field names from result.";
+"listfields() -- Lists field names from result.";
static PyObject *
pgquery_listfields(pgqueryobject * self, PyObject * args)
{
- int i, n;
- char *name;
- PyObject *fieldstuple, *str;
+ int i,
+ n;
+ char *name;
+ PyObject *fieldstuple,
+ *str;
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method listfields() takes no parameters.");
+ "method listfields() takes no parameters.");
return NULL;
}
@@ -897,19 +910,19 @@ pgquery_listfields(pgqueryobject * self, PyObject * args)
/* get field name from last result */
static char pgquery_fieldname__doc__[] =
- "fieldname() -- returns name of field from result from its position.";
+"fieldname() -- returns name of field from result from its position.";
static PyObject *
pgquery_fieldname(pgqueryobject * self, PyObject * args)
{
- int i;
- char *name;
+ int i;
+ char *name;
/* gets args */
if (!PyArg_ParseTuple(args, "i", &i))
{
PyErr_SetString(PyExc_TypeError,
- "fieldname(number), with number(integer).");
+ "fieldname(number), with number(integer).");
return NULL;
}
@@ -927,13 +940,13 @@ pgquery_fieldname(pgqueryobject * self, PyObject * args)
/* gets fields number from name in last result */
static char pgquery_fieldnum__doc__[] =
- "fieldnum() -- returns position in query for field from its name.";
+"fieldnum() -- returns position in query for field from its name.";
static PyObject *
pgquery_fieldnum(pgqueryobject * self, PyObject * args)
{
- char *name;
- int num;
+ char *name;
+ int num;
/* gets args */
if (!PyArg_ParseTuple(args, "s", &name))
@@ -954,21 +967,27 @@ pgquery_fieldnum(pgqueryobject * self, PyObject * args)
/* retrieves last result */
static char pgquery_getresult__doc__[] =
- "getresult() -- Gets the result of a query. The result is returned "
- "as a list of rows, each one a list of fields in the order returned "
- "by the server.";
+"getresult() -- Gets the result of a query. The result is returned "
+"as a list of rows, each one a list of fields in the order returned "
+"by the server.";
static PyObject *
pgquery_getresult(pgqueryobject * self, PyObject * args)
{
- PyObject *rowtuple, *reslist, *val;
- int i, j, m, n, *typ;
+ PyObject *rowtuple,
+ *reslist,
+ *val;
+ int i,
+ j,
+ m,
+ n,
+ *typ;
/* checks args (args == NULL for an internal call) */
if ((args != NULL) && (!PyArg_ParseTuple(args, "")))
{
PyErr_SetString(PyExc_SyntaxError,
- "method getresult() takes no parameters.");
+ "method getresult() takes no parameters.");
return NULL;
}
@@ -1013,9 +1032,9 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
rowtuple = PyTuple_New(n);
for (j = 0; j < n; j++)
{
- int k;
- char *s = PQgetvalue(self->last_result, i, j);
- char cashbuf[64];
+ int k;
+ char *s = PQgetvalue(self->last_result, i, j);
+ char cashbuf[64];
switch (typ[j])
{
@@ -1027,8 +1046,9 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
val = PyFloat_FromDouble(strtod(s, NULL));
break;
- case 3: /* get rid of the '$' and commas */
- if (*s == '$') /* there's talk of getting rid of it */
+ case 3: /* get rid of the '$' and commas */
+ if (*s == '$') /* there's talk of getting rid of
+ * it */
s++;
if ((s[0] == '-' || s[0] == '(') && s[1] == '$')
@@ -1062,21 +1082,27 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
/* retrieves last result as a list of dictionaries*/
static char pgquery_dictresult__doc__[] =
- "dictresult() -- Gets the result of a query. The result is returned "
- "as a list of rows, each one a dictionary with the field names used "
- "as the labels.";
+"dictresult() -- Gets the result of a query. The result is returned "
+"as a list of rows, each one a dictionary with the field names used "
+"as the labels.";
static PyObject *
pgquery_dictresult(pgqueryobject * self, PyObject * args)
{
- PyObject *dict, *reslist, *val;
- int i, j, m, n, *typ;
+ PyObject *dict,
+ *reslist,
+ *val;
+ int i,
+ j,
+ m,
+ n,
+ *typ;
/* checks args (args == NULL for an internal call) */
if ((args != NULL) && (!PyArg_ParseTuple(args, "")))
{
PyErr_SetString(PyExc_SyntaxError,
- "method getresult() takes no parameters.");
+ "method getresult() takes no parameters.");
return NULL;
}
@@ -1121,9 +1147,9 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
dict = PyDict_New();
for (j = 0; j < n; j++)
{
- int k;
- char *s = PQgetvalue(self->last_result, i, j);
- char cashbuf[64];
+ int k;
+ char *s = PQgetvalue(self->last_result, i, j);
+ char cashbuf[64];
switch (typ[j])
{
@@ -1135,8 +1161,9 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
val = PyFloat_FromDouble(strtod(s, NULL));
break;
- case 3: /* get rid of the '$' and commas */
- if (*s == '$') /* there's talk of getting rid of it */
+ case 3: /* get rid of the '$' and commas */
+ if (*s == '$') /* there's talk of getting rid of
+ * it */
s++;
if ((s[0] == '-' || s[0] == '(') && s[1] == '$')
@@ -1170,15 +1197,16 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
}
/* gets asynchronous notify */
-static char pg_getnotify__doc__[] =
- "getnotify() -- get database notify for this connection.";
+static char pg_getnotify__doc__[] =
+"getnotify() -- get database notify for this connection.";
static PyObject *
pg_getnotify(pgobject * self, PyObject * args)
{
- PGnotify *notify;
- PGresult *result;
- PyObject *notify_result, *temp;
+ PGnotify *notify;
+ PGresult *result;
+ PyObject *notify_result,
+ *temp;
if (!self->cnx)
{
@@ -1190,12 +1218,16 @@ pg_getnotify(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method getnotify() takes no parameters.");
+ "method getnotify() takes no parameters.");
return NULL;
}
/* gets notify and builds result */
- /* notifies only come back as result of a query, so I send an empty query */
+
+ /*
+ * notifies only come back as result of a query, so I send an empty
+ * query
+ */
result = PQexec(self->cnx, " ");
if ((notify = PQnotifies(self->cnx)) != NULL)
@@ -1221,15 +1253,15 @@ pg_getnotify(pgobject * self, PyObject * args)
/* database query */
static char pg_query__doc__[] =
- "query() -- creates a new query object for this connection.";
+"query() -- creates a new query object for this connection.";
static PyObject *
pg_query(pgobject * self, PyObject * args)
{
- char *query;
- PGresult *result;
- pgqueryobject *npgobj;
- int status;
+ char *query;
+ PGresult *result;
+ pgqueryobject *npgobj;
+ int status;
if (!self->cnx)
{
@@ -1271,7 +1303,7 @@ pg_query(pgobject * self, PyObject * args)
case PGRES_NONFATAL_ERROR:
PyErr_SetString(PGError, PQerrorMessage(self->cnx));
break;
- case PGRES_COMMAND_OK: /* could be an INSERT */
+ case PGRES_COMMAND_OK: /* could be an INSERT */
if (*(str = PQoidStatus(result)) == 0) /* nope */
{
Py_INCREF(Py_None);
@@ -1281,13 +1313,13 @@ pg_query(pgobject * self, PyObject * args)
/* otherwise, return the oid */
return PyInt_FromLong(strtol(str, NULL, 10));
- case PGRES_COPY_OUT: /* no data will be received */
+ case PGRES_COPY_OUT: /* no data will be received */
case PGRES_COPY_IN:
Py_INCREF(Py_None);
return Py_None;
default:
PyErr_SetString(PGError, "internal error: "
- "unknown result status.");
+ "unknown result status.");
break;
}
@@ -1304,13 +1336,13 @@ pg_query(pgobject * self, PyObject * args)
#ifdef DIRECT_ACCESS
static char pg_putline__doc__[] =
- "putline() -- sends a line directly to the backend";
+"putline() -- sends a line directly to the backend";
/* direct acces function : putline */
static PyObject *
pg_putline(pgobject * self, PyObject * args)
{
- char *line;
+ char *line;
if (!self->cnx)
{
@@ -1333,14 +1365,14 @@ pg_putline(pgobject * self, PyObject * args)
/* direct access function : getline */
static char pg_getline__doc__[] =
- "getline() -- gets a line directly from the backend.";
+"getline() -- gets a line directly from the backend.";
static PyObject *
pg_getline(pgobject * self, PyObject * args)
{
- char line[MAX_BUFFER_SIZE];
- PyObject *str = NULL; /* GCC */
- int ret;
+ char line[MAX_BUFFER_SIZE];
+ PyObject *str = NULL; /* GCC */
+ int ret;
if (!self->cnx)
{
@@ -1352,7 +1384,7 @@ pg_getline(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method getline() takes no parameters.");
+ "method getline() takes no parameters.");
return NULL;
}
@@ -1377,7 +1409,7 @@ pg_getline(pgobject * self, PyObject * args)
/* direct access function : end copy */
static char pg_endcopy__doc__[] =
- "endcopy() -- synchronizes client and server";
+"endcopy() -- synchronizes client and server";
static PyObject *
pg_endcopy(pgobject * self, PyObject * args)
@@ -1392,7 +1424,7 @@ pg_endcopy(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method endcopy() takes no parameters.");
+ "method endcopy() takes no parameters.");
return NULL;
}
@@ -1401,16 +1433,17 @@ pg_endcopy(pgobject * self, PyObject * args)
Py_INCREF(Py_None);
return Py_None;
}
-#endif /* DIRECT_ACCESS */
+
+#endif /* DIRECT_ACCESS */
static PyObject *
-pgquery_print(pgqueryobject *self, FILE *fp, int flags)
+pgquery_print(pgqueryobject * self, FILE *fp, int flags)
{
- PQprintOpt op;
+ PQprintOpt op;
memset(&op, 0, sizeof(op));
- op.align = 1;
+ op.align = 1;
op.header = 1;
op.fieldSep = "|";
op.pager = 1;
@@ -1419,20 +1452,25 @@ pgquery_print(pgqueryobject *self, FILE *fp, int flags)
}
/* insert table */
-static char pg_inserttable__doc__[] =
- "inserttable(string, list) -- insert list in table. The fields in the list "
- "must be in the same order as in the table.";
+static char pg_inserttable__doc__[] =
+"inserttable(string, list) -- insert list in table. The fields in the list "
+"must be in the same order as in the table.";
static PyObject *
pg_inserttable(pgobject * self, PyObject * args)
{
- PGresult *result;
- char *table, *buffer, *temp;
- char temp_buffer[256];
- PyObject *list, *sublist, *item;
- PyObject *(*getitem) (PyObject *, int);
- PyObject *(*getsubitem) (PyObject *, int);
- int i, j;
+ PGresult *result;
+ char *table,
+ *buffer,
+ *temp;
+ char temp_buffer[256];
+ PyObject *list,
+ *sublist,
+ *item;
+ PyObject *(*getitem) (PyObject *, int);
+ PyObject *(*getsubitem) (PyObject *, int);
+ int i,
+ j;
if (!self->cnx)
{
@@ -1444,8 +1482,8 @@ pg_inserttable(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, "sO:filter", &table, &list))
{
PyErr_SetString(PyExc_TypeError,
- "tableinsert(table, content), with table (string) "
- "and content (list).");
+ "tableinsert(table, content), with table (string) "
+ "and content (list).");
return NULL;
}
@@ -1457,7 +1495,7 @@ pg_inserttable(pgobject * self, PyObject * args)
else
{
PyErr_SetString(PyExc_TypeError,
- "second arg must be some kind of array.");
+ "second arg must be some kind of array.");
return NULL;
}
@@ -1467,7 +1505,7 @@ pg_inserttable(pgobject * self, PyObject * args)
if (!PyTuple_Check(sublist) && !PyList_Check(sublist))
{
PyErr_SetString(PyExc_TypeError,
- "second arg must contain some kind of arrays.");
+ "second arg must contain some kind of arrays.");
return NULL;
}
}
@@ -1509,7 +1547,7 @@ pg_inserttable(pgobject * self, PyObject * args)
PyArg_ParseTuple(item, "s", &temp);
else if (PyInt_Check(item))
{
- int k;
+ int k;
PyArg_ParseTuple(item, "i", &k);
sprintf(temp_buffer, "%d", k);
@@ -1517,7 +1555,7 @@ pg_inserttable(pgobject * self, PyObject * args)
}
else if (PyLong_Check(item))
{
- long k;
+ long k;
PyArg_ParseTuple(item, "l", &k);
sprintf(temp_buffer, "%ld", k);
@@ -1525,7 +1563,7 @@ pg_inserttable(pgobject * self, PyObject * args)
}
else if (PyFloat_Check(item))
{
- double k;
+ double k;
PyArg_ParseTuple(item, "d", &k);
sprintf(temp_buffer, "%g", k);
@@ -1535,8 +1573,8 @@ pg_inserttable(pgobject * self, PyObject * args)
{
free(buffer);
PyErr_SetString(PyExc_ValueError,
- "items must be strings, integers, "
- "longs or double (real).");
+ "items must be strings, integers, "
+ "longs or double (real).");
return NULL;
}
@@ -1565,49 +1603,50 @@ pg_inserttable(pgobject * self, PyObject * args)
}
/* creates large object */
-static char pg_locreate__doc__[] =
- "locreate() -- creates a new large object in the database.";
+static char pg_locreate__doc__[] =
+"locreate() -- creates a new large object in the database.";
-static PyObject *
+static PyObject *
pg_locreate(pgobject * self, PyObject * args)
{
- int mode;
- Oid lo_oid;
+ int mode;
+ Oid lo_oid;
/* checks validity */
if (!check_cnx_obj(self))
- return NULL;
+ return NULL;
/* gets arguments */
if (!PyArg_ParseTuple(args, "i", &mode))
{
PyErr_SetString(PyExc_TypeError,
- "locreate(mode), with mode (integer).");
+ "locreate(mode), with mode (integer).");
return NULL;
}
/* creates large object */
lo_oid = lo_creat(self->cnx, mode);
- if (lo_oid == 0) {
+ if (lo_oid == 0)
+ {
PyErr_SetString(PGError, "can't create large object.");
return NULL;
- }
+ }
return (PyObject *) pglarge_new(self, lo_oid);
}
/* init from already known oid */
-static char pg_getlo__doc__[] =
- "getlo(long) -- create a large object instance for the specified oid.";
+static char pg_getlo__doc__[] =
+"getlo(long) -- create a large object instance for the specified oid.";
static PyObject *
pg_getlo(pgobject * self, PyObject * args)
{
- int lo_oid;
+ int lo_oid;
/* checks validity */
if (!check_cnx_obj(self))
- return NULL;
+ return NULL;
/* gets arguments */
if (!PyArg_ParseTuple(args, "i", &lo_oid))
@@ -1627,18 +1666,18 @@ pg_getlo(pgobject * self, PyObject * args)
}
/* import unix file */
-static char pg_loimport__doc__[] =
- "loimport(string) -- create a new large object from specified file.";
+static char pg_loimport__doc__[] =
+"loimport(string) -- create a new large object from specified file.";
static PyObject *
pg_loimport(pgobject * self, PyObject * args)
{
- char *name;
- Oid lo_oid;
+ char *name;
+ Oid lo_oid;
/* checks validity */
if (!check_cnx_obj(self))
- return NULL;
+ return NULL;
/* gets arguments */
if (!PyArg_ParseTuple(args, "s", &name))
@@ -1661,24 +1700,24 @@ pg_loimport(pgobject * self, PyObject * args)
/* connection object methods */
static struct PyMethodDef pgobj_methods[] = {
- {"query", (PyCFunction) pg_query, 1, pg_query__doc__ },
- {"reset", (PyCFunction) pg_reset, 1, pg_reset__doc__ },
- {"close", (PyCFunction) pg_close, 1, pg_close__doc__ },
- {"fileno", (PyCFunction) pg_fileno,1, pg_fileno__doc__ },
- {"getnotify", (PyCFunction) pg_getnotify, 1, pg_getnotify__doc__ },
- {"inserttable", (PyCFunction) pg_inserttable, 1, pg_inserttable__doc__ },
+ {"query", (PyCFunction) pg_query, 1, pg_query__doc__},
+ {"reset", (PyCFunction) pg_reset, 1, pg_reset__doc__},
+ {"close", (PyCFunction) pg_close, 1, pg_close__doc__},
+ {"fileno", (PyCFunction) pg_fileno, 1, pg_fileno__doc__},
+ {"getnotify", (PyCFunction) pg_getnotify, 1, pg_getnotify__doc__},
+ {"inserttable", (PyCFunction) pg_inserttable, 1, pg_inserttable__doc__},
#ifdef DIRECT_ACCESS
- {"putline", (PyCFunction) pg_putline, 1, pg_putline__doc__ },
- {"getline", (PyCFunction) pg_getline, 1, pg_getline__doc__ },
- {"endcopy", (PyCFunction) pg_endcopy, 1, pg_endcopy__doc__ },
-#endif /* DIRECT_ACCESS */
+ {"putline", (PyCFunction) pg_putline, 1, pg_putline__doc__},
+ {"getline", (PyCFunction) pg_getline, 1, pg_getline__doc__},
+ {"endcopy", (PyCFunction) pg_endcopy, 1, pg_endcopy__doc__},
+#endif /* DIRECT_ACCESS */
#ifdef LARGE_OBJECTS
- {"locreate", (PyCFunction) pg_locreate, 1, pg_locreate__doc__ },
- {"getlo", (PyCFunction) pg_getlo, 1, pg_getlo__doc__ },
- {"loimport", (PyCFunction) pg_loimport, 1, pg_loimport__doc__ },
-#endif /* LARGE_OBJECTS */
+ {"locreate", (PyCFunction) pg_locreate, 1, pg_locreate__doc__},
+ {"getlo", (PyCFunction) pg_getlo, 1, pg_getlo__doc__},
+ {"loimport", (PyCFunction) pg_loimport, 1, pg_loimport__doc__},
+#endif /* LARGE_OBJECTS */
{NULL, NULL} /* sentinel */
};
@@ -1687,9 +1726,12 @@ static struct PyMethodDef pgobj_methods[] = {
static PyObject *
pg_getattr(pgobject * self, char *name)
{
- /* Although we could check individually, there are only a few
- attributes that don't require a live connection and unless
- someone has an urgent need, this will have to do */
+
+ /*
+ * Although we could check individually, there are only a few
+ * attributes that don't require a live connection and unless someone
+ * has an urgent need, this will have to do
+ */
if (!self->cnx)
{
PyErr_SetString(PyExc_TypeError, "Connection is not valid");
@@ -1701,7 +1743,8 @@ pg_getattr(pgobject * self, char *name)
/* postmaster host */
if (!strcmp(name, "host"))
{
- char *r = PQhost(self->cnx);
+ char *r = PQhost(self->cnx);
+
return r ? PyString_FromString(r) : PyString_FromString("localhost");
}
@@ -1732,12 +1775,12 @@ pg_getattr(pgobject * self, char *name)
/* provided user name */
if (!strcmp(name, "user"))
return PyString_FromString("Deprecated facility");
- /* return PyString_FromString(fe_getauthname("<unknown user>")); */
+ /* return PyString_FromString(fe_getauthname("<unknown user>")); */
/* attributes list */
if (!strcmp(name, "__members__"))
{
- PyObject *list = PyList_New(8);
+ PyObject *list = PyList_New(8);
if (list)
{
@@ -1780,16 +1823,16 @@ staticforward PyTypeObject PgType = {
/* query object methods */
static struct PyMethodDef pgquery_methods[] = {
- {"getresult", (PyCFunction) pgquery_getresult, 1, pgquery_getresult__doc__},
- {"dictresult", (PyCFunction) pgquery_dictresult, 1, pgquery_dictresult__doc__},
- {"fieldname", (PyCFunction) pgquery_fieldname, 1, pgquery_fieldname__doc__},
- {"fieldnum", (PyCFunction) pgquery_fieldnum, 1, pgquery_fieldnum__doc__},
- {"listfields", (PyCFunction) pgquery_listfields, 1, pgquery_listfields__doc__},
- {"ntuples", (PyCFunction) pgquery_ntuples, 1, pgquery_ntuples__doc__},
+ {"getresult", (PyCFunction) pgquery_getresult, 1, pgquery_getresult__doc__},
+ {"dictresult", (PyCFunction) pgquery_dictresult, 1, pgquery_dictresult__doc__},
+ {"fieldname", (PyCFunction) pgquery_fieldname, 1, pgquery_fieldname__doc__},
+ {"fieldnum", (PyCFunction) pgquery_fieldnum, 1, pgquery_fieldnum__doc__},
+ {"listfields", (PyCFunction) pgquery_listfields, 1, pgquery_listfields__doc__},
+ {"ntuples", (PyCFunction) pgquery_ntuples, 1, pgquery_ntuples__doc__},
{NULL, NULL}
};
-/* gets query object attributes */
+/* gets query object attributes */
static PyObject *
pgquery_getattr(pgqueryobject * self, char *name)
{
@@ -1800,21 +1843,21 @@ pgquery_getattr(pgqueryobject * self, char *name)
/* query type definition */
staticforward PyTypeObject PgQueryType = {
PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "pgqueryobject", /* tp_name */
- sizeof(pgqueryobject), /* tp_basicsize */
- 0, /* tp_itemsize */
+ 0, /* ob_size */
+ "pgqueryobject", /* tp_name */
+ sizeof(pgqueryobject), /* tp_basicsize */
+ 0, /* tp_itemsize */
/* methods */
- (destructor) pgquery_dealloc, /* tp_dealloc */
- (printfunc) pgquery_print, /* tp_print */
- (getattrfunc) pgquery_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
+ (destructor) pgquery_dealloc, /* tp_dealloc */
+ (printfunc) pgquery_print, /* tp_print */
+ (getattrfunc) pgquery_getattr, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
};
@@ -1827,16 +1870,16 @@ staticforward PyTypeObject PgQueryType = {
/* gets default host */
static char getdefhost__doc__[] =
- "get_defhost() -- return default database host.";
+"get_defhost() -- return default database host.";
-static PyObject *
-pggetdefhost(PyObject *self, PyObject *args)
+static PyObject *
+pggetdefhost(PyObject * self, PyObject * args)
{
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method get_defhost() takes no parameter.");
+ "method get_defhost() takes no parameter.");
return NULL;
}
@@ -1846,19 +1889,19 @@ pggetdefhost(PyObject *self, PyObject *args)
/* sets default host */
static char setdefhost__doc__[] =
- "set_defhost(string) -- set default database host. Return previous value.";
+"set_defhost(string) -- set default database host. Return previous value.";
-static PyObject *
-pgsetdefhost(PyObject * self, PyObject *args)
+static PyObject *
+pgsetdefhost(PyObject * self, PyObject * args)
{
- char *temp = NULL;
- PyObject *old;
+ char *temp = NULL;
+ PyObject *old;
/* gets arguments */
if (!PyArg_ParseTuple(args, "z", &temp))
{
PyErr_SetString(PyExc_TypeError,
- "set_defhost(name), with name (string/None).");
+ "set_defhost(name), with name (string/None).");
return NULL;
}
@@ -1878,16 +1921,16 @@ pgsetdefhost(PyObject * self, PyObject *args)
/* gets default base */
static char getdefbase__doc__[] =
- "get_defbase() -- return default database name.";
+"get_defbase() -- return default database name.";
-static PyObject *
-pggetdefbase(PyObject * self, PyObject *args)
+static PyObject *
+pggetdefbase(PyObject * self, PyObject * args)
{
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method get_defbase() takes no parameter.");
+ "method get_defbase() takes no parameter.");
return NULL;
}
@@ -1897,19 +1940,19 @@ pggetdefbase(PyObject * self, PyObject *args)
/* sets default base */
static char setdefbase__doc__[] =
- "set_defbase(string) -- set default database name. Return previous value";
+"set_defbase(string) -- set default database name. Return previous value";
-static PyObject *
-pgsetdefbase(PyObject * self, PyObject *args)
+static PyObject *
+pgsetdefbase(PyObject * self, PyObject * args)
{
- char *temp = NULL;
- PyObject *old;
+ char *temp = NULL;
+ PyObject *old;
/* gets arguments */
if (!PyArg_ParseTuple(args, "z", &temp))
{
PyErr_SetString(PyExc_TypeError,
- "set_defbase(name), with name (string/None).");
+ "set_defbase(name), with name (string/None).");
return NULL;
}
@@ -1929,16 +1972,16 @@ pgsetdefbase(PyObject * self, PyObject *args)
/* gets default options */
static char getdefopt__doc__[] =
- "get_defopt() -- return default database options.";
+"get_defopt() -- return default database options.";
-static PyObject *
-pggetdefopt(PyObject * self, PyObject *args)
+static PyObject *
+pggetdefopt(PyObject * self, PyObject * args)
{
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method get_defopt() takes no parameter.");
+ "method get_defopt() takes no parameter.");
return NULL;
}
@@ -1948,19 +1991,19 @@ pggetdefopt(PyObject * self, PyObject *args)
/* sets default opt */
static char setdefopt__doc__[] =
- "set_defopt(string) -- set default database options. Return previous value.";
+"set_defopt(string) -- set default database options. Return previous value.";
-static PyObject *
-pgsetdefopt(PyObject * self, PyObject *args)
+static PyObject *
+pgsetdefopt(PyObject * self, PyObject * args)
{
- char *temp = NULL;
- PyObject *old;
+ char *temp = NULL;
+ PyObject *old;
/* gets arguments */
if (!PyArg_ParseTuple(args, "z", &temp))
{
PyErr_SetString(PyExc_TypeError,
- "set_defopt(name), with name (string/None).");
+ "set_defopt(name), with name (string/None).");
return NULL;
}
@@ -1980,16 +2023,16 @@ pgsetdefopt(PyObject * self, PyObject *args)
/* gets default tty */
static char getdeftty__doc__[] =
- "get_deftty() -- return default database debug terminal.";
+"get_deftty() -- return default database debug terminal.";
-static PyObject *
-pggetdeftty(PyObject * self, PyObject *args)
+static PyObject *
+pggetdeftty(PyObject * self, PyObject * args)
{
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method get_deftty() takes no parameter.");
+ "method get_deftty() takes no parameter.");
return NULL;
}
@@ -1999,20 +2042,20 @@ pggetdeftty(PyObject * self, PyObject *args)
/* sets default tty */
static char setdeftty__doc__[] =
- "set_deftty(string) -- set default database debug terminal. "
- "Return previous value.";
+"set_deftty(string) -- set default database debug terminal. "
+"Return previous value.";
-static PyObject *
-pgsetdeftty(PyObject * self, PyObject *args)
+static PyObject *
+pgsetdeftty(PyObject * self, PyObject * args)
{
- char *temp = NULL;
- PyObject *old;
+ char *temp = NULL;
+ PyObject *old;
/* gets arguments */
if (!PyArg_ParseTuple(args, "z", &temp))
{
PyErr_SetString(PyExc_TypeError,
- "set_deftty(name), with name (string/None).");
+ "set_deftty(name), with name (string/None).");
return NULL;
}
@@ -2032,16 +2075,16 @@ pgsetdeftty(PyObject * self, PyObject *args)
/* gets default username */
static char getdefuser__doc__[] =
- "get_defuser() -- return default database username.";
+"get_defuser() -- return default database username.";
-static PyObject *
-pggetdefuser(PyObject * self, PyObject *args)
+static PyObject *
+pggetdefuser(PyObject * self, PyObject * args)
{
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method get_defuser() takes no parameter.");
+ "method get_defuser() takes no parameter.");
return NULL;
}
@@ -2052,19 +2095,19 @@ pggetdefuser(PyObject * self, PyObject *args)
/* sets default username */
static char setdefuser__doc__[] =
- "set_defuser() -- set default database username. Return previous value.";
+"set_defuser() -- set default database username. Return previous value.";
-static PyObject *
-pgsetdefuser(PyObject * self, PyObject *args)
+static PyObject *
+pgsetdefuser(PyObject * self, PyObject * args)
{
- char *temp = NULL;
- PyObject *old;
+ char *temp = NULL;
+ PyObject *old;
/* gets arguments */
if (!PyArg_ParseTuple(args, "z", &temp))
{
PyErr_SetString(PyExc_TypeError,
- "set_defuser(name), with name (string/None).");
+ "set_defuser(name), with name (string/None).");
return NULL;
}
@@ -2084,20 +2127,19 @@ pgsetdefuser(PyObject * self, PyObject *args)
/* sets default password */
static char setdefpasswd__doc__[] =
- "set_defpasswd() -- set default database password.";
+"set_defpasswd() -- set default database password.";
-static PyObject *
-pgsetdefpasswd(PyObject * self, PyObject *args)
+static PyObject *
+pgsetdefpasswd(PyObject * self, PyObject * args)
{
- char *temp = NULL;
- PyObject *old;
+ char *temp = NULL;
+ PyObject *old;
/* gets arguments */
if (!PyArg_ParseTuple(args, "z", &temp))
{
PyErr_SetString(PyExc_TypeError,
- "set_defpasswd(password), with password (string/
-None).");
+ "set_defpasswd(password), with password (string/None).");
return NULL;
}
@@ -2112,22 +2154,22 @@ None).");
pg_default_passwd = Py_None;
}
- Py_INCREF(Py_None);
+ Py_INCREF(Py_None);
return Py_None;
}
/* gets default port */
static char getdefport__doc__[] =
- "get_defport() -- return default database port.";
+"get_defport() -- return default database port.";
-static PyObject *
-pggetdefport(PyObject * self, PyObject *args)
+static PyObject *
+pggetdefport(PyObject * self, PyObject * args)
{
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method get_defport() takes no parameter.");
+ "method get_defport() takes no parameter.");
return NULL;
}
@@ -2137,19 +2179,19 @@ pggetdefport(PyObject * self, PyObject *args)
/* sets default port */
static char setdefport__doc__[] =
- "set_defport(integer) -- set default database port. Return previous value.";
+"set_defport(integer) -- set default database port. Return previous value.";
-static PyObject *
-pgsetdefport(PyObject * self, PyObject *args)
+static PyObject *
+pgsetdefport(PyObject * self, PyObject * args)
{
- long int port = -2;
- PyObject *old;
+ long int port = -2;
+ PyObject *old;
/* gets arguments */
if ((!PyArg_ParseTuple(args, "l", &port)) || (port < -1))
{
PyErr_SetString(PyExc_TypeError, "set_defport(port), with port "
- "(positive integer/-1).");
+ "(positive integer/-1).");
return NULL;
}
@@ -2167,39 +2209,41 @@ pgsetdefport(PyObject * self, PyObject *args)
return old;
}
-#endif /* DEFAULT_VARS */
+#endif /* DEFAULT_VARS */
/* List of functions defined in the module */
static struct PyMethodDef pg_methods[] = {
- {"connect", (PyCFunction) pgconnect, 3, connect__doc__ },
+ {"connect", (PyCFunction) pgconnect, 3, connect__doc__},
#ifdef DEFAULT_VARS
- {"get_defhost", pggetdefhost, 1, getdefhost__doc__ },
- {"set_defhost", pgsetdefhost, 1, setdefhost__doc__ },
- {"get_defbase", pggetdefbase, 1, getdefbase__doc__ },
- {"set_defbase", pgsetdefbase, 1, setdefbase__doc__ },
- {"get_defopt", pggetdefopt, 1, getdefopt__doc__ },
- {"set_defopt", pgsetdefopt, 1, setdefopt__doc__ },
- {"get_deftty", pggetdeftty, 1, getdeftty__doc__ },
- {"set_deftty", pgsetdeftty, 1, setdeftty__doc__ },
- {"get_defport", pggetdefport, 1, getdefport__doc__ },
- {"set_defport", pgsetdefport, 1, setdefport__doc__ },
- {"get_defuser", pggetdefuser, 1, getdefuser__doc__ },
- {"set_defuser", pgsetdefuser, 1, setdefuser__doc__ },
- {"set_defpasswd", pgsetdefpasswd, 1, setdefpasswd__doc__ },
-#endif /* DEFAULT_VARS */
+ {"get_defhost", pggetdefhost, 1, getdefhost__doc__},
+ {"set_defhost", pgsetdefhost, 1, setdefhost__doc__},
+ {"get_defbase", pggetdefbase, 1, getdefbase__doc__},
+ {"set_defbase", pgsetdefbase, 1, setdefbase__doc__},
+ {"get_defopt", pggetdefopt, 1, getdefopt__doc__},
+ {"set_defopt", pgsetdefopt, 1, setdefopt__doc__},
+ {"get_deftty", pggetdeftty, 1, getdeftty__doc__},
+ {"set_deftty", pgsetdeftty, 1, setdeftty__doc__},
+ {"get_defport", pggetdefport, 1, getdefport__doc__},
+ {"set_defport", pgsetdefport, 1, setdefport__doc__},
+ {"get_defuser", pggetdefuser, 1, getdefuser__doc__},
+ {"set_defuser", pgsetdefuser, 1, setdefuser__doc__},
+ {"set_defpasswd", pgsetdefpasswd, 1, setdefpasswd__doc__},
+#endif /* DEFAULT_VARS */
{NULL, NULL} /* sentinel */
};
-static char pg__doc__[] = "Python interface to PostgreSQL DB";
+static char pg__doc__[] = "Python interface to PostgreSQL DB";
/* Initialization function for the module */
-void init_pg(void); /* Python doesn't prototype this */
+void init_pg(void); /* Python doesn't prototype this */
void
init_pg(void)
{
- PyObject *mod, *dict, *v;
+ PyObject *mod,
+ *dict,
+ *v;
/* Initialize here because some WIN platforms get confused otherwise */
PglargeType.ob_type = PgType.ob_type = PgQueryType.ob_type = &PyType_Type;
@@ -2227,18 +2271,25 @@ init_pg(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 */
- Py_INCREF(Py_None); pg_default_host = Py_None;
- Py_INCREF(Py_None); pg_default_base = Py_None;
- Py_INCREF(Py_None); pg_default_opt = Py_None;
- Py_INCREF(Py_None); pg_default_port = Py_None;
- Py_INCREF(Py_None); pg_default_tty = Py_None;
- Py_INCREF(Py_None); pg_default_user = Py_None;
- Py_INCREF(Py_None); pg_default_passwd = Py_None;
-#endif /* DEFAULT_VARS */
+ Py_INCREF(Py_None);
+ pg_default_host = Py_None;
+ Py_INCREF(Py_None);
+ pg_default_base = Py_None;
+ Py_INCREF(Py_None);
+ pg_default_opt = Py_None;
+ Py_INCREF(Py_None);
+ pg_default_port = Py_None;
+ Py_INCREF(Py_None);
+ pg_default_tty = Py_None;
+ Py_INCREF(Py_None);
+ pg_default_user = Py_None;
+ Py_INCREF(Py_None);
+ pg_default_passwd = Py_None;
+#endif /* DEFAULT_VARS */
/* Check for errors */
if (PyErr_Occurred())