Stored Proc for DXCC info

pull/195/head
Andy 2016-02-28 14:09:08 +00:00
rodzic 3459a81098
commit 35363f2374
6 zmienionych plików z 81 dodań i 13 usunięć

Wyświetl plik

@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE;
| be upgraded / downgraded to.
|
*/
$config['migration_version'] = 12;
$config['migration_version'] = 13;
/*

Wyświetl plik

@ -351,6 +351,19 @@ class Logbook extends CI_Controller {
echo $json;
}
/*
* Provide a dxcc search, returning results json encoded
*/
function local_find_dxcc($call = "", $date = "") {
$this->load->model("logbook_model");
if ($date == ''){
$date = date("Y-m-d");
}
$ans = $this->logbook_model->check_dxcc_stored_proc($call, $date);
print json_encode($ans);
}
/* return station bearing */
function bearing() {
$this->load->library('Qra');

Wyświetl plik

@ -1,10 +0,0 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

Wyświetl plik

@ -0,0 +1,46 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_add_dxcc_stored_proc extends CI_Migration {
public function up(){
$res = $this->db->query("drop procedure if exists `find_country`");
if (!$res){
print ("Error dropping stored proc");
exit(0);
}
$sql = <<<EOF
CREATE PROCEDURE `find_country`(
IN callsign varchar(10),
IN qso_date date,
OUT country varchar(255),
OUT dxcc_id int)
begin
declare calllen int default 0;
set calllen = char_length(callsign);
L1: while calllen >0 do
select `entity`, `adif` into country, dxcc_id
from dxcc_prefixes
where `call`= substring(callsign, 1, calllen)
and (`start` <= qso_date or `start`='0000-00-00')
and (`end` >= qso_date or `end`='0000-00-00');
if (FOUND_ROWS() >0) THEN
LEAVE L1;
else
set calllen = calllen - 1;
end IF;
end WHILE;
end
EOF;
$res = $this->db->query($sql);
if (!$res){
print ("Error setting stored proc");
exit(0);
}
}
public function down(){
$this->db->query("drop procedure if exists `find_country`");
}
}

Wyświetl plik

@ -967,6 +967,21 @@ class Logbook_model extends CI_Model {
return array("Not Found", "Not Found");
}
/*
* Same as check_dxcc_table, but the functionality is in
* a stored procedure which we call
*/
public function check_dxcc_stored_proc($call, $date){
$this->db->query("call find_country('".$call."','".$date."', @country, @adif)");
$res = $this->db->query("select @country as country, @adif as adif");
$d = $res->result_array();
// Should only be one result.
// NOTE: might cause unexpected data if there's an
// error with clublog.org data.
return $d[0];
}
public function check_missing_dxcc_id($all){
// get all records with no COL_DXCC
$this->db->select("COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_TIME_OFF");
@ -986,8 +1001,12 @@ class Logbook_model extends CI_Model {
$qso_date = $row['COL_TIME_OFF']=='' ? $row['COL_TIME_ON'] : $row['COL_TIME_ON'];
$qso_date = strftime("%Y-%m-%d", strtotime($qso_date));
// Manual call
$d = $this->check_dxcc_table($row['COL_CALL'], $qso_date);
// Stored procedure call
//$d = $this->check_dxcc_stored_proc($row["COL_CALL"], $qso_date);
if ($d[0] != 'Not Found'){
$sql = sprintf("update %s set COL_COUNTRY = '%s', COL_DXCC='%s' where COL_PRIMARY_KEY=%d",
$this->config->item('table_name'), addslashes(ucwords(strtolower($d[1]))), $d[0], $row['COL_PRIMARY_KEY']);

Wyświetl plik

@ -8,8 +8,8 @@
Status:</br>
</div>
<br/>
<a href="update/check_missing_dxcc">Check missing DXCC/Countries values</a>
<a href="update/check_missing_dxcc/all">[Re-Check ALL]</a>
<a href="check_missing_dxcc">Check missing DXCC/Countries values</a>
<a href="check_missing_dxcc/all">[Re-Check ALL]</a>
</div>
<style>