mirror of
https://github.com/postgres/postgres.git
synced 2025-05-06 19:59:18 +03:00
Some cleanup in ecpg code:
Use bool as type for booleans instead of int. Do not implicitely cast size_t to int. Make the compiler stop complaining about unused variables by adding an empty statement.
This commit is contained in:
parent
8c843fff2d
commit
35d5d962e1
@ -178,8 +178,8 @@ deccopy(decimal *src, decimal *target)
|
|||||||
static char *
|
static char *
|
||||||
ecpg_strndup(const char *str, size_t len)
|
ecpg_strndup(const char *str, size_t len)
|
||||||
{
|
{
|
||||||
int real_len = strlen(str);
|
size_t real_len = strlen(str);
|
||||||
int use_len = (real_len > len) ? (int) len : real_len;
|
int use_len = (int) ((real_len > len) ? len : real_len);
|
||||||
|
|
||||||
char *new = malloc(use_len + 1);
|
char *new = malloc(use_len + 1);
|
||||||
|
|
||||||
@ -983,24 +983,33 @@ ldchar(char *src, int len, char *dest)
|
|||||||
int
|
int
|
||||||
rgetmsg(int msgnum, char *s, int maxsize)
|
rgetmsg(int msgnum, char *s, int maxsize)
|
||||||
{
|
{
|
||||||
|
(void) msgnum; /* keep the compiler quiet */
|
||||||
|
(void) s; /* keep the compiler quiet */
|
||||||
|
(void) maxsize; /* keep the compiler quiet */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rtypalign(int offset, int type)
|
rtypalign(int offset, int type)
|
||||||
{
|
{
|
||||||
|
(void) offset; /* keep the compiler quiet */
|
||||||
|
(void) type; /* keep the compiler quiet */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rtypmsize(int type, int len)
|
rtypmsize(int type, int len)
|
||||||
{
|
{
|
||||||
|
(void) type; /* keep the compiler quiet */
|
||||||
|
(void) len; /* keep the compiler quiet */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rtypwidth(int sqltype, int sqllen)
|
rtypwidth(int sqltype, int sqllen)
|
||||||
{
|
{
|
||||||
|
(void) sqltype; /* keep the compiler quiet */
|
||||||
|
(void) sqllen; /* keep the compiler quiet */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,9 +214,9 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
|
|||||||
char *sqlstate = PQresultErrorField(result, PG_DIAG_SQLSTATE);
|
char *sqlstate = PQresultErrorField(result, PG_DIAG_SQLSTATE);
|
||||||
char *message = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY);
|
char *message = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY);
|
||||||
struct sqlca_t *sqlca = ECPGget_sqlca();
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
|
|
||||||
int sqlcode;
|
int sqlcode;
|
||||||
|
|
||||||
|
(void) arg; /* keep the compiler quiet */
|
||||||
if (sqlstate == NULL)
|
if (sqlstate == NULL)
|
||||||
sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
|
sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ struct connection
|
|||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
PGconn *connection;
|
PGconn *connection;
|
||||||
int autocommit;
|
bool autocommit;
|
||||||
struct ECPGtype_information_cache *cache_head;
|
struct ECPGtype_information_cache *cache_head;
|
||||||
struct prepared_statement *prep_stmts;
|
struct prepared_statement *prep_stmts;
|
||||||
struct connection *next;
|
struct connection *next;
|
||||||
|
@ -75,6 +75,7 @@ static pthread_once_t auto_mem_once = PTHREAD_ONCE_INIT;
|
|||||||
static void
|
static void
|
||||||
auto_mem_destructor(void *arg)
|
auto_mem_destructor(void *arg)
|
||||||
{
|
{
|
||||||
|
(void) arg; /* keep the compiler quiet */
|
||||||
ECPGfree_auto_mem();
|
ECPGfree_auto_mem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ replace_variables(char **text, int lineno)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
prepare_common(int lineno, struct connection * con, const bool questionmarks, const char *name, const char *variable)
|
prepare_common(int lineno, struct connection * con, const char *name, const char *variable)
|
||||||
{
|
{
|
||||||
struct statement *stmt;
|
struct statement *stmt;
|
||||||
struct prepared_statement *this;
|
struct prepared_statement *this;
|
||||||
@ -156,7 +156,7 @@ prepare_common(int lineno, struct connection * con, const bool questionmarks, co
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* handle the EXEC SQL PREPARE statement */
|
/* handle the EXEC SQL PREPARE statement */
|
||||||
/* questionmarks is not needed but remians in there for the time being to not change the API */
|
/* questionmarks is not needed but remains in there for the time being to not change the API */
|
||||||
bool
|
bool
|
||||||
ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
|
ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
|
||||||
{
|
{
|
||||||
@ -164,6 +164,7 @@ ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, c
|
|||||||
struct prepared_statement *this,
|
struct prepared_statement *this,
|
||||||
*prev;
|
*prev;
|
||||||
|
|
||||||
|
(void) questionmarks; /* quiet the compiler */
|
||||||
con = ecpg_get_connection(connection_name);
|
con = ecpg_get_connection(connection_name);
|
||||||
|
|
||||||
if (!ecpg_init(con, connection_name, lineno))
|
if (!ecpg_init(con, connection_name, lineno))
|
||||||
@ -174,7 +175,7 @@ ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, c
|
|||||||
if (this && !deallocate_one(lineno, ECPG_COMPAT_PGSQL, con, prev, this))
|
if (this && !deallocate_one(lineno, ECPG_COMPAT_PGSQL, con, prev, this))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return prepare_common(lineno, con, questionmarks, name, variable);
|
return prepare_common(lineno, con, name, variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct prepared_statement *
|
struct prepared_statement *
|
||||||
@ -304,6 +305,7 @@ ecpg_prepared(const char *name, struct connection * con)
|
|||||||
char *
|
char *
|
||||||
ECPGprepared_statement(const char *connection_name, const char *name, int lineno)
|
ECPGprepared_statement(const char *connection_name, const char *name, int lineno)
|
||||||
{
|
{
|
||||||
|
(void)lineno; /* keep the compiler quiet */
|
||||||
return ecpg_prepared(name, ecpg_get_connection(connection_name));
|
return ecpg_prepared(name, ecpg_get_connection(connection_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,7 +486,7 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, cha
|
|||||||
con = ecpg_get_connection(connection_name);
|
con = ecpg_get_connection(connection_name);
|
||||||
prep = ecpg_find_prepared_statement(stmtID, con, NULL);
|
prep = ecpg_find_prepared_statement(stmtID, con, NULL);
|
||||||
/* This prepared name doesn't exist on this connection. */
|
/* This prepared name doesn't exist on this connection. */
|
||||||
if (!prep && !prepare_common(lineno, con, 0, stmtID, query))
|
if (!prep && !prepare_common(lineno, con, stmtID, query))
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
*name = ecpg_strdup(stmtID, lineno);
|
*name = ecpg_strdup(stmtID, lineno);
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
int ret_value = 0,
|
int ret_value = 0;
|
||||||
autocommit = false,
|
bool autocommit = false,
|
||||||
auto_create_c = false,
|
auto_create_c = false,
|
||||||
system_includes = false,
|
system_includes = false,
|
||||||
force_indicator = true,
|
force_indicator = true,
|
||||||
@ -126,9 +126,9 @@ main(int argc, char *const argv[])
|
|||||||
|
|
||||||
int fnr,
|
int fnr,
|
||||||
c,
|
c,
|
||||||
verbose = false,
|
|
||||||
header_mode = false,
|
|
||||||
out_option = 0;
|
out_option = 0;
|
||||||
|
bool verbose = false,
|
||||||
|
header_mode = false;
|
||||||
struct _include_path *ip;
|
struct _include_path *ip;
|
||||||
const char *progname;
|
const char *progname;
|
||||||
char my_exec_path[MAXPGPATH];
|
char my_exec_path[MAXPGPATH];
|
||||||
|
@ -270,7 +270,7 @@ prepared_name: name {
|
|||||||
$$ = $1;
|
$$ = $1;
|
||||||
else /* not quoted => convert to lowercase */
|
else /* not quoted => convert to lowercase */
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i< strlen($1); i++)
|
for (i = 0; i< strlen($1); i++)
|
||||||
$1[i] = tolower((unsigned char) $1[i]);
|
$1[i] = tolower((unsigned char) $1[i]);
|
||||||
|
@ -18,17 +18,17 @@
|
|||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
|
|
||||||
extern int braces_open,
|
extern bool autocommit,
|
||||||
autocommit,
|
|
||||||
auto_create_c,
|
auto_create_c,
|
||||||
system_includes,
|
system_includes,
|
||||||
force_indicator,
|
force_indicator,
|
||||||
questionmarks,
|
questionmarks,
|
||||||
ret_value,
|
|
||||||
struct_level,
|
|
||||||
ecpg_internal_var,
|
|
||||||
regression_mode,
|
regression_mode,
|
||||||
auto_prepare;
|
auto_prepare;
|
||||||
|
extern int braces_open,
|
||||||
|
ret_value,
|
||||||
|
struct_level,
|
||||||
|
ecpg_internal_var;
|
||||||
extern char *current_function;
|
extern char *current_function;
|
||||||
extern char *descriptor_index;
|
extern char *descriptor_index;
|
||||||
extern char *descriptor_name;
|
extern char *descriptor_name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user