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