From 0754b391f30e17fde9d7d14d5e0eb458fc02289a Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Wed, 20 May 2009 16:13:18 +0000 Subject: [PATCH] Removed some unneeded variables and comparisons --- src/interfaces/ecpg/ecpglib/execute.c | 6 ++-- src/interfaces/ecpg/ecpglib/extern.h | 6 ++-- src/interfaces/ecpg/ecpglib/prepare.c | 18 +++++----- src/interfaces/ecpg/include/ecpglib.h | 4 +-- src/interfaces/ecpg/pgtypeslib/datetime.c | 4 +-- src/interfaces/ecpg/pgtypeslib/dt.h | 6 ++-- src/interfaces/ecpg/pgtypeslib/dt_common.c | 34 +++++++++---------- src/interfaces/ecpg/pgtypeslib/interval.c | 8 ++--- src/interfaces/ecpg/pgtypeslib/timestamp.c | 4 +-- .../ecpg/test/expected/sql-code100.c | 2 +- .../ecpg/test/expected/thread-alloc.c | 2 +- .../ecpg/test/expected/thread-descriptor.c | 2 +- src/interfaces/ecpg/test/sql/code100.pgc | 2 +- src/interfaces/ecpg/test/thread/alloc.pgc | 2 +- .../ecpg/test/thread/descriptor.pgc | 2 +- 15 files changed, 52 insertions(+), 50 deletions(-) diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 97524f82d1..9363b5668f 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.82 2009/02/03 08:55:45 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.83 2009/05/20 16:13:18 meskes Exp $ */ /* * The aim is to get a simpler inteface to the database routines. @@ -1501,7 +1501,7 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char */ if (statement_type == ECPGst_prepnormal) { - if (!ecpg_auto_prepare(lineno, connection_name, compat, questionmarks, &prepname, query)) + if (!ecpg_auto_prepare(lineno, connection_name, compat, &prepname, query)) return (false); /* @@ -1519,7 +1519,7 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char if (statement_type == ECPGst_execute) { /* if we have an EXECUTE command, only the name is send */ - char *command = ecpg_prepared(stmt->command, con, lineno); + char *command = ecpg_prepared(stmt->command, con); if (command) { diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h index 41098903ec..dab33e337b 100644 --- a/src/interfaces/ecpg/ecpglib/extern.h +++ b/src/interfaces/ecpg/ecpglib/extern.h @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.34 2008/02/07 11:09:12 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.35 2009/05/20 16:13:18 meskes Exp $ */ #ifndef _ECPG_LIB_EXTERN_H #define _ECPG_LIB_EXTERN_H @@ -143,10 +143,10 @@ bool ecpg_store_input(const int, const bool, const struct variable *, char **, bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE); void ecpg_raise(int line, int code, const char *sqlstate, const char *str); void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat); -char *ecpg_prepared(const char *, struct connection *, int); +char *ecpg_prepared(const char *, struct connection *); bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection * conn); void ecpg_log(const char *format,...); -bool ecpg_auto_prepare(int, const char *, int, const int, char **, const char *); +bool ecpg_auto_prepare(int, const char *, const int, char **, const char *); void ecpg_init_sqlca(struct sqlca_t * sqlca); /* SQLSTATE values generated or processed by ecpglib (intentionally diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c index f6a88d877a..637d77b206 100644 --- a/src/interfaces/ecpg/ecpglib/prepare.c +++ b/src/interfaces/ecpg/ecpglib/prepare.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.29 2008/05/16 15:20:03 petere Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.30 2009/05/20 16:13:18 meskes Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -56,7 +56,7 @@ isvarchar(unsigned char c) } static bool -replace_variables(char **text, int lineno, bool questionmarks) +replace_variables(char **text, int lineno) { bool string = false; int counter = 1, @@ -110,8 +110,9 @@ replace_variables(char **text, int lineno, bool questionmarks) } /* handle the EXEC SQL PREPARE statement */ +/* questionmarks is not needed but remians in there for the time being to not change the API */ bool -ECPGprepare(int lineno, const char *connection_name, const int questionmarks, const char *name, const char *variable) +ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable) { struct connection *con; struct statement *stmt; @@ -148,7 +149,7 @@ ECPGprepare(int lineno, const char *connection_name, const int questionmarks, co stmt->inlist = stmt->outlist = NULL; /* if we have C variables in our statment replace them with '?' */ - replace_variables(&(stmt->command), lineno, questionmarks); + replace_variables(&(stmt->command), lineno); /* add prepared statement to our list */ this->name = (char *) name; @@ -290,7 +291,7 @@ ECPGdeallocate_all(int lineno, int compat, const char *connection_name) } char * -ecpg_prepared(const char *name, struct connection * con, int lineno) +ecpg_prepared(const char *name, struct connection * con) { struct prepared_statement *this; @@ -299,10 +300,11 @@ ecpg_prepared(const char *name, struct connection * con, int lineno) } /* return the prepared statement */ +/* lineno is not used here, but kept in to not break API */ char * ECPGprepared_statement(const char *connection_name, const char *name, int lineno) { - return ecpg_prepared(name, ecpg_get_connection(connection_name), lineno); + return ecpg_prepared(name, ecpg_get_connection(connection_name)); } /* @@ -460,7 +462,7 @@ AddStmtToCache(int lineno, /* line # of statement */ /* handle cache and preparation of statments in auto-prepare mode */ bool -ecpg_auto_prepare(int lineno, const char *connection_name, int compat, const int questionmarks, char **name, const char *query) +ecpg_auto_prepare(int lineno, const char *connection_name, int compat, char **name, const char *query) { int entNo; @@ -481,7 +483,7 @@ ecpg_auto_prepare(int lineno, const char *connection_name, int compat, const int *name = (char *) ecpg_alloc(STMTID_SIZE, lineno); sprintf(*name, "ecpg%d", nextStmtID++); - if (!ECPGprepare(lineno, connection_name, questionmarks, ecpg_strdup(*name, lineno), query)) + if (!ECPGprepare(lineno, connection_name, 0, ecpg_strdup(*name, lineno), query)) return (false); if (AddStmtToCache(lineno, *name, connection_name, compat, query) < 0) return (false); diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h index 8c682e5782..5830df8bdc 100644 --- a/src/interfaces/ecpg/include/ecpglib.h +++ b/src/interfaces/ecpg/include/ecpglib.h @@ -1,7 +1,7 @@ /* * this is a small part of c.h since we don't want to leak all postgres * definitions into ecpg programs - * $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpglib.h,v 1.77 2008/05/16 15:20:04 petere Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpglib.h,v 1.78 2009/05/20 16:13:18 meskes Exp $ */ #ifndef _ECPGLIB_H @@ -54,7 +54,7 @@ bool ECPGconnect(int, int, const char *, const char *, const char *, const char bool ECPGdo(const int, const int, const int, const char *, const bool, const int, const char *,...); bool ECPGtrans(int, const char *, const char *); bool ECPGdisconnect(int, const char *); -bool ECPGprepare(int, const char *, const int, const char *, const char *); +bool ECPGprepare(int, const char *, const bool, const char *, const char *); bool ECPGdeallocate(int, int, const char *, const char *); bool ECPGdeallocate_all(int, int, const char *); char *ECPGprepared_statement(const char *, const char *, int); diff --git a/src/interfaces/ecpg/pgtypeslib/datetime.c b/src/interfaces/ecpg/pgtypeslib/datetime.c index 9dc900e9b2..eae776bf23 100644 --- a/src/interfaces/ecpg/pgtypeslib/datetime.c +++ b/src/interfaces/ecpg/pgtypeslib/datetime.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.35 2009/02/04 08:51:09 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.36 2009/05/20 16:13:18 meskes Exp $ */ #include "postgres_fe.h" @@ -74,7 +74,7 @@ PGTYPESdate_from_asc(char *str, char **endptr) return INT_MIN; } - if (ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0 || + if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 || DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, EuroDates) != 0) { errno = PGTYPES_DATE_BAD_DATE; diff --git a/src/interfaces/ecpg/pgtypeslib/dt.h b/src/interfaces/ecpg/pgtypeslib/dt.h index ac0b136902..1da5b8cc52 100644 --- a/src/interfaces/ecpg/pgtypeslib/dt.h +++ b/src/interfaces/ecpg/pgtypeslib/dt.h @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.41 2009/02/04 08:51:09 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.42 2009/05/20 16:13:18 meskes Exp $ */ #ifndef DT_H #define DT_H @@ -334,7 +334,7 @@ do { \ int DecodeTimeOnly(char **, int *, int, int *, struct tm *, fsec_t *, int *); int DecodeInterval(char **, int *, int, int *, struct tm *, fsec_t *); -int DecodeTime(char *, int, int *, struct tm *, fsec_t *); +int DecodeTime(char *, int *, struct tm *, fsec_t *); int EncodeTimeOnly(struct tm *, fsec_t, int *, int, char *); int EncodeDateTime(struct tm *, fsec_t, int *, char **, int, char *, bool); int EncodeInterval(struct tm *, fsec_t, int, char *); @@ -343,7 +343,7 @@ int DecodeUnits(int field, char *lowtoken, int *val); bool CheckDateTokenTables(void); int EncodeDateOnly(struct tm *, int, char *, bool); int GetEpochTime(struct tm *); -int ParseDateTime(char *, char *, char **, int *, int, int *, char **); +int ParseDateTime(char *, char *, char **, int *, int *, char **); int DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, bool); void j2date(int, int *, int *, int *); void GetCurrentDateTime(struct tm *); diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c index a778960bc4..20e0a9d311 100644 --- a/src/interfaces/ecpg/pgtypeslib/dt_common.c +++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.48 2009/03/22 01:12:32 tgl Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.49 2009/05/20 16:13:18 meskes Exp $ */ #include "postgres_fe.h" @@ -1132,7 +1132,7 @@ dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec) */ static int DecodeNumberField(int len, char *str, int fmask, - int *tmask, struct tm * tm, fsec_t *fsec, int *is2digits, bool EuroDates) + int *tmask, struct tm * tm, fsec_t *fsec, int *is2digits) { char *cp; @@ -1258,7 +1258,7 @@ DecodeNumber(int flen, char *str, int fmask, */ if (cp - str > 2) return DecodeNumberField(flen, str, (fmask | DTK_DATE_M), - tmask, tm, fsec, is2digits, EuroDates); + tmask, tm, fsec, is2digits); *fsec = strtod(cp, &cp); if (*cp != '\0') @@ -1476,7 +1476,7 @@ DecodeDate(char *str, int fmask, int *tmask, struct tm * tm, bool EuroDates) * can be used to represent time spans. */ int -DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec) +DecodeTime(char *str, int *tmask, struct tm * tm, fsec_t *fsec) { char *cp; @@ -1640,7 +1640,7 @@ DecodePosixTimezone(char *str, int *tzp) */ int ParseDateTime(char *timestr, char *lowstr, - char **field, int *ftype, int maxfields, int *numfields, char **endstr) + char **field, int *ftype, int *numfields, char **endstr) { int nf = 0; char *lp = lowstr; @@ -1928,7 +1928,7 @@ DecodeDateTime(char **field, int *ftype, int nf, * time */ if ((ftype[i] = DecodeNumberField(strlen(field[i]), field[i], fmask, - &tmask, tm, fsec, &is2digits, EuroDates)) < 0) + &tmask, tm, fsec, &is2digits)) < 0) return -1; /* @@ -1951,7 +1951,7 @@ DecodeDateTime(char **field, int *ftype, int nf, break; case DTK_TIME: - if (DecodeTime(field[i], fmask, &tmask, tm, fsec) != 0) + if (DecodeTime(field[i], &tmask, tm, fsec) != 0) return -1; /* @@ -2116,7 +2116,7 @@ DecodeDateTime(char **field, int *ftype, int nf, case DTK_TIME: /* previous field was "t" for ISO time */ if ((ftype[i] = DecodeNumberField(strlen(field[i]), field[i], (fmask | DTK_DATE_M), - &tmask, tm, fsec, &is2digits, EuroDates)) < 0) + &tmask, tm, fsec, &is2digits)) < 0) return -1; if (tmask != DTK_TIME_M) @@ -2154,13 +2154,13 @@ DecodeDateTime(char **field, int *ftype, int nf, * Example: 20011223 or 040506 */ if ((ftype[i] = DecodeNumberField(flen, field[i], fmask, - &tmask, tm, fsec, &is2digits, EuroDates)) < 0) + &tmask, tm, fsec, &is2digits)) < 0) return -1; } else if (flen > 4) { if ((ftype[i] = DecodeNumberField(flen, field[i], fmask, - &tmask, tm, fsec, &is2digits, EuroDates)) < 0) + &tmask, tm, fsec, &is2digits)) < 0) return -1; } /* otherwise it is a single date/time field... */ @@ -2580,10 +2580,10 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d, int scan_type; char *pstr, - *pfmt, - *tmp; - int err = 1; - int j; + *pfmt, + *tmp; + int err = 1; + int j; struct tm tm; pfmt = fmt; @@ -2908,7 +2908,7 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d, pfmt++; scan_type = PGTYPES_TYPE_UINT; err = pgtypes_defmt_scan(&scan_val, scan_type, &pstr, pfmt); - if (scan_val.uint_val < 0 || scan_val.uint_val > 53) + if (scan_val.uint_val > 53) err = 1; break; case 'V': @@ -2922,14 +2922,14 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d, pfmt++; scan_type = PGTYPES_TYPE_UINT; err = pgtypes_defmt_scan(&scan_val, scan_type, &pstr, pfmt); - if (scan_val.uint_val < 0 || scan_val.uint_val > 6) + if (scan_val.uint_val > 6) err = 1; break; case 'W': pfmt++; scan_type = PGTYPES_TYPE_UINT; err = pgtypes_defmt_scan(&scan_val, scan_type, &pstr, pfmt); - if (scan_val.uint_val < 0 || scan_val.uint_val > 53) + if (scan_val.uint_val > 53) err = 1; break; case 'x': diff --git a/src/interfaces/ecpg/pgtypeslib/interval.c b/src/interfaces/ecpg/pgtypeslib/interval.c index 4b2c97f9d0..2ab84a38e0 100644 --- a/src/interfaces/ecpg/pgtypeslib/interval.c +++ b/src/interfaces/ecpg/pgtypeslib/interval.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/interval.c,v 1.39 2008/11/26 16:47:08 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/interval.c,v 1.40 2009/05/20 16:13:18 meskes Exp $ */ #include "postgres_fe.h" #include @@ -362,7 +362,7 @@ DecodeInterval(char **field, int *ftype, int nf, /*int range,*/ switch (ftype[i]) { case DTK_TIME: - dterr = DecodeTime(field[i], fmask, /* range, */ + dterr = DecodeTime(field[i], /* range, */ &tmask, tm, fsec); if (dterr) return dterr; @@ -384,7 +384,7 @@ DecodeInterval(char **field, int *ftype, int nf, /*int range,*/ * and signed year-month values. */ if (strchr(field[i] + 1, ':') != NULL && - DecodeTime(field[i] + 1, fmask, /* INTERVAL_FULL_RANGE, */ + DecodeTime(field[i] + 1, /* INTERVAL_FULL_RANGE, */ &tmask, tm, fsec) == 0) { if (*field[i] == '-') @@ -1096,7 +1096,7 @@ PGTYPESinterval_from_asc(char *str, char **endptr) return NULL; } - if (ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0 || + if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 || (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0 && DecodeISO8601Interval(str, &dtype, tm, &fsec) != 0)) { diff --git a/src/interfaces/ecpg/pgtypeslib/timestamp.c b/src/interfaces/ecpg/pgtypeslib/timestamp.c index e4ff8b664e..ff44a85756 100644 --- a/src/interfaces/ecpg/pgtypeslib/timestamp.c +++ b/src/interfaces/ecpg/pgtypeslib/timestamp.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/timestamp.c,v 1.43 2009/02/04 08:51:10 meskes Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/timestamp.c,v 1.44 2009/05/20 16:13:18 meskes Exp $ */ #include "postgres_fe.h" @@ -302,7 +302,7 @@ PGTYPEStimestamp_from_asc(char *str, char **endptr) return (noresult); } - if (ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0 || + if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 || DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, 0) != 0) { errno = PGTYPES_TS_BAD_TIMESTAMP; diff --git a/src/interfaces/ecpg/test/expected/sql-code100.c b/src/interfaces/ecpg/test/expected/sql-code100.c index 2fc320d5c0..e250690e9c 100644 --- a/src/interfaces/ecpg/test/expected/sql-code100.c +++ b/src/interfaces/ecpg/test/expected/sql-code100.c @@ -92,7 +92,7 @@ struct sqlca_t *ECPGget_sqlca(void); -int main(int argc, char **argv) +int main() { /* exec sql begin declare section */ diff --git a/src/interfaces/ecpg/test/expected/thread-alloc.c b/src/interfaces/ecpg/test/expected/thread-alloc.c index 2cb8bde4f4..b99b868001 100644 --- a/src/interfaces/ecpg/test/expected/thread-alloc.c +++ b/src/interfaces/ecpg/test/expected/thread-alloc.c @@ -185,7 +185,7 @@ if (sqlca.sqlcode < 0) sqlprint();} return 0; } -int main (int argc, char** argv) +int main () { int i; #ifdef WIN32 diff --git a/src/interfaces/ecpg/test/expected/thread-descriptor.c b/src/interfaces/ecpg/test/expected/thread-descriptor.c index d842e8a38b..2584626f4f 100644 --- a/src/interfaces/ecpg/test/expected/thread-descriptor.c +++ b/src/interfaces/ecpg/test/expected/thread-descriptor.c @@ -126,7 +126,7 @@ if (sqlca.sqlcode < 0) sqlprint(); return 0; } -int main (int argc, char** argv) +int main () { #ifdef ENABLE_THREAD_SAFETY int i; diff --git a/src/interfaces/ecpg/test/sql/code100.pgc b/src/interfaces/ecpg/test/sql/code100.pgc index 69614534fe..2ae6d15ead 100644 --- a/src/interfaces/ecpg/test/sql/code100.pgc +++ b/src/interfaces/ecpg/test/sql/code100.pgc @@ -4,7 +4,7 @@ exec sql include sqlca; exec sql include ../regression; -int main(int argc, char **argv) +int main() { exec sql begin declare section; int index; exec sql end declare section; diff --git a/src/interfaces/ecpg/test/thread/alloc.pgc b/src/interfaces/ecpg/test/thread/alloc.pgc index 1b28d3a5b6..220dc43fb8 100644 --- a/src/interfaces/ecpg/test/thread/alloc.pgc +++ b/src/interfaces/ecpg/test/thread/alloc.pgc @@ -57,7 +57,7 @@ static void* fn(void* arg) return 0; } -int main (int argc, char** argv) +int main () { int i; #ifdef WIN32 diff --git a/src/interfaces/ecpg/test/thread/descriptor.pgc b/src/interfaces/ecpg/test/thread/descriptor.pgc index 9560d105b6..e07a5e22b7 100644 --- a/src/interfaces/ecpg/test/thread/descriptor.pgc +++ b/src/interfaces/ecpg/test/thread/descriptor.pgc @@ -33,7 +33,7 @@ static void* fn(void* arg) return 0; } -int main (int argc, char** argv) +int main () { #ifdef ENABLE_THREAD_SAFETY int i;