diff options
author | Bruce Momjian <bruce@momjian.us> | 2001-03-22 04:01:46 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2001-03-22 04:01:46 +0000 |
commit | 9e1552607a9dc6bc23e43d46770a9063ade4f3f0 (patch) | |
tree | 6a230d81917ebc004e40cd46c48f2aa27eec153e /src/interfaces/ecpg/lib | |
parent | 6cf8707b828b14b5c2336076ce358b18b67829d6 (diff) | |
download | postgresql-9e1552607a9dc6bc23e43d46770a9063ade4f3f0.tar.gz postgresql-9e1552607a9dc6bc23e43d46770a9063ade4f3f0.zip |
pgindent run. Make it all clean.
Diffstat (limited to 'src/interfaces/ecpg/lib')
-rw-r--r-- | src/interfaces/ecpg/lib/connect.c | 331 | ||||
-rw-r--r-- | src/interfaces/ecpg/lib/data.c | 80 | ||||
-rw-r--r-- | src/interfaces/ecpg/lib/descriptor.c | 4 | ||||
-rw-r--r-- | src/interfaces/ecpg/lib/error.c | 19 | ||||
-rw-r--r-- | src/interfaces/ecpg/lib/execute.c | 86 | ||||
-rw-r--r-- | src/interfaces/ecpg/lib/extern.h | 14 | ||||
-rw-r--r-- | src/interfaces/ecpg/lib/typename.c | 39 |
7 files changed, 315 insertions, 258 deletions
diff --git a/src/interfaces/ecpg/lib/connect.c b/src/interfaces/ecpg/lib/connect.c index a7804f8ec9b..eac4fcc028e 100644 --- a/src/interfaces/ecpg/lib/connect.c +++ b/src/interfaces/ecpg/lib/connect.c @@ -27,8 +27,9 @@ ecpg_finish(struct connection * act) { if (act != NULL) { - struct ECPGtype_information_cache *cache, *ptr; - + struct ECPGtype_information_cache *cache, + *ptr; + ECPGlog("ecpg_finish: finishing %s.\n", act->name); PQfinish(act->connection); @@ -115,114 +116,141 @@ ECPGnoticeProcessor_raise(int code, const char *message) { sqlca.sqlcode = code; strncpy(sqlca.sqlerrm.sqlerrmc, message, sizeof(sqlca.sqlerrm.sqlerrmc)); - sqlca.sqlerrm.sqlerrmc[sizeof(sqlca.sqlerrm.sqlerrmc)-1]=0; + sqlca.sqlerrm.sqlerrmc[sizeof(sqlca.sqlerrm.sqlerrmc) - 1] = 0; sqlca.sqlerrm.sqlerrml = strlen(sqlca.sqlerrm.sqlerrmc); - + /* remove trailing newline */ - if (sqlca.sqlerrm.sqlerrml - && sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml-1]=='\n') + if (sqlca.sqlerrm.sqlerrml + && sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml - 1] == '\n') { - sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml-1]=0; + sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml - 1] = 0; sqlca.sqlerrm.sqlerrml--; } - - ECPGlog("raising sqlcode %d\n",code); + + ECPGlog("raising sqlcode %d\n", code); } -/* - * I know this is a mess, but we can't redesign the backend +/* + * I know this is a mess, but we can't redesign the backend */ static void ECPGnoticeProcessor(void *arg, const char *message) { - /* these notices raise an error */ - if (strncmp(message,"NOTICE: ",8)) + /* these notices raise an error */ + if (strncmp(message, "NOTICE: ", 8)) { ECPGlog("ECPGnoticeProcessor: strange notice '%s'\n", message); ECPGnoticeProcessor_raise(ECPG_NOTICE_UNRECOGNIZED, message); return; } - - message+=8; - while (*message==' ') message++; + + message += 8; + while (*message == ' ') + message++; ECPGlog("NOTICE: %s", message); - - /* NOTICE: (transaction aborted): queries ignored until END */ - /* NOTICE: current transaction is aborted, queries ignored until end of transaction block */ - if (strstr(message,"queries ignored") && strstr(message,"transaction") - && strstr(message,"aborted")) + + /* NOTICE: (transaction aborted): queries ignored until END */ + + /* + * NOTICE: current transaction is aborted, queries ignored until end + * of transaction block + */ + if (strstr(message, "queries ignored") && strstr(message, "transaction") + && strstr(message, "aborted")) { ECPGnoticeProcessor_raise(ECPG_NOTICE_QUERY_IGNORED, message); return; } - - /* NOTICE: PerformPortalClose: portal "*" not found */ - if ((!strncmp(message,"PerformPortalClose: portal",26) - || !strncmp(message,"PerformPortalFetch: portal",26)) - && strstr(message+26,"not found")) + + /* NOTICE: PerformPortalClose: portal "*" not found */ + if ((!strncmp(message, "PerformPortalClose: portal", 26) + || !strncmp(message, "PerformPortalFetch: portal", 26)) + && strstr(message + 26, "not found")) { ECPGnoticeProcessor_raise(ECPG_NOTICE_UNKNOWN_PORTAL, message); return; } - - /* NOTICE: BEGIN: already a transaction in progress */ - if (!strncmp(message,"BEGIN: already a transaction in progress",40)) + + /* NOTICE: BEGIN: already a transaction in progress */ + if (!strncmp(message, "BEGIN: already a transaction in progress", 40)) { ECPGnoticeProcessor_raise(ECPG_NOTICE_IN_TRANSACTION, message); return; } - - /* NOTICE: AbortTransaction and not in in-progress state */ - /* NOTICE: COMMIT: no transaction in progress */ - /* NOTICE: ROLLBACK: no transaction in progress */ - if (!strncmp(message,"AbortTransaction and not in in-progress state",45) - || !strncmp(message,"COMMIT: no transaction in progress",34) - || !strncmp(message,"ROLLBACK: no transaction in progress",36)) + + /* NOTICE: AbortTransaction and not in in-progress state */ + /* NOTICE: COMMIT: no transaction in progress */ + /* NOTICE: ROLLBACK: no transaction in progress */ + if (!strncmp(message, "AbortTransaction and not in in-progress state", 45) + || !strncmp(message, "COMMIT: no transaction in progress", 34) + || !strncmp(message, "ROLLBACK: no transaction in progress", 36)) { ECPGnoticeProcessor_raise(ECPG_NOTICE_NO_TRANSACTION, message); return; } - - /* NOTICE: BlankPortalAssignName: portal * already exists */ - if (!strncmp(message,"BlankPortalAssignName: portal",29) - && strstr(message+29,"already exists")) + + /* NOTICE: BlankPortalAssignName: portal * already exists */ + if (!strncmp(message, "BlankPortalAssignName: portal", 29) + && strstr(message + 29, "already exists")) { ECPGnoticeProcessor_raise(ECPG_NOTICE_PORTAL_EXISTS, message); return; } /* these are harmless - do nothing */ - /* NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index '*' for table '*' */ - /* NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s) */ - /* NOTICE: CREATE TABLE will create implicit sequence '*' for SERIAL column '*.*' */ - /* NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s) */ - if ((!strncmp(message,"CREATE TABLE",12) || !strncmp(message,"ALTER TABLE",11)) - && strstr(message+11,"will create implicit")) + + /* + * NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index '*' + * for table '*' + */ + + /* + * NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit + * trigger(s) for FOREIGN KEY check(s) + */ + + /* + * NOTICE: CREATE TABLE will create implicit sequence '*' for SERIAL + * column '*.*' + */ + + /* + * NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN + * KEY check(s) + */ + if ((!strncmp(message, "CREATE TABLE", 12) || !strncmp(message, "ALTER TABLE", 11)) + && strstr(message + 11, "will create implicit")) return; - - /* NOTICE: QUERY PLAN: */ - if (!strncmp(message,"QUERY PLAN:",11)) /* do we really see these? */ + + /* NOTICE: QUERY PLAN: */ + if (!strncmp(message, "QUERY PLAN:", 11)) /* do we really see these? */ return; - - /* NOTICE: DROP TABLE implicitly drops referential integrity trigger from table "*" */ - if (!strncmp(message,"DROP TABLE implicitly drops",27)) + + /* + * NOTICE: DROP TABLE implicitly drops referential integrity trigger + * from table "*" + */ + if (!strncmp(message, "DROP TABLE implicitly drops", 27)) return; - - /* NOTICE: Caution: DROP INDEX cannot be rolled back, so don't abort now */ - if (strstr(message,"cannot be rolled back")) + + /* + * NOTICE: Caution: DROP INDEX cannot be rolled back, so don't abort + * now + */ + if (strstr(message, "cannot be rolled back")) return; /* these and other unmentioned should set sqlca.sqlwarn[2] */ - /* NOTICE: The ':' operator is deprecated. Use exp(x) instead. */ - /* NOTICE: Rel *: Uninitialized page 0 - fixing */ - /* NOTICE: PortalHeapMemoryFree: * not in alloc set! */ - /* NOTICE: Too old parent tuple found - can't continue vc_repair_frag */ - /* NOTICE: identifier "*" will be truncated to "*" */ - /* NOTICE: InvalidateSharedInvalid: cache state reset */ - /* NOTICE: RegisterSharedInvalid: SI buffer overflow */ - sqlca.sqlwarn[2]='W'; - sqlca.sqlwarn[0]='W'; + /* NOTICE: The ':' operator is deprecated. Use exp(x) instead. */ + /* NOTICE: Rel *: Uninitialized page 0 - fixing */ + /* NOTICE: PortalHeapMemoryFree: * not in alloc set! */ + /* NOTICE: Too old parent tuple found - can't continue vc_repair_frag */ + /* NOTICE: identifier "*" will be truncated to "*" */ + /* NOTICE: InvalidateSharedInvalid: cache state reset */ + /* NOTICE: RegisterSharedInvalid: SI buffer overflow */ + sqlca.sqlwarn[2] = 'W'; + sqlca.sqlwarn[0] = 'W'; } /* this contains some quick hacks, needs to be cleaned up, but it works */ @@ -230,7 +258,12 @@ bool ECPGconnect(int lineno, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit) { struct connection *this; - char *dbname = strdup(name), *host = NULL, *tmp, *port = NULL, *realname = NULL, *options = NULL; + char *dbname = strdup(name), + *host = NULL, + *tmp, + *port = NULL, + *realname = NULL, + *options = NULL; init_sqlca(); @@ -239,72 +272,74 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd, if (dbname == NULL && connection_name == NULL) connection_name = "DEFAULT"; - + /* get the detail information out of dbname */ if (strchr(dbname, '@') != NULL) - { - /* old style: dbname[@server][:port] */ - tmp = strrchr(dbname, ':'); - if (tmp != NULL) /* port number given */ - { - port = strdup(tmp + 1); - *tmp = '\0'; - } - - tmp = strrchr(dbname, '@'); - if (tmp != NULL) /* host name given */ - { - host = strdup(tmp + 1); - *tmp = '\0'; + { + /* old style: dbname[@server][:port] */ + tmp = strrchr(dbname, ':'); + if (tmp != NULL) /* port number given */ + { + port = strdup(tmp + 1); + *tmp = '\0'; + } + + tmp = strrchr(dbname, '@'); + if (tmp != NULL) /* host name given */ + { + host = strdup(tmp + 1); + *tmp = '\0'; } realname = strdup(dbname); } else if (strncmp(dbname, "tcp:", 4) == 0 || strncmp(dbname, "unix:", 5) == 0) { - int offset = 0; - + int offset = 0; + /* * only allow protocols tcp and unix */ if (strncmp(dbname, "tcp:", 4) == 0) - offset = 4; + offset = 4; else if (strncmp(dbname, "unix:", 5) == 0) - offset = 5; - - if (strncmp(dbname + offset, "postgresql://", strlen("postgresql://")) == 0) - { - /* + offset = 5; + + if (strncmp(dbname + offset, "postgresql://", strlen("postgresql://")) == 0) + { + + /* * new style: - * <tcp|unix>:postgresql://server[:port|:/unixsocket/path:][/dbname][?options] - */ - offset += strlen("postgresql://"); - - tmp = strrchr(dbname + offset, '?'); - if (tmp != NULL) /* options given */ - { - options = strdup(tmp + 1); - *tmp = '\0'; - } - - tmp = strrchr(dbname + offset, '/'); - if (tmp != NULL) /* database name given */ - { - realname = strdup(tmp + 1); - *tmp = '\0'; - } - - tmp = strrchr(dbname + offset, ':'); - if (tmp != NULL) /* port number or Unix socket path given */ - { - char *tmp2; - - *tmp = '\0'; + * <tcp|unix>:postgresql://server[:port|:/unixsocket/path:][/db + * name][?options] + */ + offset += strlen("postgresql://"); + + tmp = strrchr(dbname + offset, '?'); + if (tmp != NULL) /* options given */ + { + options = strdup(tmp + 1); + *tmp = '\0'; + } + + tmp = strrchr(dbname + offset, '/'); + if (tmp != NULL) /* database name given */ + { + realname = strdup(tmp + 1); + *tmp = '\0'; + } + + tmp = strrchr(dbname + offset, ':'); + if (tmp != NULL) /* port number or Unix socket path given */ + { + char *tmp2; + + *tmp = '\0'; if ((tmp2 = strchr(tmp + 1, ':')) != NULL) { *tmp2 = '\0'; host = strdup(tmp + 1); - if (strncmp(dbname, "unix:", 5) != 0) - { + if (strncmp(dbname, "unix:", 5) != 0) + { ECPGlog("connect: socketname %s given for TCP connection in line %d\n", host, lineno); ECPGraise(lineno, ECPG_CONNECT, realname ? realname : "<DEFAULT>"); if (host) @@ -318,19 +353,17 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd, if (dbname) free(dbname); return false; - } - } - else - { - port = strdup(tmp + 1); - } - } - - if (strncmp(dbname, "unix:", 5) == 0) - { - if (strcmp(dbname + offset, "localhost") != 0 && strcmp(dbname + offset, "127.0.0.1") != 0) - { - ECPGlog("connect: non-localhost access via sockets in line %d\n", lineno); + } + } + else + port = strdup(tmp + 1); + } + + if (strncmp(dbname, "unix:", 5) == 0) + { + if (strcmp(dbname + offset, "localhost") != 0 && strcmp(dbname + offset, "127.0.0.1") != 0) + { + ECPGlog("connect: non-localhost access via sockets in line %d\n", lineno); ECPGraise(lineno, ECPG_CONNECT, realname ? realname : "<DEFAULT>"); if (host) free(host); @@ -340,27 +373,25 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd, free(options); if (realname) free(realname); - if(dbname) + if (dbname) free(dbname); return false; - } - } - else - { - host = strdup(dbname + offset); - } - - } + } + } + else + host = strdup(dbname + offset); + + } } else realname = strdup(dbname); - + /* add connection to our list */ if (connection_name != NULL) this->name = ecpg_strdup(connection_name, lineno); else this->name = ecpg_strdup(realname, lineno); - + this->cache_head = NULL; if (all_connections == NULL) @@ -371,9 +402,9 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd, actual_connection = all_connections = this; ECPGlog("ECPGconnect: opening database %s on %s port %s %s%s%s%s\n", - realname ? realname : "<DEFAULT>", - host ? host : "<DEFAULT>", - port ? port : "<DEFAULT>", + realname ? realname : "<DEFAULT>", + host ? host : "<DEFAULT>", + port ? port : "<DEFAULT>", options ? "with options " : "", options ? options : "", user ? "for user " : "", user ? user : ""); @@ -389,25 +420,25 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd, free(realname); if (dbname) free(dbname); - + if (PQstatus(this->connection) == CONNECTION_BAD) { ecpg_finish(this); ECPGlog("connect: could not open database %s on %s port %s %s%s%s%s in line %d\n", - realname ? realname : "<DEFAULT>", - host ? host : "<DEFAULT>", - port ? port : "<DEFAULT>", - options ? "with options " : "", options ? options : "", - user ? "for user " : "", user ? user : "", - lineno); + realname ? realname : "<DEFAULT>", + host ? host : "<DEFAULT>", + port ? port : "<DEFAULT>", + options ? "with options " : "", options ? options : "", + user ? "for user " : "", user ? user : "", + lineno); ECPGraise(lineno, ECPG_CONNECT, realname ? realname : "<DEFAULT>"); return false; } this->committed = true; this->autocommit = autocommit; - - PQsetNoticeProcessor(this->connection,&ECPGnoticeProcessor,(void*)this); + + PQsetNoticeProcessor(this->connection, &ECPGnoticeProcessor, (void *) this); return true; } diff --git a/src/interfaces/ecpg/lib/data.c b/src/interfaces/ecpg/lib/data.c index b6cc32b8563..50640ba1a46 100644 --- a/src/interfaces/ecpg/lib/data.c +++ b/src/interfaces/ecpg/lib/data.c @@ -33,13 +33,13 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno, switch (type) { case ECPGt_char: - case ECPGt_unsigned_char: - case ECPGt_varchar: - break; - - default: - pval++; - break; + case ECPGt_unsigned_char: + case ECPGt_varchar: + break; + + default: + pval++; + break; } } @@ -64,12 +64,12 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno, break; #ifdef HAVE_LONG_LONG_INT_64 case ECPGt_long_long: - ((long long int*) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field); - break; + ((long long int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field); + break; case ECPGt_unsigned_long_long: - ((unsigned long long int*) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field); - break; -#endif /* HAVE_LONG_LONG_INT_64 */ + ((unsigned long long int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field); + break; +#endif /* HAVE_LONG_LONG_INT_64 */ case ECPGt_NO_INDICATOR: if (PQgetisnull(results, act_tuple, act_field)) { @@ -159,7 +159,7 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno, break; #ifdef HAVE_LONG_LONG_INT_64 -# ifdef HAVE_STRTOLL +#ifdef HAVE_STRTOLL case ECPGt_long_long: if (pval) { @@ -168,15 +168,15 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno, || (!isarray && *scan_length != '\0')) /* Garbage left */ { ECPGraise(lineno, ECPG_INT_FORMAT, pval); - return (false); - } + return (false); + } } - else - ((long long int *) var)[act_tuple] = 0LL; - + else + ((long long int *) var)[act_tuple] = (long long) 0; + break; -# endif /* HAVE_STRTOLL */ -# ifdef HAVE_STRTOULL +#endif /* HAVE_STRTOLL */ +#ifdef HAVE_STRTOULL case ECPGt_unsigned_long_long: if (pval) { @@ -185,16 +185,16 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno, || (!isarray && *scan_length != '\0')) /* Garbage left */ { ECPGraise(lineno, ECPG_UINT_FORMAT, pval); - return (false); - } + return (false); + } } - else - ((unsigned long long int *) var)[act_tuple] = 0LL; - + else + ((unsigned long long int *) var)[act_tuple] = (long long) 0; + break; -# endif /* HAVE_STRTOULL */ -#endif /* HAVE_LONG_LONG_INT_64 */ - +#endif /* HAVE_STRTOULL */ +#endif /* HAVE_LONG_LONG_INT_64 */ + case ECPGt_float: case ECPGt_double: if (pval) @@ -203,10 +203,10 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno, dres = strtod(pval + 1, &scan_length); else dres = strtod(pval, &scan_length); - + if (isarray && *scan_length == '"') - scan_length++; - + scan_length++; + if ((isarray && *scan_length != ',' && *scan_length != '}') || (!isarray && *scan_length != '\0')) /* Garbage left */ { @@ -236,16 +236,22 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno, { if (pval[0] == 'f' && pval[1] == '\0') { - if (offset==sizeof(char)) ((char *) var)[act_tuple] = false; - else if (offset==sizeof(int)) ((int *) var)[act_tuple] = false; - else ECPGraise(lineno, ECPG_CONVERT_BOOL, "different size"); + if (offset == sizeof(char)) + ((char *) var)[act_tuple] = false; + else if (offset == sizeof(int)) + ((int *) var)[act_tuple] = false; + else + ECPGraise(lineno, ECPG_CONVERT_BOOL, "different size"); break; } else if (pval[0] == 't' && pval[1] == '\0') { - if (offset==sizeof(char)) ((char *) var)[act_tuple] = true; - else if (offset==sizeof(int)) ((int *) var)[act_tuple] = true; - else ECPGraise(lineno, ECPG_CONVERT_BOOL, "different size"); + if (offset == sizeof(char)) + ((char *) var)[act_tuple] = true; + else if (offset == sizeof(int)) + ((int *) var)[act_tuple] = true; + else + ECPGraise(lineno, ECPG_CONVERT_BOOL, "different size"); break; } else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field)) diff --git a/src/interfaces/ecpg/lib/descriptor.c b/src/interfaces/ecpg/lib/descriptor.c index 5cdf8dc1f38..bbf239e3920 100644 --- a/src/interfaces/ecpg/lib/descriptor.c +++ b/src/interfaces/ecpg/lib/descriptor.c @@ -65,7 +65,7 @@ get_int_item(int lineno, void *var, enum ECPGttype vartype, int value) { switch (vartype) { - case ECPGt_short: + case ECPGt_short: *(short *) var = (short) value; break; case ECPGt_int: @@ -90,7 +90,7 @@ get_int_item(int lineno, void *var, enum ECPGttype vartype, int value) case ECPGt_unsigned_long_long: *(unsigned long long int *) var = (unsigned long long int) value; break; -#endif /* HAVE_LONG_LONG_INT_64 */ +#endif /* HAVE_LONG_LONG_INT_64 */ case ECPGt_float: *(float *) var = (float) value; break; diff --git a/src/interfaces/ecpg/lib/error.c b/src/interfaces/ecpg/lib/error.c index 0c9c197edfc..72b005bb9ac 100644 --- a/src/interfaces/ecpg/lib/error.c +++ b/src/interfaces/ecpg/lib/error.c @@ -119,15 +119,16 @@ ECPGraise(int line, int code, const char *str) break; case ECPG_PGSQL: - { - int slen = strlen(str); - /* strip trailing newline */ - if (slen > 0 && str[slen - 1] == '\n') - slen--; - snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), - "'%.*s' in line %d.", slen, str, line); - break; - } + { + int slen = strlen(str); + + /* strip trailing newline */ + if (slen > 0 && str[slen - 1] == '\n') + slen--; + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "'%.*s' in line %d.", slen, str, line); + break; + } case ECPG_TRANS: snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), diff --git a/src/interfaces/ecpg/lib/execute.c b/src/interfaces/ecpg/lib/execute.c index 50ebf904a47..99177844717 100644 --- a/src/interfaces/ecpg/lib/execute.c +++ b/src/interfaces/ecpg/lib/execute.c @@ -104,7 +104,7 @@ quote_postgres(char *arg, int lineno) return (res); res[ri++] = '\''; - + for (i = 0; arg[i]; i++, ri++) { switch (arg[i]) @@ -121,7 +121,7 @@ quote_postgres(char *arg, int lineno) res[ri] = arg[i]; } - + res[ri++] = '\''; res[ri] = '\0'; @@ -253,11 +253,10 @@ next_insert(char *text) for (; *ptr != '\0' && (*ptr != '?' || string); ptr++) { - if (*ptr == '\\') /* escape character */ + if (*ptr == '\\') /* escape character */ ptr++; - else - if (*ptr == '\'' ) - string = string ? false : true; + else if (*ptr == '\'') + string = string ? false : true; } return (*ptr == '\0') ? NULL : ptr; @@ -268,10 +267,11 @@ next_insert(char *text) */ static void -ECPGtypeinfocache_push(struct ECPGtype_information_cache **cache, int oid, bool isarray, int lineno) +ECPGtypeinfocache_push(struct ECPGtype_information_cache ** cache, int oid, bool isarray, int lineno) { - struct ECPGtype_information_cache *new_entry - = (struct ECPGtype_information_cache *) ecpg_alloc(sizeof(struct ECPGtype_information_cache), lineno); + struct ECPGtype_information_cache *new_entry + = (struct ECPGtype_information_cache *) ecpg_alloc(sizeof(struct ECPGtype_information_cache), lineno); + new_entry->oid = oid; new_entry->isarray = isarray; new_entry->next = *cache; @@ -279,17 +279,21 @@ ECPGtypeinfocache_push(struct ECPGtype_information_cache **cache, int oid, bool } static bool -ECPGis_type_an_array(int type,const struct statement * stmt,const struct variable *var) +ECPGis_type_an_array(int type, const struct statement * stmt, const struct variable * var) { char *array_query; - int isarray = 0; - PGresult *query; - struct ECPGtype_information_cache *cache_entry; - - if ((stmt->connection->cache_head)==NULL) - { - /* Text like types are not an array for ecpg, but postgres counts them as - an array. This define reminds you to not 'correct' these values. */ + int isarray = 0; + PGresult *query; + struct ECPGtype_information_cache *cache_entry; + + if ((stmt->connection->cache_head) == NULL) + { + + /* + * Text like types are not an array for ecpg, but postgres counts + * them as an array. This define reminds you to not 'correct' + * these values. + */ #define not_an_array_in_ecpg false /* populate cache with well known types to speed things up */ @@ -310,7 +314,7 @@ ECPGis_type_an_array(int type,const struct statement * stmt,const struct variabl ECPGtypeinfocache_push(&(stmt->connection->cache_head), OIDVECTOROID, true, stmt->lineno); ECPGtypeinfocache_push(&(stmt->connection->cache_head), POINTOID, true, stmt->lineno); ECPGtypeinfocache_push(&(stmt->connection->cache_head), LSEGOID, true, stmt->lineno); - ECPGtypeinfocache_push(&(stmt->connection->cache_head), PATHOID, not_an_array_in_ecpg , stmt->lineno); + ECPGtypeinfocache_push(&(stmt->connection->cache_head), PATHOID, not_an_array_in_ecpg, stmt->lineno); ECPGtypeinfocache_push(&(stmt->connection->cache_head), BOXOID, true, stmt->lineno); ECPGtypeinfocache_push(&(stmt->connection->cache_head), POLYGONOID, false, stmt->lineno); ECPGtypeinfocache_push(&(stmt->connection->cache_head), LINEOID, true, stmt->lineno); @@ -336,12 +340,12 @@ ECPGis_type_an_array(int type,const struct statement * stmt,const struct variabl ECPGtypeinfocache_push(&(stmt->connection->cache_head), NUMERICOID, false, stmt->lineno); } - for (cache_entry = (stmt->connection->cache_head);cache_entry != NULL;cache_entry=cache_entry->next) + for (cache_entry = (stmt->connection->cache_head); cache_entry != NULL; cache_entry = cache_entry->next) { - if (cache_entry->oid==type) + if (cache_entry->oid == type) return cache_entry->isarray; } - + array_query = (char *) ecpg_alloc(strlen("select typelem from pg_type where oid=") + 11, stmt->lineno); sprintf(array_query, "select typelem from pg_type where oid=%d", type); query = PQexec(stmt->connection->connection, array_query); @@ -354,8 +358,7 @@ ECPGis_type_an_array(int type,const struct statement * stmt,const struct variabl { /* - * arrays of character strings are not yet - * implemented + * arrays of character strings are not yet implemented */ isarray = false; } @@ -391,7 +394,7 @@ ECPGexecute(struct statement * stmt) char *tobeinserted = NULL; char *p; char buff[20]; - int hostvarl = 0; + int hostvarl = 0; /* * Some special treatment is needed for records since we want @@ -422,10 +425,10 @@ ECPGexecute(struct statement * stmt) #ifdef HAVE_LONG_LONG_INT_64 case ECPGt_long_long: case ECPGt_unsigned_long_long: - if (*(long long int*) var->ind_value < 0LL) + if (*(long long int *) var->ind_value < (long long) 0) strcpy(buff, "null"); - break; -#endif /* HAVE_LONG_LONG_INT_64 */ + break; +#endif /* HAVE_LONG_LONG_INT_64 */ default: break; } @@ -583,11 +586,11 @@ ECPGexecute(struct statement * stmt) strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); } else - sprintf(mallocedval, "%llu", *((unsigned long long*) var->value)); + sprintf(mallocedval, "%llu", *((unsigned long long *) var->value)); tobeinserted = mallocedval; break; -#endif /* HAVE_LONG_LONG_INT_64 */ +#endif /* HAVE_LONG_LONG_INT_64 */ case ECPGt_float: if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno))) return false; @@ -634,11 +637,15 @@ ECPGexecute(struct statement * stmt) { strncpy(mallocedval, "'{", sizeof("'{")); - if (var->offset==sizeof(char)) + if (var->offset == sizeof(char)) for (element = 0; element < var->arrsize; element++) sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f'); - /* this is necessary since sizeof(C++'s bool)==sizeof(int) */ - else if (var->offset==sizeof(int)) + + /* + * this is necessary since sizeof(C++'s + * bool)==sizeof(int) + */ + else if (var->offset == sizeof(int)) for (element = 0; element < var->arrsize; element++) sprintf(mallocedval + strlen(mallocedval), "%c,", (((int *) var->value)[element]) ? 't' : 'f'); else @@ -648,9 +655,9 @@ ECPGexecute(struct statement * stmt) } else { - if (var->offset==sizeof(char)) + if (var->offset == sizeof(char)) sprintf(mallocedval, "'%c'", (*((char *) var->value)) ? 't' : 'f'); - else if (var->offset==sizeof(int)) + else if (var->offset == sizeof(int)) sprintf(mallocedval, "'%c'", (*((int *) var->value)) ? 't' : 'f'); else ECPGraise(stmt->lineno, ECPG_CONVERT_BOOL, "different size"); @@ -734,6 +741,7 @@ ECPGexecute(struct statement * stmt) strcpy(newcopy, copiedquery); if ((p = next_insert(newcopy + hostvarl)) == NULL) { + /* * We have an argument but we dont have the matched up string * in the string @@ -932,9 +940,9 @@ ECPGexecute(struct statement * stmt) sqlca.sqlerrd[1] = atol(PQoidStatus(results)); sqlca.sqlerrd[2] = atol(PQcmdTuples(results)); ECPGlog("ECPGexecute line %d Ok: %s\n", stmt->lineno, PQcmdStatus(results)); - if (!sqlca.sqlerrd[2] && (!strncmp(PQcmdStatus(results),"UPDATE",6) - || !strncmp(PQcmdStatus(results),"INSERT",6) - || !strncmp(PQcmdStatus(results),"DELETE",6))) + if (!sqlca.sqlerrd[2] && (!strncmp(PQcmdStatus(results), "UPDATE", 6) + || !strncmp(PQcmdStatus(results), "INSERT", 6) + || !strncmp(PQcmdStatus(results), "DELETE", 6))) ECPGraise(stmt->lineno, ECPG_NOT_FOUND, NULL); break; case PGRES_NONFATAL_ERROR: @@ -1024,7 +1032,7 @@ ECPGdo(int lineno, const char *connection_name, char *query,...) * * Copyright (c) 2000, Christof Petig <christof.petig@wtal.de> * - * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.18 2001/02/12 13:56:37 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.19 2001/03/22 04:01:19 momjian Exp $ */ PGconn *ECPG_internal_get_connection(char *name); diff --git a/src/interfaces/ecpg/lib/extern.h b/src/interfaces/ecpg/lib/extern.h index 3278b0d079c..b9318d05c98 100644 --- a/src/interfaces/ecpg/lib/extern.h +++ b/src/interfaces/ecpg/lib/extern.h @@ -24,12 +24,12 @@ struct ECPGgeneric_varchar /* * type information cache */ - + 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 */ @@ -47,8 +47,8 @@ struct connection { char *name; PGconn *connection; - bool committed; - int autocommit; - struct ECPGtype_information_cache *cache_head; + bool committed; + int autocommit; + struct ECPGtype_information_cache *cache_head; struct connection *next; }; diff --git a/src/interfaces/ecpg/lib/typename.c b/src/interfaces/ecpg/lib/typename.c index 710354ffe29..78c2665ed8f 100644 --- a/src/interfaces/ecpg/lib/typename.c +++ b/src/interfaces/ecpg/lib/typename.c @@ -15,7 +15,7 @@ ECPGtype_name(enum ECPGttype typ) { switch (typ) { - case ECPGt_char: + case ECPGt_char: return "char"; case ECPGt_unsigned_char: return "unsigned char"; @@ -36,7 +36,7 @@ ECPGtype_name(enum ECPGttype typ) return "long long"; case ECPGt_unsigned_long_long: return "unsigned long long"; -#endif /* HAVE_LONG_LONG_INT_64 */ +#endif /* HAVE_LONG_LONG_INT_64 */ case ECPGt_float: return "float"; case ECPGt_double: @@ -58,18 +58,29 @@ ECPGDynamicType(Oid type) { switch (type) { - case BOOLOID: return SQL3_BOOLEAN; /* bool */ - case INT2OID: return SQL3_SMALLINT; /* int2 */ - case INT4OID: return SQL3_INTEGER;/* int4 */ - case TEXTOID: return SQL3_CHARACTER; /* text */ - case FLOAT4OID: return SQL3_REAL; /* float4 */ - case FLOAT8OID: return SQL3_DOUBLE_PRECISION; /* float8 */ - case BPCHAROID: return SQL3_CHARACTER; /* bpchar */ - case VARCHAROID: return SQL3_CHARACTER_VARYING; /* varchar */ - case DATEOID: return SQL3_DATE_TIME_TIMESTAMP; /* date */ - case TIMEOID: return SQL3_DATE_TIME_TIMESTAMP; /* time */ - case TIMESTAMPOID: return SQL3_DATE_TIME_TIMESTAMP; /* datetime */ - case NUMERICOID: return SQL3_NUMERIC;/* numeric */ + case BOOLOID:return SQL3_BOOLEAN; /* bool */ + case INT2OID: + return SQL3_SMALLINT; /* int2 */ + case INT4OID: + return SQL3_INTEGER;/* int4 */ + case TEXTOID: + return SQL3_CHARACTER; /* text */ + case FLOAT4OID: + return SQL3_REAL; /* float4 */ + case FLOAT8OID: + return SQL3_DOUBLE_PRECISION; /* float8 */ + case BPCHAROID: + return SQL3_CHARACTER; /* bpchar */ + case VARCHAROID: + return SQL3_CHARACTER_VARYING; /* varchar */ + case DATEOID: + return SQL3_DATE_TIME_TIMESTAMP; /* date */ + case TIMEOID: + return SQL3_DATE_TIME_TIMESTAMP; /* time */ + case TIMESTAMPOID: + return SQL3_DATE_TIME_TIMESTAMP; /* datetime */ + case NUMERICOID: + return SQL3_NUMERIC;/* numeric */ default: return -type; } |