@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | /** |
| 158 | 158 | * @param string $query |
| 159 | 159 | * |
| 160 | - * @return mixed|string |
|
| 160 | + * @return string |
|
| 161 | 161 | */ |
| 162 | 162 | public function replaceTablePlaceholders($query) { |
| 163 | 163 | $sql = $query; |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
| 174 | - * @param $query |
|
| 174 | + * @param string $query |
|
| 175 | 175 | */ |
| 176 | 176 | protected function logQuery($query) { |
| 177 | 177 | if (!classSupernova::$config->debug) { |
@@ -286,6 +286,7 @@ discard block |
||
| 286 | 286 | * @param array $fields |
| 287 | 287 | * @param array $where |
| 288 | 288 | * @param bool $isOneRecord |
| 289 | + * @param boolean $forUpdate |
|
| 289 | 290 | * |
| 290 | 291 | * @return array|bool|mysqli_result|null |
| 291 | 292 | */ |
@@ -332,6 +333,11 @@ discard block |
||
| 332 | 333 | |
| 333 | 334 | |
| 334 | 335 | // INSERT/REPLACE |
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * @param string $table |
|
| 339 | + * @param integer $replace |
|
| 340 | + */ |
|
| 335 | 341 | protected function doSet($table, $fieldsAndValues, $replace = DB_INSERT_PLAIN) { |
| 336 | 342 | $query = DbQuery::build($this) |
| 337 | 343 | ->setTable($table) |
@@ -369,6 +375,10 @@ discard block |
||
| 369 | 375 | |
| 370 | 376 | |
| 371 | 377 | // INSERTERS |
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * @param string $query |
|
| 381 | + */ |
|
| 372 | 382 | public function doInsertComplex($query) { |
| 373 | 383 | return $this->doSql($query); |
| 374 | 384 | } |
@@ -386,7 +396,7 @@ discard block |
||
| 386 | 396 | * Values should be passed as-is |
| 387 | 397 | * |
| 388 | 398 | * @param string $table |
| 389 | - * @param array $fields |
|
| 399 | + * @param string[] $fields |
|
| 390 | 400 | * @param string[] $values |
| 391 | 401 | * |
| 392 | 402 | * @return array|bool|mysqli_result|null |
@@ -438,7 +448,7 @@ discard block |
||
| 438 | 448 | * Self-contained - means no params used |
| 439 | 449 | * Such queries usually used to make large amount of in-base calculations |
| 440 | 450 | * |
| 441 | - * @param $query |
|
| 451 | + * @param string $query |
|
| 442 | 452 | * |
| 443 | 453 | * @return array|bool|mysqli_result|null |
| 444 | 454 | */ |
@@ -456,13 +466,16 @@ discard block |
||
| 456 | 466 | } |
| 457 | 467 | |
| 458 | 468 | /** |
| 459 | - * @param $DbQuery DbQuery |
|
| 469 | + * @param DbQuery $DbQuery DbQuery |
|
| 460 | 470 | */ |
| 461 | 471 | public function doUpdateDbQueryAdjust($DbQuery) { |
| 462 | 472 | return $this->doUpdateDbQuery($DbQuery); |
| 463 | 473 | } |
| 464 | 474 | |
| 465 | 475 | |
| 476 | + /** |
|
| 477 | + * @param boolean $isOneRecord |
|
| 478 | + */ |
|
| 466 | 479 | protected function doUpdateWhere($table, $fieldsSet, $fieldsAdjust = array(), $where = array(), $isOneRecord = DB_RECORDS_ALL, $whereDanger = array()) { |
| 467 | 480 | // $query = DbQuery::build($this) |
| 468 | 481 | // ->setTable($table) |
@@ -498,10 +511,16 @@ discard block |
||
| 498 | 511 | return $this->doSql($query); |
| 499 | 512 | } |
| 500 | 513 | |
| 514 | + /** |
|
| 515 | + * @param string $table |
|
| 516 | + */ |
|
| 501 | 517 | public function doUpdateRowSet($table, $fieldsAndValues, $where) { |
| 502 | 518 | return $this->doUpdateWhere($table, $fieldsAndValues, array(), $where, DB_RECORD_ONE); |
| 503 | 519 | } |
| 504 | 520 | |
| 521 | + /** |
|
| 522 | + * @param string $table |
|
| 523 | + */ |
|
| 505 | 524 | public function doUpdateTableSet($table, $fieldsAndValues, $where = array()) { |
| 506 | 525 | return $this->doUpdateWhere($table, $fieldsAndValues, array(), $where, DB_RECORDS_ALL); |
| 507 | 526 | } |
@@ -708,6 +727,10 @@ discard block |
||
| 708 | 727 | } |
| 709 | 728 | |
| 710 | 729 | // TODO Заменить это на новый логгер |
| 730 | + |
|
| 731 | + /** |
|
| 732 | + * @param string $query |
|
| 733 | + */ |
|
| 711 | 734 | protected function security_watch_user_queries($query) { |
| 712 | 735 | global $user; |
| 713 | 736 | |
@@ -731,6 +754,9 @@ discard block |
||
| 731 | 754 | } |
| 732 | 755 | |
| 733 | 756 | |
| 757 | + /** |
|
| 758 | + * @param string $query |
|
| 759 | + */ |
|
| 734 | 760 | public function security_query_check_bad_words($query) { |
| 735 | 761 | if ($this->skipQueryCheck) { |
| 736 | 762 | return; |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | public function load_db_settings($configFile = '') { |
| 92 | 92 | $dbsettings = array(); |
| 93 | 93 | |
| 94 | - empty($configFile) ? $configFile = SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX : false; |
|
| 94 | + empty($configFile) ? $configFile = SN_ROOT_PHYSICAL."config".DOT_PHP_EX : false; |
|
| 95 | 95 | |
| 96 | 96 | require $configFile; |
| 97 | 97 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | if (empty($this->dbsettings)) { |
| 114 | - $this->load_db_settings(SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX); |
|
| 114 | + $this->load_db_settings(SN_ROOT_PHYSICAL."config".DOT_PHP_EX); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $sql = $query; |
| 164 | 164 | if (strpos($sql, '{{') !== false) { |
| 165 | 165 | foreach ($this->table_list as $tableName) { |
| 166 | - $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql); |
|
| 166 | + $sql = str_replace("{{{$tableName}}}", $this->db_prefix.$tableName, $sql); |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
@@ -234,12 +234,12 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | $queryResult = null; |
| 236 | 236 | try { |
| 237 | - $queryResult = $this->db_sql_query($stringQuery . DbSqlHelper::quoteComment($queryTrace)); |
|
| 237 | + $queryResult = $this->db_sql_query($stringQuery.DbSqlHelper::quoteComment($queryTrace)); |
|
| 238 | 238 | if (!$queryResult) { |
| 239 | 239 | throw new Exception(); |
| 240 | 240 | } |
| 241 | 241 | } catch (Exception $e) { |
| 242 | - classSupernova::$debug->error($this->db_error() . "<br />{$query}<br />", 'SQL Error'); |
|
| 242 | + classSupernova::$debug->error($this->db_error()."<br />{$query}<br />", 'SQL Error'); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | return $queryResult; |
@@ -291,19 +291,19 @@ discard block |
||
| 291 | 291 | */ |
| 292 | 292 | public function doSelectDanger($table, $fields, $where = array(), $isOneRecord = DB_RECORDS_ALL, $forUpdate = DB_SELECT_PLAIN) { |
| 293 | 293 | // TODO - TEMPORARY UNTIL DbQuery |
| 294 | - if(!empty($where)) { |
|
| 294 | + if (!empty($where)) { |
|
| 295 | 295 | foreach ($where as $key => &$value) { |
| 296 | - if(!is_int($key)) { |
|
| 297 | - $value = "`$key` = '" . $this->db_escape($value). "'"; |
|
| 296 | + if (!is_int($key)) { |
|
| 297 | + $value = "`$key` = '".$this->db_escape($value)."'"; |
|
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | $query = |
| 303 | - "SELECT " . implode(',', $fields) . |
|
| 304 | - " FROM `{{{$table}}}`" . |
|
| 305 | - (!empty($where) ? ' WHERE ' . implode(' AND ', $where) : '') . |
|
| 306 | - ($isOneRecord == DB_RECORD_ONE ? ' LIMIT 1' : '') . |
|
| 303 | + "SELECT ".implode(',', $fields). |
|
| 304 | + " FROM `{{{$table}}}`". |
|
| 305 | + (!empty($where) ? ' WHERE '.implode(' AND ', $where) : ''). |
|
| 306 | + ($isOneRecord == DB_RECORD_ONE ? ' LIMIT 1' : ''). |
|
| 307 | 307 | ($forUpdate == DB_SELECT_FOR_UPDATE ? ' FOR UPDATE' : '') |
| 308 | 308 | ; |
| 309 | 309 | |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | case TYPE_EMPTY: |
| 607 | 607 | // No-type defaults to string |
| 608 | 608 | default: |
| 609 | - $value = "'" . $this->db_escape((string)$value) . "'"; |
|
| 609 | + $value = "'".$this->db_escape((string) $value)."'"; |
|
| 610 | 610 | break; |
| 611 | 611 | } |
| 612 | 612 | |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | if (is_int($fieldName)) { |
| 635 | 635 | $result[$fieldName] = $fieldValue; |
| 636 | 636 | } else { |
| 637 | - $result[$fieldName] = "`{$fieldName}` = " . $this->castAsDbValue($fieldValue); |
|
| 637 | + $result[$fieldName] = "`{$fieldName}` = ".$this->castAsDbValue($fieldValue); |
|
| 638 | 638 | } |
| 639 | 639 | } |
| 640 | 640 | |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | if (is_int($fieldName)) { |
| 664 | 664 | $result[$fieldName] = $fieldValue; |
| 665 | 665 | } else { |
| 666 | - $result[$fieldName] = "`{$fieldName}` = `{$fieldName}` + (" . $this->castAsDbValue($fieldValue) . ")"; |
|
| 666 | + $result[$fieldName] = "`{$fieldName}` = `{$fieldName}` + (".$this->castAsDbValue($fieldValue).")"; |
|
| 667 | 667 | } |
| 668 | 668 | } |
| 669 | 669 | |
@@ -720,10 +720,10 @@ discard block |
||
| 720 | 720 | $this->isWatching = true; |
| 721 | 721 | $msg = "\$query = \"{$query}\"\n\r"; |
| 722 | 722 | if (!empty($_POST)) { |
| 723 | - $msg .= "\n\r" . dump($_POST, '$_POST'); |
|
| 723 | + $msg .= "\n\r".dump($_POST, '$_POST'); |
|
| 724 | 724 | } |
| 725 | 725 | if (!empty($_GET)) { |
| 726 | - $msg .= "\n\r" . dump($_GET, '$_GET'); |
|
| 726 | + $msg .= "\n\r".dump($_GET, '$_GET'); |
|
| 727 | 727 | } |
| 728 | 728 | classSupernova::$debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true)); |
| 729 | 729 | $this->isWatching = false; |
@@ -749,37 +749,37 @@ discard block |
||
| 749 | 749 | case stripos($query, 'RPG_POINTS') != false && stripos(trim($query), 'UPDATE ') === 0 && !$dm_change_legit: |
| 750 | 750 | case stripos($query, 'METAMATTER') != false && stripos(trim($query), 'UPDATE ') === 0 && !$mm_change_legit: |
| 751 | 751 | case stripos($query, 'AUTHLEVEL') != false && $user['authlevel'] < 3 && stripos($query, 'SELECT') !== 0: |
| 752 | - $report = "Hacking attempt (" . date("d.m.Y H:i:s") . " - [" . time() . "]):\n"; |
|
| 752 | + $report = "Hacking attempt (".date("d.m.Y H:i:s")." - [".time()."]):\n"; |
|
| 753 | 753 | $report .= ">Database Inforamation\n"; |
| 754 | - $report .= "\tID - " . $user['id'] . "\n"; |
|
| 755 | - $report .= "\tUser - " . $user['username'] . "\n"; |
|
| 756 | - $report .= "\tAuth level - " . $user['authlevel'] . "\n"; |
|
| 757 | - $report .= "\tAdmin Notes - " . $user['adminNotes'] . "\n"; |
|
| 758 | - $report .= "\tCurrent Planet - " . $user['current_planet'] . "\n"; |
|
| 759 | - $report .= "\tUser IP - " . $user['user_lastip'] . "\n"; |
|
| 760 | - $report .= "\tUser IP at Reg - " . $user['ip_at_reg'] . "\n"; |
|
| 761 | - $report .= "\tUser Agent- " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
| 762 | - $report .= "\tCurrent Page - " . $user['current_page'] . "\n"; |
|
| 763 | - $report .= "\tRegister Time - " . $user['register_time'] . "\n"; |
|
| 754 | + $report .= "\tID - ".$user['id']."\n"; |
|
| 755 | + $report .= "\tUser - ".$user['username']."\n"; |
|
| 756 | + $report .= "\tAuth level - ".$user['authlevel']."\n"; |
|
| 757 | + $report .= "\tAdmin Notes - ".$user['adminNotes']."\n"; |
|
| 758 | + $report .= "\tCurrent Planet - ".$user['current_planet']."\n"; |
|
| 759 | + $report .= "\tUser IP - ".$user['user_lastip']."\n"; |
|
| 760 | + $report .= "\tUser IP at Reg - ".$user['ip_at_reg']."\n"; |
|
| 761 | + $report .= "\tUser Agent- ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
| 762 | + $report .= "\tCurrent Page - ".$user['current_page']."\n"; |
|
| 763 | + $report .= "\tRegister Time - ".$user['register_time']."\n"; |
|
| 764 | 764 | $report .= "\n"; |
| 765 | 765 | |
| 766 | 766 | $report .= ">Query Information\n"; |
| 767 | - $report .= "\tQuery - " . $query . "\n"; |
|
| 767 | + $report .= "\tQuery - ".$query."\n"; |
|
| 768 | 768 | $report .= "\n"; |
| 769 | 769 | |
| 770 | 770 | $report .= ">\$_SERVER Information\n"; |
| 771 | - $report .= "\tIP - " . $_SERVER['REMOTE_ADDR'] . "\n"; |
|
| 772 | - $report .= "\tHost Name - " . $_SERVER['HTTP_HOST'] . "\n"; |
|
| 773 | - $report .= "\tUser Agent - " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
| 774 | - $report .= "\tRequest Method - " . $_SERVER['REQUEST_METHOD'] . "\n"; |
|
| 775 | - $report .= "\tCame From - " . $_SERVER['HTTP_REFERER'] . "\n"; |
|
| 776 | - $report .= "\tPage is - " . $_SERVER['SCRIPT_NAME'] . "\n"; |
|
| 777 | - $report .= "\tUses Port - " . $_SERVER['REMOTE_PORT'] . "\n"; |
|
| 778 | - $report .= "\tServer Protocol - " . $_SERVER['SERVER_PROTOCOL'] . "\n"; |
|
| 771 | + $report .= "\tIP - ".$_SERVER['REMOTE_ADDR']."\n"; |
|
| 772 | + $report .= "\tHost Name - ".$_SERVER['HTTP_HOST']."\n"; |
|
| 773 | + $report .= "\tUser Agent - ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
| 774 | + $report .= "\tRequest Method - ".$_SERVER['REQUEST_METHOD']."\n"; |
|
| 775 | + $report .= "\tCame From - ".$_SERVER['HTTP_REFERER']."\n"; |
|
| 776 | + $report .= "\tPage is - ".$_SERVER['SCRIPT_NAME']."\n"; |
|
| 777 | + $report .= "\tUses Port - ".$_SERVER['REMOTE_PORT']."\n"; |
|
| 778 | + $report .= "\tServer Protocol - ".$_SERVER['SERVER_PROTOCOL']."\n"; |
|
| 779 | 779 | |
| 780 | 780 | $report .= "\n--------------------------------------------------------------------------------------------------\n"; |
| 781 | 781 | |
| 782 | - $fp = fopen(SN_ROOT_PHYSICAL . 'badqrys.txt', 'a'); |
|
| 782 | + $fp = fopen(SN_ROOT_PHYSICAL.'badqrys.txt', 'a'); |
|
| 783 | 783 | fwrite($fp, $report); |
| 784 | 784 | fclose($fp); |
| 785 | 785 | |
@@ -155,10 +155,17 @@ discard block |
||
| 155 | 155 | return $this->field(DbSqlLiteral::build($this->db)->literal($field)); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | + /** |
|
| 159 | + * @param string $functionName |
|
| 160 | + * @param string $alias |
|
| 161 | + */ |
|
| 158 | 162 | public function fieldSingleFunction($functionName, $field = '*', $alias = DbSqlLiteral::SQL_LITERAL_ALIAS_NONE) { |
| 159 | 163 | return $this->field(DbSqlLiteral::build($this->db)->buildSingleArgument($functionName, $field, $alias)); |
| 160 | 164 | } |
| 161 | 165 | |
| 166 | + /** |
|
| 167 | + * @param string $alias |
|
| 168 | + */ |
|
| 162 | 169 | public function fieldCount($field = '*', $alias = DbSqlLiteral::SQL_LITERAL_ALIAS_NONE) { |
| 163 | 170 | return $this->field(DbSqlLiteral::build($this->db)->count($field, $alias)); |
| 164 | 171 | } |
@@ -240,7 +247,7 @@ discard block |
||
| 240 | 247 | |
| 241 | 248 | /** |
| 242 | 249 | * @param db_mysql|null $db |
| 243 | - * @param string|object|DBStaticRecord|DbSqlAware $className |
|
| 250 | + * @param string $className |
|
| 244 | 251 | * |
| 245 | 252 | * @return static |
| 246 | 253 | */ |
@@ -444,7 +451,6 @@ discard block |
||
| 444 | 451 | } |
| 445 | 452 | |
| 446 | 453 | /** |
| 447 | - * @param bool $skip_query_check |
|
| 448 | 454 | * |
| 449 | 455 | * @return array |
| 450 | 456 | */ |
@@ -455,7 +461,6 @@ discard block |
||
| 455 | 461 | } |
| 456 | 462 | |
| 457 | 463 | /** |
| 458 | - * @param bool $skip_query_check |
|
| 459 | 464 | * |
| 460 | 465 | * @return mixed|null |
| 461 | 466 | */ |
@@ -61,11 +61,10 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public static function db_planet_by_vector($vector, $prefix = '', $for_update = false, $fields = '*') { |
| 64 | - $galaxy = isset($vector[$prefix . 'galaxy']) ? intval($vector[$prefix . 'galaxy']) : 0; |
|
| 65 | - $system = isset($vector[$prefix . 'system']) ? intval($vector[$prefix . 'system']) : 0; |
|
| 66 | - $planet = isset($vector[$prefix . 'planet']) ? intval($vector[$prefix . 'planet']) : 0; |
|
| 67 | - $planet_type = isset($vector[$prefix . 'planet_type']) ? intval($vector[$prefix . 'planet_type']) : |
|
| 68 | - (isset($vector[$prefix . 'type']) ? intval($vector[$prefix . 'type']) : 0); |
|
| 64 | + $galaxy = isset($vector[$prefix.'galaxy']) ? intval($vector[$prefix.'galaxy']) : 0; |
|
| 65 | + $system = isset($vector[$prefix.'system']) ? intval($vector[$prefix.'system']) : 0; |
|
| 66 | + $planet = isset($vector[$prefix.'planet']) ? intval($vector[$prefix.'planet']) : 0; |
|
| 67 | + $planet_type = isset($vector[$prefix.'planet_type']) ? intval($vector[$prefix.'planet_type']) : (isset($vector[$prefix.'type']) ? intval($vector[$prefix.'type']) : 0); |
|
| 69 | 68 | $planet_type = $planet_type == PT_DEBRIS ? PT_PLANET : $planet_type; |
| 70 | 69 | |
| 71 | 70 | return DBStaticPlanet::db_planet_by_gspt_safe($galaxy, $system, $planet, $planet_type, $for_update, $fields); |
@@ -116,7 +115,7 @@ discard block |
||
| 116 | 115 | } |
| 117 | 116 | |
| 118 | 117 | return classSupernova::$gc->cacheOperator->db_get_record_list(LOC_PLANET, |
| 119 | - "`planet_type` = " . PT_MOON . " AND `id_owner` = {$user_id} AND `id` != {$this_moon_id}"); |
|
| 118 | + "`planet_type` = ".PT_MOON." AND `id_owner` = {$user_id} AND `id` != {$this_moon_id}"); |
|
| 120 | 119 | } |
| 121 | 120 | |
| 122 | 121 | public static function db_planet_list_in_system($galaxy, $system) { |
@@ -142,7 +141,7 @@ discard block |
||
| 142 | 141 | ); |
| 143 | 142 | $order_by = classSupernova::$user_options[PLAYER_OPTION_PLANET_SORT]; |
| 144 | 143 | empty($sort_orders[$order_by]) ? $order_by = SORT_ID : false; |
| 145 | - $order_by = $sort_orders[$order_by] . ' ' . (classSupernova::$user_options[PLAYER_OPTION_PLANET_SORT_INVERSE] == SORT_ASCENDING ? 'ASC' : 'DESC'); |
|
| 144 | + $order_by = $sort_orders[$order_by].' '.(classSupernova::$user_options[PLAYER_OPTION_PLANET_SORT_INVERSE] == SORT_ASCENDING ? 'ASC' : 'DESC'); |
|
| 146 | 145 | |
| 147 | 146 | // Compilating query |
| 148 | 147 | return classSupernova::$gc->cacheOperator->db_get_record_list(LOC_PLANET, |
@@ -170,7 +169,7 @@ discard block |
||
| 170 | 169 | foreach ($planetRowFieldChanges as $resourceId => $value) { |
| 171 | 170 | $fields[pname_resource_name($resourceId)] = $value; |
| 172 | 171 | } |
| 173 | - if(!empty($fields)) { |
|
| 172 | + if (!empty($fields)) { |
|
| 174 | 173 | classSupernova::$gc->db->doUpdateRowAdjust( |
| 175 | 174 | TABLE_PLANETS, |
| 176 | 175 | array(), |
@@ -214,7 +213,7 @@ discard block |
||
| 214 | 213 | 'system' => $ui_system, |
| 215 | 214 | 'planet' => $ui_planet, |
| 216 | 215 | ); |
| 217 | - if(intval($ui_planet_type)) { |
|
| 216 | + if (intval($ui_planet_type)) { |
|
| 218 | 217 | $where['planet_type'] = $ui_planet_type; |
| 219 | 218 | } |
| 220 | 219 | classSupernova::$gc->cacheOperator->db_upd_record_list( |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @return string |
| 312 | 312 | */ |
| 313 | 313 | protected function stringValue($value) { |
| 314 | - return "'" . $this->escape((string)$value) . "'"; |
|
| 314 | + return "'".$this->escape((string) $value)."'"; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * @return string |
| 323 | 323 | */ |
| 324 | 324 | protected function quote($fieldName) { |
| 325 | - return "`" . $this->escape((string)$fieldName) . "`"; |
|
| 325 | + return "`".$this->escape((string) $fieldName)."`"; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | * @return string |
| 334 | 334 | */ |
| 335 | 335 | protected function quoteTable($tableName) { |
| 336 | - return "`{{" . $this->escape((string)$tableName) . "}}`"; |
|
| 336 | + return "`{{".$this->escape((string) $tableName)."}}`"; |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | protected function castAsDbValue($value) { |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | foreach ($fieldValues as $fieldName => $fieldValue) { |
| 415 | 415 | // Integer $fieldName is DANGER! They skipped there! |
| 416 | 416 | if (!is_int($fieldName)) { |
| 417 | - $result[$fieldName] = $this->quote($fieldName) . " = " . $this->castAsDbValue($fieldValue); |
|
| 417 | + $result[$fieldName] = $this->quote($fieldName)." = ".$this->castAsDbValue($fieldValue); |
|
| 418 | 418 | } |
| 419 | 419 | } |
| 420 | 420 | |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | foreach ($fields as $fieldName => $fieldValue) { |
| 471 | 471 | // Integer $fieldName means "leave as is" - for expressions and already processed fields |
| 472 | 472 | if (is_string($fieldName)) { |
| 473 | - $result[$fieldName] = "`{$fieldName}` = `{$fieldName}` + (" . $this->castAsDbValue($fieldValue) . ")"; |
|
| 473 | + $result[$fieldName] = "`{$fieldName}` = `{$fieldName}` + (".$this->castAsDbValue($fieldValue).")"; |
|
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | 476 | |
@@ -481,21 +481,21 @@ discard block |
||
| 481 | 481 | protected function buildCommand() { |
| 482 | 482 | switch ($this->command) { |
| 483 | 483 | case static::UPDATE: |
| 484 | - $this->build[] = $this->command . " " . $this->quoteTable($this->table); |
|
| 484 | + $this->build[] = $this->command." ".$this->quoteTable($this->table); |
|
| 485 | 485 | break; |
| 486 | 486 | |
| 487 | 487 | case static::DELETE: |
| 488 | - $this->build[] = $this->command . " FROM " . $this->quoteTable($this->table); |
|
| 488 | + $this->build[] = $this->command." FROM ".$this->quoteTable($this->table); |
|
| 489 | 489 | break; |
| 490 | 490 | |
| 491 | 491 | case static::REPLACE: |
| 492 | 492 | case static::INSERT_IGNORE: |
| 493 | 493 | case static::INSERT: |
| 494 | - $this->build[] = $this->command . " INTO " . $this->quoteTable($this->table); |
|
| 494 | + $this->build[] = $this->command." INTO ".$this->quoteTable($this->table); |
|
| 495 | 495 | break; |
| 496 | 496 | |
| 497 | 497 | case static::SELECT: |
| 498 | - $this->build[] = $this->command . " "; |
|
| 498 | + $this->build[] = $this->command." "; |
|
| 499 | 499 | break; |
| 500 | 500 | } |
| 501 | 501 | } |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | $compiled = array(); |
| 548 | 548 | |
| 549 | 549 | foreach ($this->values as $valuesVector) { |
| 550 | - $compiled[] = '(' . implode(',', $this->safeValuesScalar($valuesVector)) . ')'; |
|
| 550 | + $compiled[] = '('.implode(',', $this->safeValuesScalar($valuesVector)).')'; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | $this->build[] = implode(',', $compiled); |
@@ -230,7 +230,7 @@ |
||
| 230 | 230 | array("distinct({{{$location_info[P_TABLE_NAME]}}}.{$owner_data[P_OWNER_FIELD]}) AS parent_id"), |
| 231 | 231 | $filter, |
| 232 | 232 | // Always selecting all records for correctly perform FILTER locks |
| 233 | - $fetch ? DB_RECORD_ONE : DB_RECORDS_ALL, |
|
| 233 | + $fetch ? DB_RECORD_ONE : DB_RECORDS_ALL, |
|
| 234 | 234 | // DB_RECORDS_ALL, |
| 235 | 235 | DB_SELECT_PLAIN |
| 236 | 236 | ); |
@@ -193,13 +193,13 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | // TODO - Change $filter to only array class |
| 195 | 195 | public function db_get_record_list($location_type, $filter = '', $fetch = false, $no_return = false) { |
| 196 | - if(is_array($filter)) { |
|
| 196 | + if (is_array($filter)) { |
|
| 197 | 197 | // TODO - TEMPORARY |
| 198 | 198 | $filterString = array(); |
| 199 | - if(!empty($filter)) { |
|
| 199 | + if (!empty($filter)) { |
|
| 200 | 200 | foreach ($filter as $key => $value) { |
| 201 | - if(!is_int($key)) { |
|
| 202 | - $value = "`$key` = '" . $this->db->db_escape($value). "'"; |
|
| 201 | + if (!is_int($key)) { |
|
| 202 | + $value = "`$key` = '".$this->db->db_escape($value)."'"; |
|
| 203 | 203 | } |
| 204 | 204 | $filterString[$key] = $value; |
| 205 | 205 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | |
| 208 | 208 | $filterString = implode(',', $filterString); |
| 209 | 209 | } else { |
| 210 | - $filterString = $filter; |
|
| 210 | + $filterString = $filter; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | |
@@ -238,8 +238,8 @@ discard block |
||
| 238 | 238 | $query = $this->db->doSelect( |
| 239 | 239 | "SELECT |
| 240 | 240 | distinct({{{$location_info[P_TABLE_NAME]}}}.{$owner_data[P_OWNER_FIELD]}) AS parent_id |
| 241 | - FROM {{{$location_info[P_TABLE_NAME]}}}" . |
|
| 242 | - ($filter ? ' WHERE ' . $filter : '') . |
|
| 241 | + FROM {{{$location_info[P_TABLE_NAME]}}}". |
|
| 242 | + ($filter ? ' WHERE '.$filter : ''). |
|
| 243 | 243 | ($fetch ? ' LIMIT 1' : '')); |
| 244 | 244 | } |
| 245 | 245 | while ($row = db_fetch($query)) { |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | $indexes_str = implode(',', $parent_id_list); |
| 255 | 255 | $parent_id_field = static::$location_info[$owner_location_type][P_ID]; |
| 256 | 256 | $this->db_get_record_list($owner_location_type, |
| 257 | - $parent_id_field . ( |
|
| 257 | + $parent_id_field.( |
|
| 258 | 258 | count($parent_id_list) > 1 |
| 259 | 259 | ? " IN ({$indexes_str})" |
| 260 | 260 | : " = {$indexes_str}" |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | ); |
| 278 | 278 | } else { |
| 279 | 279 | $query = $this->db->doSelect( |
| 280 | - "SELECT * FROM {{{$location_info[P_TABLE_NAME]}}}" . |
|
| 280 | + "SELECT * FROM {{{$location_info[P_TABLE_NAME]}}}". |
|
| 281 | 281 | (($filter = trim($filter)) ? " WHERE {$filter}" : '') |
| 282 | 282 | . " FOR UPDATE" |
| 283 | 283 | ); |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | public function db_lock_tables($tables) { |
| 456 | 456 | $tables = is_array($tables) ? $tables : array($tables => ''); |
| 457 | 457 | foreach ($tables as $table_name => $condition) { |
| 458 | - $this->db->doSelect("SELECT 1 FROM {{{$table_name}}}" . ($condition ? ' WHERE ' . $condition : '')); |
|
| 458 | + $this->db->doSelect("SELECT 1 FROM {{{$table_name}}}".($condition ? ' WHERE '.$condition : '')); |
|
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | } |