Browse Source

ckdb/sql - db update and store address+agent for sdiff shares

master
kanoi 9 years ago
parent
commit
39f2cf70e4
  1. 8
      sql/ckdb.sql
  2. 26
      sql/v1.0.5-v1.0.6.sql
  3. 10
      src/ckdb.h
  4. 17
      src/ckdb_cmd.c
  5. 16
      src/ckdb_dbio.c

8
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, workinfoid bigint NOT NULL,
userid bigint NOT NULL, userid bigint NOT NULL,
workername character varying(256) 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, secondaryuserid character varying(64) NOT NULL,
ntime character varying(64) NOT NULL, ntime character varying(64) NOT NULL,
minsdiff float 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, createdate timestamp with time zone NOT NULL,
createby character varying(64) DEFAULT ''::character varying NOT NULL, createby character varying(64) DEFAULT ''::character varying NOT NULL,
createcode character varying(128) 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, userid bigint NOT NULL,
workername character varying(256) NOT NULL, workername character varying(256) NOT NULL,
workinfoid bigint NOT NULL, workinfoid bigint NOT NULL,
@ -472,4 +474,4 @@ CREATE TABLE version (
PRIMARY KEY (vlock) PRIMARY KEY (vlock)
); );
insert into version (vlock,version) values (1,'1.0.5'); insert into version (vlock,version) values (1,'1.0.6');

26
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;

10
src/ckdb.h

