diff options
Diffstat (limited to 'src/interfaces/ecpg')
27 files changed, 406 insertions, 356 deletions
diff --git a/src/interfaces/ecpg/compatlib/informix.c b/src/interfaces/ecpg/compatlib/informix.c index ad55a542e28..d8d95c03ccc 100644 --- a/src/interfaces/ecpg/compatlib/informix.c +++ b/src/interfaces/ecpg/compatlib/informix.c @@ -12,7 +12,7 @@ #include <pgtypes_numeric.h> #include <sqltypes.h> -char *ECPGalloc(long, int); +char *ECPGalloc(long, int); static int deccall2(decimal * arg1, decimal * arg2, int (*ptr) (numeric *, numeric *)) @@ -60,7 +60,10 @@ deccall3(decimal * arg1, decimal * arg2, decimal * result, int (*ptr) (numeric * *nres; int i; - /* we must NOT set the result to NULL here because it may be the same variable as one of the arguments */ + /* + * we must NOT set the result to NULL here because it may be the same + * variable as one of the arguments + */ if (risnull(CDECIMALTYPE, (char *) arg1) || risnull(CDECIMALTYPE, (char *) arg2)) return 0; @@ -100,12 +103,12 @@ deccall3(decimal * arg1, decimal * arg2, decimal * result, int (*ptr) (numeric * if (i == 0) /* No error */ { - + /* set the result to null in case it errors out later */ rsetnull(CDECIMALTYPE, (char *) result); PGTYPESnumeric_to_decimal(nres, result); } - + PGTYPESnumeric_free(nres); PGTYPESnumeric_free(a1); PGTYPESnumeric_free(a2); @@ -161,8 +164,9 @@ ecpg_strndup(const char *str, size_t len) int deccvasc(char *cp, int len, decimal * np) { - char *str = ecpg_strndup(cp, len); /* decimal_in always converts the - * complete string */ + char *str = ecpg_strndup(cp, len); /* decimal_in always + * converts the complete + * string */ int ret = 0; numeric *result; @@ -269,7 +273,7 @@ deccvlong(long lng, decimal * np) int decdiv(decimal * n1, decimal * n2, decimal * result) { - + int i; i = deccall3(n1, n2, result, PGTYPESnumeric_div); @@ -295,7 +299,7 @@ int decmul(decimal * n1, decimal * n2, decimal * result) { int i; - + i = deccall3(n1, n2, result, PGTYPESnumeric_mul); if (i != 0) @@ -316,7 +320,7 @@ int decsub(decimal * n1, decimal * n2, decimal * result) { int i; - + i = deccall3(n1, n2, result, PGTYPESnumeric_sub); if (i != 0) @@ -452,48 +456,50 @@ int rstrdate(char *str, date * d) { date dat; - char strbuf[10]; - int i,j; - - rsetnull(CDATETYPE, (char *)&dat); - /* - * we have to flip the year month date around for postgres - * expects yyyymmdd - * - */ - - for (i=0,j=0; i < 10; i++ ) + char strbuf[10]; + int i, + j; + + rsetnull(CDATETYPE, (char *) &dat); + + /* + * we have to flip the year month date around for postgres expects + * yyyymmdd + * + */ + + for (i = 0, j = 0; i < 10; i++) { /* ignore non-digits */ - if ( isdigit((unsigned char) str[i]) ) + if (isdigit((unsigned char) str[i])) { - + /* j only increments if it is a digit */ - switch(j) + switch (j) { - /* stick the month into the 4th, 5th position */ + /* stick the month into the 4th, 5th position */ case 0: case 1: - strbuf[j+4] = str[i]; + strbuf[j + 4] = str[i]; break; - /* stick the day into the 6th, and 7th position */ + /* stick the day into the 6th, and 7th position */ case 2: case 3: - strbuf[j+4] = str[i]; + strbuf[j + 4] = str[i]; break; - /* stick the year into the first 4 positions */ + /* stick the year into the first 4 positions */ case 4: case 5: case 6: case 7: - strbuf[j-4] = str[i]; + strbuf[j - 4] = str[i]; break; - + } j++; - } - } + } + } strbuf[8] = '\0'; dat = PGTYPESdate_from_asc(strbuf, NULL); @@ -581,13 +587,13 @@ rdayofweek(date d) /* And the datetime stuff */ void -dtcurrent(timestamp *ts) +dtcurrent(timestamp * ts) { PGTYPEStimestamp_current(ts); } int -dtcvasc(char *str, timestamp *ts) +dtcvasc(char *str, timestamp * ts) { timestamp ts_tmp; int i; @@ -610,13 +616,13 @@ dtcvasc(char *str, timestamp *ts) } int -dtsub(timestamp *ts1, timestamp *ts2, interval *iv) +dtsub(timestamp * ts1, timestamp * ts2, interval * iv) { return PGTYPEStimestamp_sub(ts1, ts2, iv); } int -dttoasc(timestamp *ts, char *output) +dttoasc(timestamp * ts, char *output) { char *asctime = PGTYPEStimestamp_to_asc(*ts); @@ -626,13 +632,13 @@ dttoasc(timestamp *ts, char *output) } int -dttofmtasc(timestamp *ts, char *output, int str_len, char *fmtstr) +dttofmtasc(timestamp * ts, char *output, int str_len, char *fmtstr) { return PGTYPEStimestamp_fmt_asc(ts, output, str_len, fmtstr); } int -intoasc(interval *i, char *str) +intoasc(interval * i, char *str) { str = PGTYPESinterval_to_asc(i); @@ -665,46 +671,48 @@ static struct * of the long value */ static void -initValue (long lng_val) -{ - int i, j; - long l, dig; - - /* set some obvious things */ - value.val = lng_val >= 0 ? lng_val : lng_val * (-1); - value.sign = lng_val >= 0 ? '+' : '-'; - value.maxdigits = log10 (2) * (8 * sizeof (long) - 1); - - /* determine the number of digits */ - i = 0; - l = 1; - do - { - i++; - l *= 10; - } - while ((l - 1) < value.val && l <= LONG_MAX / 10); - - if (l <= LONG_MAX/10) - { - value.digits = i; - l /= 10; - } - else - value.digits = i + 1; - - value.remaining = value.digits; - - /* convert the long to string */ - value.val_string = (char *) malloc (value.digits + 1); - dig = value.val; - for (i = value.digits, j = 0; i > 0; i--, j++) - { - value.val_string[j] = dig/l + '0'; - dig = dig % l; - l /= 10; - } - value.val_string[value.digits] = '\0'; +initValue(long lng_val) +{ + int i, + j; + long l, + dig; + + /* set some obvious things */ + value.val = lng_val >= 0 ? lng_val : lng_val * (-1); + value.sign = lng_val >= 0 ? '+' : '-'; + value.maxdigits = log10(2) * (8 * sizeof(long) - 1); + + /* determine the number of digits */ + i = 0; + l = 1; + do + { + i++; + l *= 10; + } + while ((l - 1) < value.val && l <= LONG_MAX / 10); + + if (l <= LONG_MAX / 10) + { + value.digits = i; + l /= 10; + } + else + value.digits = i + 1; + + value.remaining = value.digits; + + /* convert the long to string */ + value.val_string = (char *) malloc(value.digits + 1); + dig = value.val; + for (i = value.digits, j = 0; i > 0; i--, j++) + { + value.val_string[j] = dig / l + '0'; + dig = dig % l; + l /= 10; + } + value.val_string[value.digits] = '\0'; } /* return the position oft the right-most dot in some string */ diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c index 838cedf5c94..2dded3a17d4 100644 --- a/src/interfaces/ecpg/ecpglib/connect.c +++ b/src/interfaces/ecpg/ecpglib/connect.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.22 2004/06/10 22:26:21 momjian Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.23 2004/08/29 05:06:59 momjian Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -14,8 +14,9 @@ #ifdef ENABLE_THREAD_SAFETY static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_key_t actual_connection_key; +static pthread_key_t actual_connection_key; static pthread_once_t actual_connection_key_once = PTHREAD_ONCE_INIT; + #else static struct connection *actual_connection = NULL; #endif @@ -25,7 +26,7 @@ static struct connection *all_connections = NULL; static void ecpg_actual_connection_init(void) { - pthread_key_create(&actual_connection_key, NULL); + pthread_key_create(&actual_connection_key, NULL); } #endif @@ -114,8 +115,8 @@ ecpg_finish(struct connection * act) } #ifdef ENABLE_THREAD_SAFETY - if( pthread_getspecific(actual_connection_key) == act ) - pthread_setspecific(actual_connection_key, all_connections); + if (pthread_getspecific(actual_connection_key) == act) + pthread_setspecific(actual_connection_key, all_connections); #else if (actual_connection == act) actual_connection = all_connections; diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c index 04e944ce892..25738796fb2 100644 --- a/src/interfaces/ecpg/ecpglib/data.c +++ b/src/interfaces/ecpg/ecpglib/data.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.26 2004/07/04 15:02:22 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.27 2004/08/29 05:06:59 momjian Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -16,12 +16,16 @@ #include "pgtypes_timestamp.h" #include "pgtypes_interval.h" -static bool garbage_left(enum ARRAY_TYPE isarray, char *scan_length, enum COMPAT_MODE compat) +static bool +garbage_left(enum ARRAY_TYPE isarray, char *scan_length, enum COMPAT_MODE compat) { - /* INFORMIX allows for selecting a numeric into an int, the result is truncated */ - if (isarray == ECPG_ARRAY_NONE && INFORMIX_MODE(compat) && *scan_length == '.') + /* + * INFORMIX allows for selecting a numeric into an int, the result is + * truncated + */ + if (isarray == ECPG_ARRAY_NONE && INFORMIX_MODE(compat) && *scan_length == '.') return false; - + if (isarray == ECPG_ARRAY_ARRAY && *scan_length != ',' && *scan_length != '}') return true; @@ -44,7 +48,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, char *pval = (char *) PQgetvalue(results, act_tuple, act_field); int value_for_indicator = 0; - ECPGlog("ECPGget_data line %d: RESULT: %s offset: %ld array: %s\n", lineno, pval ? pval : "", offset, isarray?"Yes":"No"); + ECPGlog("ECPGget_data line %d: RESULT: %s offset: %ld array: %s\n", lineno, pval ? pval : "", offset, isarray ? "Yes" : "No"); /* pval is a pointer to the value */ /* let's check if it really is an array if it should be one */ @@ -228,7 +232,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, { *((unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10); if ((isarray && *scan_length != ',' && *scan_length != '}') - || (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */ + || (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */ { ECPGraise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); @@ -419,7 +423,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, if (INFORMIX_MODE(compat)) { - /* Informix wants its own NULL value here instead of an error */ + /* + * Informix wants its own NULL value here + * instead of an error + */ ECPGset_noind_null(ECPGt_numeric, nres); } else @@ -463,7 +470,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, { if (INFORMIX_MODE(compat)) { - /* Informix wants its own NULL value here instead of an error */ + /* + * Informix wants its own NULL value here + * instead of an error + */ ECPGset_noind_null(ECPGt_interval, ires); } else @@ -503,7 +513,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, { if (INFORMIX_MODE(compat)) { - /* Informix wants its own NULL value here instead of an error */ + /* + * Informix wants its own NULL value here + * instead of an error + */ ECPGset_noind_null(ECPGt_date, &ddres); } else @@ -542,7 +555,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, { if (INFORMIX_MODE(compat)) { - /* Informix wants its own NULL value here instead of an error */ + /* + * Informix wants its own NULL value here + * instead of an error + */ ECPGset_noind_null(ECPGt_timestamp, &tres); } else diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c index bc56b0222bc..08c8d3479ce 100644 --- a/src/interfaces/ecpg/ecpglib/descriptor.c +++ b/src/interfaces/ecpg/ecpglib/descriptor.c @@ -1,6 +1,6 @@ /* dynamic SQL support routines * - * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.11 2004/07/05 09:45:53 meskes Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.12 2004/08/29 05:06:59 momjian Exp $ */ #define POSTGRES_ECPG_INTERNAL @@ -434,10 +434,10 @@ bool ECPGset_desc_header(int lineno, char *desc_name, int count) { struct descriptor *desc; - + for (desc = all_descriptors; desc; desc = desc->next) { - if (strcmp(desc_name, desc->name)==0) + if (strcmp(desc_name, desc->name) == 0) break; } @@ -461,7 +461,7 @@ ECPGset_desc(int lineno, char *desc_name, int index,...) for (desc = all_descriptors; desc; desc = desc->next) { - if (strcmp(desc_name, desc->name)==0) + if (strcmp(desc_name, desc->name) == 0) break; } @@ -486,7 +486,7 @@ ECPGset_desc(int lineno, char *desc_name, int index,...) } if (!(var = (struct variable *) ECPGalloc(sizeof(struct variable), lineno))) - return false; + return false; va_start(args, index); @@ -494,7 +494,7 @@ ECPGset_desc(int lineno, char *desc_name, int index,...) { enum ECPGdtype itemtype; enum ECPGttype type; - const char *tobeinserted = NULL; + const char *tobeinserted = NULL; bool malloced; itemtype = va_arg(args, enum ECPGdtype); @@ -508,17 +508,17 @@ ECPGset_desc(int lineno, char *desc_name, int index,...) switch (itemtype) { case ECPGd_data: - { - if (!ECPGstore_input(lineno, true, var, &tobeinserted, &malloced)) { - ECPGfree(var); - return false; + if (!ECPGstore_input(lineno, true, var, &tobeinserted, &malloced)) + { + ECPGfree(var); + return false; + } + + desc_item->data = (char *) tobeinserted; + tobeinserted = NULL; + break; } - - desc_item->data = (char *) tobeinserted; - tobeinserted = NULL; - break; - } case ECPGd_indicator: set_int_item(lineno, &desc_item->indicator, var->pointer, var->type); @@ -541,20 +541,20 @@ ECPGset_desc(int lineno, char *desc_name, int index,...) break; default: - { - char type_str[20]; - snprintf(type_str, sizeof(type_str), "%d", itemtype); - ECPGraise(lineno, ECPG_UNKNOWN_DESCRIPTOR_ITEM, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, type_str); - ECPGfree(var); - return false; - } + { + char type_str[20]; + + snprintf(type_str, sizeof(type_str), "%d", itemtype); + ECPGraise(lineno, ECPG_UNKNOWN_DESCRIPTOR_ITEM, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, type_str); + ECPGfree(var); + return false; + } } - /*if (itemtype == ECPGd_data) - { - free(desc_item->data); - desc_item->data = NULL; - }*/ + /* + * if (itemtype == ECPGd_data) { free(desc_item->data); + * desc_item->data = NULL; } + */ } while (true); ECPGfree(var); diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index a3a601aed52..ac16e457dd8 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.37 2004/07/05 09:45:53 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.38 2004/08/29 05:06:59 momjian Exp $ */ /* * The aim is to get a simpler inteface to the database routines. @@ -70,7 +70,7 @@ quote_postgres(char *arg, int lineno) } void -ECPGget_variable(va_list *ap, enum ECPGttype type, struct variable *var, bool indicator) +ECPGget_variable(va_list *ap, enum ECPGttype type, struct variable * var, bool indicator) { var->type = type; var->pointer = va_arg(*ap, char *); @@ -78,15 +78,14 @@ ECPGget_variable(va_list *ap, enum ECPGttype type, struct variable *var, bool in 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 = *((char **) (var->pointer)); else var->value = var->pointer; /* - * negative values are used to indicate an array without given - * bounds + * negative values are used to indicate an array without given bounds */ /* reset to zero for us */ if (var->arrsize < 0) @@ -95,7 +94,7 @@ ECPGget_variable(va_list *ap, enum ECPGttype type, struct variable *var, bool in var->varcharsize = 0; var->next = NULL; - + if (indicator) { var->ind_type = va_arg(*ap, enum ECPGttype); @@ -245,19 +244,19 @@ ECPGtypeinfocache_push(struct ECPGtype_information_cache ** cache, int oid, bool { struct ECPGtype_information_cache *new_entry = (struct ECPGtype_information_cache *) ECPGalloc(sizeof(struct ECPGtype_information_cache), lineno); - + new_entry->oid = oid; new_entry->isarray = isarray; new_entry->next = *cache; *cache = new_entry; } - + static enum ARRAY_TYPE ECPGis_type_an_array(int type, const struct statement * stmt, const struct variable * var) { - char *array_query; - enum ARRAY_TYPE isarray = ECPG_ARRAY_NOT_SET; - PGresult *query; + char *array_query; + enum ARRAY_TYPE isarray = ECPG_ARRAY_NOT_SET; + PGresult *query; struct ECPGtype_information_cache *cache_entry; if ((stmt->connection->cache_head) == NULL) @@ -319,14 +318,14 @@ ECPGis_type_an_array(int type, const struct statement * stmt, const struct varia if (cache_entry->oid == type) return cache_entry->isarray; } - + array_query = (char *) ECPGalloc(strlen("select typlen from pg_type where oid= and typelem<>0") + 11, stmt->lineno); sprintf(array_query, "select typlen from pg_type where oid=%d and typelem<>0", type); query = PQexec(stmt->connection->connection, array_query); ECPGfree(array_query); - if (PQresultStatus(query) == PGRES_TUPLES_OK ) + if (PQresultStatus(query) == PGRES_TUPLES_OK) { - if ( PQntuples(query) == 0 ) + if (PQntuples(query) == 0) isarray = ECPG_ARRAY_NONE; else { @@ -343,7 +342,7 @@ ECPGis_type_an_array(int type, const struct statement * stmt, const struct varia } PQclear(query); ECPGtypeinfocache_push(&(stmt->connection->cache_head), type, isarray, stmt->lineno); - ECPGlog("ECPGis_type_an_array line %d: TYPE database: %d C: %d array: %s\n", stmt->lineno, type, var->type, isarray?"Yes":"No"); + ECPGlog("ECPGis_type_an_array line %d: TYPE database: %d C: %d array: %s\n", stmt->lineno, type, var->type, isarray ? "Yes" : "No"); return isarray; } @@ -352,7 +351,7 @@ bool ECPGstore_result(const PGresult *results, int act_field, const struct statement * stmt, struct variable * var) { - enum ARRAY_TYPE isarray; + enum ARRAY_TYPE isarray; int act_tuple, ntuples = PQntuples(results); bool status = true; @@ -368,7 +367,7 @@ ECPGstore_result(const PGresult *results, int act_field, { ECPGlog("ECPGstore_result line %d: Incorrect number of matches: %d don't fit into array of %d\n", stmt->lineno, ntuples, var->arrsize); - ECPGraise(stmt->lineno, INFORMIX_MODE(stmt->compat)?ECPG_INFORMIX_SUBSELECT_NOT_ONE:ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL); + ECPGraise(stmt->lineno, INFORMIX_MODE(stmt->compat) ? ECPG_INFORMIX_SUBSELECT_NOT_ONE : ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL); return false; } } @@ -797,7 +796,7 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia case ECPGt_unsigned_char: { /* set slen to string length if type is char * */ - int slen = (var->varcharsize == 0) ? strlen((char *) var->value) : var->varcharsize; + int slen = (var->varcharsize == 0) ? strlen((char *) var->value) : var->varcharsize; if (!(newcopy = ECPGalloc(slen + 1, lineno))) return false; @@ -1036,7 +1035,7 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia free(str); } break; - + case ECPGt_descriptor: break; @@ -1059,7 +1058,7 @@ ECPGexecute(struct statement * stmt) PGresult *results; PGnotify *notify; struct variable *var; - int desc_counter = 0; + int desc_counter = 0; copiedquery = ECPGstrdup(stmt->command, stmt->lineno); @@ -1074,32 +1073,39 @@ ECPGexecute(struct statement * stmt) while (var) { char *newcopy = NULL; - const char *tobeinserted; + const char *tobeinserted; char *p; - bool malloced = FALSE; - int hostvarl = 0; + bool malloced = FALSE; + int hostvarl = 0; tobeinserted = NULL; - - /* A descriptor is a special case since it contains many variables but is listed only once. */ + + /* + * A descriptor is a special case since it contains many variables + * but is listed only once. + */ if (var->type == ECPGt_descriptor) { - /* We create an additional variable list here, so the same logic applies. */ + /* + * We create an additional variable list here, so the same + * logic applies. + */ struct variable desc_inlist; struct descriptor *desc; struct descriptor_item *desc_item; + for (desc = all_descriptors; desc; desc = desc->next) { if (strcmp(var->pointer, desc->name) == 0) break; } - + if (desc == NULL) { ECPGraise(stmt->lineno, ECPG_UNKNOWN_DESCRIPTOR, ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME, var->pointer); return false; } - + desc_counter++; if (desc->count < 0 || desc->count >= desc_counter) { @@ -1129,7 +1135,7 @@ ECPGexecute(struct statement * stmt) } if (!ECPGstore_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, &malloced)) return false; - + break; } } @@ -1145,12 +1151,12 @@ ECPGexecute(struct statement * stmt) if (!ECPGstore_input(stmt->lineno, stmt->force_indicator, var, &tobeinserted, &malloced)) return false; } - + if (tobeinserted) { /* - * 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 */ if (!(newcopy = (char *) ECPGalloc(strlen(copiedquery) + strlen(tobeinserted) + 1, stmt->lineno))) return false; @@ -1159,8 +1165,8 @@ ECPGexecute(struct statement * stmt) if ((p = next_insert(newcopy + hostvarl)) == 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 */ ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL); return false; @@ -1171,8 +1177,8 @@ ECPGexecute(struct statement * stmt) hostvarl = strlen(newcopy); /* - * 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 @@ -1181,9 +1187,9 @@ ECPGexecute(struct statement * stmt) } /* - * Now everything is safely copied to the newcopy. Lets free the - * oldcopy and let the copiedquery get the var->value from the - * newcopy. + * Now everything is safely copied to the newcopy. Lets free + * the oldcopy and let the copiedquery get the var->value from + * the newcopy. */ if (malloced) { @@ -1194,9 +1200,9 @@ ECPGexecute(struct statement * stmt) ECPGfree(copiedquery); copiedquery = newcopy; } - + if (desc_counter == 0) - var = var->next; + var = var->next; } /* Check if there are unmatched things left. */ diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h index 74a8b046c92..8a04ad0aaf1 100644 --- a/src/interfaces/ecpg/ecpglib/extern.h +++ b/src/interfaces/ecpg/ecpglib/extern.h @@ -7,42 +7,42 @@ enum COMPAT_MODE { - ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE + ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE }; #define INFORMIX_MODE(X) ((X) == ECPG_COMPAT_INFORMIX || (X) == ECPG_COMPAT_INFORMIX_SE) enum ARRAY_TYPE { - ECPG_ARRAY_NOT_SET, ECPG_ARRAY_ARRAY, ECPG_ARRAY_VECTOR, ECPG_ARRAY_NONE + ECPG_ARRAY_NOT_SET, ECPG_ARRAY_ARRAY, ECPG_ARRAY_VECTOR, ECPG_ARRAY_NONE }; /* Here are some methods used by the lib. */ /* Returns a pointer to a string containing a simple type name. */ -void ECPGadd_mem (void *ptr, int lineno); - -bool ECPGget_data (const PGresult *, int, int, int, enum ECPGttype type, - enum ECPGttype, char *, char *, long, long, long, - enum ARRAY_TYPE, enum COMPAT_MODE, bool); -struct connection *ECPGget_connection (const char *); -char *ECPGalloc (long, int); -char *ECPGrealloc (void *, long, int); -void ECPGfree (void *); -bool ECPGinit (const struct connection *, const char *, const int); -char *ECPGstrdup (const char *, int); -const char *ECPGtype_name (enum ECPGttype); -unsigned int ECPGDynamicType (Oid); -void ECPGfree_auto_mem (void); -void ECPGclear_auto_mem (void); - -struct descriptor *ecpggetdescp (int, char *); +void ECPGadd_mem(void *ptr, int lineno); + +bool ECPGget_data(const PGresult *, int, int, int, enum ECPGttype type, + enum ECPGttype, char *, char *, long, long, long, + enum ARRAY_TYPE, enum COMPAT_MODE, bool); +struct connection *ECPGget_connection(const char *); +char *ECPGalloc(long, int); +char *ECPGrealloc(void *, long, int); +void ECPGfree(void *); +bool ECPGinit(const struct connection *, const char *, const int); +char *ECPGstrdup(const char *, int); +const char *ECPGtype_name(enum ECPGttype); +unsigned int ECPGDynamicType(Oid); +void ECPGfree_auto_mem(void); +void ECPGclear_auto_mem(void); + +struct descriptor *ecpggetdescp(int, char *); /* A generic varchar type. */ struct ECPGgeneric_varchar { - int len; - char arr[1]; + int len; + char arr[1]; }; /* @@ -51,81 +51,81 @@ struct ECPGgeneric_varchar struct ECPGtype_information_cache { - struct ECPGtype_information_cache *next; - int oid; - bool isarray; + struct ECPGtype_information_cache *next; + int oid; + bool isarray; }; /* structure to store one statement */ struct statement { - int lineno; - char *command; - struct connection *connection; - enum COMPAT_MODE compat; - bool force_indicator; - struct variable *inlist; - struct variable *outlist; + int lineno; + char *command; + struct connection *connection; + enum COMPAT_MODE compat; + bool force_indicator; + struct variable *inlist; + struct variable *outlist; }; /* structure to store connections */ struct connection { - char *name; - PGconn *connection; - bool committed; - int autocommit; - struct ECPGtype_information_cache *cache_head; - struct connection *next; + char *name; + PGconn *connection; + bool committed; + int autocommit; + struct ECPGtype_information_cache *cache_head; + struct connection *next; }; /* structure to store descriptors */ struct descriptor { - char *name; - PGresult *result; - struct descriptor *next; - int count; - struct descriptor_item *items; + char *name; + PGresult *result; + struct descriptor *next; + int count; + struct descriptor_item *items; }; extern struct descriptor *all_descriptors; struct descriptor_item { - int num; - char *data; - int indicator; - int length; - int precision; - int scale; - int type; - struct descriptor_item *next; + int num; + char *data; + int indicator; + int length; + int precision; + int scale; + int type; + struct descriptor_item *next; }; struct variable { - enum ECPGttype type; - void *value; - void *pointer; - long varcharsize; - long arrsize; - long offset; - enum ECPGttype ind_type; - void *ind_value; - void *ind_pointer; - long ind_varcharsize; - long ind_arrsize; - long ind_offset; - struct variable *next; + enum ECPGttype type; + void *value; + void *pointer; + long varcharsize; + long arrsize; + long offset; + enum ECPGttype ind_type; + void *ind_value; + void *ind_pointer; + long ind_varcharsize; + long ind_arrsize; + long ind_offset; + struct variable *next; }; -PGresult **ECPGdescriptor_lvalue (int line, const char *descriptor); +PGresult **ECPGdescriptor_lvalue(int line, const char *descriptor); -bool ECPGstore_result (const PGresult * results, int act_field, - const struct statement *stmt, struct variable *var); -bool ECPGstore_input(const int, const bool, const struct variable *, const char **, bool *); -void ECPGget_variable(va_list *, enum ECPGttype, struct variable *, bool); +bool ECPGstore_result(const PGresult *results, int act_field, + const struct statement * stmt, struct variable * var); +bool ECPGstore_input(const int, const bool, const struct variable *, const char **, bool *); +void ECPGget_variable(va_list *, enum ECPGttype, struct variable *, bool); /* SQLSTATE values generated or processed by ecpglib (intentionally * not exported -- users should refer to the codes directly) */ @@ -153,4 +153,4 @@ void ECPGget_variable(va_list *, enum ECPGttype, struct variable *, bool); #define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR "YE000" #define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY "YE001" -#endif /* _ECPG_LIB_EXTERN_H */ +#endif /* _ECPG_LIB_EXTERN_H */ diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c index 8faf6b2fdff..69789d9da17 100644 --- a/src/interfaces/ecpg/ecpglib/misc.c +++ b/src/interfaces/ecpg/ecpglib/misc.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.21 2004/06/27 12:28:40 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.22 2004/08/29 05:06:59 momjian Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -118,15 +118,18 @@ ECPGinit(const struct connection * con, const char *connection_name, const int l } #ifdef ENABLE_THREAD_SAFETY -static void ecpg_sqlca_key_destructor(void *arg) +static void +ecpg_sqlca_key_destructor(void *arg) { - if( arg != NULL ) - free(arg); /* sqlca structure allocated in ECPGget_sqlca */ + if (arg != NULL) + free(arg); /* sqlca structure allocated in + * ECPGget_sqlca */ } -static void ecpg_sqlca_key_init(void) +static void +ecpg_sqlca_key_init(void) { - pthread_key_create(&sqlca_key, ecpg_sqlca_key_destructor); + pthread_key_create(&sqlca_key, ecpg_sqlca_key_destructor); } #endif diff --git a/src/interfaces/ecpg/include/datetime.h b/src/interfaces/ecpg/include/datetime.h index 13940cda398..b4108c5d2b8 100644 --- a/src/interfaces/ecpg/include/datetime.h +++ b/src/interfaces/ecpg/include/datetime.h @@ -6,4 +6,4 @@ typedef timestamp dtime_t; typedef interval intrvl_t; -#endif /* ndef _ECPG_DATETIME_H */ +#endif /* ndef _ECPG_DATETIME_H */ diff --git a/src/interfaces/ecpg/include/decimal.h b/src/interfaces/ecpg/include/decimal.h index 111a97a9dab..80cef55d1e1 100644 --- a/src/interfaces/ecpg/include/decimal.h +++ b/src/interfaces/ecpg/include/decimal.h @@ -5,4 +5,4 @@ typedef decimal dec_t; -#endif /* ndef _ECPG_DECIMAL_H */ +#endif /* ndef _ECPG_DECIMAL_H */ diff --git a/src/interfaces/ecpg/include/ecpg_informix.h b/src/interfaces/ecpg/include/ecpg_informix.h index 2a17202010e..3e3fcfcfcaa 100644 --- a/src/interfaces/ecpg/include/ecpg_informix.h +++ b/src/interfaces/ecpg/include/ecpg_informix.h @@ -1,7 +1,7 @@ /* * This file contains stuff needed to be as compatible to Informix as possible. * - * $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpg_informix.h,v 1.15 2004/05/10 13:46:06 meskes Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpg_informix.h,v 1.16 2004/08/29 05:06:59 momjian Exp $ */ #ifndef _ECPG_INFORMIX_H #define _ECPG_INFORMIX_H @@ -15,14 +15,14 @@ #define SQLNOTFOUND 100 #define ECPG_INFORMIX_NUM_OVERFLOW -1200 -#define ECPG_INFORMIX_NUM_UNDERFLOW -1201 +#define ECPG_INFORMIX_NUM_UNDERFLOW -1201 #define ECPG_INFORMIX_DIVIDE_ZERO -1202 #define ECPG_INFORMIX_BAD_YEAR -1204 #define ECPG_INFORMIX_BAD_MONTH -1205 #define ECPG_INFORMIX_BAD_DAY -1206 #define ECPG_INFORMIX_ENOSHORTDATE -1209 #define ECPG_INFORMIX_DATE_CONVERT -1210 -#define ECPG_INFORMIX_OUT_OF_MEMORY -1211 +#define ECPG_INFORMIX_OUT_OF_MEMORY -1211 #define ECPG_INFORMIX_ENOTDMY -1212 #define ECPG_INFORMIX_BAD_NUMERIC -1213 #define ECPG_INFORMIX_BAD_EXPONENT -1216 @@ -30,12 +30,12 @@ #define ECPG_INFORMIX_EXTRA_CHARS -1264 #ifdef __cplusplus -extern "C" +extern "C" { #endif extern int rdatestr(date, char *); -extern void rtoday(date *); +extern void rtoday(date *); extern int rjulmdy(date, short *); extern int rdefmtdate(date *, char *, char *); extern int rfmtdate(date, char *, char *); @@ -50,7 +50,7 @@ extern int rsetnull(int, char *); extern int rtypalign(int, int); extern int rtypmsize(int, int); extern int rtypwidth(int, int); -extern void rupshift(char *); +extern void rupshift(char *); extern int byleng(char *, int); extern void ldchar(char *, int, char *); @@ -59,25 +59,25 @@ extern void ECPG_informix_set_var(int, void *, int); extern void *ECPG_informix_get_var(int); /* Informix defines these in decimal.h */ -int decadd(decimal *, decimal *, decimal *); -int deccmp(decimal *, decimal *); -void deccopy(decimal *, decimal *); -int deccvasc(char *, int, decimal *); -int deccvdbl(double, decimal *); -int deccvint(int, decimal *); -int deccvlong(long, decimal *); -int decdiv(decimal *, decimal *, decimal *); -int decmul(decimal *, decimal *, decimal *); -int decsub(decimal *, decimal *, decimal *); -int dectoasc(decimal *, char *, int, int); -int dectodbl(decimal *, double *); -int dectoint(decimal *, int *); -int dectolong(decimal *, long *); +int decadd(decimal *, decimal *, decimal *); +int deccmp(decimal *, decimal *); +void deccopy(decimal *, decimal *); +int deccvasc(char *, int, decimal *); +int deccvdbl(double, decimal *); +int deccvint(int, decimal *); +int deccvlong(long, decimal *); +int decdiv(decimal *, decimal *, decimal *); +int decmul(decimal *, decimal *, decimal *); +int decsub(decimal *, decimal *, decimal *); +int dectoasc(decimal *, char *, int, int); +int dectodbl(decimal *, double *); +int dectoint(decimal *, int *); +int dectolong(decimal *, long *); /* Informix defines these in datetime.h */ -extern void dtcurrent(timestamp *); -extern int dtcvasc(char *, timestamp *); -extern int dtsub(timestamp *, timestamp *, interval *); +extern void dtcurrent(timestamp *); +extern int dtcvasc(char *, timestamp *); +extern int dtsub(timestamp *, timestamp *, interval *); extern int dttoasc(timestamp *, char *); extern int dttofmtasc(timestamp *, char *, int, char *); extern int intoasc(interval *, char *); @@ -87,4 +87,4 @@ extern int dtcvfmtasc(char *, char *, timestamp *); } #endif -#endif /* ndef _ECPG_INFORMIX_H */ +#endif /* ndef _ECPG_INFORMIX_H */ diff --git a/src/interfaces/ecpg/include/pgtypes_date.h b/src/interfaces/ecpg/include/pgtypes_date.h index 0e30823d2f0..8a98c710d92 100644 --- a/src/interfaces/ecpg/include/pgtypes_date.h +++ b/src/interfaces/ecpg/include/pgtypes_date.h @@ -4,8 +4,9 @@ #include <pgtypes_timestamp.h> typedef long date; + #ifdef __cplusplus -extern "C" +extern "C" { #endif diff --git a/src/interfaces/ecpg/include/pgtypes_interval.h b/src/interfaces/ecpg/include/pgtypes_interval.h index c963b1b89e4..f1edf1618cb 100644 --- a/src/interfaces/ecpg/include/pgtypes_interval.h +++ b/src/interfaces/ecpg/include/pgtypes_interval.h @@ -12,10 +12,10 @@ typedef struct #endif long month; /* months and years, after time for * alignment */ -} interval; +} interval; #ifdef __cplusplus -extern "C" +extern "C" { #endif diff --git a/src/interfaces/ecpg/include/pgtypes_numeric.h b/src/interfaces/ecpg/include/pgtypes_numeric.h index 951f7dfc0e6..d4846a337ab 100644 --- a/src/interfaces/ecpg/include/pgtypes_numeric.h +++ b/src/interfaces/ecpg/include/pgtypes_numeric.h @@ -23,7 +23,7 @@ typedef struct * NUMERIC_NAN */ NumericDigit *buf; /* start of alloc'd space for digits[] */ NumericDigit *digits; /* decimal digits */ -} numeric; +} numeric; typedef struct { @@ -38,11 +38,11 @@ typedef struct } decimal; #ifdef __cplusplus -extern "C" +extern "C" { #endif - -numeric *PGTYPESnumeric_new(void); + + numeric * PGTYPESnumeric_new(void); void PGTYPESnumeric_free(numeric *); numeric *PGTYPESnumeric_from_asc(char *, char **); char *PGTYPESnumeric_to_asc(numeric *, int); diff --git a/src/interfaces/ecpg/include/pgtypes_timestamp.h b/src/interfaces/ecpg/include/pgtypes_timestamp.h index 3b93a43e5a6..b6f1745a5e0 100644 --- a/src/interfaces/ecpg/include/pgtypes_timestamp.h +++ b/src/interfaces/ecpg/include/pgtypes_timestamp.h @@ -13,7 +13,7 @@ typedef double TimestampTz; #endif #ifdef __cplusplus -extern "C" +extern "C" { #endif diff --git a/src/interfaces/ecpg/include/sql3types.h b/src/interfaces/ecpg/include/sql3types.h index 56366e204c8..6909f2cde08 100644 --- a/src/interfaces/ecpg/include/sql3types.h +++ b/src/interfaces/ecpg/include/sql3types.h @@ -5,7 +5,7 @@ * * Copyright (c) 2000, Christof Petig <christof.petig@wtal.de> * - * $PostgreSQL: pgsql/src/interfaces/ecpg/include/sql3types.h,v 1.9 2003/11/29 19:52:08 pgsql Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/include/sql3types.h,v 1.10 2004/08/29 05:06:59 momjian Exp $ */ /* chapter 13.1 table 2: Codes used for SQL data types in Dynamic SQL */ @@ -45,4 +45,4 @@ enum * standard) */ }; -#endif /* !_ECPG_SQL3TYPES_H */ +#endif /* !_ECPG_SQL3TYPES_H */ diff --git a/src/interfaces/ecpg/include/sqltypes.h b/src/interfaces/ecpg/include/sqltypes.h index 522e6977aa6..f93bd41f8e0 100644 --- a/src/interfaces/ecpg/include/sqltypes.h +++ b/src/interfaces/ecpg/include/sqltypes.h @@ -27,4 +27,4 @@ #define CLVCHARPTRTYPE 124 #define CTYPEMAX 25 -#endif /* ndef ECPG_SQLTYPES_H */ +#endif /* ndef ECPG_SQLTYPES_H */ diff --git a/src/interfaces/ecpg/pgtypeslib/datetime.c b/src/interfaces/ecpg/pgtypeslib/datetime.c index a8a26cd4439..cc8788af578 100644 --- a/src/interfaces/ecpg/pgtypeslib/datetime.c +++ b/src/interfaces/ecpg/pgtypeslib/datetime.c @@ -124,8 +124,8 @@ int PGTYPESdate_dayofweek(date dDate) { /* - * Sunday: 0 Monday: 1 Tuesday: 2 Wednesday: 3 - * Thursday: 4 Friday: 5 Saturday: 6 + * Sunday: 0 Monday: 1 Tuesday: 2 Wednesday: 3 Thursday: + * 4 Friday: 5 Saturday: 6 */ return (int) (dDate + date2j(2000, 1, 1) + 1) % 7; } diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c index f906b449b08..a5a13f8b537 100644 --- a/src/interfaces/ecpg/pgtypeslib/dt_common.c +++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c @@ -2729,7 +2729,7 @@ int PGTYPEStimestamp_defmt_scan(char **, char *, timestamp *, int *, int *, int int *, int *, int *, int *); int -PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d, +PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d, int *year, int *month, int *day, int *hour, int *minute, int *second, int *tz) diff --git a/src/interfaces/ecpg/pgtypeslib/interval.c b/src/interfaces/ecpg/pgtypeslib/interval.c index e1d34e8a7b2..39576bf369e 100644 --- a/src/interfaces/ecpg/pgtypeslib/interval.c +++ b/src/interfaces/ecpg/pgtypeslib/interval.c @@ -720,7 +720,7 @@ interval2tm(interval span, struct tm * tm, fsec_t *fsec) } /* interval2tm() */ static int -tm2interval(struct tm * tm, fsec_t fsec, interval *span) +tm2interval(struct tm * tm, fsec_t fsec, interval * span) { span->month = ((tm->tm_year * 12) + tm->tm_mon); #ifdef HAVE_INT64_TIMESTAMP @@ -797,7 +797,7 @@ PGTYPESinterval_from_asc(char *str, char **endptr) } char * -PGTYPESinterval_to_asc(interval *span) +PGTYPESinterval_to_asc(interval * span) { struct tm tt, *tm = &tt; @@ -821,7 +821,7 @@ PGTYPESinterval_to_asc(interval *span) } int -PGTYPESinterval_copy(interval *intvlsrc, interval *intrcldest) +PGTYPESinterval_copy(interval * intvlsrc, interval * intrcldest) { intrcldest->time = intvlsrc->time; intrcldest->month = intvlsrc->month; diff --git a/src/interfaces/ecpg/pgtypeslib/numeric.c b/src/interfaces/ecpg/pgtypeslib/numeric.c index b06b8d14e56..a79d8bcf90c 100644 --- a/src/interfaces/ecpg/pgtypeslib/numeric.c +++ b/src/interfaces/ecpg/pgtypeslib/numeric.c @@ -28,7 +28,7 @@ * ---------- */ static int -apply_typmod(numeric *var, long typmod) +apply_typmod(numeric * var, long typmod) { int precision; int scale; @@ -108,7 +108,7 @@ apply_typmod(numeric *var, long typmod) * ---------- */ static int -alloc_var(numeric *var, int ndigits) +alloc_var(numeric * var, int ndigits) { digitbuf_free(var->buf); var->buf = digitbuf_alloc(ndigits + 1); @@ -141,7 +141,7 @@ PGTYPESnumeric_new(void) * ---------- */ static int -set_var_from_str(char *str, char **ptr, numeric *dest) +set_var_from_str(char *str, char **ptr, numeric * dest) { bool have_dp = FALSE; int i = 0; @@ -271,7 +271,7 @@ set_var_from_str(char *str, char **ptr, numeric *dest) * ---------- */ static char * -get_str_from_var(numeric *var, int dscale) +get_str_from_var(numeric * var, int dscale) { char *str; char *cp; @@ -385,7 +385,7 @@ PGTYPESnumeric_from_asc(char *str, char **endptr) } char * -PGTYPESnumeric_to_asc(numeric *num, int dscale) +PGTYPESnumeric_to_asc(numeric * num, int dscale) { if (dscale < 0) dscale = num->dscale; @@ -401,7 +401,7 @@ PGTYPESnumeric_to_asc(numeric *num, int dscale) * ---------- */ static void -zero_var(numeric *var) +zero_var(numeric * var) { digitbuf_free(var->buf); var->buf = NULL; @@ -412,7 +412,7 @@ zero_var(numeric *var) } void -PGTYPESnumeric_free(numeric *var) +PGTYPESnumeric_free(numeric * var) { digitbuf_free(var->buf); free(var); @@ -428,7 +428,7 @@ PGTYPESnumeric_free(numeric *var) * ---------- */ static int -cmp_abs(numeric *var1, numeric *var2) +cmp_abs(numeric * var1, numeric * var2) { int i1 = 0; int i2 = 0; @@ -486,7 +486,7 @@ cmp_abs(numeric *var1, numeric *var2) * ---------- */ static int -add_abs(numeric *var1, numeric *var2, numeric *result) +add_abs(numeric * var1, numeric * var2, numeric * result) { NumericDigit *res_buf; NumericDigit *res_digits; @@ -574,7 +574,7 @@ add_abs(numeric *var1, numeric *var2, numeric *result) * ---------- */ static int -sub_abs(numeric *var1, numeric *var2, numeric *result) +sub_abs(numeric * var1, numeric * var2, numeric * result) { NumericDigit *res_buf; NumericDigit *res_digits; @@ -658,7 +658,7 @@ sub_abs(numeric *var1, numeric *var2, numeric *result) * ---------- */ int -PGTYPESnumeric_add(numeric *var1, numeric *var2, numeric *result) +PGTYPESnumeric_add(numeric * var1, numeric * var2, numeric * result) { /* * Decide on the signs of the two variables what to do @@ -787,7 +787,7 @@ PGTYPESnumeric_add(numeric *var1, numeric *var2, numeric *result) * ---------- */ int -PGTYPESnumeric_sub(numeric *var1, numeric *var2, numeric *result) +PGTYPESnumeric_sub(numeric * var1, numeric * var2, numeric * result) { /* * Decide on the signs of the two variables what to do @@ -918,7 +918,7 @@ PGTYPESnumeric_sub(numeric *var1, numeric *var2, numeric *result) * ---------- */ int -PGTYPESnumeric_mul(numeric *var1, numeric *var2, numeric *result) +PGTYPESnumeric_mul(numeric * var1, numeric * var2, numeric * result) { NumericDigit *res_buf; NumericDigit *res_digits; @@ -1009,7 +1009,7 @@ PGTYPESnumeric_mul(numeric *var1, numeric *var2, numeric *result) * Note that this must be called before div_var. */ static int -select_div_scale(numeric *var1, numeric *var2, int *rscale) +select_div_scale(numeric * var1, numeric * var2, int *rscale) { int weight1, weight2, @@ -1076,7 +1076,7 @@ select_div_scale(numeric *var1, numeric *var2, int *rscale) } int -PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result) +PGTYPESnumeric_div(numeric * var1, numeric * var2, numeric * result) { NumericDigit *res_digits; int res_ndigits; @@ -1282,7 +1282,7 @@ PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result) int -PGTYPESnumeric_cmp(numeric *var1, numeric *var2) +PGTYPESnumeric_cmp(numeric * var1, numeric * var2) { /* use cmp_abs function to calculate the result */ @@ -1313,7 +1313,7 @@ PGTYPESnumeric_cmp(numeric *var1, numeric *var2) } int -PGTYPESnumeric_from_int(signed int int_val, numeric *var) +PGTYPESnumeric_from_int(signed int int_val, numeric * var) { /* implicit conversion */ signed long int long_int = int_val; @@ -1322,7 +1322,7 @@ PGTYPESnumeric_from_int(signed int int_val, numeric *var) } int -PGTYPESnumeric_from_long(signed long int long_val, numeric *var) +PGTYPESnumeric_from_long(signed long int long_val, numeric * var) { /* calculate the size of the long int number */ /* a number n needs log_10 n digits */ @@ -1351,9 +1351,9 @@ PGTYPESnumeric_from_long(signed long int long_val, numeric *var) { size++; reach_limit *= 10; - } while ((reach_limit - 1) < abs_long_val && reach_limit <= LONG_MAX/10); + } while ((reach_limit - 1) < abs_long_val && reach_limit <= LONG_MAX / 10); - if (reach_limit > LONG_MAX/10) + if (reach_limit > LONG_MAX / 10) { /* add the first digit and a .0 */ size += 2; @@ -1392,11 +1392,12 @@ PGTYPESnumeric_from_long(signed long int long_val, numeric *var) } int -PGTYPESnumeric_copy(numeric *src, numeric *dst) +PGTYPESnumeric_copy(numeric * src, numeric * dst) { int i; - if ( dst == NULL ) return -1; + if (dst == NULL) + return -1; zero_var(dst); dst->weight = src->weight; @@ -1414,7 +1415,7 @@ PGTYPESnumeric_copy(numeric *src, numeric *dst) } int -PGTYPESnumeric_from_double(double d, numeric *dst) +PGTYPESnumeric_from_double(double d, numeric * dst) { char buffer[100]; numeric *tmp; @@ -1431,7 +1432,7 @@ PGTYPESnumeric_from_double(double d, numeric *dst) } static int -numericvar_to_double_no_overflow(numeric *var, double *dp) +numericvar_to_double_no_overflow(numeric * var, double *dp) { char *tmp; double val; @@ -1455,7 +1456,7 @@ numericvar_to_double_no_overflow(numeric *var, double *dp) } int -PGTYPESnumeric_to_double(numeric *nv, double *dp) +PGTYPESnumeric_to_double(numeric * nv, double *dp) { double tmp; int i; @@ -1467,7 +1468,7 @@ PGTYPESnumeric_to_double(numeric *nv, double *dp) } int -PGTYPESnumeric_to_int(numeric *nv, int *ip) +PGTYPESnumeric_to_int(numeric * nv, int *ip) { long l; int i; @@ -1486,7 +1487,7 @@ PGTYPESnumeric_to_int(numeric *nv, int *ip) } int -PGTYPESnumeric_to_long(numeric *nv, long *lp) +PGTYPESnumeric_to_long(numeric * nv, long *lp) { int i; long l = 0; @@ -1514,7 +1515,7 @@ PGTYPESnumeric_to_long(numeric *nv, long *lp) } int -PGTYPESnumeric_to_decimal(numeric *src, decimal * dst) +PGTYPESnumeric_to_decimal(numeric * src, decimal * dst) { int i; @@ -1537,7 +1538,7 @@ PGTYPESnumeric_to_decimal(numeric *src, decimal * dst) } int -PGTYPESnumeric_from_decimal(decimal * src, numeric *dst) +PGTYPESnumeric_from_decimal(decimal * src, numeric * dst) { int i; diff --git a/src/interfaces/ecpg/pgtypeslib/timestamp.c b/src/interfaces/ecpg/pgtypeslib/timestamp.c index 19146d03e10..671d42e67d2 100644 --- a/src/interfaces/ecpg/pgtypeslib/timestamp.c +++ b/src/interfaces/ecpg/pgtypeslib/timestamp.c @@ -50,14 +50,15 @@ dt2local(timestamp dt, int tz) * Returns -1 on failure (overflow). */ int -tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp *result) +tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp * result) { #ifdef HAVE_INT64_TIMESTAMP - int dDate; + int dDate; int64 time; #else - double dDate, time; + double dDate, + time; #endif /* Julian day routines are not correct for negative Julian days */ @@ -142,11 +143,13 @@ static int timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn) { #ifdef HAVE_INT64_TIMESTAMP - int dDate, date0; + int dDate, + date0; int64 time; #else - double dDate, date0; + double dDate, + date0; double time; #endif time_t utime; @@ -337,7 +340,10 @@ PGTYPEStimestamp_from_asc(char *str, char **endptr) /* AdjustTimestampForTypmod(&result, typmod); */ - /* Since it's difficult to test for noresult, make sure errno is 0 if no error occured. */ + /* + * Since it's difficult to test for noresult, make sure errno is 0 if + * no error occured. + */ errno = 0; return result; } @@ -366,7 +372,7 @@ PGTYPEStimestamp_to_asc(timestamp tstamp) } void -PGTYPEStimestamp_current(timestamp *ts) +PGTYPEStimestamp_current(timestamp * ts) { struct tm tm; @@ -376,7 +382,7 @@ PGTYPEStimestamp_current(timestamp *ts) } static int -dttofmtasc_replace(timestamp *ts, date dDate, int dow, struct tm * tm, +dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm * tm, char *output, int *pstr_len, char *fmtstr) { union un_fmt_comb replace_val; @@ -766,7 +772,7 @@ dttofmtasc_replace(timestamp *ts, date dDate, int dow, struct tm * tm, int -PGTYPEStimestamp_fmt_asc(timestamp *ts, char *output, int str_len, char *fmtstr) +PGTYPEStimestamp_fmt_asc(timestamp * ts, char *output, int str_len, char *fmtstr) { struct tm tm; fsec_t fsec; @@ -781,7 +787,7 @@ PGTYPEStimestamp_fmt_asc(timestamp *ts, char *output, int str_len, char *fmtstr) } int -PGTYPEStimestamp_sub(timestamp *ts1, timestamp *ts2, interval *iv) +PGTYPEStimestamp_sub(timestamp * ts1, timestamp * ts2, interval * iv) { if (TIMESTAMP_NOT_FINITE(*ts1) || TIMESTAMP_NOT_FINITE(*ts2)) return PGTYPES_TS_ERR_EINFTIME; @@ -798,7 +804,7 @@ PGTYPEStimestamp_sub(timestamp *ts1, timestamp *ts2, interval *iv) } int -PGTYPEStimestamp_defmt_asc(char *str, char *fmt, timestamp *d) +PGTYPEStimestamp_defmt_asc(char *str, char *fmt, timestamp * d) { int year, month, diff --git a/src/interfaces/ecpg/preproc/descriptor.c b/src/interfaces/ecpg/preproc/descriptor.c index 43193364b47..7ba6aa520d7 100644 --- a/src/interfaces/ecpg/preproc/descriptor.c +++ b/src/interfaces/ecpg/preproc/descriptor.c @@ -315,10 +315,10 @@ struct variable * descriptor_variable(const char *name, int input) { static char descriptor_names[2][MAX_DESCRIPTOR_NAMELEN]; - static const struct ECPGtype descriptor_type = { ECPGt_descriptor, 0 }; + static const struct ECPGtype descriptor_type = {ECPGt_descriptor, 0}; static const struct variable varspace[2] = { - { descriptor_names[0], (struct ECPGtype *) & descriptor_type, 0, NULL }, - { descriptor_names[1], (struct ECPGtype *) & descriptor_type, 0, NULL } + {descriptor_names[0], (struct ECPGtype *) & descriptor_type, 0, NULL}, + {descriptor_names[1], (struct ECPGtype *) & descriptor_type, 0, NULL} }; strncpy(descriptor_names[input], name, MAX_DESCRIPTOR_NAMELEN); diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c index 5592b42a79d..9d0648289cf 100644 --- a/src/interfaces/ecpg/preproc/ecpg.c +++ b/src/interfaces/ecpg/preproc/ecpg.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.89 2004/07/20 18:06:41 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.90 2004/08/29 05:07:00 momjian Exp $ */ /* New main for ecpg, the PostgreSQL embedded SQL precompiler. */ /* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */ @@ -121,9 +121,9 @@ main(int argc, char *const argv[]) out_option = 0; struct _include_path *ip; const char *progname; - char my_exec_path[MAXPGPATH]; - char include_path[MAXPGPATH]; - + char my_exec_path[MAXPGPATH]; + char include_path[MAXPGPATH]; + progname = get_progname(argv[0]); if (argc > 1) @@ -180,9 +180,9 @@ main(int argc, char *const argv[]) case 'C': if (strncmp(optarg, "INFORMIX", strlen("INFORMIX")) == 0) { - char pkginclude_path[MAXPGPATH]; - char informix_path[MAXPGPATH]; - + char pkginclude_path[MAXPGPATH]; + char informix_path[MAXPGPATH]; + compat = (strcmp(optarg, "INFORMIX") == 0) ? ECPG_COMPAT_INFORMIX : ECPG_COMPAT_INFORMIX_SE; /* system_includes = true; */ add_preprocessor_define("dec_t=decimal"); @@ -281,7 +281,7 @@ main(int argc, char *const argv[]) ptr2ext[0] = '.'; ptr2ext[1] = 'p'; ptr2ext[2] = 'g'; - ptr2ext[3] = (header_mode == true)? 'h' : 'c'; + ptr2ext[3] = (header_mode == true) ? 'h' : 'c'; ptr2ext[4] = '\0'; } @@ -298,7 +298,7 @@ main(int argc, char *const argv[]) ptr2ext = strrchr(output_filename, '.'); /* make extension = .c resp. .h */ - ptr2ext[1] = (header_mode == true)? 'h' : 'c'; + ptr2ext[1] = (header_mode == true) ? 'h' : 'c'; ptr2ext[2] = '\0'; yyout = fopen(output_filename, PG_BINARY_W); @@ -403,7 +403,7 @@ main(int argc, char *const argv[]) /* we need several includes */ /* but not if we are in header mode */ fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL); - + if (header_mode == false) { fprintf(yyout, "/* These include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n#include <ecpgerrno.h>\n#include <sqlca.h>\n"); @@ -416,24 +416,27 @@ main(int argc, char *const argv[]) } fprintf(yyout, "#line 1 \"%s\"\n", input_filename); - + /* and parse the source */ yyparse(); /* check if all cursors were indeed opened */ for (ptr = cur; ptr != NULL;) { - char errortext[128]; - + char errortext[128]; + if (!(ptr->opened)) { - /* Does not really make sense to declare a cursor but not open it */ + /* + * Does not really make sense to declare a cursor + * but not open it + */ snprintf(errortext, sizeof(errortext), "cursor `%s´ has been declared but ot opened\n", ptr->name); mmerror(PARSE_ERROR, ET_WARNING, errortext); } ptr = ptr->next; } - + if (yyin != NULL && yyin != stdin) fclose(yyin); if (out_option == 0 && yyout != stdout) diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h index 6f9518f7e61..06cc74f2040 100644 --- a/src/interfaces/ecpg/preproc/extern.h +++ b/src/interfaces/ecpg/preproc/extern.h @@ -62,7 +62,7 @@ extern int yylex(void); extern void yyerror(char *); extern void *mm_alloc(size_t), *mm_realloc(void *, size_t); extern char *mm_strdup(const char *); -extern void mmerror(int, enum errortype, char *, ...); +extern void mmerror(int, enum errortype, char *,...); extern ScanKeyword *ScanECPGKeywordLookup(char *); extern ScanKeyword *ScanCKeywordLookup(char *); extern void output_get_descr_header(char *); diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c index 77caff9ac2a..24185222046 100644 --- a/src/interfaces/ecpg/preproc/type.c +++ b/src/interfaces/ecpg/preproc/type.c @@ -47,7 +47,11 @@ ECPGstruct_member_dup(struct ECPGstruct_member * rm) type = ECPGmake_struct_type(rm->type->u.members, rm->type->type, rm->type->struct_sizeof); break; case ECPGt_array: - /* if this array does contain a struct again, we have to create the struct too */ + + /* + * if this array does contain a struct again, we have to + * create the struct too + */ if (rm->type->u.element->type == ECPGt_struct) type = ECPGmake_struct_type(rm->type->u.element->u.members, rm->type->u.element->type, rm->type->u.element->struct_sizeof); else diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h index 9aab463aa1c..1a5471fe153 100644 --- a/src/interfaces/ecpg/preproc/type.h +++ b/src/interfaces/ecpg/preproc/type.h @@ -115,7 +115,7 @@ struct cursor char *name; char *command; char *connection; - bool opened; + bool opened; struct arguments *argsinsert; struct arguments *argsresult; struct cursor *next; @@ -123,28 +123,28 @@ struct cursor struct typedefs { - char *name; - struct this_type *type; - struct ECPGstruct_member *struct_member_list; - int brace_level; - struct typedefs *next; + char *name; + struct this_type *type; + struct ECPGstruct_member *struct_member_list; + int brace_level; + struct typedefs *next; }; struct _defines { - char *old; - char *new; - int pertinent; - void *used; + char *old; + char *new; + int pertinent; + void *used; struct _defines *next; }; /* This is a linked list of the variable names and types. */ struct variable { - char *name; + char *name; struct ECPGtype *type; - int brace_level; + int brace_level; struct variable *next; }; diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c index 207d2647718..6037d978c70 100644 --- a/src/interfaces/ecpg/preproc/variable.c +++ b/src/interfaces/ecpg/preproc/variable.c @@ -267,7 +267,7 @@ remove_typedefs(int brace_level) else prev->next = p->next; - if (p->type->type_enum == ECPGt_struct || p->type->type_enum == ECPGt_union) + if (p->type->type_enum == ECPGt_struct || p->type->type_enum == ECPGt_union) free(p->struct_member_list); free(p->type); free(p->name); @@ -366,7 +366,7 @@ reset_variables(void) argsresult = NULL; } -/* Insert a new variable into our request list. +/* Insert a new variable into our request list. * Note: The list is dumped from the end, * so we have to add new entries at the beginning */ void @@ -554,9 +554,10 @@ adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *ty * given bounds */ if (atoi(*dimension) < 0 && !type_definition) + /* - * do not change this for typedefs - * since it will be changed later on when the variable is defined + * do not change this for typedefs since it will be + * changed later on when the variable is defined */ *length = make_str("1"); else if (atoi(*dimension) == 0) |