| @@ -7,13 +7,12 @@ | ||
| 7 | 7 | class BVDBCallback extends BVCallbackBase { |
| 8 | 8 | public $db; |
| 9 | 9 | public $stream; |
| 10 | 10 | public $account; |
| 11 | - public $siteinfo; | |
| 12 | 11 | |
| 13 | 12 | public static $bvTables = array("fw_requests", "lp_requests", "ip_store"); |
| 14 | 13 | |
| 15 | - const DB_WING_VERSION = 1.3; | |
| 14 | + const DB_WING_VERSION = 1.1; | |
| 16 | 15 | |
| 17 | 16 | public function __construct($callback_handler) { |
| 18 | 17 | $this->db = $callback_handler->db; |
| 19 | 18 | $this->account = $callback_handler->account; |
| @@ -27,9 +26,9 @@ | ||
| 27 | 26 | } |
| 28 | 27 | return $last_ids; |
| 29 | 28 | } |
| 30 | 29 | |
| 31 | - public function getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, $include_rows = false) { | |
| 30 | + public function getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, $include_rows = false) { | |
| 32 | 31 | $tinfo = array(); |
| 33 | 32 | |
| 34 | 33 | $rows_count = $this->db->rowsCount($table); |
| 35 | 34 | $result = array('count' => $rows_count); |
| @@ -68,59 +67,12 @@ | ||
| 68 | 67 | $result['tinfo'] = $tinfo; |
| 69 | 68 | return $result; |
| 70 | 69 | } |
| 71 | 70 | |
| 72 | - public function streamQueryResult($identifier, $query, $pkeys) { | |
| 73 | - $data = array(); | |
| 74 | - $data["identifier"] = $identifier; | |
| 75 | - $data["query"] = $query; | |
| 76 | - | |
| 77 | - $data["query_start_time"] = time(); | |
| 78 | - $rows = $this->db->getResult($query); | |
| 79 | - $srows = sizeof($rows); | |
| 80 | - $data["size"] = $srows; | |
| 81 | - $data["query_end_time"] = time(); | |
| 82 | - if (!empty($pkeys) && $srows > 0) { | |
| 83 | - $end_row = end($rows); | |
| 84 | - $last_ids = $this->getLastID($pkeys, $end_row); | |
| 85 | - $data['last_ids'] = $last_ids; | |
| 86 | - } | |
| 87 | - $result = array_merge($data); | |
| 88 | - $data["rows"] = $rows; | |
| 89 | - $serialized_rows = serialize($data); | |
| 90 | - $this->stream->writeStream($serialized_rows); | |
| 91 | - $result['length'] = strlen($serialized_rows); | |
| 92 | - return $result; | |
| 93 | - } | |
| 94 | - | |
| 95 | - function getRandomData($totalSize, $bsize) { | |
| 96 | - if ($bsize == 0) { | |
| 97 | - $bsize = $totalSize; | |
| 98 | - } | |
| 99 | - | |
| 100 | - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
| 101 | - $charactersLength = strlen($characters); | |
| 102 | - | |
| 103 | - while ($totalSize > 0) { | |
| 104 | - if ($bsize > $totalSize) { | |
| 105 | - $bsize = $totalSize; | |
| 106 | - } | |
| 107 | - | |
| 108 | - $randomString = ''; | |
| 109 | - for ($i = 0; $i < $bsize; $i++) { | |
| 110 | - $randomString .= $characters[rand(0, $charactersLength - 1)]; | |
| 111 | - } | |
| 112 | - | |
| 113 | - $this->stream->writeStream($randomString); | |
| 114 | - $totalSize -= $bsize; | |
| 115 | - } | |
| 116 | - return array("status" => "true"); | |
| 117 | - } | |
| 118 | - | |
| 119 | 71 | public function getCreateTableQueries($tables) { |
| 120 | 72 | $resp = array(); |
| 121 | 73 | foreach($tables as $table) { |
| 122 | - $tname = $table; | |
| 74 | + $tname = urldecode($table); | |
| 123 | 75 | $resp[$tname] = array("create" => $this->db->showTableCreate($table)); |
| 124 | 76 | } |
| 125 | 77 | return $resp; |
| 126 | 78 | } |
| @@ -127,9 +79,9 @@ | ||
| 127 | 79 | |
| 128 | 80 | public function checkTables($tables, $type) { |
| 129 | 81 | $resp = array(); |
| 130 | 82 | foreach($tables as $table) { |
| 131 | - $tname = $table; | |
| 83 | + $tname = urldecode($table); | |
| 132 | 84 | $resp[$tname] = array("status" => $this->db->checkTable($table, $type)); |
| 133 | 85 | } |
| 134 | 86 | return $resp; |
| 135 | 87 | } |
| @@ -136,11 +88,10 @@ | ||
| 136 | 88 | |
| 137 | 89 | public function describeTables($tables) { |
| 138 | 90 | $resp = array(); |
| 139 | 91 | foreach($tables as $table) { |
| 140 | - $tname = $table; | |
| 92 | + $tname = urldecode($table); | |
| 141 | 93 | $resp[$tname] = array("description" => $this->db->describeTable($table)); |
| 142 | - $resp[$tname]["primary_keys_index"] = $this->db->showTableIndex($table); | |
| 143 | 94 | } |
| 144 | 95 | return $resp; |
| 145 | 96 | } |
| 146 | 97 | |
| @@ -146,9 +97,9 @@ | ||
| 146 | 97 | |
| 147 | 98 | public function checkTablesExist($tables) { |
| 148 | 99 | $resp = array(); |
| 149 | 100 | foreach($tables as $table) { |
| 150 | - $tname = $table; | |
| 101 | + $tname = urldecode($table); | |
| 151 | 102 | $resp[$tname] = array("tblexists" => $this->db->isTablePresent($table)); |
| 152 | 103 | } |
| 153 | 104 | return $resp; |
| 154 | 105 | } |
| @@ -155,9 +106,9 @@ | ||
| 155 | 106 | |
| 156 | 107 | public function getTablesRowCount($tables) { |
| 157 | 108 | $resp = array(); |
| 158 | 109 | foreach($tables as $table) { |
| 159 | - $tname = $table; | |
| 110 | + $tname = urldecode($table); | |
| 160 | 111 | $resp[$tname] = array("count" => $this->db->rowsCount($table)); |
| 161 | 112 | } |
| 162 | 113 | return $resp; |
| 163 | 114 | } |
| @@ -164,22 +115,14 @@ | ||
| 164 | 115 | |
| 165 | 116 | public function getTablesKeys($tables) { |
| 166 | 117 | $resp = array(); |
| 167 | 118 | foreach($tables as $table) { |
| 168 | - $tname = $table; | |
| 119 | + $tname = urldecode($table); | |
| 169 | 120 | $resp[$tname] = array("keys" => $this->db->tableKeys($table)); |
| 170 | 121 | } |
| 171 | 122 | return $resp; |
| 172 | 123 | } |
| 173 | 124 | |
| 174 | - public function multiGetResult($queries) { | |
| 175 | - $resp = array(); | |
| 176 | - foreach($queries as $query) { | |
| 177 | - array_push($resp, $this->db->getResult($query)); | |
| 178 | - } | |
| 179 | - return $resp; | |
| 180 | - } | |
| 181 | - | |
| 182 | 125 | public function process($request) { |
| 183 | 126 | $db = $this->db; |
| 184 | 127 | $params = $request->params; |
| 185 | 128 | $stream_init_info = BVStream::startStream($this->account, $request); |
| @@ -193,27 +136,26 @@ | ||
| 193 | 136 | case "tblstatus": |
| 194 | 137 | $resp = array("statuses" => $db->showTableStatus()); |
| 195 | 138 | break; |
| 196 | 139 | case "tablekeys": |
| 197 | - $table = $params['table']; | |
| 140 | + $table = urldecode($params['table']); | |
| 198 | 141 | $resp = array("table_keys" => $db->tableKeys($table)); |
| 199 | 142 | break; |
| 200 | 143 | case "describetable": |
| 201 | - $table = $params['table']; | |
| 144 | + $table = urldecode($params['table']); | |
| 202 | 145 | $resp = array("table_description" => $db->describeTable($table)); |
| 203 | - $resp["primary_keys_index"] = $db->showTableIndex($table); | |
| 204 | 146 | break; |
| 205 | 147 | case "checktable": |
| 206 | - $table = $params['table']; | |
| 207 | - $type = $params['type']; | |
| 148 | + $table = urldecode($params['table']); | |
| 149 | + $type = urldecode($params['type']); | |
| 208 | 150 | $resp = array("status" => $db->checkTable($table, $type)); |
| 209 | 151 | break; |
| 210 | 152 | case "repairtable": |
| 211 | - $table = $params['table']; | |
| 153 | + $table = urldecode($params['table']); | |
| 212 | 154 | $resp = array("status" => $db->repairTable($table)); |
| 213 | 155 | break; |
| 214 | 156 | case "gettcrt": |
| 215 | - $table = $params['table']; | |
| 157 | + $table = urldecode($params['table']); | |
| 216 | 158 | $resp = array("create" => $db->showTableCreate($table)); |
| 217 | 159 | break; |
| 218 | 160 | case "tblskys": |
| 219 | 161 | $tables = $params['tables']; |
| @@ -232,9 +174,9 @@ | ||
| 232 | 174 | $resp = $this->getTablesRowCount($tables); |
| 233 | 175 | break; |
| 234 | 176 | case "chktabls": |
| 235 | 177 | $tables = $params['tables']; |
| 236 | - $type = $params['type']; | |
| 178 | + $type = urldecode($params['type']); | |
| 237 | 179 | $resp = $this->checkTables($tables, $type); |
| 238 | 180 | break; |
| 239 | 181 | case "chktablsxist": |
| 240 | 182 | $tables = $params['tables']; |
| @@ -240,18 +182,18 @@ | ||
| 240 | 182 | $tables = $params['tables']; |
| 241 | 183 | $resp = $this->checkTablesExist($tables); |
| 242 | 184 | break; |
| 243 | 185 | case "getrowscount": |
| 244 | - $table = $params['table']; | |
| 186 | + $table = urldecode($params['table']); | |
| 245 | 187 | $resp = array("count" => $db->rowsCount($table)); |
| 246 | 188 | break; |
| 247 | 189 | case "gettablecontent": |
| 248 | 190 | $result = array(); |
| 249 | - $table = $params['table']; | |
| 250 | - $fields = $params['fields']; | |
| 251 | - $filter = (array_key_exists('filter', $params)) ? $params['filter'] : ""; | |
| 252 | - $limit = intval($params['limit']); | |
| 253 | - $offset = intval($params['offset']); | |
| 191 | + $table = urldecode($params['table']); | |
| 192 | + $fields = urldecode($params['fields']); | |
| 193 | + $filter = (array_key_exists('filter', $params)) ? urldecode($params['filter']) : ""; | |
| 194 | + $limit = intval(urldecode($params['limit'])); | |
| 195 | + $offset = intval(urldecode($params['offset'])); | |
| 254 | 196 | $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array(); |
| 255 | 197 | $result['timestamp'] = time(); |
| 256 | 198 | $result['tablename'] = $table; |
| 257 | 199 | $rows = $db->getTableContent($table, $fields, $filter, $limit, $offset); |
| @@ -289,16 +231,17 @@ | ||
| 289 | 231 | $resp[$identifier] = $result; |
| 290 | 232 | } |
| 291 | 233 | break; |
| 292 | 234 | case "tableinfo": |
| 293 | - $table = $params['table']; | |
| 294 | - $offset = intval($params['offset']); | |
| 295 | - $limit = intval($params['limit']); | |
| 296 | - $bsize = intval($params['bsize']); | |
| 297 | - $filter = (array_key_exists('filter', $params)) ? $params['filter'] : ""; | |
| 298 | - $tname = $params['tname']; | |
| 235 | + $table = urldecode($params['table']); | |
| 236 | + $offset = intval(urldecode($params['offset'])); | |
| 237 | + $limit = intval(urldecode($params['limit'])); | |
| 238 | + $bsize = intval(urldecode($params['bsize'])); | |
| 239 | + $filter = (array_key_exists('filter', $params)) ? urldecode($params['filter']) : ""; | |
| 240 | + $rcount = intval(urldecode($params['rcount'])); | |
| 241 | + $tname = urldecode($params['tname']); | |
| 299 | 242 | $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array(); |
| 300 | - $resp = $this->getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, false); | |
| 243 | + $resp = $this->getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, false); | |
| 301 | 244 | break; |
| 302 | 245 | case "getmulttables": |
| 303 | 246 | $result = array(); |
| 304 | 247 | $tableParams = $params['table_params']; |
| @@ -303,27 +246,29 @@ | ||
| 303 | 246 | $result = array(); |
| 304 | 247 | $tableParams = $params['table_params']; |
| 305 | 248 | $resp = array(); |
| 306 | 249 | foreach($tableParams as $tableParam) { |
| 307 | - $table = $tableParam['table']; | |
| 308 | - $tname = $tableParam['tname']; | |
| 309 | - $filter = (array_key_exists('filter', $tableParam)) ? $tableParam['filter'] : ""; | |
| 310 | - $limit = intval($tableParam['limit']); | |
| 311 | - $offset = intval($tableParam['offset']); | |
| 312 | - $bsize = intval($tableParam['bsize']); | |
| 250 | + $table = urldecode($tableParam['table']); | |
| 251 | + $tname = urldecode($tableParam['tname']); | |
| 252 | + $rcount = intval(urldecode($tableParam['rcount'])); | |
| 253 | + $filter = (array_key_exists('filter', $tableParam)) ? urldecode($tableParam['filter']) : ""; | |
| 254 | + $limit = intval(urldecode($tableParam['limit'])); | |
| 255 | + $offset = intval(urldecode($tableParam['offset'])); | |
| 256 | + $bsize = intval(urldecode($tableParam['bsize'])); | |
| 313 | 257 | $pkeys = (array_key_exists('pkeys', $tableParam)) ? $tableParam['pkeys'] : array(); |
| 314 | - $resp[$tname] = $this->getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, true); | |
| 258 | + $resp[$tname] = $this->getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, true); | |
| 315 | 259 | } |
| 316 | 260 | break; |
| 317 | 261 | case "uploadrows": |
| 318 | - $table = $params['table']; | |
| 319 | - $offset = intval($params['offset']); | |
| 320 | - $limit = intval($params['limit']); | |
| 321 | - $bsize = intval($params['bsize']); | |
| 322 | - $filter = (array_key_exists('filter', $params)) ? $params['filter'] : ""; | |
| 323 | - $tname = $params['tname']; | |
| 262 | + $table = urldecode($params['table']); | |
| 263 | + $offset = intval(urldecode($params['offset'])); | |
| 264 | + $limit = intval(urldecode($params['limit'])); | |
| 265 | + $bsize = intval(urldecode($params['bsize'])); | |
| 266 | + $filter = (array_key_exists('filter', $params)) ? urldecode($params['filter']) : ""; | |
| 267 | + $rcount = intval(urldecode($params['rcount'])); | |
| 268 | + $tname = urldecode($params['tname']); | |
| 324 | 269 | $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array(); |
| 325 | - $resp = $this->getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, true); | |
| 270 | + $resp = $this->getTableData($table, $tname, $rcount, $offset, $limit, $bsize, $filter, $pkeys, true); | |
| 326 | 271 | break; |
| 327 | 272 | case "tblexists": |
| 328 | 273 | $resp = array("tblexists" => $db->isTablePresent($params['table'])); |
| 329 | 274 | break; |
| @@ -338,25 +283,8 @@ | ||
| 338 | 283 | $resp = array("trttbl" => $db->truncateBVTable($params['table'])); |
| 339 | 284 | break; |
| 340 | 285 | case "altrtbl": |
| 341 | 286 | $resp = array("altrtbl" => $db->alterBVTable($params['query'], $params['query'])); |
| 342 | - break; | |
| 343 | - case "mltigtrslt": | |
| 344 | - $resp = array("mltigtrslt" => $this->multiGetResult($params['queries'])); | |
| 345 | - break; | |
| 346 | - case "mltiqrsstrm": | |
| 347 | - $queries = $params['queries']; | |
| 348 | - $result = array(); | |
| 349 | - foreach ($queries as $qparams) { | |
| 350 | - $identifier = $qparams['identifier']; | |
| 351 | - $query = $qparams['query']; | |
| 352 | - $pkeys = (array_key_exists('pkeys', $qparams)) ? $qparams['pkeys'] : array(); | |
| 353 | - array_push($result, $this->streamQueryResult($identifier, $query, $pkeys)); | |
| 354 | - } | |
| 355 | - $resp = array('mltqrsstrm' => $result); | |
| 356 | - break; | |
| 357 | - case "getrndmdata": | |
| 358 | - $resp = array("getrndmdata" => $this->getRandomData($params['size'], $params['batch_size'])); | |
| 359 | 287 | break; |
| 360 | 288 | case "tbls": |
| 361 | 289 | $resp = array(); |
| 362 | 290 | |