@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | function DBMssql($auto_connect = TRUE) |
| 46 | 46 | { |
| 47 | 47 | $this->_setDBInfo(); |
| 48 | - if($auto_connect) $this->_connect(); |
|
| 48 | + if ($auto_connect) $this->_connect(); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | //sqlsrv_configure( 'LogSubsystems', SQLSRV_LOG_SYSTEM_ALL ); |
| 71 | 71 | $result = @sqlsrv_connect($connection["db_hostname"], array('Database' => $connection["db_database"], 'UID' => $connection["db_userid"], 'PWD' => $connection["db_password"])); |
| 72 | 72 | |
| 73 | - if(!$result) |
|
| 73 | + if (!$result) |
|
| 74 | 74 | { |
| 75 | 75 | $errors = print_r(sqlsrv_errors(), true); |
| 76 | - $this->setError(-1, 'database connect fail' . PHP_EOL . $errors); |
|
| 76 | + $this->setError(-1, 'database connect fail'.PHP_EOL.$errors); |
|
| 77 | 77 | return; |
| 78 | 78 | } |
| 79 | 79 | return $result; |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | function addQuotes($string) |
| 101 | 101 | { |
| 102 | - if(version_compare(PHP_VERSION, "5.4.0", "<") && get_magic_quotes_gpc()) |
|
| 102 | + if (version_compare(PHP_VERSION, "5.4.0", "<") && get_magic_quotes_gpc()) |
|
| 103 | 103 | { |
| 104 | 104 | $string = stripslashes(str_replace("\\", "\\\\", $string)); |
| 105 | 105 | } |
@@ -117,16 +117,16 @@ discard block |
||
| 117 | 117 | { |
| 118 | 118 | $connection = $this->_getConnection('master'); |
| 119 | 119 | |
| 120 | - if(!$transactionLevel) |
|
| 120 | + if (!$transactionLevel) |
|
| 121 | 121 | { |
| 122 | - if(sqlsrv_begin_transaction($connection) === false) |
|
| 122 | + if (sqlsrv_begin_transaction($connection) === false) |
|
| 123 | 123 | { |
| 124 | 124 | return; |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | else |
| 128 | 128 | { |
| 129 | - $this->_query("SAVE TRANS SP" . $transactionLevel, $connection); |
|
| 129 | + $this->_query("SAVE TRANS SP".$transactionLevel, $connection); |
|
| 130 | 130 | } |
| 131 | 131 | return true; |
| 132 | 132 | } |
@@ -142,9 +142,9 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | $point = $transactionLevel - 1; |
| 144 | 144 | |
| 145 | - if($point) |
|
| 145 | + if ($point) |
|
| 146 | 146 | { |
| 147 | - $this->_query("ROLLBACK TRANS SP" . $point, $connection); |
|
| 147 | + $this->_query("ROLLBACK TRANS SP".$point, $connection); |
|
| 148 | 148 | } |
| 149 | 149 | else |
| 150 | 150 | { |
@@ -176,18 +176,18 @@ discard block |
||
| 176 | 176 | { |
| 177 | 177 | $_param = array(); |
| 178 | 178 | |
| 179 | - if(count($this->param)) |
|
| 179 | + if (count($this->param)) |
|
| 180 | 180 | { |
| 181 | - foreach($this->param as $k => $o) |
|
| 181 | + foreach ($this->param as $k => $o) |
|
| 182 | 182 | { |
| 183 | - if($o->isColumnName()) |
|
| 183 | + if ($o->isColumnName()) |
|
| 184 | 184 | { |
| 185 | 185 | continue; |
| 186 | 186 | } |
| 187 | - if($o->getType() == 'number') |
|
| 187 | + if ($o->getType() == 'number') |
|
| 188 | 188 | { |
| 189 | 189 | $value = $o->getUnescapedValue(); |
| 190 | - if(is_array($value)) |
|
| 190 | + if (is_array($value)) |
|
| 191 | 191 | { |
| 192 | 192 | $_param = array_merge($_param, $value); |
| 193 | 193 | } |
@@ -199,9 +199,9 @@ discard block |
||
| 199 | 199 | else |
| 200 | 200 | { |
| 201 | 201 | $value = $o->getUnescapedValue(); |
| 202 | - if(is_array($value)) |
|
| 202 | + if (is_array($value)) |
|
| 203 | 203 | { |
| 204 | - foreach($value as $v) |
|
| 204 | + foreach ($value as $v) |
|
| 205 | 205 | { |
| 206 | 206 | $_param[] = array($v, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')); |
| 207 | 207 | } |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | // Run the query statement |
| 218 | 218 | $result = false; |
| 219 | - if(count($_param)) |
|
| 219 | + if (count($_param)) |
|
| 220 | 220 | { |
| 221 | 221 | $args = $this->_getParametersByReference($_param); |
| 222 | 222 | $stmt = sqlsrv_prepare($connection, $query, $args); |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | $stmt = sqlsrv_prepare($connection, $query); |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - if(!$stmt) |
|
| 229 | + if (!$stmt) |
|
| 230 | 230 | { |
| 231 | 231 | $result = false; |
| 232 | 232 | } |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // Error Check |
| 239 | - if(!$result) |
|
| 239 | + if (!$result) |
|
| 240 | 240 | { |
| 241 | 241 | $this->setError(print_r(sqlsrv_errors(), true)); |
| 242 | 242 | } |
@@ -259,9 +259,9 @@ discard block |
||
| 259 | 259 | $copy = array(); |
| 260 | 260 | $args = array(); |
| 261 | 261 | $i = 0; |
| 262 | - foreach($_param as $key => $value) |
|
| 262 | + foreach ($_param as $key => $value) |
|
| 263 | 263 | { |
| 264 | - if(is_array($value)) |
|
| 264 | + if (is_array($value)) |
|
| 265 | 265 | { |
| 266 | 266 | $value_copy = $value; |
| 267 | 267 | $value_arg = array(); |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | function _fetch($result, $arrayIndexEndValue = NULL) |
| 289 | 289 | { |
| 290 | 290 | $output = array(); |
| 291 | - if(!$this->isConnected() || $this->isError() || !$result) |
|
| 291 | + if (!$this->isConnected() || $this->isError() || !$result) |
|
| 292 | 292 | { |
| 293 | 293 | return $output; |
| 294 | 294 | } |
@@ -296,18 +296,18 @@ discard block |
||
| 296 | 296 | $c = sqlsrv_num_fields($result); |
| 297 | 297 | $m = null; |
| 298 | 298 | |
| 299 | - while(sqlsrv_fetch($result)) |
|
| 299 | + while (sqlsrv_fetch($result)) |
|
| 300 | 300 | { |
| 301 | - if(!$m) |
|
| 301 | + if (!$m) |
|
| 302 | 302 | { |
| 303 | 303 | $m = sqlsrv_field_metadata($result); |
| 304 | 304 | } |
| 305 | 305 | unset($row); |
| 306 | - for($i = 0; $i < $c; $i++) |
|
| 306 | + for ($i = 0; $i < $c; $i++) |
|
| 307 | 307 | { |
| 308 | 308 | $row->{$m[$i]['Name']} = sqlsrv_get_field($result, $i, SQLSRV_PHPTYPE_STRING('utf-8')); |
| 309 | 309 | } |
| 310 | - if($arrayIndexEndValue) |
|
| 310 | + if ($arrayIndexEndValue) |
|
| 311 | 311 | { |
| 312 | 312 | $output[$arrayIndexEndValue--] = $row; |
| 313 | 313 | } |
@@ -317,9 +317,9 @@ discard block |
||
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - if(count($output) == 1) |
|
| 320 | + if (count($output) == 1) |
|
| 321 | 321 | { |
| 322 | - if(isset($arrayIndexEndValue)) |
|
| 322 | + if (isset($arrayIndexEndValue)) |
|
| 323 | 323 | { |
| 324 | 324 | return $output; |
| 325 | 325 | } |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | $result = $this->_query($query); |
| 361 | 361 | $tmp = $this->_fetch($result); |
| 362 | 362 | |
| 363 | - if(!$tmp) |
|
| 363 | + if (!$tmp) |
|
| 364 | 364 | { |
| 365 | 365 | return false; |
| 366 | 366 | } |
@@ -379,18 +379,18 @@ discard block |
||
| 379 | 379 | */ |
| 380 | 380 | function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = null, $notnull = false) |
| 381 | 381 | { |
| 382 | - if($this->isColumnExists($table_name, $column_name)) |
|
| 382 | + if ($this->isColumnExists($table_name, $column_name)) |
|
| 383 | 383 | { |
| 384 | 384 | return; |
| 385 | 385 | } |
| 386 | 386 | $type = $this->column_type[$type]; |
| 387 | - if(strtoupper($type) == 'INTEGER') |
|
| 387 | + if (strtoupper($type) == 'INTEGER') |
|
| 388 | 388 | { |
| 389 | 389 | $size = ''; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | $query = sprintf("alter table %s%s add \"%s\" ", $this->prefix, $table_name, $column_name); |
| 393 | - if($size) |
|
| 393 | + if ($size) |
|
| 394 | 394 | { |
| 395 | 395 | $query .= sprintf(" %s(%s) ", $type, $size); |
| 396 | 396 | } |
@@ -399,11 +399,11 @@ discard block |
||
| 399 | 399 | $query .= sprintf(" %s ", $type); |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - if(isset($default)) |
|
| 402 | + if (isset($default)) |
|
| 403 | 403 | { |
| 404 | 404 | $query .= sprintf(" default '%s' ", $default); |
| 405 | 405 | } |
| 406 | - if($notnull) |
|
| 406 | + if ($notnull) |
|
| 407 | 407 | { |
| 408 | 408 | $query .= " not null "; |
| 409 | 409 | } |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | */ |
| 420 | 420 | function dropColumn($table_name, $column_name) |
| 421 | 421 | { |
| 422 | - if(!$this->isColumnExists($table_name, $column_name)) |
|
| 422 | + if (!$this->isColumnExists($table_name, $column_name)) |
|
| 423 | 423 | { |
| 424 | 424 | return; |
| 425 | 425 | } |
@@ -437,12 +437,12 @@ discard block |
||
| 437 | 437 | { |
| 438 | 438 | $query = sprintf("select syscolumns.name as name from syscolumns, sysobjects where sysobjects.name = '%s%s' and sysobjects.id = syscolumns.id and syscolumns.name = '%s'", $this->prefix, $table_name, $column_name); |
| 439 | 439 | $result = $this->_query($query); |
| 440 | - if($this->isError()) |
|
| 440 | + if ($this->isError()) |
|
| 441 | 441 | { |
| 442 | 442 | return; |
| 443 | 443 | } |
| 444 | 444 | $tmp = $this->_fetch($result); |
| 445 | - if(!$tmp->name) |
|
| 445 | + if (!$tmp->name) |
|
| 446 | 446 | { |
| 447 | 447 | return false; |
| 448 | 448 | } |
@@ -461,11 +461,11 @@ discard block |
||
| 461 | 461 | */ |
| 462 | 462 | function addIndex($table_name, $index_name, $target_columns, $is_unique = false) |
| 463 | 463 | { |
| 464 | - if($this->isIndexExists($table_name, $index_name)) |
|
| 464 | + if ($this->isIndexExists($table_name, $index_name)) |
|
| 465 | 465 | { |
| 466 | 466 | return; |
| 467 | 467 | } |
| 468 | - if(!is_array($target_columns)) |
|
| 468 | + if (!is_array($target_columns)) |
|
| 469 | 469 | { |
| 470 | 470 | $target_columns = array($target_columns); |
| 471 | 471 | } |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | */ |
| 484 | 484 | function dropIndex($table_name, $index_name, $is_unique = false) |
| 485 | 485 | { |
| 486 | - if(!$this->isIndexExists($table_name, $index_name)) |
|
| 486 | + if (!$this->isIndexExists($table_name, $index_name)) |
|
| 487 | 487 | { |
| 488 | 488 | return; |
| 489 | 489 | } |
@@ -502,13 +502,13 @@ discard block |
||
| 502 | 502 | $query = sprintf("select sysindexes.name as name from sysindexes, sysobjects where sysobjects.name = '%s%s' and sysobjects.id = sysindexes.id and sysindexes.name = '%s'", $this->prefix, $table_name, $index_name); |
| 503 | 503 | |
| 504 | 504 | $result = $this->_query($query); |
| 505 | - if($this->isError()) |
|
| 505 | + if ($this->isError()) |
|
| 506 | 506 | { |
| 507 | 507 | return; |
| 508 | 508 | } |
| 509 | 509 | $tmp = $this->_fetch($result); |
| 510 | 510 | |
| 511 | - if(!$tmp->name) |
|
| 511 | + if (!$tmp->name) |
|
| 512 | 512 | { |
| 513 | 513 | return false; |
| 514 | 514 | } |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | */ |
| 533 | 533 | function createTableByXmlFile($file_name) |
| 534 | 534 | { |
| 535 | - if(!file_exists($file_name)) |
|
| 535 | + if (!file_exists($file_name)) |
|
| 536 | 536 | { |
| 537 | 537 | return; |
| 538 | 538 | } |
@@ -557,22 +557,22 @@ discard block |
||
| 557 | 557 | $xml_obj = $oXml->parse($xml_doc); |
| 558 | 558 | // Create a table schema |
| 559 | 559 | $table_name = $xml_obj->table->attrs->name; |
| 560 | - if($this->isTableExists($table_name)) |
|
| 560 | + if ($this->isTableExists($table_name)) |
|
| 561 | 561 | { |
| 562 | 562 | return; |
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - if($table_name == 'sequence') |
|
| 565 | + if ($table_name == 'sequence') |
|
| 566 | 566 | { |
| 567 | - $table_name = $this->prefix . $table_name; |
|
| 567 | + $table_name = $this->prefix.$table_name; |
|
| 568 | 568 | $query = sprintf('create table %s ( sequence int identity(1,1), seq int )', $table_name); |
| 569 | 569 | return $this->_query($query); |
| 570 | 570 | } |
| 571 | 571 | else |
| 572 | 572 | { |
| 573 | - $table_name = $this->prefix . $table_name; |
|
| 573 | + $table_name = $this->prefix.$table_name; |
|
| 574 | 574 | |
| 575 | - if(!is_array($xml_obj->table->column)) |
|
| 575 | + if (!is_array($xml_obj->table->column)) |
|
| 576 | 576 | { |
| 577 | 577 | $columns[] = $xml_obj->table->column; |
| 578 | 578 | } |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | $index_list = array(); |
| 587 | 587 | |
| 588 | 588 | $typeList = array('number' => 1, 'text' => 1); |
| 589 | - foreach($columns as $column) |
|
| 589 | + foreach ($columns as $column) |
|
| 590 | 590 | { |
| 591 | 591 | $name = $column->attrs->name; |
| 592 | 592 | $type = $column->attrs->type; |
@@ -598,48 +598,48 @@ discard block |
||
| 598 | 598 | $default = $column->attrs->default; |
| 599 | 599 | $auto_increment = $column->attrs->auto_increment; |
| 600 | 600 | |
| 601 | - $column_schema[] = sprintf('[%s] %s%s %s %s %s', $name, $this->column_type[$type], !isset($typeList[$type]) && $size ? '(' . $size . ')' : '', isset($default) ? "default '" . $default . "'" : '', $notnull ? 'not null' : 'null', $auto_increment ? 'identity(1,1)' : ''); |
|
| 601 | + $column_schema[] = sprintf('[%s] %s%s %s %s %s', $name, $this->column_type[$type], !isset($typeList[$type]) && $size ? '('.$size.')' : '', isset($default) ? "default '".$default."'" : '', $notnull ? 'not null' : 'null', $auto_increment ? 'identity(1,1)' : ''); |
|
| 602 | 602 | |
| 603 | - if($primary_key) |
|
| 603 | + if ($primary_key) |
|
| 604 | 604 | { |
| 605 | 605 | $primary_list[] = $name; |
| 606 | 606 | } |
| 607 | - else if($unique) |
|
| 607 | + else if ($unique) |
|
| 608 | 608 | { |
| 609 | 609 | $unique_list[$unique][] = $name; |
| 610 | 610 | } |
| 611 | - else if($index) |
|
| 611 | + else if ($index) |
|
| 612 | 612 | { |
| 613 | 613 | $index_list[$index][] = $name; |
| 614 | 614 | } |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - if(count($primary_list)) |
|
| 617 | + if (count($primary_list)) |
|
| 618 | 618 | { |
| 619 | - $column_schema[] = sprintf("primary key (%s)", '"' . implode($primary_list, '","') . '"'); |
|
| 619 | + $column_schema[] = sprintf("primary key (%s)", '"'.implode($primary_list, '","').'"'); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | $schema = sprintf('create table [%s] (%s%s)', $this->addQuotes($table_name), "\n", implode($column_schema, ",\n")); |
| 623 | 623 | $output = $this->_query($schema); |
| 624 | - if(!$output) |
|
| 624 | + if (!$output) |
|
| 625 | 625 | { |
| 626 | 626 | return false; |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - if(count($unique_list)) |
|
| 629 | + if (count($unique_list)) |
|
| 630 | 630 | { |
| 631 | - foreach($unique_list as $key => $val) |
|
| 631 | + foreach ($unique_list as $key => $val) |
|
| 632 | 632 | { |
| 633 | - $query = sprintf("create unique index %s on %s (%s);", $key, $table_name, '[' . implode('],[', $val) . ']'); |
|
| 633 | + $query = sprintf("create unique index %s on %s (%s);", $key, $table_name, '['.implode('],[', $val).']'); |
|
| 634 | 634 | $this->_query($query); |
| 635 | 635 | } |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - if(count($index_list)) |
|
| 638 | + if (count($index_list)) |
|
| 639 | 639 | { |
| 640 | - foreach($index_list as $key => $val) |
|
| 640 | + foreach ($index_list as $key => $val) |
|
| 641 | 641 | { |
| 642 | - $query = sprintf("create index %s on %s (%s);", $key, $table_name, '[' . implode('],[', $val) . ']'); |
|
| 642 | + $query = sprintf("create index %s on %s (%s);", $key, $table_name, '['.implode('],[', $val).']'); |
|
| 643 | 643 | $this->_query($query); |
| 644 | 644 | } |
| 645 | 645 | } |
@@ -682,34 +682,34 @@ discard block |
||
| 682 | 682 | function getUpdateSql($query, $with_values = true, $with_priority = false) |
| 683 | 683 | { |
| 684 | 684 | $columnsList = $query->getUpdateString($with_values); |
| 685 | - if($columnsList == '') |
|
| 685 | + if ($columnsList == '') |
|
| 686 | 686 | { |
| 687 | 687 | return new Object(-1, "Invalid query"); |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | $from = $query->getFromString($with_values); |
| 691 | - if($from == '') |
|
| 691 | + if ($from == '') |
|
| 692 | 692 | { |
| 693 | 693 | return new Object(-1, "Invalid query"); |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | $tables = $query->getTables(); |
| 697 | 697 | $alias_list = ''; |
| 698 | - foreach($tables as $table) |
|
| 698 | + foreach ($tables as $table) |
|
| 699 | 699 | { |
| 700 | 700 | $alias_list .= $table->getAlias(); |
| 701 | 701 | } |
| 702 | 702 | implode(',', explode(' ', $alias_list)); |
| 703 | 703 | |
| 704 | 704 | $where = $query->getWhereString($with_values); |
| 705 | - if($where != '') |
|
| 705 | + if ($where != '') |
|
| 706 | 706 | { |
| 707 | - $where = ' WHERE ' . $where; |
|
| 707 | + $where = ' WHERE '.$where; |
|
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | $priority = $with_priority ? $query->getPriority() : ''; |
| 711 | 711 | |
| 712 | - return "UPDATE $priority $alias_list SET $columnsList FROM " . $from . $where; |
|
| 712 | + return "UPDATE $priority $alias_list SET $columnsList FROM ".$from.$where; |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | /** |
@@ -730,7 +730,7 @@ discard block |
||
| 730 | 730 | * @param boolean $with_values |
| 731 | 731 | * @return string |
| 732 | 732 | */ |
| 733 | - function getSelectSql($query, $with_values = TRUE, $connection=NULL) |
|
| 733 | + function getSelectSql($query, $with_values = TRUE, $connection = NULL) |
|
| 734 | 734 | { |
| 735 | 735 | $with_values = false; |
| 736 | 736 | |
@@ -740,75 +740,75 @@ discard block |
||
| 740 | 740 | $limit = ''; |
| 741 | 741 | $limitCount = ''; |
| 742 | 742 | $limitQueryPart = $query->getLimit(); |
| 743 | - if($limitQueryPart) |
|
| 743 | + if ($limitQueryPart) |
|
| 744 | 744 | { |
| 745 | 745 | $limitCount = $limitQueryPart->getLimit(); |
| 746 | 746 | } |
| 747 | - if($limitCount != '') |
|
| 747 | + if ($limitCount != '') |
|
| 748 | 748 | { |
| 749 | - $limit = 'SELECT TOP ' . $limitCount; |
|
| 749 | + $limit = 'SELECT TOP '.$limitCount; |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | $select = $query->getSelectString($with_values); |
| 753 | - if($select == '') |
|
| 753 | + if ($select == '') |
|
| 754 | 754 | { |
| 755 | 755 | return new Object(-1, "Invalid query"); |
| 756 | 756 | } |
| 757 | - if($limit != '') |
|
| 757 | + if ($limit != '') |
|
| 758 | 758 | { |
| 759 | - $select = $limit . ' ' . $select; |
|
| 759 | + $select = $limit.' '.$select; |
|
| 760 | 760 | } |
| 761 | 761 | else |
| 762 | 762 | { |
| 763 | - $select = 'SELECT ' . $select; |
|
| 763 | + $select = 'SELECT '.$select; |
|
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | $from = $query->getFromString($with_values); |
| 767 | - if($from == '') |
|
| 767 | + if ($from == '') |
|
| 768 | 768 | { |
| 769 | 769 | return new Object(-1, "Invalid query"); |
| 770 | 770 | } |
| 771 | - $from = ' FROM ' . $from; |
|
| 771 | + $from = ' FROM '.$from; |
|
| 772 | 772 | |
| 773 | 773 | $where = $query->getWhereString($with_values); |
| 774 | - if($where != '') |
|
| 774 | + if ($where != '') |
|
| 775 | 775 | { |
| 776 | - $where = ' WHERE ' . $where; |
|
| 776 | + $where = ' WHERE '.$where; |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | $groupBy = $query->getGroupByString(); |
| 780 | - if($groupBy != '') |
|
| 780 | + if ($groupBy != '') |
|
| 781 | 781 | { |
| 782 | - $groupBy = ' GROUP BY ' . $groupBy; |
|
| 782 | + $groupBy = ' GROUP BY '.$groupBy; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | $orderBy = $query->getOrderByString(); |
| 786 | - if($orderBy != '') |
|
| 786 | + if ($orderBy != '') |
|
| 787 | 787 | { |
| 788 | - $orderBy = ' ORDER BY ' . $orderBy; |
|
| 788 | + $orderBy = ' ORDER BY '.$orderBy; |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | - if($limitCount != '' && $query->limit->start > 0) |
|
| 791 | + if ($limitCount != '' && $query->limit->start > 0) |
|
| 792 | 792 | { |
| 793 | 793 | $order = $query->getOrder(); |
| 794 | 794 | $first_columns = array(); |
| 795 | - foreach($order as $val) |
|
| 795 | + foreach ($order as $val) |
|
| 796 | 796 | { |
| 797 | 797 | $tmpColumnName = $val->getPureColumnName(); |
| 798 | - $first_columns[] = sprintf('%s(%s) as %s', $val->getPureSortOrder()=='asc'?'max':'min', $tmpColumnName, $tmpColumnName); |
|
| 798 | + $first_columns[] = sprintf('%s(%s) as %s', $val->getPureSortOrder() == 'asc' ? 'max' : 'min', $tmpColumnName, $tmpColumnName); |
|
| 799 | 799 | $first_sub_columns[] = $tmpColumnName; |
| 800 | 800 | } |
| 801 | 801 | |
| 802 | - $first_query = sprintf("select %s from (select top %d %s %s %s %s %s) xet", implode(',',$first_columns), $query->limit->start, implode(',',$first_sub_columns), $from, $where, $groupBy, $orderBy); |
|
| 802 | + $first_query = sprintf("select %s from (select top %d %s %s %s %s %s) xet", implode(',', $first_columns), $query->limit->start, implode(',', $first_sub_columns), $from, $where, $groupBy, $orderBy); |
|
| 803 | 803 | $this->param = $query->getArguments(); |
| 804 | 804 | $result = $this->__query($first_query, $connection); |
| 805 | 805 | $tmp = $this->_fetch($result); |
| 806 | 806 | |
| 807 | 807 | $sub_cond = array(); |
| 808 | - foreach($order as $k => $v) |
|
| 808 | + foreach ($order as $k => $v) |
|
| 809 | 809 | { |
| 810 | 810 | //for example... use Document |
| 811 | - if(get_class($v->sort_order) == 'SortArgument') |
|
| 811 | + if (get_class($v->sort_order) == 'SortArgument') |
|
| 812 | 812 | { |
| 813 | 813 | $sort_order = $v->sort_order->value; |
| 814 | 814 | } |
@@ -818,19 +818,19 @@ discard block |
||
| 818 | 818 | $sort_order = $v->sort_order; |
| 819 | 819 | } |
| 820 | 820 | |
| 821 | - $sub_cond[] = sprintf("%s %s '%s'", $v->getPureColumnName(), $sort_order=='asc'?'>':'<', $tmp->{$v->getPureColumnName()}); |
|
| 821 | + $sub_cond[] = sprintf("%s %s '%s'", $v->getPureColumnName(), $sort_order == 'asc' ? '>' : '<', $tmp->{$v->getPureColumnName()}); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | - if(!$where) |
|
| 824 | + if (!$where) |
|
| 825 | 825 | { |
| 826 | - $sub_condition = ' WHERE ( '.implode(' and ',$sub_cond).' )'; |
|
| 826 | + $sub_condition = ' WHERE ( '.implode(' and ', $sub_cond).' )'; |
|
| 827 | 827 | } |
| 828 | 828 | else |
| 829 | 829 | { |
| 830 | - $sub_condition = ' and ( '.implode(' and ',$sub_cond).' )'; |
|
| 830 | + $sub_condition = ' and ( '.implode(' and ', $sub_cond).' )'; |
|
| 831 | 831 | } |
| 832 | 832 | } |
| 833 | - return $select . ' ' . $from . ' ' . $where .$sub_condition. ' ' . $groupBy . ' ' . $orderBy; |
|
| 833 | + return $select.' '.$from.' '.$where.$sub_condition.' '.$groupBy.' '.$orderBy; |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | /** |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | { |
| 846 | 846 | $query = $this->getSelectSql($queryObject, true, $connection); |
| 847 | 847 | |
| 848 | - if(strpos($query, "substr")) |
|
| 848 | + if (strpos($query, "substr")) |
|
| 849 | 849 | { |
| 850 | 850 | $query = str_replace("substr", "substring", $query); |
| 851 | 851 | } |
@@ -853,10 +853,10 @@ discard block |
||
| 853 | 853 | // TODO Decide if we continue to pass parameters like this |
| 854 | 854 | $this->param = $queryObject->getArguments(); |
| 855 | 855 | |
| 856 | - $query .= (__DEBUG_QUERY__ & 1 && $output->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : ''; |
|
| 856 | + $query .= (__DEBUG_QUERY__ & 1 && $output->query_id) ? sprintf(' '.$this->comment_syntax, $this->query_id) : ''; |
|
| 857 | 857 | $result = $this->_query($query, $connection); |
| 858 | 858 | |
| 859 | - if($this->isError()) |
|
| 859 | + if ($this->isError()) |
|
| 860 | 860 | { |
| 861 | 861 | return $this->queryError($queryObject); |
| 862 | 862 | } |
@@ -884,9 +884,9 @@ discard block |
||
| 884 | 884 | function queryError($queryObject) |
| 885 | 885 | { |
| 886 | 886 | $limit = $queryObject->getLimit(); |
| 887 | - if($limit && $limit->isPageHandler()) |
|
| 887 | + if ($limit && $limit->isPageHandler()) |
|
| 888 | 888 | { |
| 889 | - $buff = new Object (); |
|
| 889 | + $buff = new Object(); |
|
| 890 | 890 | $buff->total_count = 0; |
| 891 | 891 | $buff->total_page = 0; |
| 892 | 892 | $buff->page = 1; |
@@ -910,52 +910,52 @@ discard block |
||
| 910 | 910 | function queryPageLimit($queryObject, $result, $connection) |
| 911 | 911 | { |
| 912 | 912 | $limit = $queryObject->getLimit(); |
| 913 | - if($limit && $limit->isPageHandler()) |
|
| 913 | + if ($limit && $limit->isPageHandler()) |
|
| 914 | 914 | { |
| 915 | 915 | // Total count |
| 916 | 916 | $temp_where = $queryObject->getWhereString(true, false); |
| 917 | - $count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($temp_where === '' ? '' : ' WHERE ' . $temp_where)); |
|
| 917 | + $count_query = sprintf('select count(*) as "count" %s %s', 'FROM '.$queryObject->getFromString(), ($temp_where === '' ? '' : ' WHERE '.$temp_where)); |
|
| 918 | 918 | |
| 919 | 919 | // Check for distinct query and if found update count query structure |
| 920 | 920 | $temp_select = $queryObject->getSelectString(true); |
| 921 | 921 | $uses_distinct = stripos($temp_select, "distinct") !== false; |
| 922 | 922 | $uses_groupby = $queryObject->getGroupByString() != ''; |
| 923 | - if($uses_distinct || $uses_groupby) |
|
| 923 | + if ($uses_distinct || $uses_groupby) |
|
| 924 | 924 | { |
| 925 | 925 | $count_query = sprintf('select %s %s %s %s' |
| 926 | 926 | , $temp_select |
| 927 | - , 'FROM ' . $queryObject->getFromString(true) |
|
| 928 | - , ($temp_where === '' ? '' : ' WHERE ' . $temp_where) |
|
| 929 | - , ($uses_groupby ? ' GROUP BY ' . $queryObject->getGroupByString() : '') |
|
| 927 | + , 'FROM '.$queryObject->getFromString(true) |
|
| 928 | + , ($temp_where === '' ? '' : ' WHERE '.$temp_where) |
|
| 929 | + , ($uses_groupby ? ' GROUP BY '.$queryObject->getGroupByString() : '') |
|
| 930 | 930 | ); |
| 931 | 931 | |
| 932 | 932 | // If query uses grouping or distinct, count from original select |
| 933 | 933 | $count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query); |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | - $count_query .= (__DEBUG_QUERY__ & 1 && $queryObject->queryID) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : ''; |
|
| 936 | + $count_query .= (__DEBUG_QUERY__ & 1 && $queryObject->queryID) ? sprintf(' '.$this->comment_syntax, $this->query_id) : ''; |
|
| 937 | 937 | $this->param = $queryObject->getArguments(); |
| 938 | 938 | $result_count = $this->_query($count_query, $connection); |
| 939 | 939 | $count_output = $this->_fetch($result_count); |
| 940 | 940 | $total_count = (int) $count_output->count; |
| 941 | 941 | |
| 942 | 942 | $list_count = $limit->list_count->getValue(); |
| 943 | - if(!$list_count) |
|
| 943 | + if (!$list_count) |
|
| 944 | 944 | { |
| 945 | 945 | $list_count = 20; |
| 946 | 946 | } |
| 947 | 947 | $page_count = $limit->page_count->getValue(); |
| 948 | - if(!$page_count) |
|
| 948 | + if (!$page_count) |
|
| 949 | 949 | { |
| 950 | 950 | $page_count = 10; |
| 951 | 951 | } |
| 952 | 952 | $page = $limit->page->getValue(); |
| 953 | - if(!$page || $page < 1) |
|
| 953 | + if (!$page || $page < 1) |
|
| 954 | 954 | { |
| 955 | 955 | $page = 1; |
| 956 | 956 | } |
| 957 | 957 | // Total pages |
| 958 | - if($total_count) |
|
| 958 | + if ($total_count) |
|
| 959 | 959 | { |
| 960 | 960 | $total_page = (int) (($total_count - 1) / $list_count) + 1; |
| 961 | 961 | } |
@@ -965,11 +965,11 @@ discard block |
||
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | // check the page variables |
| 968 | - if($page > $total_page) |
|
| 968 | + if ($page > $total_page) |
|
| 969 | 969 | { |
| 970 | 970 | // If requested page is bigger than total number of pages, return empty list |
| 971 | 971 | |
| 972 | - $buff = new Object (); |
|
| 972 | + $buff = new Object(); |
|
| 973 | 973 | $buff->total_count = $total_count; |
| 974 | 974 | $buff->total_page = $total_page; |
| 975 | 975 | $buff->page = $page; |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | $buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count); |
| 978 | 978 | return $buff; |
| 979 | 979 | |
| 980 | - if($queryObject->usesClickCount()) |
|
| 980 | + if ($queryObject->usesClickCount()) |
|
| 981 | 981 | { |
| 982 | 982 | $update_query = $this->getClickCountQuery($queryObject); |
| 983 | 983 | $this->_executeUpdateAct($update_query); |
@@ -989,7 +989,7 @@ discard block |
||
| 989 | 989 | $virtual_no = $total_count - $start_count; |
| 990 | 990 | $data = $this->_fetch($result, $virtual_no); |
| 991 | 991 | |
| 992 | - $buff = new Object (); |
|
| 992 | + $buff = new Object(); |
|
| 993 | 993 | $buff->total_count = $total_count; |
| 994 | 994 | $buff->total_page = $total_page; |
| 995 | 995 | $buff->page = $page; |
@@ -999,7 +999,7 @@ discard block |
||
| 999 | 999 | else |
| 1000 | 1000 | { |
| 1001 | 1001 | $data = $this->_fetch($result); |
| 1002 | - $buff = new Object (); |
|
| 1002 | + $buff = new Object(); |
|
| 1003 | 1003 | $buff->data = $data; |
| 1004 | 1004 | } |
| 1005 | 1005 | return $buff; |