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
174
175
176
177
|
<?php
if (!defined('ABSPATH')) exit; if (!class_exists('BVDBCallback')) : require_once dirname( __FILE__ ) . '/../streams.php';
class BVDBCallback extends BVCallbackBase { public $db; public $stream; public $account;
public static $bvTables = array("fw_requests", "lp_requests", "ip_store");
public function __construct($callback_handler) { $this->db = $callback_handler->db; $this->account = $callback_handler->account; $this->siteinfo = $callback_handler->siteinfo; }
public function getLastID($pkeys, $end_row) { $last_ids = array(); foreach($pkeys as $pk) { $last_ids[$pk] = $end_row[$pk]; } return $last_ids; }
public function getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, $include_rows = false) { $tinfo = array(); $rows_count = $this->db->rowsCount($table); $result = array('count' => $rows_count); if ($limit == 0) { $limit = $rows_count; } $srows = 1; while (($limit > 0) && ($srows > 0)) { if ($bsize > $limit) $bsize = $limit; $rows = $this->db->getTableContent($table, '*', $filter, $bsize, $offset); $srows = sizeof($rows); $data = array(); $data["offset"] = $offset; $data["size"] = $srows; $serialized_rows = serialize($rows); $data['md5'] = md5($serialized_rows); $data['length'] = strlen($serialized_rows); array_push($tinfo, $data); if (!empty($pkeys) && $srows > 0) { $end_row = end($rows); $last_ids = $this->getLastID($pkeys, $end_row); $data['last_ids'] = $last_ids; $result['last_ids'] = $last_ids; } if ($include_rows) { $data["rows"] = $rows; $str = serialize($data); $this->stream->writeStream($str); } $offset += $srows; $limit -= $srows; } $result['size'] = $offset; $result['tinfo'] = $tinfo; return $result; }
public function process($request) { $db = $this->db; $params = $request->params; $stream_init_info = BVStream::startStream($this->account, $request);
if (array_key_exists('stream', $stream_init_info)) { $this->stream = $stream_init_info['stream']; switch ($request->method) { case "gettbls": $resp = array("tables" => $db->showTables()); break; case "tblstatus": $resp = array("statuses" => $db->showTableStatus()); break; case "tablekeys": $table = urldecode($params['table']); $resp = array("table_keys" => $db->tableKeys($table)); break; case "describetable": $table = urldecode($params['table']); $resp = array("table_description" => $db->describeTable($table)); break; case "checktable": $table = urldecode($params['table']); $type = urldecode($params['type']); $resp = array("status" => $db->checkTable($table, $type)); break; case "repairtable": $table = urldecode($params['table']); $resp = array("status" => $db->repairTable($table)); break; case "gettcrt": $table = urldecode($params['table']); $resp = array("create" => $db->showTableCreate($table)); break; case "getrowscount": $table = urldecode($params['table']); $resp = array("count" => $db->rowsCount($table)); break; case "gettablecontent": $result = array(); $table = urldecode($params['table']); $fields = urldecode($params['fields']); $filter = (array_key_exists('filter', $params)) ? urldecode($params['filter']) : ""; $limit = intval(urldecode($params['limit'])); $offset = intval(urldecode($params['offset'])); $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array(); $result['timestamp'] = time(); $result['tablename'] = $table; $rows = $db->getTableContent($table, $fields, $filter, $limit, $offset); $srows = sizeof($rows); if (!empty($pkeys) && $srows > 0) { $end_row = end($rows); $result['last_ids'] = $this->getLastID($pkeys, $end_row); } $result["rows"] = $rows; $resp = $result; break; case "tableinfo": $table = urldecode($params['table']); $offset = intval(urldecode($params['offset'])); $limit = intval(urldecode($params['limit'])); $bsize = intval(urldecode($params['bsize'])); $filter = (array_key_exists('filter', $params)) ? urldecode($params['filter']) : ""; $rcount = intval(urldecode($params['rcount'])); $tname = urldecode($params['tname']); $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array(); $resp = $this->getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, false); break; case "uploadrows": $table = urldecode($params['table']); $offset = intval(urldecode($params['offset'])); $limit = intval(urldecode($params['limit'])); $bsize = intval(urldecode($params['bsize'])); $filter = (array_key_exists('filter', $params)) ? urldecode($params['filter']) : ""; $rcount = intval(urldecode($params['rcount'])); $tname = urldecode($params['tname']); $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array(); $resp = $this->getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, true); break; case "tblexists": $resp = array("tblexists" => $db->isTablePresent($params['table'])); break; case "crttbl": $usedbdelta = array_key_exists('usedbdelta', $params); $resp = array("crttbl" => $db->createTable($params['query'], $params['table'], $usedbdelta)); break; case "drptbl": $resp = array("drptbl" => $db->dropBVTable($params['table'])); break; case "trttbl": $resp = array("trttbl" => $db->truncateBVTable($params['table'])); break; case "altrtbl": $resp = array("altrtbl" => $db->alterBVTable($params['query'], $params['query'])); break; default: $resp = false; } $end_stream_info = $this->stream->endStream(); if (!empty($end_stream_info) && is_array($resp)) { $resp = array_merge($resp, $end_stream_info); } } else { $resp = $stream_init_info; } return $resp; } } endif;
|