Changeset 3749:66047a2eda22
- Timestamp:
- 04/04/18 11:58:36 (7 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.sql.statement.php
r3748 r3749 8 8 * @subpackage Core 9 9 * 10 * @copyright Bruno Hondelatte& Association Dotclear10 * @copyright Olivier Meunier & Association Dotclear 11 11 * @copyright GPL-2.0-only 12 12 */ … … 20 20 protected $con; 21 21 22 protected $ctx; // Context (may be useful for behaviour's callback) 23 22 24 protected $columns; 23 25 protected $from; … … 30 32 * 31 33 * @param dcCore $core dcCore instance 32 * @param mixed $ from optional from clause(s)33 */ 34 public function __construct(&$core, $ from= null)34 * @param mixed $ctx optional context 35 */ 36 public function __construct(&$core, $ctx = null) 35 37 { 36 38 $this->core = &$core; 37 39 $this->con = &$core->con; 40 $this->ctx = $ctx; 38 41 39 42 $this->columns = … … 43 46 $this->sql = 44 47 array(); 45 46 if ($from !== null) {47 if (is_array($from)) {48 $this->froms($from);49 } else {50 $this->from($from);51 }52 }53 48 } 54 49 … … 88 83 89 84 /** 85 * Adds context 86 * 87 * @param mixed $c the context(s) 88 * 89 * @return dcSelectStatement self instance, enabling to chain calls 90 */ 91 public function ctx($c) 92 { 93 $this->ctx = $c; 94 return $this; 95 } 96 97 /** 90 98 * Adds column(s) 91 99 * … … 135 143 } 136 144 if (is_array($c)) { 137 $filter = function ($v) {145 $filter = function ($v) { 138 146 return trim(ltrim($v, ',')); 139 147 }; … … 280 288 } else { 281 289 $clause = "LIKE '" . 282 290 $sql->escape(preg_replace(array('%', '_', '!'), array('!%', '!_', '!!'), $value)) . 283 291 "%' ESCAPE '!'"; 284 292 } … … 303 311 { 304 312 $filter = function ($s) { 305 $s = strtoupper($s);313 $s = strtoupper($s); 306 314 $patterns = array( 307 315 '\s+' => ' ', // Multiple spaces/tabs -> one space … … 336 344 * 337 345 * @param dcCore $core dcCore instance 338 * @param mixed $ from optional from clause(s)339 */ 340 public function __construct(&$core, $ from= null)341 { 342 $this->join 343 $this->having 344 $this->order 345 $this->group 346 * @param mixed $ctx optional context 347 */ 348 public function __construct(&$core, $ctx = null) 349 { 350 $this->join = 351 $this->having = 352 $this->order = 353 $this->group = 346 354 array(); 347 355 … … 350 358 $this->distinct = false; 351 359 352 parent::__construct($core, $ from);360 parent::__construct($core, $ctx); 353 361 } 354 362 … … 496 504 public function statement() 497 505 { 506 # --BEHAVIOR-- coreBeforeSelectStatement 507 $this->core->callBehavior('coreBeforeSelectStatement', $this); 508 498 509 // Check if source given 499 510 if (!count($this->from)) { … … 563 574 } 564 575 565 return trim($query); 576 $query = trim($query); 577 578 # --BEHAVIOR-- coreAfertSelectStatement 579 $this->core->callBehavior('coreAfterSelectStatement', $this, $query); 580 581 return $query; 566 582 } 567 583 } … … 579 595 public function statement() 580 596 { 597 # --BEHAVIOR-- coreBeforeDeleteStatement 598 $this->core->callBehavior('coreBeforeDeleteStatement', $this); 599 581 600 // Check if source given 582 601 if (!count($this->from)) { … … 609 628 } 610 629 611 return trim($query); 630 $query = trim($query); 631 632 # --BEHAVIOR-- coreAfertDeleteStatement 633 $this->core->callBehavior('coreAfterDeleteStatement', $this, $query); 634 635 return $query; 612 636 } 613 637 } … … 624 648 * 625 649 * @param dcCore $core dcCore instance 626 * @param mixed $ from optional from clause(s)627 */ 628 public function __construct(&$core, $ from= null)650 * @param mixed $ctx optional context 651 */ 652 public function __construct(&$core, $ctx = null) 629 653 { 630 654 $this->set = array(); 631 655 632 parent::__construct($core, $ from);656 parent::__construct($core, $ctx); 633 657 } 634 658 … … 700 724 public function whereStatement() 701 725 { 726 # --BEHAVIOR-- coreBeforeUpdateWhereStatement 727 $this->core->callBehavior('coreBeforeUpdateWhereStatement', $this); 728 702 729 $query = ''; 703 730 … … 720 747 } 721 748 722 return trim($query); 749 $query = trim($query); 750 751 # --BEHAVIOR-- coreAfertUpdateWhereStatement 752 $this->core->callBehavior('coreAfterUpdateWhereStatement', $this, $query); 753 754 return $query; 723 755 } 724 756 … … 730 762 public function statement() 731 763 { 764 # --BEHAVIOR-- coreBeforeUpdateStatement 765 $this->core->callBehavior('coreBeforeUpdateStatement', $this); 766 732 767 // Check if source given 733 768 if (!count($this->from)) { … … 765 800 } 766 801 767 return trim($query); 802 $query = trim($query); 803 804 # --BEHAVIOR-- coreAfertUpdateStatement 805 $this->core->callBehavior('coreAfterUpdateStatement', $this, $query); 806 807 return $query; 768 808 } 769 809 } … … 780 820 * 781 821 * @param dcCore $core dcCore instance 782 * @param mixed $ into optional into clause(s)783 */ 784 public function __construct(&$core, $ into= null)822 * @param mixed $ctx optional context 823 */ 824 public function __construct(&$core, $ctx = null) 785 825 { 786 826 $this->lines = array(); 787 827 788 parent::__construct($core, $ into);828 parent::__construct($core, $ctx); 789 829 } 790 830 … … 843 883 public function statement() 844 884 { 885 # --BEHAVIOR-- coreBeforeInsertStatement 886 $this->core->callBehavior('coreBeforeInsertStatement', $this); 887 845 888 // Check if source given 846 889 if (!count($this->from)) { … … 873 916 } 874 917 875 return trim($query); 918 $query = trim($query); 919 920 # --BEHAVIOR-- coreAfertInsertStatement 921 $this->core->callBehavior('coreAfterInsertStatement', $this, $query); 922 923 return $query; 876 924 } 877 925 }
Note: See TracChangeset
for help on using the changeset viewer.