diff options
Diffstat (limited to 'src/interfaces')
-rw-r--r-- | src/interfaces/ecpg/include/ecpglib.h | 32 | ||||
-rw-r--r-- | src/interfaces/ecpg/include/ecpgtype.h | 21 | ||||
-rw-r--r-- | src/interfaces/ecpg/include/sqlca.h | 17 | ||||
-rw-r--r-- | src/interfaces/ecpg/lib/ecpglib.c | 66 | ||||
-rw-r--r-- | src/interfaces/ecpg/lib/typename.c | 42 | ||||
-rw-r--r-- | src/interfaces/ecpg/preproc/ecpg.c | 26 | ||||
-rw-r--r-- | src/interfaces/ecpg/preproc/extern.h | 15 | ||||
-rw-r--r-- | src/interfaces/ecpg/preproc/type.c | 546 | ||||
-rw-r--r-- | src/interfaces/ecpg/preproc/type.h | 85 | ||||
-rw-r--r-- | src/interfaces/ecpg/test/Ptest1.c | 69 | ||||
-rw-r--r-- | src/interfaces/ecpg/test/test1.c | 70 | ||||
-rw-r--r-- | src/interfaces/libpgtcl/pgtclCmds.c | 29 | ||||
-rw-r--r-- | src/interfaces/libpgtcl/pgtclId.c | 4 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-auth.c | 54 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-connect.c | 108 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-connect.h | 4 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-exec.c | 17 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-misc.c | 6 | ||||
-rw-r--r-- | src/interfaces/libpq/libpq-fe.h | 12 | ||||
-rw-r--r-- | src/interfaces/python/pgmodule.c | 486 |
20 files changed, 926 insertions, 783 deletions
diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h index 4634b695735..a19b1a4f7a1 100644 --- a/src/interfaces/ecpg/include/ecpglib.h +++ b/src/interfaces/ecpg/include/ecpglib.h @@ -1,32 +1,34 @@ #include <c.h> -void ECPGdebug(int, FILE *); -bool ECPGconnect(const char * dbname); -bool ECPGdo(int, char *, ...); -bool ECPGcommit(int); -bool ECPGrollback(int); -bool ECPGfinish(); -bool ECPGstatus(); +void ECPGdebug(int, FILE *); +bool ECPGconnect(const char *dbname); +bool ECPGdo(int, char *,...); +bool ECPGcommit(int); +bool ECPGrollback(int); +bool ECPGfinish(); +bool ECPGstatus(); -void ECPGlog(const char * format, ...); +void ECPGlog(const char *format,...); #ifdef LIBPQ_FE_H -bool ECPGsetdb(PGconn *); +bool ECPGsetdb(PGconn *); + #endif /* Here are some methods used by the lib. */ /* Returns a pointer to a string containing a simple type name. */ -const char * ECPGtype_name(enum ECPGttype); +const char *ECPGtype_name(enum ECPGttype); /* A generic varchar type. */ -struct ECPGgeneric_varchar { - int len; - char arr[1]; +struct ECPGgeneric_varchar +{ + int len; + char arr[1]; }; /* print an error message */ -void sqlprint(void); +void sqlprint(void); /* define this for simplicity as well as compatibility */ -#define SQLCODE sqlca.sqlcode +#define SQLCODE sqlca.sqlcode diff --git a/src/interfaces/ecpg/include/ecpgtype.h b/src/interfaces/ecpg/include/ecpgtype.h index 496c934f4f4..35bac4d0288 100644 --- a/src/interfaces/ecpg/include/ecpgtype.h +++ b/src/interfaces/ecpg/include/ecpgtype.h @@ -29,16 +29,17 @@ */ #include <stdio.h> -enum ECPGttype { - ECPGt_char = 1, ECPGt_unsigned_char, ECPGt_short, ECPGt_unsigned_short, - ECPGt_int, ECPGt_unsigned_int, ECPGt_long, ECPGt_unsigned_long, - ECPGt_bool, - ECPGt_float, ECPGt_double, - ECPGt_varchar, ECPGt_varchar2, - ECPGt_array, - ECPGt_record, - ECPGt_EOIT, /* End of insert types. */ - ECPGt_EORT /* End of result types. */ +enum ECPGttype +{ + ECPGt_char = 1, ECPGt_unsigned_char, ECPGt_short, ECPGt_unsigned_short, + ECPGt_int, ECPGt_unsigned_int, ECPGt_long, ECPGt_unsigned_long, + ECPGt_bool, + ECPGt_float, ECPGt_double, + ECPGt_varchar, ECPGt_varchar2, + ECPGt_array, + ECPGt_record, + ECPGt_EOIT, /* End of insert types. */ + ECPGt_EORT /* End of result types. */ }; #define IS_SIMPLE_TYPE(type) ((type) >= ECPGt_char && (type) <= ECPGt_varchar2) diff --git a/src/interfaces/ecpg/include/sqlca.h b/src/interfaces/ecpg/include/sqlca.h index 0e7126e7b36..454eba22018 100644 --- a/src/interfaces/ecpg/include/sqlca.h +++ b/src/interfaces/ecpg/include/sqlca.h @@ -1,11 +1,14 @@ #ifndef POSTGRES_SQLCA_H #define POSTGRES_SQLCA_H -struct sqlca { - int sqlcode; - struct { - int sqlerrml; - char sqlerrmc[1000]; - } sqlerrm; -} sqlca; +struct sqlca +{ + int sqlcode; + struct + { + int sqlerrml; + char sqlerrmc[1000]; + } sqlerrm; +} sqlca; + #endif diff --git a/src/interfaces/ecpg/lib/ecpglib.c b/src/interfaces/ecpg/lib/ecpglib.c index 823a335c764..f5778f9ac3c 100644 --- a/src/interfaces/ecpg/lib/ecpglib.c +++ b/src/interfaces/ecpg/lib/ecpglib.c @@ -45,7 +45,7 @@ register_error(int code, char *fmt,...) in the argument quoted with \. */ static -char * +char * quote_postgres(char *arg) { char *res = (char *) malloc(2 * strlen(arg) + 1); @@ -89,9 +89,10 @@ ECPGdo(int lineno, char *query,...) type = va_arg(ap, enum ECPGttype); /* - * Now, if the type is one of the fill in types then we take the argument - * and enter that in the string at the first %s position. Then if there - * are any more fill in types we fill in at the next and so on. + * Now, if the type is one of the fill in types then we take the + * argument and enter that in the string at the first %s position. + * Then if there are any more fill in types we fill in at the next and + * so on. */ while (type != ECPGt_EOIT) { @@ -106,8 +107,11 @@ ECPGdo(int lineno, char *query,...) char *p; char buff[20]; - /* Some special treatment is needed for records since we want their - contents to arrive in a comma-separated list on insert (I think). */ + /* + * Some special treatment is needed for records since we want + * their contents to arrive in a comma-separated list on insert (I + * think). + */ value = va_arg(ap, void *); varcharsize = va_arg(ap, long); @@ -157,8 +161,8 @@ ECPGdo(int lineno, char *query,...) case ECPGt_unsigned_char: { /* set slen to string length if type is char * */ - int slen = (varcharsize == 0) ? strlen((char *) value) : varcharsize; - + int slen = (varcharsize == 0) ? strlen((char *) value) : varcharsize; + newcopy = (char *) malloc(slen + 1); strncpy(newcopy, (char *) value, slen); newcopy[slen] = '\0'; @@ -203,8 +207,9 @@ ECPGdo(int lineno, char *query,...) break; } - /* Now tobeinserted points to an area that is to be inserted at - the first %s + /* + * Now tobeinserted points to an area that is to be inserted at + * the first %s */ newcopy = (char *) malloc(strlen(copiedquery) + strlen(tobeinserted) @@ -212,8 +217,10 @@ ECPGdo(int lineno, char *query,...) strcpy(newcopy, copiedquery); if ((p = strstr(newcopy, ";;")) == NULL) { - /* We have an argument but we dont have the matched up string - in the string + + /* + * We have an argument but we dont have the matched up string + * in the string */ register_error(-1, "Too many arguments line %d.", lineno); return false; @@ -221,16 +228,20 @@ ECPGdo(int lineno, char *query,...) else { strcpy(p, tobeinserted); - /* The strange thing in the second argument is the rest of the - string from the old string */ + + /* + * The strange thing in the second argument is the rest of the + * string from the old string + */ strcat(newcopy, copiedquery + (p - newcopy) + 2 /* Length of ;; */ ); } - /* Now everything is safely copied to the newcopy. Lets free the - oldcopy and let the copiedquery get the value from the newcopy. + /* + * Now everything is safely copied to the newcopy. Lets free the + * oldcopy and let the copiedquery get the value from the newcopy. */ if (mallocedval != NULL) { @@ -283,9 +294,11 @@ ECPGdo(int lineno, char *query,...) x; case PGRES_TUPLES_OK: - /* XXX Cheap Hack. For now, we see only the last group - * of tuples. This is clearly not the right - * way to do things !! + + /* + * XXX Cheap Hack. For now, we see only the last group of + * tuples. This is clearly not the right way to do things + * !! */ m = PQnfields(results); @@ -318,10 +331,10 @@ ECPGdo(int lineno, char *query,...) char *pval = PQgetvalue(results, 0, x); - /*long int * res_int; - char ** res_charstar; - char * res_char; - int res_len; */ + /* + * long int * res_int; char ** res_charstar; char * + * res_char; int res_len; + */ char *scan_length; ECPGlog("ECPGdo line %d: RESULT: %s\n", lineno, pval ? pval : ""); @@ -476,7 +489,7 @@ ECPGdo(int lineno, char *query,...) strncpy((char *) value, pval, varcharsize); } break; - + case ECPGt_varchar: { struct ECPGgeneric_varchar *var = @@ -673,8 +686,9 @@ ECPGlog(const char *format,...) } /* print out an error message */ -void sqlprint(void) +void +sqlprint(void) { sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0'; - printf ("sql error %s\n", sqlca.sqlerrm.sqlerrmc); + printf("sql error %s\n", sqlca.sqlerrm.sqlerrmc); } diff --git a/src/interfaces/ecpg/lib/typename.c b/src/interfaces/ecpg/lib/typename.c index 55756037b30..a79fa67202d 100644 --- a/src/interfaces/ecpg/lib/typename.c +++ b/src/interfaces/ecpg/lib/typename.c @@ -5,20 +5,30 @@ const char * ECPGtype_name(enum ECPGttype typ) { - switch (typ) - { - case ECPGt_char: return "char"; - case ECPGt_unsigned_char: return "unsigned char"; - case ECPGt_short: return "short"; - case ECPGt_unsigned_short: return "unsigned short"; - case ECPGt_int: return "int"; - case ECPGt_unsigned_int: return "unsigned int"; - case ECPGt_long: return "long"; - case ECPGt_unsigned_long: return "unsigned long"; - case ECPGt_float: return "float"; - case ECPGt_double: return "double"; - case ECPGt_bool: return "bool"; - default: - abort(); - } + switch (typ) + { + case ECPGt_char:return "char"; + case ECPGt_unsigned_char: + return "unsigned char"; + case ECPGt_short: + return "short"; + case ECPGt_unsigned_short: + return "unsigned short"; + case ECPGt_int: + return "int"; + case ECPGt_unsigned_int: + return "unsigned int"; + case ECPGt_long: + return "long"; + case ECPGt_unsigned_long: + return "unsigned long"; + case ECPGt_float: + return "float"; + case ECPGt_double: + return "double"; + case ECPGt_bool: + return "bool"; + default: + abort(); + } } diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c index 0239ece7d3c..483a7c52fcc 100644 --- a/src/interfaces/ecpg/preproc/ecpg.c +++ b/src/interfaces/ecpg/preproc/ecpg.c @@ -6,15 +6,15 @@ #include <stdio.h> #if HAVE_GETOPT_H -# include <getopt.h> +#include <getopt.h> #else -# include <unistd.h> +#include <unistd.h> #endif #include <stdlib.h> #if defined(HAVE_STRING_H) -# include <string.h> +#include <string.h> #else -# include <strings.h> +#include <strings.h> #endif #include "extern.h" @@ -29,7 +29,8 @@ usage(char *progname) int main(int argc, char *const argv[]) { - char c, out_option = 0; + char c, + out_option = 0; int fnr; while ((c = getopt(argc, argv, "vdo:")) != EOF) @@ -52,15 +53,16 @@ main(int argc, char *const argv[]) } } - if (optind >= argc) /* no files specified */ + if (optind >= argc) /* no files specified */ usage(argv[0]); else { /* after the options there must not be anything but filenames */ for (fnr = optind; fnr < argc; fnr++) { - char *filename, *ptr2ext; - int ext = 0; + char *filename, + *ptr2ext; + int ext = 0; filename = mm_alloc(strlen(argv[fnr]) + 4); @@ -69,9 +71,9 @@ main(int argc, char *const argv[]) ptr2ext = strrchr(filename, '.'); /* no extension or extension not equal .pgc */ if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0) - { + { if (ptr2ext == NULL) - ext = 1; /* we need this information a while later */ + ext = 1; /* we need this information a while later */ ptr2ext = filename + strlen(filename); ptr2ext[0] = '.'; } @@ -80,7 +82,7 @@ main(int argc, char *const argv[]) ptr2ext[1] = 'c'; ptr2ext[2] = '\0'; - if (out_option == 0) /* calculate the output name */ + if (out_option == 0)/* calculate the output name */ { yyout = fopen(filename, "w"); if (yyout == NULL) @@ -91,7 +93,7 @@ main(int argc, char *const argv[]) } } - if (ext == 1) + if (ext == 1) { /* no extension => add .pgc */ ptr2ext = strrchr(filename, '.'); diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h index 8055e5b07c1..b6166f9bb9f 100644 --- a/src/interfaces/ecpg/preproc/extern.h +++ b/src/interfaces/ecpg/preproc/extern.h @@ -1,14 +1,17 @@ /* variables */ -extern int debugging, braces_open; -extern char * yytext; -extern int yylineno, yyleng; -extern FILE *yyin, *yyout; +extern int debugging, + braces_open; +extern char *yytext; +extern int yylineno, + yyleng; +extern FILE *yyin, + *yyout; /* functions */ extern void lex_init(void); -extern char * input_filename; -extern int yyparse(void); +extern char *input_filename; +extern int yyparse(void); extern void *mm_alloc(size_t), *mm_realloc(void *, size_t); diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c index a436997aaa2..f5ff41c8c76 100644 --- a/src/interfaces/ecpg/preproc/type.c +++ b/src/interfaces/ecpg/preproc/type.c @@ -5,31 +5,33 @@ #include "type.h" /* malloc + error check */ -void *mm_alloc(size_t size) +void * +mm_alloc(size_t size) { - void *ptr = malloc(size); + void *ptr = malloc(size); - if (ptr == NULL) - { - fprintf(stderr, "Out of memory\n"); - exit(1); - } + if (ptr == NULL) + { + fprintf(stderr, "Out of memory\n"); + exit(1); + } - return (ptr); + return (ptr); } /* realloc + error check */ -void *mm_realloc(void * ptr, size_t size) +void * +mm_realloc(void *ptr, size_t size) { - ptr = realloc(ptr, size); + ptr = realloc(ptr, size); - if (ptr == NULL) - { - fprintf(stderr, "Out of memory\n"); - exit(1); - } + if (ptr == NULL) + { + fprintf(stderr, "Out of memory\n"); + exit(1); + } - return (ptr); + return (ptr); } /* Constructors @@ -38,75 +40,76 @@ void *mm_realloc(void * ptr, size_t size) /* The NAME argument is copied. The type argument is preserved as a pointer. */ struct ECPGrecord_member * -ECPGmake_record_member(char *name, struct ECPGtype *type, struct ECPGrecord_member **start) +ECPGmake_record_member(char *name, struct ECPGtype * type, struct ECPGrecord_member ** start) { - struct ECPGrecord_member *ptr, *ne = - (struct ECPGrecord_member *) mm_alloc(sizeof(struct ECPGrecord_member)); + struct ECPGrecord_member *ptr, + *ne = + (struct ECPGrecord_member *) mm_alloc(sizeof(struct ECPGrecord_member)); - ne->name = strdup(name); - ne->typ = type; - ne->next = NULL; + ne->name = strdup(name); + ne->typ = type; + ne->next = NULL; - for (ptr = *start; ptr && ptr->next; ptr = ptr->next); + for (ptr = *start; ptr && ptr->next; ptr = ptr->next); - if (ptr) - ptr->next=ne; - else - *start=ne; - return ne; + if (ptr) + ptr->next = ne; + else + *start = ne; + return ne; } struct ECPGtype * ECPGmake_simple_type(enum ECPGttype typ, long siz) { - struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype)); + struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype)); - ne->typ = typ; - ne->size = siz; - ne->u.element = 0; + ne->typ = typ; + ne->size = siz; + ne->u.element = 0; - return ne; + return ne; } struct ECPGtype * ECPGmake_varchar_type(enum ECPGttype typ, long siz) { - struct ECPGtype *ne = ECPGmake_simple_type(typ, 1); + struct ECPGtype *ne = ECPGmake_simple_type(typ, 1); - ne->size = siz; + ne->size = siz; - return ne; + return ne; } struct ECPGtype * -ECPGmake_array_type(struct ECPGtype *typ, long siz) +ECPGmake_array_type(struct ECPGtype * typ, long siz) { - struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, siz); + struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, siz); - ne->size = siz; - ne->u.element = typ; + ne->size = siz; + ne->u.element = typ; - return ne; + return ne; } struct ECPGtype * -ECPGmake_record_type(struct ECPGrecord_member *rm) +ECPGmake_record_type(struct ECPGrecord_member * rm) { - struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_record, 1); + struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_record, 1); - ne->u.members = rm; + ne->u.members = rm; - return ne; + return ne; } /* Dump a type. The type is dumped as: - type-tag <comma> - enum ECPGttype + type-tag <comma> - enum ECPGttype reference-to-variable <comma> - void * - size <comma> - long size of this field (if varchar) - arrsize <comma> - long number of elements in the arr - offset <comma> - offset to the next element + size <comma> - long size of this field (if varchar) + arrsize <comma> - long number of elements in the arr + offset <comma> - offset to the next element Where: type-tag is one of the simple types or varchar. reference-to-variable can be a reference to a struct element. @@ -114,47 +117,49 @@ ECPGmake_record_type(struct ECPGrecord_member *rm) size is the maxsize in case it is a varchar. Otherwise it is the size of the variable (required to do array fetches of records). */ -void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ, - long varcharsize, - long arrsiz, const char *siz, const char *prefix); -void ECPGdump_a_record(FILE *o, const char *name, long arrsiz, - struct ECPGtype *typ, const char *offset, const char *prefix); +void +ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ, + long varcharsize, + long arrsiz, const char *siz, const char *prefix); +void +ECPGdump_a_record(FILE *o, const char *name, long arrsiz, + struct ECPGtype * typ, const char *offset, const char *prefix); void -ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *typ, const char *prefix) +ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * typ, const char *prefix) { - if (IS_SIMPLE_TYPE(typ->typ)) - { - ECPGdump_a_simple(o, name, typ->typ, typ->size, 0, 0, prefix); - } - else if (typ->typ == ECPGt_array) - { - if (IS_SIMPLE_TYPE(typ->u.element->typ)) - ECPGdump_a_simple(o, name, typ->u.element->typ, - typ->u.element->size, typ->size, 0, prefix); - else if (typ->u.element->typ == ECPGt_array) - { - abort(); /* Array of array, */ - } - else if (typ->u.element->typ == ECPGt_record) - { - /* Array of records. */ - ECPGdump_a_record(o, name, typ->size, typ->u.element, 0, prefix); - } - else - { - abort(); - } - } - else if (typ->typ == ECPGt_record) - { - ECPGdump_a_record(o, name, 0, typ, 0, prefix); - } - else - { - abort(); - } + if (IS_SIMPLE_TYPE(typ->typ)) + { + ECPGdump_a_simple(o, name, typ->typ, typ->size, 0, 0, prefix); + } + else if (typ->typ == ECPGt_array) + { + if (IS_SIMPLE_TYPE(typ->u.element->typ)) + ECPGdump_a_simple(o, name, typ->u.element->typ, + typ->u.element->size, typ->size, 0, prefix); + else if (typ->u.element->typ == ECPGt_array) + { + abort(); /* Array of array, */ + } + else if (typ->u.element->typ == ECPGt_record) + { + /* Array of records. */ + ECPGdump_a_record(o, name, typ->size, typ->u.element, 0, prefix); + } + else + { + abort(); + } + } + else if (typ->typ == ECPGt_record) + { + ECPGdump_a_record(o, name, 0, typ, 0, prefix); + } + else + { + abort(); + } } @@ -162,163 +167,170 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *typ, const char *pre string, it represents the offset needed if we are in an array of records. */ void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ, - long varcharsize, - long arrsiz, - const char *siz, - const char *prefix) + long varcharsize, + long arrsiz, + const char *siz, + const char *prefix) { - switch (typ) - { - case ECPGt_char: - if (varcharsize == 0) /* pointer */ - fprintf(o, "\n\tECPGt_char,%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz, - siz == NULL ? "sizeof(char)" : siz); - else - fprintf(o, "\n\tECPGt_char,&%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz, - siz == NULL ? "sizeof(char)" : siz); - break; - case ECPGt_unsigned_char: - if (varcharsize == 0) /* pointer */ - fprintf(o, "\n\tECPGt_unsigned_char,%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz, - siz == NULL ? "sizeof(char)" : siz); - else - fprintf(o, "\n\tECPGt_unsigned_char,&%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz, - siz == NULL ? "sizeof(unsigned char)" : siz); - break; - case ECPGt_short: - fprintf(o, "\n\tECPGt_short,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, - siz == NULL ? "sizeof(short)" : siz); - break; - case ECPGt_unsigned_short: - fprintf(o, - "\n\tECPGt_unsigned_short,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, - siz == NULL ? "sizeof(unsigned short)" : siz); - break; - case ECPGt_int: - fprintf(o, "\n\tECPGt_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, - siz == NULL ? "sizeof(int)" : siz); - break; - case ECPGt_unsigned_int: - fprintf(o, "\n\tECPGt_unsigned_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, - siz == NULL ? "sizeof(unsigned int)" : siz); - break; - case ECPGt_long: - fprintf(o, "\n\tECPGt_long,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, - siz == NULL ? "sizeof(long)" : siz); - break; - case ECPGt_unsigned_long: - fprintf(o, "\n\tECPGt_unsigned_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, - siz == NULL ? "sizeof(unsigned int)" : siz); - break; - case ECPGt_float: - fprintf(o, "\n\tECPGt_float,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, - siz == NULL ? "sizeof(float)" : siz); - break; - case ECPGt_double: - fprintf(o, "\n\tECPGt_double,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, - siz == NULL ? "sizeof(double)" : siz); - break; - case ECPGt_bool: - fprintf(o, "\n\tECPGt_bool,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, - siz == NULL ? "sizeof(bool)" : siz); - break; - case ECPGt_varchar: - case ECPGt_varchar2: - if (siz == NULL) - fprintf(o, "\n\tECPGt_varchar,&%s%s,%ldL,%ldL,sizeof(struct varchar_%s), ", - prefix ? prefix : "", name, - varcharsize, - arrsiz, name); - else - fprintf(o, "\n\tECPGt_varchar,&%s%s,%ldL,%ldL,%s, ", - prefix ? prefix : "", name, - varcharsize, - arrsiz, siz); - break; - default: - abort(); - } + switch (typ) + { + case ECPGt_char: + if (varcharsize == 0) /* pointer */ + fprintf(o, "\n\tECPGt_char,%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz, + siz == NULL ? "sizeof(char)" : siz); + else + fprintf(o, "\n\tECPGt_char,&%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz, + siz == NULL ? "sizeof(char)" : siz); + break; + case ECPGt_unsigned_char: + if (varcharsize == 0) /* pointer */ + fprintf(o, "\n\tECPGt_unsigned_char,%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz, + siz == NULL ? "sizeof(char)" : siz); + else + fprintf(o, "\n\tECPGt_unsigned_char,&%s%s,%ldL,%ldL,%s, ", prefix ? prefix : "", name, varcharsize, arrsiz, + siz == NULL ? "sizeof(unsigned char)" : siz); + break; + case ECPGt_short: + fprintf(o, "\n\tECPGt_short,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, + siz == NULL ? "sizeof(short)" : siz); + break; + case ECPGt_unsigned_short: + fprintf(o, + "\n\tECPGt_unsigned_short,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, + siz == NULL ? "sizeof(unsigned short)" : siz); + break; + case ECPGt_int: + fprintf(o, "\n\tECPGt_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, + siz == NULL ? "sizeof(int)" : siz); + break; + case ECPGt_unsigned_int: + fprintf(o, "\n\tECPGt_unsigned_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, + siz == NULL ? "sizeof(unsigned int)" : siz); + break; + case ECPGt_long: + fprintf(o, "\n\tECPGt_long,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, + siz == NULL ? "sizeof(long)" : siz); + break; + case ECPGt_unsigned_long: + fprintf(o, "\n\tECPGt_unsigned_int,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, + siz == NULL ? "sizeof(unsigned int)" : siz); + break; + case ECPGt_float: + fprintf(o, "\n\tECPGt_float,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, + siz == NULL ? "sizeof(float)" : siz); + break; + case ECPGt_double: + fprintf(o, "\n\tECPGt_double,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, + siz == NULL ? "sizeof(double)" : siz); + break; + case ECPGt_bool: + fprintf(o, "\n\tECPGt_bool,&%s%s,0L,%ldL,%s, ", prefix ? prefix : "", name, arrsiz, + siz == NULL ? "sizeof(bool)" : siz); + break; + case ECPGt_varchar: + case ECPGt_varchar2: + if (siz == NULL) + fprintf(o, "\n\tECPGt_varchar,&%s%s,%ldL,%ldL,sizeof(struct varchar_%s), ", + prefix ? prefix : "", name, + varcharsize, + arrsiz, name); + else + fprintf(o, "\n\tECPGt_varchar,&%s%s,%ldL,%ldL,%s, ", + prefix ? prefix : "", name, + varcharsize, + arrsiz, siz); + break; + default: + abort(); + } } /* Penetrate a record and dump the contents. */ void -ECPGdump_a_record(FILE *o, const char *name, long arrsiz, struct ECPGtype *typ, const char *offsetarg, const char *prefix) +ECPGdump_a_record(FILE *o, const char *name, long arrsiz, struct ECPGtype * typ, const char *offsetarg, const char *prefix) { - /* If offset is NULL, then this is the first recursive level. If not then - we are in a record in a record and the offset is used as offset. - */ - struct ECPGrecord_member *p; - char obuf[BUFSIZ]; - char pbuf[BUFSIZ]; - const char *offset; - - if (offsetarg == NULL) - { - sprintf(obuf, "sizeof(%s)", name); - offset = obuf; - } - else - { - offset = offsetarg; - } - - sprintf(pbuf, "%s%s.", prefix ? prefix : "", name); - prefix = pbuf; - - for (p = typ->u.members; p; p=p->next) - { + + /* + * If offset is NULL, then this is the first recursive level. If not + * then we are in a record in a record and the offset is used as + * offset. + */ + struct ECPGrecord_member *p; + char obuf[BUFSIZ]; + char pbuf[BUFSIZ]; + const char *offset; + + if (offsetarg == NULL) + { + sprintf(obuf, "sizeof(%s)", name); + offset = obuf; + } + else + { + offset = offsetarg; + } + + sprintf(pbuf, "%s%s.", prefix ? prefix : "", name); + prefix = pbuf; + + for (p = typ->u.members; p; p = p->next) + { #if 0 - if (IS_SIMPLE_TYPE(p->typ->typ)) - { - sprintf(buf, "%s.%s", name, p->name); - ECPGdump_a_simple(o, buf, p->typ->typ, p->typ->size, - arrsiz, offset); - } - else if (p->typ->typ == ECPGt_array) - { - int i; - - for (i = 0; i < p->typ->size; i++) - { - if (IS_SIMPLE_TYPE(p->typ->u.element->typ)) - { - /* sprintf(buf, "%s.%s[%d]", name, p->name, i); */ - sprintf(buf, "%s.%s", name, p->name); - ECPGdump_a_simple(o, buf, p->typ->u.element->typ, p->typ->u.element->size, - p->typ->u.element->size, offset); - } - else if (p->typ->u.element->typ == ECPGt_array) - { - /* Array within an array. NOT implemented. */ - abort(); - } - else if (p->typ->u.element->typ == ECPGt_record) - { - /* Record within array within record. NOT implemented yet. */ - abort(); - } - else - { - /* Unknown type */ - abort(); - } - } - } - else if (p->typ->typ == ECPGt_record) - { - /* Record within a record */ - sprintf(buf, "%s.%s", name, p->name); - ECPGdump_a_record(o, buf, arrsiz, p->typ, offset); - } - else - { - /* Unknown type */ - abort(); - } + if (IS_SIMPLE_TYPE(p->typ->typ)) + { + sprintf(buf, "%s.%s", name, p->name); + ECPGdump_a_simple(o, buf, p->typ->typ, p->typ->size, + arrsiz, offset); + } + else if (p->typ->typ == ECPGt_array) + { + int i; + + for (i = 0; i < p->typ->size; i++) + { + if (IS_SIMPLE_TYPE(p->typ->u.element->typ)) + { + /* sprintf(buf, "%s.%s[%d]", name, p->name, i); */ + sprintf(buf, "%s.%s", name, p->name); + ECPGdump_a_simple(o, buf, p->typ->u.element->typ, p->typ->u.element->size, + p->typ->u.element->size, offset); + } + else if (p->typ->u.element->typ == ECPGt_array) + { + /* Array within an array. NOT implemented. */ + abort(); + } + else if (p->typ->u.element->typ == ECPGt_record) + { + + /* + * Record within array within record. NOT implemented + * yet. + */ + abort(); + } + else + { + /* Unknown type */ + abort(); + } + } + } + else if (p->typ->typ == ECPGt_record) + { + /* Record within a record */ + sprintf(buf, "%s.%s", name, p->name); + ECPGdump_a_record(o, buf, arrsiz, p->typ, offset); + } + else + { + /* Unknown type */ + abort(); + } #endif ECPGdump_a_type(o, p->name, p->typ, prefix); - } + } } @@ -326,43 +338,43 @@ ECPGdump_a_record(FILE *o, const char *name, long arrsiz, struct ECPGtype *typ, anyway. Lets implement that last! */ void -ECPGfree_record_member(struct ECPGrecord_member *rm) +ECPGfree_record_member(struct ECPGrecord_member * rm) { - while (rm) - { - struct ECPGrecord_member *p = rm; - - rm = rm->next; - free(p->name); - free(p); - } + while (rm) + { + struct ECPGrecord_member *p = rm; + + rm = rm->next; + free(p->name); + free(p); + } } void -ECPGfree_type(struct ECPGtype *typ) +ECPGfree_type(struct ECPGtype * typ) { - if (!IS_SIMPLE_TYPE(typ->typ)) - { - if (typ->typ == ECPGt_array) - { - if (IS_SIMPLE_TYPE(typ->u.element->typ)) - free(typ->u.element); - else if (typ->u.element->typ == ECPGt_array) - abort(); /* Array of array, */ - else if (typ->u.element->typ == ECPGt_record) - /* Array of records. */ - ECPGfree_record_member(typ->u.members); - else - abort(); - } - else if (typ->typ == ECPGt_record) - { - ECPGfree_record_member(typ->u.members); - } - else - { - abort(); - } - } - free(typ); + if (!IS_SIMPLE_TYPE(typ->typ)) + { + if (typ->typ == ECPGt_array) + { + if (IS_SIMPLE_TYPE(typ->u.element->typ)) + free(typ->u.element); + else if (typ->u.element->typ == ECPGt_array) + abort(); /* Array of array, */ + else if (typ->u.element->typ == ECPGt_record) + /* Array of records. */ + ECPGfree_record_member(typ->u.members); + else + abort(); + } + else if (typ->typ == ECPGt_record) + { + ECPGfree_record_member(typ->u.members); + } + else + { + abort(); + } + } + free(typ); } diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h index 8ff6ed1b9c2..69bea16b52d 100644 --- a/src/interfaces/ecpg/preproc/type.h +++ b/src/interfaces/ecpg/preproc/type.h @@ -1,36 +1,39 @@ #include <ecpgtype.h> struct ECPGtype; -struct ECPGrecord_member { - char * name; - struct ECPGtype * typ; - struct ECPGrecord_member * next; +struct ECPGrecord_member +{ + char *name; + struct ECPGtype *typ; + struct ECPGrecord_member *next; }; -struct ECPGtype { - enum ECPGttype typ; - long size; /* For array it is the number of elements. - * For varchar it is the maxsize of the area. - */ - union { - struct ECPGtype * element; /* For an array this is the type of the - * element */ +struct ECPGtype +{ + enum ECPGttype typ; + long size; /* For array it is the number of elements. + * For varchar it is the maxsize of the + * area. */ + union + { + struct ECPGtype *element; /* For an array this is the type + * of the element */ - struct ECPGrecord_member * members; - /* A pointer to a list of members. */ - } u; + struct ECPGrecord_member *members; + /* A pointer to a list of members. */ + } u; }; /* Everything is malloced. */ -struct ECPGrecord_member * ECPGmake_record_member(char *, struct ECPGtype *, struct ECPGrecord_member **); -struct ECPGtype * ECPGmake_simple_type(enum ECPGttype, long); -struct ECPGtype * ECPGmake_varchar_type(enum ECPGttype, long); -struct ECPGtype * ECPGmake_array_type(struct ECPGtype *, long); -struct ECPGtype * ECPGmake_record_type(struct ECPGrecord_member *); +struct ECPGrecord_member *ECPGmake_record_member(char *, struct ECPGtype *, struct ECPGrecord_member **); +struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, long); +struct ECPGtype *ECPGmake_varchar_type(enum ECPGttype, long); +struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, long); +struct ECPGtype *ECPGmake_record_type(struct ECPGrecord_member *); /* Frees a type. */ -void ECPGfree_record_member(struct ECPGrecord_member *); -void ECPGfree_type(struct ECPGtype *); +void ECPGfree_record_member(struct ECPGrecord_member *); +void ECPGfree_type(struct ECPGtype *); /* Dump a type. The type is dumped as: @@ -39,32 +42,34 @@ void ECPGfree_type(struct ECPGtype *); type-tag is one of the simple types or varchar. reference-to-variable can be a reference to a struct element. arrsize is the size of the array in case of array fetches. Otherwise 0. - size is the maxsize in case it is a varchar. Otherwise it is the size of - the variable (required to do array fetches of records). + size is the maxsize in case it is a varchar. Otherwise it is the size of + the variable (required to do array fetches of records). */ -void ECPGdump_a_type(FILE *, const char * name, struct ECPGtype *, const char *); +void ECPGdump_a_type(FILE *, const char *name, struct ECPGtype *, const char *); /* A simple struct to keep a variable and its type. */ -struct ECPGtemp_type { - struct ECPGtype * typ; - const char * name; +struct ECPGtemp_type +{ + struct ECPGtype *typ; + const char *name; }; -extern const char * ECPGtype_name(enum ECPGttype typ); +extern const char *ECPGtype_name(enum ECPGttype typ); /* some stuff for whenever statements */ -enum WHEN { - W_NOTHING, - W_CONTINUE, - W_BREAK, - W_SQLPRINT, - W_GOTO, - W_DO, - W_STOP +enum WHEN +{ + W_NOTHING, + W_CONTINUE, + W_BREAK, + W_SQLPRINT, + W_GOTO, + W_DO, + W_STOP }; struct when -{ - enum WHEN code; - char * str; +{ + enum WHEN code; + char *str; }; diff --git a/src/interfaces/ecpg/test/Ptest1.c b/src/interfaces/ecpg/test/Ptest1.c index 5aee48e7d5c..5418e2c1a40 100644 --- a/src/interfaces/ecpg/test/Ptest1.c +++ b/src/interfaces/ecpg/test/Ptest1.c @@ -3,62 +3,75 @@ #include <ecpglib.h> /* exec sql begin declare section */ - /* VARSIZE */struct varchar_uid { int len; char arr[200]; } uid; - struct varchar_name { int len; char arr[200]; } name; - short value; + /* VARSIZE */ struct varchar_uid +{ + int len; + char arr[200]; +} uid; +struct varchar_name +{ + int len; + char arr[200]; +} name; +short value; + /* exec sql end declare section */ #include "sqlca.h" -#define DBCP(x,y) strcpy(x.arr,y);x.len = strlen(x.arr) -#define LENFIX(x) x.len=strlen(x.arr) -#define STRFIX(x) x.arr[x.len]='\0' -#define SQLCODE sqlca.sqlcode +#define DBCP(x,y) strcpy(x.arr,y);x.len = strlen(x.arr) +#define LENFIX(x) x.len=strlen(x.arr) +#define STRFIX(x) x.arr[x.len]='\0' +#define SQLCODE sqlca.sqlcode void -db_error (char *msg) +db_error(char *msg) { sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0'; - printf ("%s: db error %s\n", msg, sqlca.sqlerrm.sqlerrmc); - exit (1); + printf("%s: db error %s\n", msg, sqlca.sqlerrm.sqlerrmc); + exit(1); } int -main () +main() { - strcpy (uid.arr, "test/test"); - LENFIX (uid); + strcpy(uid.arr, "test/test"); + LENFIX(uid); ECPGconnect("kom"); if (SQLCODE) - db_error ("connect"); + db_error("connect"); - strcpy (name.arr, "opt1"); - LENFIX (name); + strcpy(name.arr, "opt1"); + LENFIX(name); + + ECPGdo(__LINE__, "declare cur cursor for select name , value from pace_test ", ECPGt_EOIT, ECPGt_EORT); + if (SQLCODE) + db_error("declare"); - ECPGdo(__LINE__, "declare cur cursor for select name , value from pace_test ", ECPGt_EOIT, ECPGt_EORT ); - if (SQLCODE) db_error ("declare"); - if (SQLCODE) - db_error ("open"); + db_error("open"); - while (1) { - ECPGdo(__LINE__, "fetch in cur ", ECPGt_EOIT, ECPGt_varchar,&name,200,0,sizeof(struct varchar_name), ECPGt_short,&value,0,0,sizeof(short), ECPGt_EORT ); + while (1) + { + ECPGdo(__LINE__, "fetch in cur ", ECPGt_EOIT, ECPGt_varchar, &name, 200, 0, sizeof(struct varchar_name), ECPGt_short, &value, 0, 0, sizeof(short), ECPGt_EORT); if (SQLCODE) break; - STRFIX (name); - printf ("%s\t%d\n", name.arr, value); + STRFIX(name); + printf("%s\t%d\n", name.arr, value); } if (SQLCODE < 0) - db_error ("fetch"); + db_error("fetch"); - ECPGdo(__LINE__, "close cur ", ECPGt_EOIT, ECPGt_EORT ); - if (SQLCODE) db_error ("close"); + ECPGdo(__LINE__, "close cur ", ECPGt_EOIT, ECPGt_EORT); + if (SQLCODE) + db_error("close"); ECPGcommit(__LINE__); - if (SQLCODE) db_error ("commit"); + if (SQLCODE) + db_error("commit"); return (0); } diff --git a/src/interfaces/ecpg/test/test1.c b/src/interfaces/ecpg/test/test1.c index 68d9dd53981..f2533d544d9 100644 --- a/src/interfaces/ecpg/test/test1.c +++ b/src/interfaces/ecpg/test/test1.c @@ -1,60 +1,72 @@ exec sql begin declare section; -VARCHAR uid[200 /* VARSIZE */]; -varchar name[200]; -short value; +VARCHAR uid[200 /* VARSIZE */ ]; +varchar name[200]; +short value; exec sql end declare section; exec sql include sqlca; -#define DBCP(x,y) strcpy(x.arr,y);x.len = strlen(x.arr) -#define LENFIX(x) x.len=strlen(x.arr) -#define STRFIX(x) x.arr[x.len]='\0' -#define SQLCODE sqlca.sqlcode +#define DBCP(x,y) strcpy(x.arr,y);x.len = strlen(x.arr) +#define LENFIX(x) x.len=strlen(x.arr) +#define STRFIX(x) x.arr[x.len]='\0' +#define SQLCODE sqlca.sqlcode void -db_error (char *msg) +db_error(char *msg) { sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0'; - printf ("%s: db error %s\n", msg, sqlca.sqlerrm.sqlerrmc); - exit (1); + printf("%s: db error %s\n", msg, sqlca.sqlerrm.sqlerrmc); + exit(1); } int -main () +main() { - strcpy (uid.arr, "test/test"); - LENFIX (uid); + strcpy(uid.arr, "test/test"); + LENFIX(uid); + + exec sql connect 'kom'; - exec sql connect 'kom'; if (SQLCODE) - db_error ("connect"); + db_error("connect"); + + strcpy(name.arr, "opt1"); + LENFIX(name); - strcpy (name.arr, "opt1"); - LENFIX (name); + exec sql declare cur cursor for + select name, + value from pace_test; - exec sql declare cur cursor for - select name, value from pace_test; - if (SQLCODE) db_error ("declare"); + if (SQLCODE) + db_error("declare"); exec sql open cur; + if (SQLCODE) - db_error ("open"); + db_error("open"); + + while (1) + { + exec sql fetch in cur into:name, + : value; - while (1) { - exec sql fetch in cur into :name, :value; if (SQLCODE) break; - STRFIX (name); - printf ("%s\t%d\n", name.arr, value); + STRFIX(name); + printf("%s\t%d\n", name.arr, value); } if (SQLCODE < 0) - db_error ("fetch"); + db_error("fetch"); exec sql close cur; - if (SQLCODE) db_error ("close"); - exec sql commit; - if (SQLCODE) db_error ("commit"); + + if (SQLCODE) + db_error("close"); + exec sql commit; + + if (SQLCODE) + db_error("commit"); return (0); } diff --git a/src/interfaces/libpgtcl/pgtclCmds.c b/src/interfaces/libpgtcl/pgtclCmds.c index ae14ae3a975..7f30db08183 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.20 1998/02/11 19:13:54 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.21 1998/02/26 04:44:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -41,7 +41,7 @@ static inline char * translate_escape(char *p, int isArray) { - char c, + char c, *q, *s; @@ -155,7 +155,7 @@ tcl_value(char *value) { int literal, last; - char *p; + char *p; if (!value) { @@ -645,7 +645,7 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[]) #ifdef TCL_ARRAYS for (i = 0; i < PQnfields(result); i++) { - Tcl_AppendElement(interp, PQgetvalue(result,tupno,i)); + Tcl_AppendElement(interp, PQgetvalue(result, tupno, i)); } #else /* Tcl_AppendResult(interp, PQgetvalue(result,tupno,0),NULL); */ @@ -1323,17 +1323,24 @@ Pg_select(ClientData cData, Tcl_Interp * interp, int argc, char **argv) for (column = 0; column < ncols; column++) { - Tcl_SetVar2(interp, argv[3], info[column].cname, - PQgetvalue(result, tupno, column), 0); + Tcl_SetVar2(interp, argv[3], info[column].cname, + PQgetvalue(result, tupno, column), 0); } Tcl_SetVar2(interp, argv[3], ".command", "update", 0); if ((r = Tcl_Eval(interp, argv[4])) != TCL_OK && r != TCL_CONTINUE) { - if (r == TCL_BREAK) { - /* I suppose that memory used by info and result must be released */ - free(info); PQclear(result);Tcl_UnsetVar(interp, argv[3], 0); + if (r == TCL_BREAK) + { + + /* + * I suppose that memory used by info and result must be + * released + */ + free(info); + PQclear(result); + Tcl_UnsetVar(interp, argv[3], 0); return TCL_OK; } if (r == TCL_ERROR) @@ -1345,7 +1352,9 @@ Pg_select(ClientData cData, Tcl_Interp * interp, int argc, char **argv) Tcl_AddErrorInfo(interp, msg); } /* also, releasing memory used by info and result */ - free(info); PQclear(result);Tcl_UnsetVar(interp, argv[3], 0); + free(info); + PQclear(result); + Tcl_UnsetVar(interp, argv[3], 0); return r; } } diff --git a/src/interfaces/libpgtcl/pgtclId.c b/src/interfaces/libpgtcl/pgtclId.c index 5b82ff1a51c..2473b6c3181 100644 --- a/src/interfaces/libpgtcl/pgtclId.c +++ b/src/interfaces/libpgtcl/pgtclId.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.6 1997/09/08 21:55:24 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.7 1998/02/26 04:44:53 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -49,7 +49,7 @@ PgSetConnectionId(Pg_clientData * cd, char *id, PGconn *conn) /* * Get back the connection from the Id */ -PGconn * +PGconn * PgGetConnectionId(Pg_clientData * cd, char *id) { Tcl_HashEntry *hent; diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index 7f77589a6b9..93fb4442b05 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.14 1998/01/29 03:24:03 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.15 1998/02/26 04:44:56 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -477,14 +477,14 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq) */ int fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname, - const char *password, char *PQerrormsg) + const char *password, char *PQerrormsg) { switch (areq) { - case AUTH_REQ_OK: - break; + case AUTH_REQ_OK: + break; - case AUTH_REQ_KRB4: + case AUTH_REQ_KRB4: #ifdef KRB4 if (pg_krb4_sendauth(PQerrormsg, conn->sock, &conn->laddr.in, &conn->raddr.in, @@ -496,12 +496,12 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname, } break; #else - (void)sprintf(PQerrormsg, - "fe_sendauth: krb4 authentication not supported\n"); - return (STATUS_ERROR); + (void) sprintf(PQerrormsg, + "fe_sendauth: krb4 authentication not supported\n"); + return (STATUS_ERROR); #endif - case AUTH_REQ_KRB5: + case AUTH_REQ_KRB5: #ifdef KRB5 if (pg_krb5_sendauth(PQerrormsg, conn->sock, &conn->laddr.in, &conn->raddr.in, @@ -513,27 +513,27 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname, } break; #else - (void)sprintf(PQerrormsg, - "fe_sendauth: krb5 authentication not supported\n"); - return (STATUS_ERROR); + (void) sprintf(PQerrormsg, + "fe_sendauth: krb5 authentication not supported\n"); + return (STATUS_ERROR); #endif - case AUTH_REQ_PASSWORD: - case AUTH_REQ_CRYPT: - if (pg_password_sendauth(conn, password, areq) != STATUS_OK) - { - (void)sprintf(PQerrormsg, - "fe_sendauth: error sending password authentication\n"); - return (STATUS_ERROR); - } + case AUTH_REQ_PASSWORD: + case AUTH_REQ_CRYPT: + if (pg_password_sendauth(conn, password, areq) != STATUS_OK) + { + (void) sprintf(PQerrormsg, + "fe_sendauth: error sending password authentication\n"); + return (STATUS_ERROR); + } - break; + break; - default: - (void)sprintf(PQerrormsg, - "fe_sendauth: authentication type %u not supported\n",areq); - return (STATUS_ERROR); - } + default: + (void) sprintf(PQerrormsg, + "fe_sendauth: authentication type %u not supported\n", areq); + return (STATUS_ERROR); + } return (STATUS_OK); } @@ -580,7 +580,7 @@ fe_getauthsvc(char *PQerrormsg) * name the user has authenticated to the system * if there is an error, return the error message in PQerrormsg */ -char * +char * fe_getauthname(char *PQerrormsg) { char *name = (char *) NULL; diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index f9d856d207a..30f07927c60 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.62 1998/01/31 21:27:28 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.63 1998/02/26 04:44:59 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -49,7 +49,7 @@ static void closePGconn(PGconn *conn); static int conninfo_parse(const char *conninfo, char *errorMessage); static char *conninfo_getval(char *keyword); static void conninfo_free(void); -void PQsetenv(PGconn *conn); +void PQsetenv(PGconn *conn); #define NOTIFYLIST_INITIAL_SIZE 10 #define NOTIFYLIST_GROWBY 10 @@ -114,15 +114,29 @@ struct EnvironmentOptions { /* common user-interface settings */ - { "PGDATESTYLE", "datestyle" }, - { "PGTZ", "timezone" }, + { + "PGDATESTYLE", "datestyle" + }, + { + "PGTZ", "timezone" + }, /* internal performance-related settings */ - { "PGCOSTHEAP", "cost_heap" }, - { "PGCOSTINDEX", "cost_index" }, - { "PGRPLANS", "r_plans" }, - { "PGGEQO", "geqo" }, - { NULL } + { + "PGCOSTHEAP", "cost_heap" + }, + { + "PGCOSTINDEX", "cost_index" + }, + { + "PGRPLANS", "r_plans" + }, + { + "PGGEQO", "geqo" + }, + { + NULL + } }; /* ---------------- @@ -149,7 +163,8 @@ PQconnectdb(const char *conninfo) { PGconn *conn; char errorMessage[ERROR_MSG_LENGTH]; - char* tmp; + char *tmp; + /* ---------- * Allocate memory for the conn structure * ---------- @@ -190,7 +205,7 @@ PQconnectdb(const char *conninfo) tmp = conninfo_getval("port"); conn->pgport = tmp ? strdup(tmp) : NULL; tmp = conninfo_getval("tty"); - conn->pgtty = tmp ? strdup(tmp) : NULL; + conn->pgtty = tmp ? strdup(tmp) : NULL; tmp = conninfo_getval("options"); conn->pgoptions = tmp ? strdup(tmp) : NULL; tmp = conninfo_getval("user"); @@ -291,7 +306,7 @@ PQconndefaults(void) * * ---------------- */ -PGconn * +PGconn * PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, const char *pgtty, const char *dbName, const char *login, const char *pwd) { PGconn *conn; @@ -399,8 +414,8 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, cons conn->dbName = strdup(conn->pguser); /* - * if the database name is surrounded by double-quotes, - * then don't convert case + * if the database name is surrounded by double-quotes, then + * don't convert case */ if (*conn->dbName == '"') { @@ -455,8 +470,8 @@ connectDB(PGconn *conn) { struct hostent *hp; - StartupPacket sp; - AuthRequest areq; + StartupPacket sp; + AuthRequest areq; int laddrlen = sizeof(SockAddr); int portno, family, @@ -466,9 +481,9 @@ connectDB(PGconn *conn) * Initialize the startup packet. */ - MemSet((char *)&sp, 0, sizeof (StartupPacket)); + MemSet((char *) &sp, 0, sizeof(StartupPacket)); - sp.protoVersion = (ProtocolVersion)htonl(PG_PROTOCOL_LATEST); + sp.protoVersion = (ProtocolVersion) htonl(PG_PROTOCOL_LATEST); strncpy(sp.user, conn->pguser, SM_USER); strncpy(sp.database, conn->dbName, SM_DATABASE); @@ -491,7 +506,8 @@ connectDB(PGconn *conn) conn->pghost); goto connect_errReturn; } - } else + } + else hp = NULL; #if FALSE @@ -572,7 +588,7 @@ connectDB(PGconn *conn) /* Send the startup packet. */ - if (packetSend(conn, (char *)&sp, sizeof(StartupPacket)) != STATUS_OK) + if (packetSend(conn, (char *) &sp, sizeof(StartupPacket)) != STATUS_OK) { sprintf(conn->errorMessage, "connectDB() -- couldn't send complete packet: errno=%d\n%s\n", errno, strerror(errno)); @@ -586,12 +602,12 @@ connectDB(PGconn *conn) do { - int beresp; + int beresp; if ((beresp = pqGetc(conn->Pfin, conn->Pfdebug)) == EOF) { - (void)sprintf(conn->errorMessage, - "connectDB() -- error getting authentication request\n"); + (void) sprintf(conn->errorMessage, + "connectDB() -- error getting authentication request\n"); goto connect_errReturn; } @@ -600,8 +616,8 @@ connectDB(PGconn *conn) if (beresp == 'E') { - pqGets(conn->errorMessage, sizeof (conn->errorMessage), - conn->Pfin, conn->Pfdebug); + pqGets(conn->errorMessage, sizeof(conn->errorMessage), + conn->Pfin, conn->Pfdebug); goto connect_errReturn; } @@ -610,18 +626,18 @@ connectDB(PGconn *conn) if (beresp != 'R') { - (void)sprintf(conn->errorMessage, - "connectDB() -- expected authentication request\n"); + (void) sprintf(conn->errorMessage, + "connectDB() -- expected authentication request\n"); goto connect_errReturn; } /* Get the type of request. */ - if (pqGetInt((int *)&areq, 4, conn->Pfin, conn->Pfdebug)) + if (pqGetInt((int *) &areq, 4, conn->Pfin, conn->Pfdebug)) { - (void)sprintf(conn->errorMessage, - "connectDB() -- error getting authentication request type\n"); + (void) sprintf(conn->errorMessage, + "connectDB() -- error getting authentication request type\n"); goto connect_errReturn; } @@ -629,11 +645,11 @@ connectDB(PGconn *conn) /* Get the password salt if there is one. */ if (areq == AUTH_REQ_CRYPT && - pqGetnchar(conn->salt, sizeof (conn->salt), - conn->Pfin, conn->Pfdebug)) + pqGetnchar(conn->salt, sizeof(conn->salt), + conn->Pfin, conn->Pfdebug)) { - (void)sprintf(conn->errorMessage, - "connectDB() -- error getting password salt\n"); + (void) sprintf(conn->errorMessage, + "connectDB() -- error getting password salt\n"); goto connect_errReturn; } @@ -642,7 +658,7 @@ connectDB(PGconn *conn) /* Respond to the request. */ if (fe_sendauth(areq, conn, conn->pghost, conn->pgpass, - conn->errorMessage) != STATUS_OK) + conn->errorMessage) != STATUS_OK) goto connect_errReturn; } while (areq != AUTH_REQ_OK); @@ -664,7 +680,7 @@ void PQsetenv(PGconn *conn) { struct EnvironmentOptions *eo; - char setQuery[80]; /* mjl: size okay? XXX */ + char setQuery[80]; /* mjl: size okay? XXX */ for (eo = EnvironmentOptions; eo->envName; eo++) { @@ -679,13 +695,13 @@ PQsetenv(PGconn *conn) else sprintf(setQuery, "SET %s = '%.60s'", eo->pgName, val); #ifdef CONNECTDEBUG -printf("Use environment variable %s to send %s\n", eo->envName, setQuery); + printf("Use environment variable %s to send %s\n", eo->envName, setQuery); #endif res = PQexec(conn, setQuery); - PQclear(res); /* Don't care? */ + PQclear(res); /* Don't care? */ } } -} /* PQsetenv() */ +} /* PQsetenv() */ /* * freePGconn @@ -1095,7 +1111,7 @@ conninfo_free() } /* =========== accessor functions for PGconn ========= */ -char * +char * PQdb(PGconn *conn) { if (!conn) @@ -1106,7 +1122,7 @@ PQdb(PGconn *conn) return conn->dbName; } -char * +char * PQuser(PGconn *conn) { if (!conn) @@ -1117,7 +1133,7 @@ PQuser(PGconn *conn) return conn->pguser; } -char * +char * PQhost(PGconn *conn) { if (!conn) @@ -1129,7 +1145,7 @@ PQhost(PGconn *conn) return conn->pghost; } -char * +char * PQoptions(PGconn *conn) { if (!conn) @@ -1140,7 +1156,7 @@ PQoptions(PGconn *conn) return conn->pgoptions; } -char * +char * PQtty(PGconn *conn) { if (!conn) @@ -1151,7 +1167,7 @@ PQtty(PGconn *conn) return conn->pgtty; } -char * +char * PQport(PGconn *conn) { if (!conn) @@ -1173,7 +1189,7 @@ PQstatus(PGconn *conn) return conn->status; } -char * +char * PQerrorMessage(PGconn *conn) { if (!conn) diff --git a/src/interfaces/libpq/fe-connect.h b/src/interfaces/libpq/fe-connect.h index 53c9d8e2881..e1260be533e 100644 --- a/src/interfaces/libpq/fe-connect.h +++ b/src/interfaces/libpq/fe-connect.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: fe-connect.h,v 1.7 1998/01/29 03:24:36 scrappy Exp $ + * $Id: fe-connect.h,v 1.8 1998/02/26 04:45:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -23,6 +23,6 @@ *---------------------------------------------------------------- */ -int packetSend(PGconn *conn, const char *buf, size_t len); +int packetSend(PGconn *conn, const char *buf, size_t len); #endif /* FE_CONNECT_H */ diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index b9517cebbf2..ffa15a6428c 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.46 1998/01/26 01:42:35 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.47 1998/02/26 04:45:07 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -457,10 +457,11 @@ process_response_from_backend(FILE *pfin, FILE *pfout, FILE *pfdebug, { /* hmm, no response from the backend-end, that's bad */ (void) sprintf(reason, "PQexec() -- Request was sent to backend" - ", but backend closed the channel before responding." - "\n\tThis probably means the backend terminated abnormally" - " before or while processing the request.\n"); - conn->status = CONNECTION_BAD; /* No more connection to backend */ + ", but backend closed the channel before responding." + "\n\tThis probably means the backend terminated abnormally" + " before or while processing the request.\n"); + conn->status = CONNECTION_BAD; /* No more connection to + * backend */ *result_p = (PGresult *) NULL; done = true; } @@ -1643,7 +1644,7 @@ PQnfields(PGresult *res) /* returns NULL if the field_num is invalid */ -char * +char * PQfname(PGresult *res, int field_num) { if (!res) @@ -1756,7 +1757,7 @@ PQfsize(PGresult *res, int field_num) return 0; } -char * +char * PQcmdStatus(PGresult *res) { if (!res) @@ -1853,7 +1854,7 @@ PQcmdTuples(PGresult *res) if res is not binary, a null-terminated ASCII string is returned. */ -char * +char * PQgetvalue(PGresult *res, int tup_num, int field_num) { if (!res) diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index d1c18ee05ae..8a16950cdcd 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.9 1998/01/26 01:42:36 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.10 1998/02/26 04:45:09 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -65,7 +65,7 @@ pqPutnchar(const char *s, int len, FILE *f, FILE *debug) int pqGetnchar(char *s, int len, FILE *f, FILE *debug) { - int status; + int status; status = pqGetNBytes(s, len, f); @@ -82,7 +82,7 @@ pqGetnchar(char *s, int len, FILE *f, FILE *debug) int pqGets(char *s, int len, FILE *f, FILE *debug) { - int status; + int status; status = pqGetString(s, len, f); diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h index 9248ffc4d91..4d801efd153 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.26 1998/02/24 06:04:55 scrappy Exp $ + * $Id: libpq-fe.h,v 1.27 1998/02/26 04:45:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -138,10 +138,10 @@ extern "C" FILE *Pfin; FILE *Pfout; FILE *Pfdebug; - int sock; /* The socket */ - SockAddr laddr; /* Local address */ - SockAddr raddr; /* Remote address */ - char salt[2]; + int sock; /* The socket */ + SockAddr laddr; /* Local address */ + SockAddr raddr; /* Remote address */ + char salt[2]; int asyncNotifyWaiting; Dllist *notifyList; char *pguser; /* Postgres username of user who is @@ -224,7 +224,7 @@ extern "C" extern PGconn *PQconnectdb(const char *conninfo); extern PQconninfoOption *PQconndefaults(void); extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, - const char *pgtty, const char *dbName, const char *login, const char *pwd); + const char *pgtty, const char *dbName, const char *login, const char *pwd); #define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME) PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL) /* close the current connection and free the PGconn data structure */ extern void PQfinish(PGconn *conn); diff --git a/src/interfaces/python/pgmodule.c b/src/interfaces/python/pgmodule.c index 1dbadb1fc08..44f4856e26f 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 by D'Arcy J.M. Cain (darcy@druid.net) * subject to the same terms and conditions as above. - * + * */ #include <Python.h> @@ -36,21 +36,21 @@ static PyObject *PGError; /* taken from fileobject.c */ #define BUF(v) PyString_AS_STRING((PyStringObject *)(v)) -#define CHECK_OPEN 1 -#define CHECK_CLOSE 2 +#define CHECK_OPEN 1 +#define CHECK_CLOSE 2 #define MAX_BUFFER_SIZE 8192 /* maximum transaction size */ #ifndef NO_DIRECT -#define DIRECT_ACCESS 1 /* enables direct access functions */ +#define DIRECT_ACCESS 1 /* enables direct access functions */ #endif /* NO_DIRECT */ #ifndef NO_LARGE -#define LARGE_OBJECTS 1 /* enables large objects support */ +#define LARGE_OBJECTS 1 /* enables large objects support */ #endif /* NO_LARGE */ #ifndef NO_DEF_VAR -#define DEFAULT_VARS 1 /* enables default variables use */ +#define DEFAULT_VARS 1 /* enables default variables use */ #endif /* NO_DEF_VAR */ /* --------------------------------------------------------------------- */ @@ -59,11 +59,11 @@ static PyObject *PGError; #ifdef DEFAULT_VARS -PyObject *pg_default_host; /* default database host */ -PyObject *pg_default_base; /* default database name */ -PyObject *pg_default_opt; /* default connection options */ -PyObject *pg_default_tty; /* default debug tty */ -PyObject *pg_default_port; /* default connection port */ +PyObject *pg_default_host; /* default database host */ +PyObject *pg_default_base; /* default database name */ +PyObject *pg_default_opt; /* default connection options */ +PyObject *pg_default_tty; /* default debug tty */ +PyObject *pg_default_port; /* default connection port */ #endif /* DEFAULT_VARS */ @@ -76,9 +76,9 @@ PyObject *pg_default_port; /* default connection port */ 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; @@ -89,8 +89,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; @@ -103,9 +103,9 @@ typedef struct { PyObject_HEAD pgobject * pgcnx; - Oid lo_oid; - int lo_fd; -} pglargeobject; + Oid lo_oid; + int lo_fd; +} pglargeobject; staticforward PyTypeObject PglargeType; @@ -158,17 +158,17 @@ check_lo(pglargeobject * self, int level) /* pglargeobject initialisation (from pgobject) */ /* creates large object */ -static PyObject * +static PyObject * pg_locreate(pgobject * self, PyObject * args) { - int mode; - pglargeobject *npglo; + int mode; + pglargeobject *npglo; /* gets arguments */ if (!PyArg_ParseTuple(args, "i", &mode)) { PyErr_SetString(PyExc_TypeError, - "locreate(mode), with mode (integer)."); + "locreate(mode), with mode (integer)."); return NULL; } @@ -195,8 +195,8 @@ pg_locreate(pgobject * self, PyObject * args) static PyObject * pg_getlo(pgobject * self, PyObject * args) { - int lo_oid; - pglargeobject *npglo; + int lo_oid; + pglargeobject *npglo; /* gets arguments */ if (!PyArg_ParseTuple(args, "i", &lo_oid)) @@ -227,8 +227,8 @@ pg_getlo(pgobject * self, PyObject * args) static PyObject * pg_loimport(pgobject * self, PyObject * args) { - char *name; - pglargeobject *npglo; + char *name; + pglargeobject *npglo; /* gets arguments */ if (!PyArg_ParseTuple(args, "s", &name)) @@ -273,7 +273,8 @@ pglarge_dealloc(pglargeobject * self) static PyObject * pglarge_open(pglargeobject * self, PyObject * args) { - int mode, fd; + int mode, + fd; /* check validity */ if (!check_lo(self, CHECK_CLOSE)) @@ -307,7 +308,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; } @@ -332,8 +333,8 @@ pglarge_close(pglargeobject * self, PyObject * args) static PyObject * pglarge_read(pglargeobject * self, PyObject * args) { - int size; - PyObject *buffer; + int size; + PyObject *buffer; /* checks validity */ if (!check_lo(self, CHECK_OPEN)) @@ -371,8 +372,8 @@ pglarge_read(pglargeobject * self, PyObject * args) static PyObject * pglarge_write(pglargeobject * self, PyObject * args) { - PyObject *buffer; - int size; + PyObject *buffer; + int size; /* checks validity */ if (!check_lo(self, CHECK_OPEN)) @@ -382,13 +383,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, (char *) BUF(buffer), - PyString_Size(buffer))) < PyString_Size(buffer)) + PyString_Size(buffer))) < PyString_Size(buffer)) { PyErr_SetString(PyExc_IOError, "buffer truncated during write."); return NULL; @@ -403,7 +404,9 @@ pglarge_write(pglargeobject * self, PyObject * args) static PyObject * pglarge_lseek(pglargeobject * self, PyObject * args) { - int ret, offset, whence; + int ret, + offset, + whence; /* checks validity */ if (!check_lo(self, CHECK_OPEN)) @@ -413,7 +416,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; } @@ -432,13 +435,14 @@ pglarge_lseek(pglargeobject * self, PyObject * args) 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; } @@ -461,10 +465,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; } @@ -476,13 +480,13 @@ pglarge_size(pglargeobject * self, PyObject * args) 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; } @@ -505,7 +509,7 @@ pglarge_tell(pglargeobject * self, PyObject * args) static PyObject * pglarge_export(pglargeobject * self, PyObject * args) { - char *name; + char *name; /* checks validity */ if (!check_lo(self, CHECK_CLOSE)) @@ -515,7 +519,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; } @@ -538,7 +542,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; } @@ -560,16 +564,17 @@ pglarge_unlink(pglargeobject * self, PyObject * args) /* large object methods */ static struct PyMethodDef pglarge_methods[] = { - {"open", (PyCFunction) pglarge_open, 1}, /* opens large object */ - {"close", (PyCFunction) pglarge_close, 1},/* closes large object */ - {"read", (PyCFunction) pglarge_read, 1}, /* reads from large object */ - {"write", (PyCFunction) pglarge_write, 1},/* writes to large object */ - {"seek", (PyCFunction) pglarge_lseek, 1},/* seeks position */ - {"size", (PyCFunction) pglarge_size, 1}, /* gives object size */ - {"tell", (PyCFunction) pglarge_tell, 1}, /* gives position in lobj */ - {"export", (PyCFunction) pglarge_export, 1},/* exports to unix file */ - {"unlink", (PyCFunction) pglarge_unlink, 1},/* deletes a large object */ - {NULL, NULL} /* sentinel */ + {"open", (PyCFunction) pglarge_open, 1}, /* opens large object */ + {"close", (PyCFunction) pglarge_close, 1}, /* closes large object */ + {"read", (PyCFunction) pglarge_read, 1}, /* reads from large object */ + {"write", (PyCFunction) pglarge_write, 1}, /* writes to large object */ + {"seek", (PyCFunction) pglarge_lseek, 1}, /* seeks position */ + {"size", (PyCFunction) pglarge_size, 1}, /* gives object size */ + {"tell", (PyCFunction) pglarge_tell, 1}, /* gives position in lobj */ + {"export", (PyCFunction) pglarge_export, 1}, /* exports to unix file */ + {"unlink", (PyCFunction) pglarge_unlink, 1}, /* deletes a large + * object */ + {NULL, NULL} /* sentinel */ }; /* get attribute */ @@ -608,7 +613,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) { @@ -626,22 +631,22 @@ pglarge_getattr(pglargeobject * self, char *name) /* object type definition */ staticforward PyTypeObject PglargeType = { PyObject_HEAD_INIT(&PyType_Type) - 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 */ - 0, /* 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 */ + 0, /* 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 */ @@ -655,26 +660,29 @@ staticforward PyTypeObject PglargeType = { static PyObject * pgconnect(pgobject * self, PyObject * args, PyObject * dict) { - char *pghost, *pgopt, *pgtty, *pgdbname; - int pgport; - char port_buffer[20]; - PyObject *temp; - pgobject *npgobj; - PGconn *test_cnx; + char *pghost, + *pgopt, + *pgtty, + *pgdbname; + int pgport; + char port_buffer[20]; + PyObject *temp; + pgobject *npgobj; + PGconn *test_cnx; pghost = pgopt = pgtty = pgdbname = NULL; pgport = -1; /* parses standard arguments */ if (!PyArg_ParseTuple(args, "|zzlzz", - &pgdbname, &pghost, &pgport, &pgopt, &pgtty)) + &pgdbname, &pghost, &pgport, &pgopt, &pgtty)) { PyErr_Clear(); if (!PyArg_ParseTuple(args, "")) { PyErr_SetString(PyExc_TypeError, - "connect(dbname, host, port, opt, tty), " + "connect(dbname, host, port, opt, tty), " "with args (opt., strings or None)."); return NULL; } @@ -691,14 +699,14 @@ pgconnect(pgobject * self, PyObject * args, PyObject * dict) if (pghost) { PyErr_SetString(PyExc_SyntaxError, - "Duplicate argument definition."); + "Duplicate argument definition."); return NULL; } if (!PyString_Check(temp)) { PyErr_SetString(PyExc_TypeError, - "'Host' argument must be a string."); + "'Host' argument must be a string."); return NULL; } @@ -714,14 +722,14 @@ pgconnect(pgobject * self, PyObject * args, PyObject * dict) if (pgport != -1) { PyErr_SetString(PyExc_SyntaxError, - "Duplicate argument definition."); + "Duplicate argument definition."); return NULL; } if (!PyInt_Check(temp)) { PyErr_SetString(PyExc_TypeError, - "'Port' argument must be an integer."); + "'Port' argument must be an integer."); return NULL; } @@ -737,14 +745,14 @@ pgconnect(pgobject * self, PyObject * args, PyObject * dict) if (pgtty) { PyErr_SetString(PyExc_SyntaxError, - "Duplicate argument definition."); + "Duplicate argument definition."); return NULL; } if (!PyString_Check(temp)) { PyErr_SetString(PyExc_TypeError, - "'opt' argument must be a string."); + "'opt' argument must be a string."); return NULL; } @@ -760,14 +768,14 @@ pgconnect(pgobject * self, PyObject * args, PyObject * dict) if (pgtty) { PyErr_SetString(PyExc_SyntaxError, - "Duplicate argument definition."); + "Duplicate argument definition."); return NULL; } if (!PyString_Check(temp)) { PyErr_SetString(PyExc_TypeError, - "'tty' argument must be a string."); + "'tty' argument must be a string."); return NULL; } @@ -783,14 +791,14 @@ pgconnect(pgobject * self, PyObject * args, PyObject * dict) if (pgdbname) { PyErr_SetString(PyExc_SyntaxError, - "Duplicate argument definition."); + "Duplicate argument definition."); return NULL; } if (!PyString_Check(temp)) { PyErr_SetString(PyExc_TypeError, - "'dbname' argument must be a string."); + "'dbname' argument must be a string."); return NULL; } @@ -866,7 +874,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; } @@ -880,15 +888,17 @@ pg_reset(pgobject * self, PyObject * args) static PyObject * pg_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; } @@ -910,14 +920,14 @@ pg_listfields(pgqueryobject * self, PyObject * args) static PyObject * pg_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; } @@ -937,8 +947,8 @@ pg_fieldname(pgqueryobject * self, PyObject * args) static PyObject * pg_fieldnum(pgqueryobject * self, PyObject * args) { - char *name; - int num; + char *name; + int num; /* gets args */ if (!PyArg_ParseTuple(args, "s", &name)) @@ -961,14 +971,19 @@ pg_fieldnum(pgqueryobject * self, PyObject * args) static PyObject * pg_getresult(pgqueryobject * self, PyObject * args) { - PyObject *rowtuple, *reslist, *str; - int i, j, m, n; + PyObject *rowtuple, + *reslist, + *str; + int i, + j, + m, + n; /* 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; } @@ -998,20 +1013,25 @@ pg_getresult(pgqueryobject * self, PyObject * args) static PyObject * pg_getnotify(pgobject * self, PyObject * args) { - PGnotify *notify; - PGresult *result; - PyObject *notify_result, *temp; + PGnotify *notify; + PGresult *result; + PyObject *notify_result, + *temp; /* checks 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) @@ -1039,11 +1059,17 @@ pg_getnotify(pgobject * self, PyObject * args) static PyObject * pg_query(pgobject * self, PyObject * args) { - char *query; - PGresult *result; - PyObject *rowtuple, *reslist, *str; - pgqueryobject *npgobj; - int i, j, m, n, status; + char *query; + PGresult *result; + PyObject *rowtuple, + *reslist, + *str; + pgqueryobject *npgobj; + int i, + j, + m, + n, + status; /* get query args */ if (!PyArg_ParseTuple(args, "s", &query)) @@ -1074,24 +1100,24 @@ pg_query(pgobject * self, PyObject * args) break; case PGRES_BAD_RESPONSE: PyErr_SetString(PGError, - "unexpected responsed received from server."); + "unexpected responsed received from server."); break; case PGRES_FATAL_ERROR: PyErr_SetString(PGError, - "server fatal error. " - "Please report to your db administrator."); + "server fatal error. " + "Please report to your db administrator."); break; case PGRES_NONFATAL_ERROR: PyErr_SetString(PGError, "server (non fatal) error."); break; - case PGRES_COMMAND_OK: /* no data will be received */ + case PGRES_COMMAND_OK: /* no data will be received */ case PGRES_COPY_OUT: case PGRES_COPY_IN: Py_INCREF(Py_None); return Py_None; default: PyErr_SetString(PGError, "internal error: " - "unknown result status."); + "unknown result status."); break; } @@ -1111,7 +1137,7 @@ pg_query(pgobject * self, PyObject * args) static PyObject * pg_putline(pgobject * self, PyObject * args) { - char *line; + char *line; /* reads args */ if (!PyArg_ParseTuple(args, "s", &line)) @@ -1130,15 +1156,15 @@ pg_putline(pgobject * self, PyObject * args) static PyObject * pg_getline(pgobject * self, PyObject * args) { - char *line; - PyObject *str; - int ret; + char *line; + PyObject *str; + int ret; /* checks args */ if (!PyArg_ParseTuple(args, "")) { PyErr_SetString(PyExc_SyntaxError, - "method getline() takes no parameters."); + "method getline() takes no parameters."); return NULL; } @@ -1177,7 +1203,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; } @@ -1186,16 +1212,17 @@ pg_endcopy(pgobject * self, PyObject * args) Py_INCREF(Py_None); return Py_None; } + #endif /* DIRECT_ACCESS */ static PyObject * -pg_print(pgqueryobject *self, FILE *fp, int flags) +pg_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; @@ -1207,20 +1234,25 @@ pg_print(pgqueryobject *self, FILE *fp, int flags) 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; /* gets arguments */ 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; } @@ -1232,7 +1264,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; } @@ -1242,7 +1274,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; } } @@ -1284,7 +1316,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); @@ -1292,7 +1324,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); @@ -1300,7 +1332,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); @@ -1310,8 +1342,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; } @@ -1340,21 +1372,21 @@ pg_inserttable(pgobject * self, PyObject * args) /* connection object methods */ static struct PyMethodDef pgobj_methods[] = { - {"query", (PyCFunction) pg_query, 1}, /* query method */ - {"reset", (PyCFunction) pg_reset, 1}, /* connection reset */ - {"getnotify", (PyCFunction) pg_getnotify, 1}, /* checks for notify */ - {"inserttable", (PyCFunction) pg_inserttable, 1}, /* table insert */ + {"query", (PyCFunction) pg_query, 1}, /* query method */ + {"reset", (PyCFunction) pg_reset, 1}, /* connection reset */ + {"getnotify", (PyCFunction) pg_getnotify, 1}, /* checks for notify */ + {"inserttable", (PyCFunction) pg_inserttable, 1}, /* table insert */ #ifdef DIRECT_ACCESS - {"putline", (PyCFunction) pg_putline, 1}, /* direct access: putline */ - {"getline", (PyCFunction) pg_getline, 1}, /* direct access: getline */ - {"endcopy", (PyCFunction) pg_endcopy, 1}, /* direct access: endcopy */ + {"putline", (PyCFunction) pg_putline, 1}, /* direct access: putline */ + {"getline", (PyCFunction) pg_getline, 1}, /* direct access: getline */ + {"endcopy", (PyCFunction) pg_endcopy, 1}, /* direct access: endcopy */ #endif /* DIRECT_ACCESS */ #ifdef LARGE_OBJECTS - {"locreate", (PyCFunction) pg_locreate, 1}, /* creates large object */ - {"getlo", (PyCFunction) pg_getlo, 1}, /* get lo from oid */ - {"loimport", (PyCFunction) pg_loimport, 1}, /* imports lo from file */ + {"locreate", (PyCFunction) pg_locreate, 1}, /* creates large object */ + {"getlo", (PyCFunction) pg_getlo, 1}, /* get lo from oid */ + {"loimport", (PyCFunction) pg_loimport, 1}, /* imports lo from file */ #endif /* LARGE_OBJECTS */ {NULL, NULL} /* sentinel */ @@ -1401,7 +1433,7 @@ pg_getattr(pgobject * self, char *name) /* attributes list */ if (!strcmp(name, "__members__")) { - PyObject *list = PyList_New(8); + PyObject *list = PyList_New(8); if (list) { @@ -1444,10 +1476,10 @@ staticforward PyTypeObject PgType = { /* query object methods */ static struct PyMethodDef pgquery_methods[] = { - {"getresult", (PyCFunction) pg_getresult, 1}, /* get last result */ - {"fieldname", (PyCFunction) pg_fieldname, 1}, /* get field name */ - {"fieldnum", (PyCFunction) pg_fieldnum, 1}, /* get field number */ - {"listfields", (PyCFunction) pg_listfields, 1}, /* list fields names */ + {"getresult", (PyCFunction) pg_getresult, 1}, /* get last result */ + {"fieldname", (PyCFunction) pg_fieldname, 1}, /* get field name */ + {"fieldnum", (PyCFunction) pg_fieldnum, 1}, /* get field number */ + {"listfields", (PyCFunction) pg_listfields, 1}, /* list fields names */ {NULL, NULL} /* sentinel */ }; @@ -1466,9 +1498,9 @@ staticforward PyTypeObject PgQueryType = { sizeof(pgqueryobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ - (destructor) pg_querydealloc,/* tp_dealloc */ + (destructor) pg_querydealloc, /* tp_dealloc */ (printfunc) pg_print, /* tp_print */ - (getattrfunc) pg_querygetattr,/* tp_getattr */ + (getattrfunc) pg_querygetattr, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_compare */ 0, /* tp_repr */ @@ -1487,14 +1519,14 @@ staticforward PyTypeObject PgQueryType = { #ifdef DEFAULT_VARS /* gets default host */ -PyObject * -pggetdefhost(PyObject *self, PyObject *args) +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; } @@ -1503,17 +1535,17 @@ pggetdefhost(PyObject *self, PyObject *args) } /* sets default host */ -PyObject * -pgsetdefhost(PyObject * self, PyObject *args) +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; } @@ -1532,14 +1564,14 @@ pgsetdefhost(PyObject * self, PyObject *args) } /* gets default base */ -PyObject * -pggetdefbase(PyObject * self, PyObject *args) +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; } @@ -1548,17 +1580,17 @@ pggetdefbase(PyObject * self, PyObject *args) } /* sets default base */ -PyObject * -pgsetdefbase(PyObject * self, PyObject *args) +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; } @@ -1577,14 +1609,14 @@ pgsetdefbase(PyObject * self, PyObject *args) } /* gets default options */ -PyObject * -pggetdefopt(PyObject * self, PyObject *args) +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; } @@ -1593,17 +1625,17 @@ pggetdefopt(PyObject * self, PyObject *args) } /* sets default opt */ -PyObject * -pgsetdefopt(PyObject * self, PyObject *args) +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; } @@ -1622,14 +1654,14 @@ pgsetdefopt(PyObject * self, PyObject *args) } /* gets default tty */ -PyObject * -pggetdeftty(PyObject * self, PyObject *args) +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; } @@ -1638,17 +1670,17 @@ pggetdeftty(PyObject * self, PyObject *args) } /* sets default tty */ -PyObject * -pgsetdeftty(PyObject * self, PyObject *args) +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; } @@ -1667,16 +1699,16 @@ pgsetdeftty(PyObject * self, PyObject *args) } /* gets default port */ -PyObject * -pggetdefport(PyObject * self, PyObject *args) +PyObject * +pggetdefport(PyObject * self, PyObject * args) { - char *temp; + char *temp; /* checks args */ if (!PyArg_ParseTuple(args, "")) { PyErr_SetString(PyExc_SyntaxError, - "method get_defport() takes no parameter."); + "method get_defport() takes no parameter."); return NULL; } @@ -1685,18 +1717,19 @@ pggetdefport(PyObject * self, PyObject *args) } /* sets default port */ -PyObject * -pgsetdefport(PyObject * self, PyObject *args) +PyObject * +pgsetdefport(PyObject * self, PyObject * args) { - long int port = -2; - char buffer[64], *temp; - PyObject *old; + long int port = -2; + char buffer[64], + *temp; + 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; } @@ -1719,29 +1752,31 @@ pgsetdefport(PyObject * self, PyObject *args) /* List of functions defined in the module */ static struct PyMethodDef pg_methods[] = { - {"connect", (PyCFunction) pgconnect, 3},/* connect to a postgres database */ + {"connect", (PyCFunction) pgconnect, 3}, /* connect to a postgres + * database */ #ifdef DEFAULT_VARS - {"get_defhost", pggetdefhost, 1}, /* gets default host */ - {"set_defhost", pgsetdefhost, 1}, /* sets default host */ - {"get_defbase", pggetdefbase, 1}, /* gets default base */ - {"set_defbase", pgsetdefbase, 1}, /* sets default base */ - {"get_defopt", pggetdefopt, 1}, /* gets default options */ - {"set_defopt", pgsetdefopt, 1}, /* sets default options */ - {"get_deftty", pggetdeftty, 1}, /* gets default debug tty */ - {"set_deftty", pgsetdeftty, 1}, /* sets default debug tty */ - {"get_defport", pggetdefport, 1}, /* gets default port */ - {"set_defport", pgsetdefport, 1}, /* sets default port */ + {"get_defhost", pggetdefhost, 1}, /* gets default host */ + {"set_defhost", pgsetdefhost, 1}, /* sets default host */ + {"get_defbase", pggetdefbase, 1}, /* gets default base */ + {"set_defbase", pgsetdefbase, 1}, /* sets default base */ + {"get_defopt", pggetdefopt, 1}, /* gets default options */ + {"set_defopt", pgsetdefopt, 1}, /* sets default options */ + {"get_deftty", pggetdeftty, 1}, /* gets default debug tty */ + {"set_deftty", pgsetdeftty, 1}, /* sets default debug tty */ + {"get_defport", pggetdefport, 1}, /* gets default port */ + {"set_defport", pgsetdefport, 1}, /* sets default port */ #endif /* DEFAULT_VARS */ {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 initpg(void) { - PyObject *mod, *dict; + PyObject *mod, + *dict; /* Create the module and add the functions */ mod = Py_InitModule4("pg", pg_methods, pg__doc__, NULL, PYTHON_API_VERSION); @@ -1765,11 +1800,16 @@ initpg(void) #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_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; #endif /* DEFAULT_VARS */ /* Check for errors */ |