code beautifying
This commit is contained in:
@ -85,11 +85,13 @@ int count_params(const char *stmt) {
|
|||||||
for (i = 0, done = 0; (i <= MAX_PARAM_DIGIT_NUM) && !done; i++) {
|
for (i = 0, done = 0; (i <= MAX_PARAM_DIGIT_NUM) && !done; i++) {
|
||||||
if (isdigit(*paramPtr)) {
|
if (isdigit(*paramPtr)) {
|
||||||
numBuf[i] = *paramPtr;
|
numBuf[i] = *paramPtr;
|
||||||
if (debug) syslog(LOG_DEBUG, "pgworker count_params: i=%d, nb=%c", i, numBuf[i]);
|
if (debug) syslog(LOG_DEBUG, "pgworker count_params: i=%d, nb=%c",
|
||||||
|
i, numBuf[i]);
|
||||||
paramPtr++;
|
paramPtr++;
|
||||||
} else {
|
} else {
|
||||||
numBuf[i] = '\0';
|
numBuf[i] = '\0';
|
||||||
if (debug) syslog(LOG_DEBUG, "pgworker count_params: end, i=%d, nb=%s", i, numBuf);
|
if (debug) syslog(LOG_DEBUG, "pgworker count_params: end, i=%d, nb=%s",
|
||||||
|
i, numBuf);
|
||||||
x = atoi(numBuf);
|
x = atoi(numBuf);
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
syslog(LOG_ERR, "pgworker count_params: failure, x=0");
|
syslog(LOG_ERR, "pgworker count_params: failure, x=0");
|
||||||
@ -110,7 +112,8 @@ int count_params(const char *stmt) {
|
|||||||
if (done) {
|
if (done) {
|
||||||
for (i = 0; (i <= MAX_PARAM_COUNT) && checkArray[i]; i++);
|
for (i = 0; (i <= MAX_PARAM_COUNT) && checkArray[i]; i++);
|
||||||
if (i != cnt) {
|
if (i != cnt) {
|
||||||
syslog(LOG_ERR, "pgworker count_params: none continuous sequence of param numbers, failure");
|
syslog(LOG_ERR,
|
||||||
|
"pgworker count_params: none continuous sequence of param numbers, failure");
|
||||||
res = -1;
|
res = -1;
|
||||||
} else {
|
} else {
|
||||||
if (debug) syslog(LOG_DEBUG, "pgworker count_params: %d params", cnt);
|
if (debug) syslog(LOG_DEBUG, "pgworker count_params: %d params", cnt);
|
||||||
@ -125,7 +128,8 @@ int count_params(const char *stmt) {
|
|||||||
|
|
||||||
|
|
||||||
int pg_worker_init(cfgl_t *cfg, void **handle) {
|
int pg_worker_init(cfgl_t *cfg, void **handle) {
|
||||||
pg_container_handle_t *pch = (pg_container_handle_t*)htmalloc(sizeof(pg_container_handle_t));
|
pg_container_handle_t *pch =
|
||||||
|
(pg_container_handle_t*)htmalloc(sizeof(pg_container_handle_t));
|
||||||
pch->counter = 0;
|
pch->counter = 0;
|
||||||
pch->cfg = cfg;
|
pch->cfg = cfg;
|
||||||
debug = atoi(findcfglx(pch->cfg, "debug", "0"));
|
debug = atoi(findcfglx(pch->cfg, "debug", "0"));
|
||||||
@ -139,7 +143,8 @@ int pg_worker_init(cfgl_t *cfg, void **handle) {
|
|||||||
return -1;
|
return -1;
|
||||||
pch->input_delimiter = findcfgl(pch->cfg, "input_delimiter");
|
pch->input_delimiter = findcfgl(pch->cfg, "input_delimiter");
|
||||||
if ((pch->param_cnt > 1) && (pch->input_delimiter == NULL)) {
|
if ((pch->param_cnt > 1) && (pch->input_delimiter == NULL)) {
|
||||||
syslog(LOG_ERR, "pgworker pg_worker_init: more than one parameter but no input_delimiter given");
|
syslog(LOG_ERR,
|
||||||
|
"pgworker pg_worker_init: more than one parameter but no input_delimiter given");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pch->output_format_string = findcfgl(pch->cfg, "output_format_string");
|
pch->output_format_string = findcfgl(pch->cfg, "output_format_string");
|
||||||
@ -154,7 +159,8 @@ int pg_worker_destroy(void *handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int pg_worker_work_setup(void *handle, void **work_handle) {
|
int pg_worker_work_setup(void *handle, void **work_handle) {
|
||||||
pg_worker_handle_t *pwh = (pg_worker_handle_t*)htmalloc(sizeof(pg_worker_handle_t));
|
pg_worker_handle_t *pwh =
|
||||||
|
(pg_worker_handle_t*)htmalloc(sizeof(pg_worker_handle_t));
|
||||||
pwh->counter = 0;
|
pwh->counter = 0;
|
||||||
pwh->pch = handle;
|
pwh->pch = handle;
|
||||||
*work_handle = pwh;
|
*work_handle = pwh;
|
||||||
@ -168,14 +174,16 @@ int pg_worker_work_setup(void *handle, void **work_handle) {
|
|||||||
"config",
|
"config",
|
||||||
"lurker",
|
"lurker",
|
||||||
"lurker123");
|
"lurker123");
|
||||||
syslog(LOG_DEBUG, "pgworker (%p) pg_worker_work_setup: dbconn=%p", pwh, pwh->dbconn);
|
syslog(LOG_DEBUG, "pgworker (%p) pg_worker_work_setup: dbconn=%p",
|
||||||
|
pwh, pwh->dbconn);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pg_worker_work_destroy(void *handle, void *work_handle) {
|
int pg_worker_work_destroy(void *handle, void *work_handle) {
|
||||||
pg_worker_handle_t *pwh = (pg_worker_handle_t*) work_handle;
|
pg_worker_handle_t *pwh = (pg_worker_handle_t*) work_handle;
|
||||||
syslog(LOG_DEBUG, "pgworker (%p) pg_worker_destroy: freeing the worker handle", pwh);
|
syslog(LOG_DEBUG, "pgworker (%p) pg_worker_destroy: freeing the worker handle",
|
||||||
|
pwh);
|
||||||
PQfinish(pwh->dbconn);
|
PQfinish(pwh->dbconn);
|
||||||
free(pwh->param_array);
|
free(pwh->param_array);
|
||||||
free(pwh);
|
free(pwh);
|
||||||
@ -214,7 +222,8 @@ int break_input(pg_worker_handle_t *pwh, char *input) {
|
|||||||
}
|
}
|
||||||
pwh->param_array[cnt] = nextptr;
|
pwh->param_array[cnt] = nextptr;
|
||||||
cnt++;
|
cnt++;
|
||||||
syslog(LOG_DEBUG, "pgworker (%p) break_input: param found (cnt=%d): {%s}", pwh, cnt, nextptr);
|
syslog(LOG_DEBUG, "pgworker (%p) break_input: param found (cnt=%d): {%s}",
|
||||||
|
pwh, cnt, nextptr);
|
||||||
nextptr = param + strlen(pwh->pch->input_delimiter);
|
nextptr = param + strlen(pwh->pch->input_delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +234,8 @@ int break_input(pg_worker_handle_t *pwh, char *input) {
|
|||||||
}
|
}
|
||||||
pwh->param_array[cnt] = nextptr;
|
pwh->param_array[cnt] = nextptr;
|
||||||
cnt++;
|
cnt++;
|
||||||
syslog(LOG_DEBUG, "pgworker (%p) break_input: last param (cnt=%d): {%s}", pwh, cnt, nextptr);
|
syslog(LOG_DEBUG, "pgworker (%p) break_input: last param (cnt=%d): {%s}",
|
||||||
|
pwh, cnt, nextptr);
|
||||||
|
|
||||||
if (cnt < pwh->pch->param_cnt) {
|
if (cnt < pwh->pch->param_cnt) {
|
||||||
syslog(LOG_ERR, "pgworker (%p) break_input: too few parameters", pwh);
|
syslog(LOG_ERR, "pgworker (%p) break_input: too few parameters", pwh);
|
||||||
@ -240,7 +250,8 @@ int break_input(pg_worker_handle_t *pwh, char *input) {
|
|||||||
|
|
||||||
|
|
||||||
#define MAX_RESULT_DIGIT_NUM 2
|
#define MAX_RESULT_DIGIT_NUM 2
|
||||||
int populate_output_format(pg_worker_handle_t *pwh, PGresult *pgr, char *output, int tuple_num) {
|
int populate_output_format(pg_worker_handle_t *pwh, PGresult *pgr,
|
||||||
|
char *output, int tuple_num) {
|
||||||
const char *formatPtr = pwh->pch->output_format_string;
|
const char *formatPtr = pwh->pch->output_format_string;
|
||||||
const char *tmpPtr = formatPtr;
|
const char *tmpPtr = formatPtr;
|
||||||
char numBuf[MAX_PARAM_DIGIT_NUM + 1];
|
char numBuf[MAX_PARAM_DIGIT_NUM + 1];
|
||||||
@ -251,7 +262,8 @@ int populate_output_format(pg_worker_handle_t *pwh, PGresult *pgr, char *output,
|
|||||||
|
|
||||||
while ((formatPtr = strchr(formatPtr, '$')) && (res == 0)) {
|
while ((formatPtr = strchr(formatPtr, '$')) && (res == 0)) {
|
||||||
strncat(output, tmpPtr, formatPtr - tmpPtr);
|
strncat(output, tmpPtr, formatPtr - tmpPtr);
|
||||||
syslog(LOG_DEBUG, "pgworker (%p) populate_output_format OUTPUT: %s", pwh, output);
|
syslog(LOG_DEBUG, "pgworker (%p) populate_output_format OUTPUT: %s",
|
||||||
|
pwh, output);
|
||||||
formatPtr++;
|
formatPtr++;
|
||||||
for (i = 0, done = 0; (i <= MAX_RESULT_DIGIT_NUM) && !done; i++) {
|
for (i = 0, done = 0; (i <= MAX_RESULT_DIGIT_NUM) && !done; i++) {
|
||||||
if (isdigit(*formatPtr)) {
|
if (isdigit(*formatPtr)) {
|
||||||
@ -262,17 +274,20 @@ int populate_output_format(pg_worker_handle_t *pwh, PGresult *pgr, char *output,
|
|||||||
numBuf[i] = '\0';
|
numBuf[i] = '\0';
|
||||||
x = atoi(numBuf) - 1;
|
x = atoi(numBuf) - 1;
|
||||||
if (x > PQnfields(pgr)) {
|
if (x > PQnfields(pgr)) {
|
||||||
syslog(LOG_ERR, "pgworker (%p) populate_output_format param num too high");
|
syslog(LOG_ERR,
|
||||||
|
"pgworker (%p) populate_output_format param num too high");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
s = PQgetvalue(pgr, tuple_num, x);
|
s = PQgetvalue(pgr, tuple_num, x);
|
||||||
syslog(LOG_DEBUG, "pgworker (%p) populate_output_format OUTPUT PARAM: %s", pwh, s);
|
syslog(LOG_DEBUG, "pgworker (%p) populate_output_format OUTPUT PARAM: %s",
|
||||||
|
pwh, s);
|
||||||
strcat(output, s);
|
strcat(output, s);
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!done) {
|
if (!done) {
|
||||||
syslog(LOG_ERR, "pgworker (%p) populate_outputformat, not done, failure", pwh);
|
syslog(LOG_ERR, "pgworker (%p) populate_outputformat, not done, failure",
|
||||||
|
pwh);
|
||||||
output[0] = '\0';
|
output[0] = '\0';
|
||||||
res = -1;
|
res = -1;
|
||||||
break;
|
break;
|
||||||
@ -297,7 +312,8 @@ int process(pg_worker_handle_t *pwh, char *input, char *output) {
|
|||||||
|
|
||||||
if (0 == (res = break_input(pwh, input))) {
|
if (0 == (res = break_input(pwh, input))) {
|
||||||
for (i = 0; i < pwh->pch->param_cnt; i++) {
|
for (i = 0; i < pwh->pch->param_cnt; i++) {
|
||||||
syslog(LOG_DEBUG, "pgworker (%p) process: param %d --> %s", pwh, i+1, pwh->param_array[i]);
|
syslog(LOG_DEBUG, "pgworker (%p) process: param %d --> %s",
|
||||||
|
pwh, i+1, pwh->param_array[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pgr = PQexecParams(pwh->dbconn,
|
pgr = PQexecParams(pwh->dbconn,
|
||||||
@ -320,13 +336,16 @@ int process(pg_worker_handle_t *pwh, char *input, char *output) {
|
|||||||
for (i = 0; i < t; i++) {
|
for (i = 0; i < t; i++) {
|
||||||
for (j = 0; j < f; j++) {
|
for (j = 0; j < f; j++) {
|
||||||
s = PQgetvalue(pgr, i, j);
|
s = PQgetvalue(pgr, i, j);
|
||||||
syslog(LOG_DEBUG, "pgworker (%p) process result (%d, %d) = {%s}", pwh, i, j, s);
|
syslog(LOG_DEBUG, "pgworker (%p) process result (%d, %d) = {%s}",
|
||||||
|
pwh, i, j, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == pwh->pch->output_format_string) {
|
if (NULL == pwh->pch->output_format_string) {
|
||||||
if (f > 1)
|
if (f > 1)
|
||||||
syslog(LOG_WARNING, "pgworker (%p) process: more than one result fields (%d) but no format string", pwh, f);
|
syslog(LOG_WARNING,
|
||||||
|
"pgworker (%p) process: more than one result fields (%d) but no format string",
|
||||||
|
pwh, f);
|
||||||
strcpy(output, PQgetvalue(pgr, 0, 0));
|
strcpy(output, PQgetvalue(pgr, 0, 0));
|
||||||
res = 0;
|
res = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -362,8 +381,8 @@ int process(pg_worker_handle_t *pwh, char *input, char *output) {
|
|||||||
as instances are using it.
|
as instances are using it.
|
||||||
- A position argument to identify the result parameter for the particular
|
- A position argument to identify the result parameter for the particular
|
||||||
instance will be defined.
|
instance will be defined.
|
||||||
- If a cache file should be used, the same cache file can be used of instances
|
- If a cache file should be used, the same cache file can be used of
|
||||||
using the same SQL-statement.
|
instances using the same SQL-statement.
|
||||||
|
|
||||||
C:
|
C:
|
||||||
- As B, but for each instance a list of position arguments can be given
|
- As B, but for each instance a list of position arguments can be given
|
||||||
@ -374,6 +393,6 @@ int process(pg_worker_handle_t *pwh, char *input, char *output) {
|
|||||||
- As C, but instead of a separator token a format string must be given.
|
- As C, but instead of a separator token a format string must be given.
|
||||||
|
|
||||||
E:
|
E:
|
||||||
- As D, but instead of given output positions in a separate list, the position
|
- As D, but instead of given output positions in a separate list, the
|
||||||
numbers will be used directly in the format string.
|
position numbers will be used directly in the format string.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user