diff --git a/src/ckdb.c b/src/ckdb.c index ba09f3b6..59db2800 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -5687,6 +5687,7 @@ static void *process_socket(void *arg) case CMD_GETATTS: case CMD_THREADS: case CMD_HOMEPAGE: + case CMD_QUERY: break; default: snprintf(reply, sizeof(reply), diff --git a/src/ckdb.h b/src/ckdb.h index 32b158be..383e5d4c 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -58,7 +58,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.7" -#define CKDB_VERSION DB_VERSION"-2.414" +#define CKDB_VERSION DB_VERSION"-2.415" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 61ef1fff..fed39d11 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -7665,6 +7665,67 @@ static char *cmd_query(__maybe_unused PGconn *conn, char *cmd, char *id, "Payouts", FLDSEP, "", FLDSEP); APPEND_REALLOC(buf, off, len, tmp); + ok = true; + } else if (strcasecmp(request, "shareinfo") == 0) { + /* return share information for the workinfo with wid>=value + * if wid=0 then find the oldest workinfo that has shares */ + K_ITEM *i_wid, s_look, *s_item; + SHARES lookshares, *shares; + int64_t selwid, wid, s_count = 0, s_diff = 0, s_sdiff = 0; + bool found; + + i_wid = require_name(trf_root, "wid", + 1, (char *)intpatt, + reply, siz); + if (!i_wid) + return strdup(reply); + TXT_TO_BIGINT("wid", transfer_data(i_wid), selwid); + + INIT_SHARES(&s_look); + lookshares.workinfoid = selwid; + lookshares.userid = -1; + lookshares.workername[0] = '\0'; + DATE_ZERO(&(lookshares.createdate)); + s_look.data = (void *)(&lookshares); + found = false; + K_RLOCK(shares_free); + s_item = find_after_in_ktree(shares_root, &s_look, ctx); + if (s_item) { + found = true; + DATA_SHARES(shares, s_item); + wid = shares->workinfoid; + while (s_item) { + DATA_SHARES(shares, s_item); + if (shares->workinfoid != wid) + break; + s_count++; + s_diff += shares->diff; + if (s_sdiff < shares->sdiff) + s_sdiff = shares->sdiff; + s_item = next_in_ktree(ctx); + } + } + K_RUNLOCK(shares_free); + + if (found) { + snprintf(tmp, sizeof(tmp), "selwid=%"PRId64"%c", + selwid, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + snprintf(tmp, sizeof(tmp), "wid=%"PRId64"%c", + wid, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + snprintf(tmp, sizeof(tmp), "shares=%"PRId64"%c", + s_count, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + snprintf(tmp, sizeof(tmp), "diff=%"PRId64"%c", + s_diff, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + snprintf(tmp, sizeof(tmp), "maxsdiff=%"PRId64"%c", + s_sdiff, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + rows++; + } + ok = true; } else { free(buf);