@ -51,8 +51,8 @@
* Consider adding row level locking (a per kitem usage count) if needed */ * Consider adding row level locking (a per kitem usage count) if needed */
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.5" #define DB_VERSION "1.0.6"
#define CKDB_VERSION DB_VERSION"-2.107" #define CKDB_VERSION DB_VERSION"-2.108"
#define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #define WHERE_FFL_HERE __FILE__, __func__, __LINE__
@ -1840,6 +1840,8 @@ typedef struct shares {
char secondaryuserid[TXT_SML+1]; char secondaryuserid[TXT_SML+1];
char ntime[TXT_SML+1]; char ntime[TXT_SML+1];
double minsdiff; double minsdiff;
char agent[TXT_MED+1];
char address[TXT_MED+1];
HISTORYDATECONTROLFIELDS; HISTORYDATECONTROLFIELDS;
int32_t redo; // non-DB field int32_t redo; // non-DB field
int32_t oldcount; // 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 *workername, char *clientid, char *errn,
char *enonce1, char *nonce2, char *nonce, char *diff, char *enonce1, char *nonce2, char *nonce, char *diff,
char *sdiff, char *secondaryuserid, char *ntime, char *sdiff, char *secondaryuserid, char *ntime,
char *by, char *code, char *inet, tv_t *cd, char *address, char *agent, char *by, char *code,
K_TREE *trf_root); char *inet, tv_t *cd, K_TREE *trf_root);
extern bool shares_db(PGconn *conn, K_ITEM *s_item); extern bool shares_db(PGconn *conn, K_ITEM *s_item);
extern bool shares_fill(PGconn *conn); extern bool shares_fill(PGconn *conn);
extern bool shareerrors_add(PGconn *conn, char *workinfoid, char *username, extern bool shareerrors_add(PGconn *conn, char *workinfoid, char *username,

17
src/ckdb_cmd.c

@ -2618,7 +2618,8 @@ wiconf:
} else if (strcasecmp(cmd, STR_SHARES) == 0) { } else if (strcasecmp(cmd, STR_SHARES) == 0) {
K_ITEM *i_workinfoid, *i_username, *i_workername, *i_clientid, *i_errn; 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_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; bool ok;
i_nonce = require_name(trf_root, "nonce", 1, NULL, reply, siz); i_nonce = require_name(trf_root, "nonce", 1, NULL, reply, siz);
@ -2697,6 +2698,18 @@ wiconf:
if (!i_ntime) if (!i_ntime)
return strdup(reply); 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), ok = shares_add(conn, transfer_data(i_workinfoid),
transfer_data(i_username), transfer_data(i_username),
transfer_data(i_workername), transfer_data(i_workername),
@ -2708,7 +2721,7 @@ wiconf:
transfer_data(i_diff), transfer_data(i_diff),
transfer_data(i_sdiff), transfer_data(i_sdiff),
transfer_data(i_secondaryuserid), transfer_data(i_secondaryuserid),
transfer_data(i_ntime), transfer_data(i_ntime), address, agent,
by, code, inet, cd, trf_root); by, code, inet, cd, trf_root);
if (!ok) { if (!ok) {

16
src/ckdb_dbio.c

@ -185,7 +185,7 @@ char *pqerrmsg(PGconn *conn)
#define PQPARAM16 PQPARAM8 ",$9,$10,$11,$12,$13,$14,$15,$16" #define PQPARAM16 PQPARAM8 ",$9,$10,$11,$12,$13,$14,$15,$16"
#define PQPARAM17 PQPARAM16 ",$17" #define PQPARAM17 PQPARAM16 ",$17"
#define PQPARAM18 PQPARAM16 ",$17,$18" #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 PQPARAM22 PQPARAM16 ",$17,$18,$19,$20,$21,$22"
#define PQPARAM23 PQPARAM16 ",$17,$18,$19,$20,$21,$22,$23" #define PQPARAM23 PQPARAM16 ",$17,$18,$19,$20,$21,$22,$23"
#define PQPARAM26 PQPARAM22 ",$23,$24,$25,$26" #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, bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername,
char *clientid, char *errn, char *enonce1, char *nonce2, char *clientid, char *errn, char *enonce1, char *nonce2,
char *nonce, char *diff, char *sdiff, char *secondaryuserid, char *nonce, char *diff, char *sdiff, char *secondaryuserid,
char *ntime, char *by, char *code, char *inet, tv_t *cd, char *ntime, char *address, char *agent, char *by, char *code,
K_TREE *trf_root) char *inet, tv_t *cd, K_TREE *trf_root)
{ {
K_TREE_CTX ctx[1]; K_TREE_CTX ctx[1];
K_ITEM *s_item = NULL, *s2_item = NULL, *u_item, *wi_item, *tmp_item; 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); STRNCPY(shares->ntime, ntime);
shares->minsdiff = share_min_sdiff; shares->minsdiff = share_min_sdiff;
STRNCPY(shares->address, address);
STRNCPY(shares->agent, agent);
HISTORYDATEINIT(shares, cd, by, code, inet); HISTORYDATEINIT(shares, cd, by, code, inet);
HISTORYDATETRANSFER(trf_root, shares); HISTORYDATETRANSFER(trf_root, shares);
@ -3794,7 +3796,7 @@ bool shares_db(PGconn *conn, K_ITEM *s_item)
PGresult *res; PGresult *res;
SHARES *row; SHARES *row;
char *ins; char *ins;
char *params[14 + HISTORYDATECOUNT]; char *params[16 + HISTORYDATECOUNT];
int n, par = 0; int n, par = 0;
bool ok = false; 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->secondaryuserid, NULL, 0);
params[par++] = str_to_buf(row->ntime, NULL, 0); params[par++] = str_to_buf(row->ntime, NULL, 0);
params[par++] = double_to_buf(row->minsdiff, 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); HISTORYDATEPARAMS(params, par, row);
PARCHK(par, params); PARCHK(par, params);
ins = "insert into shares " ins = "insert into shares "
"(workinfoid,userid,workername,clientid,enonce1,nonce2,nonce," "(workinfoid,userid,workername,clientid,enonce1,nonce2,nonce,"
"diff,sdiff,errn,error,secondaryuserid,ntime,minsdiff" "diff,sdiff,errn,error,secondaryuserid,ntime,minsdiff,address,"
HISTORYDATECONTROL ") values (" PQPARAM19 ")"; "agent" HISTORYDATECONTROL ") values (" PQPARAM21 ")";
if (!conn) { if (!conn) {
conn = dbconnect(); conn = dbconnect();

Loading…
Cancel
Save