| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/dbal/src/criteria/lmbSQLBaseCriteria.class.php'); 10 lmb_require('limb/dbal/src/criteria/lmbSQLFalseCriteria.class.php'); 11 lmb_require('limb/dbal/src/criteria/lmbSQLRawCriteria.class.php'); 12 lmb_require('limb/dbal/src/criteria/lmbSQLTrueCriteria.class.php'); 13 14 /** 15 * class lmbSQLFieldCriteria. 16 * 17 * @package dbal 18 * @version $Id: lmbSQLFieldCriteria.class.php 5945 2007-06-06 08:31:43Z pachanga $ 19 */ 20 class lmbSQLFieldCriteria extends lmbSQLBaseCriteria 21 { 22 const EQUAL = "="; 23 const NOT_EQUAL = "<>"; 24 const GREATER = ">"; 25 const LESS = "<"; 26 const GREATER_EQUAL = ">="; 27 const LESS_EQUAL = "<="; 28 const LIKE = " LIKE "; 29 const NOT_LIKE = " NOT LIKE "; 30 const IN = " IN "; 31 const NOT_IN = " NOT IN "; 32 const IS_NULL = " IS NULL"; 33 const IS_NOT_NULL = " IS NOT NULL"; 34 35 protected $value; 36 protected $comparison; 37 protected $column; 38 39 function __construct($column, $value, $comparison = null) 40 { 41 $this->column = $column; 42 $this->value = $value; 43 $this->comparison = ($comparison === null ? self::EQUAL : $comparison); 44 } 45 46 function getColumn() 47 { 48 return $this->column; 49 } 50 51 function getComparison() 52 { 53 return $this->comparison; 54 } 55 56 function getValue() 57 { 58 return $this->value; 59 } 60 61 protected function _appendExpressionToStatement(&$str, &$values, $conn) 62 { 63 $field = $conn->quoteIdentifier($this->column); 64 65 $stmt_placeholder = $this->_makePlaceHolder(sizeof($values) . $this->column); 66 67 // OPTION 1: column IN (?, ?) or column NOT IN (?, ?) 68 if ($this->comparison === self::IN || $this->comparison === self::NOT_IN) 69 { 70 $str .= $field . $this->comparison; 71 72 $inString = '('; 73 foreach($this->value as $key => $value) 74 { 75 $stmt_in_placeholder = $this->_makePlaceHolder($key . '_' . $stmt_placeholder); 76 $values[$stmt_in_placeholder] = $value; 77 $inString .= ':' . $stmt_in_placeholder . ':,'; 78 } 79 $str .= rtrim($inString, ',') . ')'; 80 } 81 // OPTION 2: column LIKE ? or column NOT LIKE ? 82 elseif($this->comparison === self::LIKE || $this->comparison === self::NOT_LIKE) 83 { 84 $str .= $field . $this->comparison . ':' . $stmt_placeholder . ':'; 85 $values[$stmt_placeholder] = $this->value; 86 } 87 // OPTION 3: table.column = ? or table.column >= ? etc. (traditional expressions, the default) 88 else 89 { 90 // null VALUES need special treatment because the SQL syntax is different 91 // i.e. column IS null rather than column = null 92 if ($this->value !== null) 93 { 94 $str .= $field . $this->comparison . ':' . $stmt_placeholder . ':'; 95 $values[$stmt_placeholder] = $this->value; 96 } 97 else 98 { 99 // value is null, which means it was either not specified or specifically 100 // set to null. 101 if ($this->comparison === self::EQUAL || $this->comparison === self::IS_NULL) 102 { 103 $str .= $field . self::IS_NULL; 104 } 105 elseif ($this->comparison === self::NOT_EQUAL || $this->comparison === self::IS_NOT_NULL) 106 { 107 $str .= $field . self::IS_NOT_NULL; 108 } 109 else 110 { 111 // for now throw an exception, because not sure how to interpret this 112 throw new lmbException("Could not build SQL for expression: $field " . $this->comparison . " null"); 113 } 114 } 115 } 116 } 117 } 118 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Nov 22 03:48:54 2008 | Cross-referenced by PHPXref 0.7 |