Browse Source

ckdb - organise db cmp functions - web set binary sep to be 'tab'

master
kanoi 11 years ago
parent
commit
c2e50a2f51
  1. 3
      pool/db.php
  2. 35
      src/ckdb.c

3
pool/db.php

@ -5,7 +5,7 @@ include_once('base.php');
#
global $send_sep, $fld_sep, $val_sep;
$send_sep = '.';
$fld_sep = Chr(0x2);
$fld_sep = Chr(0x9);
$val_sep = '=';
#
function myhash($str)
@ -69,7 +69,6 @@ function msgEncode($cmd, $id, $fields)
#
function getStats($user)
{
global $fld_sep;
if ($user === null)
$msg = msgEncode('homepage', 'home', array());
else

35
src/ckdb.c

@ -61,7 +61,8 @@ static char *db_pass;
#define TXT_SML 64
#define TXT_FLAG 1
#define FLDSEP 0x02
// TAB
#define FLDSEP 0x09
// Ensure long long and int64_t are both 8 bytes (and thus also the same)
#define ASSERT1(condition) __maybe_unused static char sizeof_longlong_must_be_8[(condition)?1:-1]
@ -898,6 +899,7 @@ static void setnow(tv_t *now)
now->tv_usec = spec.tv_nsec / 1000;
}
// order by name asc
static double cmp_transfer(K_ITEM *a, K_ITEM *b)
{
double c = (double)strcmp(DATA_TRANSFER(a)->name,
@ -1205,6 +1207,7 @@ static char *tv_to_buf(tv_t *data, char *buf, size_t siz)
return data_to_buf(TYPE_TV, (void *)data, buf, siz);
}
// Convert tv to seconds (ignore uS)
static char *tvs_to_buf(tv_t *data, char *buf, size_t siz)
{
return data_to_buf(TYPE_TVS, (void *)data, buf, siz);
@ -1831,6 +1834,7 @@ static K_ITEM *new_worker(PGconn *conn, bool update, int64_t userid, char *worke
idlenotificationtime, now, by, code, inet);
}
} else {
// TODO: limit how many?
item = workers_add(conn, userid, workername, diffdef,
idlenotificationenabled, idlenotificationtime,
now, by, code, inet);
@ -2441,11 +2445,11 @@ static double cmp_shares(K_ITEM *a, K_ITEM *b)
double c = (double)(DATA_SHARES(a)->workinfoid) -
(double)(DATA_SHARES(b)->workinfoid);
if (c == 0) {
c = (double)(DATA_SHARES(b)->userid) -
(double)(DATA_SHARES(a)->userid);
c = (double)(DATA_SHARES(a)->userid) -
(double)(DATA_SHARES(b)->userid);
if (c == 0) {
c = tvdiff(&(DATA_SHARES(b)->createdate),
&(DATA_SHARES(a)->createdate));
c = tvdiff(&(DATA_SHARES(a)->createdate),
&(DATA_SHARES(b)->createdate));
if (c == 0) {
c = strcmp(DATA_SHARES(a)->nonce,
DATA_SHARES(b)->nonce);
@ -2535,11 +2539,11 @@ static double cmp_shareerrors(K_ITEM *a, K_ITEM *b)
double c = (double)(DATA_SHAREERRORS(a)->workinfoid) -
(double)(DATA_SHAREERRORS(b)->workinfoid);
if (c == 0) {
c = (double)(DATA_SHAREERRORS(b)->userid) -
(double)(DATA_SHAREERRORS(a)->userid);
c = (double)(DATA_SHAREERRORS(a)->userid) -
(double)(DATA_SHAREERRORS(b)->userid);
if (c == 0) {
c = tvdiff(&(DATA_SHAREERRORS(b)->createdate),
&(DATA_SHAREERRORS(a)->createdate));
c = tvdiff(&(DATA_SHAREERRORS(a)->createdate),
&(DATA_SHAREERRORS(b)->createdate));
if (c == 0) {
c = tvdiff(&(DATA_SHAREERRORS(b)->expirydate),
&(DATA_SHAREERRORS(a)->expirydate));
@ -2616,16 +2620,17 @@ static bool shareerrors_fill()
return true;
}
// order by userid asc,createdate asc,authid asc,expirydate desc
static double cmp_auths(K_ITEM *a, K_ITEM *b)
{
double c = (double)(DATA_AUTHS(a)->authid) -
(double)(DATA_AUTHS(b)->authid);
double c = (double)(DATA_AUTHS(a)->userid) -
(double)(DATA_AUTHS(b)->userid);
if (c == 0) {
c = (double)(DATA_AUTHS(b)->userid) -
(double)(DATA_AUTHS(a)->userid);
c = tvdiff(&(DATA_AUTHS(a)->createdate),
&(DATA_AUTHS(b)->createdate));
if (c == 0) {
c = tvdiff(&(DATA_AUTHS(b)->createdate),
&(DATA_AUTHS(a)->createdate));
c = (double)(DATA_AUTHS(a)->authid) -
(double)(DATA_AUTHS(b)->authid);
if (c == 0) {
c = tvdiff(&(DATA_AUTHS(b)->expirydate),
&(DATA_AUTHS(a)->expirydate));

Loading…
Cancel
Save