00001 <?php
00002 
00003 
00004 
00005 
00006 
00007 
00008 class DBWhere implements IDBWhere {
00009         protected $table;
00010         protected $column;
00011         protected $operator;
00012         protected $value;
00013         protected $logical_operator;
00014         
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024         public function __construct(IDBTable $table, $column, $operator = null, $value = null, $mode = IDBWhere::LOGIC_AND) {
00025                 $this->table = $table;
00026                 $this->column = $column;
00027                 $this->operator = strtoupper(trim($operator)); 
00028                 $this->value = $value;
00029                 $this->logical_operator = $mode;
00030         }
00031 
00032 
00033 
00034 
00035 
00036 
00037         public function get_sql() {
00038                 $sqlbuilder = DBSqlBuilderFactory::create_builder(DBSqlBuilderFactory::WHERE, $this);
00039                 return $sqlbuilder->get_sql();
00040         }
00041         
00042 
00043 
00044 
00045 
00046 
00047         public function get_table() {
00048                 return $this->table;
00049         }
00050         
00051 
00052 
00053 
00054 
00055 
00056         public function get_column() {
00057                 return $this->column;
00058         }
00059         
00060 
00061 
00062 
00063 
00064 
00065         public function get_operator() {
00066                 return $this->operator;
00067         }
00068         
00069 
00070 
00071 
00072 
00073 
00074         public function get_value() {
00075                 return $this->value;
00076         }
00077                         
00078 
00079 
00080 
00081 
00082 
00083         public function get_logical_operator() {
00084                 return $this->logical_operator;
00085         }
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094         protected function prefix_table_name($column, $table) {
00095                 $ret = $column;
00096                 if (!String::contains($column, '.')) {
00097                         if ($table instanceof IDBTable) {
00098                                 $ret = DB::escape_database_entity($column, $table->get_table_driver(), IDBDriver::FIELD); 
00099                                 if ($table->get_table_field($column)) {
00100                                         $ret = $table->get_table_alias_escaped() . '.' . $ret;
00101                                 }
00102                         }
00103                         else {
00104                                 $ret = DB::escape_database_entity($column, DB::DEFAULT_CONNECTION, IDBDriver::FIELD);
00105                         }
00106                 }
00107                 return $ret;
00108         }
00109 }