\n";
// Function prints a description of $table
function print_describe_table_onecol($table, $which, $columns) {
$result=mysql_query("SELECT * from $table LIMIT 1");
$fields=mysql_num_fields($result);
$avgnum=(int)($fields/$columns);
if ($avgnum*$columns<$fields)
$avgnum++;
$actualcolumns=0;
while ($avgnum*$actualcolumns<$fields)
$actualcolumns++;
if ($which>$actualcolumns)
return 0;
$bot=($which-1)*$avgnum;
$top=$which*$avgnum;
$width=100.0/$actualcolumns;
// echo "
";
return 0;
}
function print_describe_table($table, $how_many_columns) {
// Number of columns for showing table description
echo "
Description of $table table fields:
\n";
echo "
\n\t
";
for ($i=1; $i<=$how_many_columns; $i++)
print_describe_table_onecol($table, $i, $how_many_columns);
echo "\t
\n
\n";
return 0;
}
function join_query_string($s1, $s2) {
if ($s1) {
if ($s2) {
return "$s1&s2";
} else {
return $s1;
}
} else {
return $s2;
}
}
// SqlQueryString maps a bunch of form items to a SQL query
//
// The items are
// table (name of table)
// id
// platformid
// appid
// workunitid
// hostid
// userid
// teamid
// nsecs (received_time > now - nsecs)
// received_time (> x)
// server_state (== x if z nonzero)
// outcome (== x if z nonzero)
// client_state (== x if z nonzero)
// exit_status (== x if z nonzero)
// clauses (literals added after the above)
// sort_by (order by x desc added after all else)
//
// Once you've parsed the items (using parse_form_items()):
//
// get_select_query(n, m) returns the SQL query to get items from m to m+n
// get_url() returns the URL-encoded version of everything
// count() returns the number of records satisfying the query
class SqlQueryString {
var $table;
var $query;
var $urlquery;
function SqlQueryString() {
$this->table = $_GET['table'];
//$this->query = $_GET['query'];
$this->query = "";
$this->urlquery = "";
}
function add($clause) {
$cleaned=boinc_real_escape_string($clause);
if (!$this->query) {
$this->query .= "where $cleaned";
} else {
$this->query .= " and $cleaned";
}
}
function addclause($clause) {
if ($clause) {
$this->add($clause);
$this->urlquery .= "&clauses=".urlencode($clause);
}
}
function addeq($name) {
$value = $_GET[$name];
if (strlen($value)) {
$this->add("$name = '$value'");
$this->urlquery .= "&$name=".urlencode($value);
}
}
function addeq_not_CHOOSE_ALL($name) {
$value = $_GET[$name];
// On the selection menu, the ALL selection criteria sets (for example)
// outcome=='CHOOSE_ALL' rather than a numeric value. This means that
// we enter no condition for this case.
if (strlen($value) && strcmp("CHOOSE_ALL", $value)) {
$this->add("$name = '$value'");
$this->urlquery .= "&$name=".urlencode($value);
}
}
function addgt($name) {
$value = $_GET[$name];
if (strlen($value) && $value > 0) {
$this->add("$name > '$value'");
$this->urlquery .= "&$name=".urlencode($value);
}
}
function addsort($name) {
$value = $_GET[$name];
if (strlen($value)) {
$this->query .= " order by $value desc";
$this->urlquery .= "&$name=".urlencode($value);
}
}
function count() {
$count_query = "select count(*) as cnt from $this->table $this->query";
$result = mysql_query($count_query);
if (!$result) return 0;
$res = mysql_fetch_object($result);
mysql_free_result($result);
return $res->cnt;
}
function get_select_query($entries_to_show, $start_at) {
if ($entries_to_show) {
if ($start_at) {
return "select * from $this->table $this->query limit $start_at,$entries_to_show";
} else {
return "select * from $this->table $this->query limit $entries_to_show";
}
} else {
return "select * from $this->table $this->query";
}
}
function get_url($base) {
$s = "db_action.php?table=$this->table$this->urlquery";
return $s;
}
function process_form_items() {
$this->addeq('id');
$this->addeq('platformid');
$this->addeq('appid');
$this->addeq('workunitid');
$this->addeq('hostid');
$this->addeq('userid');
$this->addeq('teamid');
$this->addeq('exit_status');
if ($_GET['nsecs']) {
$_GET['received_time'] = time() - $_GET['nsecs'];
}
$this->addgt('received_time');
$this->addeq_not_CHOOSE_ALL('server_state');
$this->addeq_not_CHOOSE_ALL('outcome');
$this->addeq_not_CHOOSE_ALL('client_state');
$this->addeq_not_CHOOSE_ALL('validate_state');
if ($_GET['clauses']) {
$this->addclause("( " . urldecode($_GET['clauses']) . " )");
}
$this->addsort('sort_by');
}
}
function link_results($n, $mq, $query, $clauses) {
if ($n == '0') { // intentional compare by string
return "0";
} else {
if(strlen($clauses)) {
return "$n";
}
else {
return "$n";
}
}
}
//
function exit_status_string($result) {
$x = $result->exit_status;
if ($x == 0) {
$y = parse_element($result->stderr_out, "");
if ($y) {
$x = (int)$y;
}
}
return sprintf("%d (0x%x)", $x, $x);
}
function show_result_summary() {
$ntotal =0; // TODO: how to count $result?
$nvalid = 0; // for SUCCESS results
$ninvalid = 0;
$nfile_deleted = 0;
$server_state = array();
$outcome = array();
$client_state = array();
for ($ss=1; $ss<6; $ss++) {
$server_state[$ss] = 0;
}
for ($ro=0; $ro<7; $ro++) {
$outcome[$ro] = 0;
}
for ($cs=1; $cs<6; $cs++) {
$client_state[$cs] = 0;
}
$_GET['table'] = 'result';
$_GET['sort_by'] = ''; // ignore sort
$query_appid = $_GET['appid'];
if ($_GET['nsecs'])
$query_received_time = time() - $_GET['nsecs'];
$query_wuid = $_GET['workunitid'];
$q = new SqlQueryString();
$q->process_form_items();
// Important: these need to be kept consistent with db/boinc_db.h and lib/result_state.h
$main_query = "
SELECT COUNT(id) AS nTotal,
SUM(case when server_state = '1' then 1 else 0 end) AS serverstate_inactive,
SUM(case when server_state = '2' then 1 else 0 end) AS serverstate_unset,
SUM(case when server_state = '3' then 1 else 0 end) AS serverstate_unset_seq,
SUM(case when server_state = '4' then 1 else 0 end) AS serverstate_inprogress,
SUM(case when server_state = '5' then 1 else 0 end) AS serverstate_over,
SUM(case when server_state = '5' and outcome = '0' then 1 else 0 end) AS outcome_init,
SUM(case when server_state = '5' and outcome = '1' then 1 else 0 end) AS outcome_success,
SUM(case when server_state = '5' and outcome = '2' then 1 else 0 end) AS outcome_couldntsend,
SUM(case when server_state = '5' and outcome = '3' then 1 else 0 end) AS outcome_failure,
SUM(case when server_state = '5' and outcome = '4' then 1 else 0 end) AS outcome_noreply,
SUM(case when server_state = '5' and outcome = '5' then 1 else 0 end) AS outcome_didntneed,
SUM(case when server_state = '5' and outcome = '6' then 1 else 0 end) AS outcome_validateerror,
SUM(case when server_state = '5' and outcome = '1' and validate_state = '0' then 1 else 0 end) AS validate_init,
SUM(case when server_state = '5' and outcome = '1' and validate_state = '1' then 1 else 0 end) AS validate_valid,
SUM(case when server_state = '5' and outcome = '1' and validate_state = '2' then 1 else 0 end) AS validate_invalid,
SUM(case when server_state = '5' and outcome = '1' and validate_state = '3' then 1 else 0 end) AS validate_nocheck,
SUM(case when server_state = '5' and outcome = '1' and file_delete_state = '0' then 1 else 0 end) AS filedeletestate_init,
SUM(case when server_state = '5' and outcome = '1' and file_delete_state = '1' then 1 else 0 end) AS filedeletestate_ready,
SUM(case when server_state = '5' and outcome = '1' and file_delete_state = '2' then 1 else 0 end) AS filedeletestate_done,
SUM(case when server_state = '5' and outcome = '3' and client_state = '0' then 1 else 0 end) AS clientstate_init,
SUM(case when server_state = '5' and outcome = '3' and client_state = '1' then 1 else 0 end) AS clientstate_downloading,
SUM(case when server_state = '5' and outcome = '3' and client_state = '2' then 1 else 0 end) AS clientstate_downloaded,
SUM(case when server_state = '5' and outcome = '3' and client_state = '3' then 1 else 0 end) AS clientstate_computedone,
SUM(case when server_state = '5' and outcome = '3' and client_state = '4' then 1 else 0 end) AS clientstate_uploading,
SUM(case when server_state = '5' and outcome = '3' and client_state = '5' then 1 else 0 end) AS clientstate_uploaded
FROM result WHERE
";
if ($query_appid)
$main_query .= "appid=$query_appid and ";
if ($query_received_time)
$main_query .= "received_time > $query_received_time and ";
if ($query_wuid)
$main_query .= "workunitid=$query_wuid and ";
$main_query .= "1=1";
$urlquery = $q->urlquery;
$result = mysql_query($main_query);
// echo "Main query was $main_query ";
if ($result) {
$res = mysql_fetch_object($result);
$ntotal = $res->nTotal;
$server_state[1] = $res->serverstate_inactive;
$server_state[2] = $res->serverstate_unset;
$server_state[3] = $res->serverstate_unset_seq;
$server_state[4] = $res->serverstate_inprogress;
$server_state[5] = $res->serverstate_over;
$outcome[0] = $res->outcome_init;
$outcome[1] = $res->outcome_success;
$outcome[2] = $res->outcome_couldntsend;
$outcome[3] = $res->outcome_failure;
$outcome[4] = $res->outcome_noreply;
$outcome[5] = $res->outcome_didntneed;
$outcome[6] = $res->outcome_validateerror;
$client_state[1] = $res->clientstate_downloading;
$client_state[2] = $res->clientstate_downloaded;
$client_state[3] = $res->clientstate_computedone;
$client_state[4] = $res->clientstate_uploading;
$client_state[5] = $res->clientstate_uploaded;
$nvalid = $res->validate_valid;
$ninvalid = $res->validate_invalid;
$nfile_deleted = $res->filedeletestate_ready + $res->filedeletestate_done;
mysql_free_result($result);
}
echo "