-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhl_db.inc
173 lines (141 loc) · 5.58 KB
/
hl_db.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
// MySQL code for Librarian DB
//
// unless otherwise specified, functions return true on success
require_once("db_util.inc");
//// SOURCE ////
function source_insert($source) {
global $link;
$auth = $link->escape_string($source->authenticator);
$query = "insert into source (name, authenticator, create_time) values ('$source->name', '$auth', $source->create_time)";
return mysqli_query($link, $query);
}
function source_lookup_auth($auth) {
global $link;
$auth = $link->escape_string($auth);
$query = "select * from source where authenticator='$auth'";
$r = mysqli_query($link, $query);
$source = mysqli_fetch_object($r);
mysqli_free_result($r);
return $source;
}
function source_lookup_id($id) {
return lookup_id("source", $id);
}
function source_enum($clause=null) {
return enum('source', $clause);
}
//// OBSERVATION ////
function observation_insert($obs) {
global $link;
$polarization = $link->escape_string($obs->polarization);
$query = "insert into observation (id, source_id, julian_date, polarization, length) values ($obs->id, $obs->source_id, $obs->julian_date, '$polarization', $obs->length)";
return mysqli_query($link, $query);
}
function observation_lookup_id($id) {
return lookup_id("observation", $id);
}
function observation_enum($clause=null) {
return enum('observation', $clause);
}
//// STORE ////
function store_insert($store) {
global $link;
$name = $link->escape_string($store->name);
$rsync_prefix = $link->escape_string($store->rsync_prefix);
$http_prefix = $link->escape_string($store->http_prefix);
$path_prefix = $link->escape_string($store->path_prefix);
$ssh_prefix = $link->escape_string($store->ssh_prefix);
$query = "insert into store (name, create_time, capacity, used, rsync_prefix, http_prefix, path_prefix, ssh_prefix, unavailable) values ('$name', $store->create_time, $store->capacity, $store->used, '$rsync_prefix', '$http_prefix', '$path_prefix', '$ssh_prefix', 0)";
return mysqli_query($link, $query);
}
function store_lookup_name($name) {
global $link;
$name = $link->escape_string($name);
$query = "select * from store where name='$name'";
$r = mysqli_query($link, $query);
$store = mysqli_fetch_object($r);
mysqli_free_result($r);
return $store;
}
function store_enum($clause='') {
return enum('store', $clause);
}
function store_lookup_id($id) {
return lookup_id("store", $id);
}
function store_update($id, $clause) {
global $link;
$query = "update store set $clause where id=$id";
return mysqli_query($link, $query);
}
function store_update_all($id, $store) {
global $link;
$name = $link->escape_string($store->name);
$rsync_prefix = $link->escape_string($store->rsync_prefix);
$http_prefix = $link->escape_string($store->http_prefix);
$path_prefix = $link->escape_string($store->path_prefix);
$ssh_prefix = $link->escape_string($store->ssh_prefix);
$unavailable = $store->unavailable?1:0;
$query = "update store set name='$name', capacity=$store->capacity, used=$store->used, rsync_prefix='$rsync_prefix', http_prefix='$http_prefix', path_prefix='$path_prefix', ssh_prefix='$ssh_prefix', unavailable=$unavailable where id=$id";
return mysqli_query($link, $query);
}
//// FILE ////
function file_insert($file) {
global $link;
$name = $link->escape_string($file->file_name);
$type = $link->escape_string($file->type);
$md5 = $link->escape_string($file->md5);
$query = "insert into file (name, create_time, type, obs_id, source_id, store_id, size, md5) values ('$name', $file->create_time, '$type', $file->obs_id, $file->source_id, $file->store_id, $file->size, '$md5')";
return mysqli_query($link, $query);
}
function file_lookup_name_store($name, $store_id) {
global $link;
$name = $link->escape_string($name);
$query = "select * from file where name='$name' and store_id=$store_id";
$r = mysqli_query($link, $query);
$file = mysqli_fetch_object($r);
mysqli_free_result($r);
return $file;
}
function file_enum($clause=null) {
return enum('file', $clause);
}
function file_count($clause=null) {
return table_count('file', $clause);
}
///// TASK /////
function task_lookup_id($id) {
return lookup_id("task", $id);
}
function task_enum($clause=null) {
return enum('task', $clause);
}
function task_update_all($set_clause, $where_clause) {
global $link;
$query = "update task set $set_clause where $where_clause";
return mysqli_query($link, $query);
}
function task_update($id, $clause) {
global $link;
$query = "update task set $clause where id=$id";
return mysqli_query($link, $query);
}
function task_insert($task) {
global $link;
$now = time();
$file_name = $link->escape_string($task->file_name);
$remote_site = $link->escape_string($task->remote_site_name);
$remote_store = $link->escape_string($task->remote_store_name);
$delete_when_done = $task->delete_when_done?1:0;
$query = "insert into task (create_time, task_type, local_store_id, file_name, remote_site, remote_store, in_progress, delete_when_done, state, completed, completed_time, last_error, last_error_time) values ($now, $task->task_type, $task->local_store_id, '$file_name', '$remote_site', '$remote_store', 0, $delete_when_done, 0, 0, 0, '', 0)";
return mysqli_query($link, $query);
}
function task_update_error($id, $msg) {
global $link;
$msg = $link->escape_string($msg);
$now = time();
$query = "update task set in_progress=0, last_error_time=$now, last_error='$msg' where id=$id";
return mysqli_query($link, $query);
}
?>