diff --git a/sql/ckdb.sql b/sql/ckdb.sql index 839bc8d0..33382f70 100644 --- a/sql/ckdb.sql +++ b/sql/ckdb.sql @@ -192,7 +192,7 @@ CREATE TABLE workinfo ( ); -CREATE TABLE shares ( -- only shares with sdiff >= minsdiff are stored in the DB +CREATE TABLE shares ( -- only shares with sdiff >= -D minsdiff are stored in the DB workinfoid bigint NOT NULL, userid bigint NOT NULL, workername character varying(256) NOT NULL, @@ -207,6 +207,8 @@ CREATE TABLE shares ( -- only shares with sdiff >= minsdiff are stored in the DB secondaryuserid character varying(64) NOT NULL, ntime character varying(64) NOT NULL, minsdiff float NOT NULL, + agent character varying(128) DEFAULT ''::character varying NOT NULL, + address character varying(128) DEFAULT ''::character varying NOT NULL, createdate timestamp with time zone NOT NULL, createby character varying(64) DEFAULT ''::character varying NOT NULL, createcode character varying(128) DEFAULT ''::character varying NOT NULL, @@ -233,7 +235,7 @@ CREATE TABLE shareerrors ( -- not stored in the db - only in log files ); -CREATE TABLE sharesummary ( -- per workinfo for each user+worker +CREATE TABLE sharesummary ( -- per workinfo for each user+worker - RAM not DB userid bigint NOT NULL, workername character varying(256) NOT NULL, workinfoid bigint NOT NULL, @@ -472,4 +474,4 @@ CREATE TABLE version ( PRIMARY KEY (vlock) ); -insert into version (vlock,version) values (1,'1.0.5'); +insert into version (vlock,version) values (1,'1.0.6'); diff --git a/sql/v1.0.5-v1.0.6.sql b/sql/v1.0.5-v1.0.6.sql new file mode 100644 index 00000000..d62275de --- /dev/null +++ b/sql/v1.0.5-v1.0.6.sql @@ -0,0 +1,26 @@ +SET SESSION AUTHORIZATION 'postgres'; + +BEGIN transaction; + +DO $$ +DECLARE ver TEXT; +BEGIN + + UPDATE version set version='1.0.6' where vlock=1 and version='1.0.5'; + + IF found THEN + RETURN; + END IF; + + SELECT version into ver from version + WHERE vlock=1; + + RAISE EXCEPTION 'Wrong DB version - expect "1.0.5" - found "%"', ver; + +END $$; + +ALTER TABLE ONLY shares + ADD COLUMN agent character varying(128) DEFAULT ''::character varying NOT NULL, + ADD COLUMN address character varying(128) DEFAULT ''::character varying NOT NULL; + +END transaction; diff --git a/src/ckdb.h b/src/ckdb.h index af8ebe78..72082aad 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -51,8 +51,8 @@ * Consider adding row level locking (a per kitem usage count) if needed */ #define DB_VLOCK "1" -#define DB_VERSION "1.0.5" -#define CKDB_VERSION DB_VERSION"-2.107" +#define DB_VERSION "1.0.6" +#define CKDB_VERSION DB_VERSION"-2.108" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -1840,6 +1840,8 @@ typedef struct shares { char secondaryuserid[TXT_SML+1]; char ntime[TXT_SML+1]; double minsdiff; + char agent[TXT_MED+1]; + char address[TXT_MED+1]; HISTORYDATECONTROLFIELDS; int32_t redo; // non-DB field int32_t oldcount; // non-DB field @@ -3238,8 +3240,8 @@ extern bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername, char *clientid, char *errn, char *enonce1, char *nonce2, char *nonce, char *diff, char *sdiff, char *secondaryuserid, char *ntime, - char *by, char *code, char *inet, tv_t *cd, - K_TREE *trf_root); + char *address, char *agent, char *by, char *code, + char *inet, tv_t *cd, K_TREE *trf_root); extern bool shares_db(PGconn *conn, K_ITEM *s_item); extern bool shares_fill(PGconn *conn); extern bool shareerrors_add(PGconn *conn, char *workinfoid, char *username, diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index a43a6ee4..9fc82dae 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -2618,7 +2618,8 @@ wiconf: } else if (strcasecmp(cmd, STR_SHARES) == 0) { K_ITEM *i_workinfoid, *i_username, *i_workername, *i_clientid, *i_errn; K_ITEM *i_enonce1, *i_nonce2, *i_nonce, *i_diff, *i_sdiff; - K_ITEM *i_secondaryuserid, *i_ntime; + K_ITEM *i_secondaryuserid, *i_ntime, *i_address, *i_agent; + char *address, *agent; bool ok; i_nonce = require_name(trf_root, "nonce", 1, NULL, reply, siz); @@ -2697,6 +2698,18 @@ wiconf: if (!i_ntime) return strdup(reply); + i_address = optional_name(trf_root, "address", 0, NULL, reply, siz); + if (i_address) + address = transfer_data(i_address); + else + address = EMPTY; + + i_agent = optional_name(trf_root, "agent", 0, NULL, reply, siz); + if (i_agent) + agent = transfer_data(i_agent); + else + agent = EMPTY; + ok = shares_add(conn, transfer_data(i_workinfoid), transfer_data(i_username), transfer_data(i_workername), @@ -2708,7 +2721,7 @@ wiconf: transfer_data(i_diff), transfer_data(i_sdiff), transfer_data(i_secondaryuserid), - transfer_data(i_ntime), + transfer_data(i_ntime), address, agent, by, code, inet, cd, trf_root); if (!ok) { diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index 42de12ea..80ef8d52 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -185,7 +185,7 @@ char *pqerrmsg(PGconn *conn) #define PQPARAM16 PQPARAM8 ",$9,$10,$11,$12,$13,$14,$15,$16" #define PQPARAM17 PQPARAM16 ",$17" #define PQPARAM18 PQPARAM16 ",$17,$18" -#define PQPARAM19 PQPARAM16 ",$17,$18,$19" +#define PQPARAM21 PQPARAM16 ",$17,$18,$19,$20,$21" #define PQPARAM22 PQPARAM16 ",$17,$18,$19,$20,$21,$22" #define PQPARAM23 PQPARAM16 ",$17,$18,$19,$20,$21,$22,$23" #define PQPARAM26 PQPARAM22 ",$23,$24,$25,$26" @@ -3633,8 +3633,8 @@ static void shareerrors_process_early(PGconn *conn, int64_t good_wid, bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername, char *clientid, char *errn, char *enonce1, char *nonce2, char *nonce, char *diff, char *sdiff, char *secondaryuserid, - char *ntime, char *by, char *code, char *inet, tv_t *cd, - K_TREE *trf_root) + char *ntime, char *address, char *agent, char *by, char *code, + char *inet, tv_t *cd, K_TREE *trf_root) { K_TREE_CTX ctx[1]; K_ITEM *s_item = NULL, *s2_item = NULL, *u_item, *wi_item, *tmp_item; @@ -3706,6 +3706,8 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername STRNCPY(shares->ntime, ntime); shares->minsdiff = share_min_sdiff; + STRNCPY(shares->address, address); + STRNCPY(shares->agent, agent); HISTORYDATEINIT(shares, cd, by, code, inet); HISTORYDATETRANSFER(trf_root, shares); @@ -3794,7 +3796,7 @@ bool shares_db(PGconn *conn, K_ITEM *s_item) PGresult *res; SHARES *row; char *ins; - char *params[14 + HISTORYDATECOUNT]; + char *params[16 + HISTORYDATECOUNT]; int n, par = 0; bool ok = false; @@ -3817,13 +3819,15 @@ bool shares_db(PGconn *conn, K_ITEM *s_item) params[par++] = str_to_buf(row->secondaryuserid, NULL, 0); params[par++] = str_to_buf(row->ntime, NULL, 0); params[par++] = double_to_buf(row->minsdiff, NULL, 0); + params[par++] = str_to_buf(row->address, NULL, 0); + params[par++] = str_to_buf(row->agent, NULL, 0); HISTORYDATEPARAMS(params, par, row); PARCHK(par, params); ins = "insert into shares " "(workinfoid,userid,workername,clientid,enonce1,nonce2,nonce," - "diff,sdiff,errn,error,secondaryuserid,ntime,minsdiff" - HISTORYDATECONTROL ") values (" PQPARAM19 ")"; + "diff,sdiff,errn,error,secondaryuserid,ntime,minsdiff,address," + "agent" HISTORYDATECONTROL ") values (" PQPARAM21 ")"; if (!conn) { conn = dbconnect();