DBSqlBuilderWhere Class Reference
[Model]
SQL Builder for WHERE clauses. More...
Inheritance diagram for
DBSqlBuilderWhere:
Public Member Functions |
|
__construct ($where, $params=false) | |
get_sql () | |
Return SQL fragment. |
|
Protected Member Functions |
|
prefix_column ($column, $table) | |
Prefix column with table name. |
|
Protected Attributes |
|
$where = null |
Detailed Description
SQL Builder for WHERE clauses.
Definition at line 8 of file dbsqlbuilder.where.cls.php.
Constructor & Destructor Documentation
DBSqlBuilderWhere::__construct | ( | $ | where, | |
$ | params = false |
|||
) |
- Parameters:
-
IDBWhere $where
Definition at line 17 of file dbsqlbuilder.where.cls.php.
00017 { 00018 $this->where = $where; 00019 }
Member Function Documentation
DBSqlBuilderWhere::get_sql | ( | ) |
Return SQL fragment.
- Returns:
- string
Implements IDBSqlBuilder.
Definition at line 26 of file dbsqlbuilder.where.cls.php.
00026 { 00027 $operator = $this->where->get_operator(); 00028 $column = $this->where->get_column(); 00029 if (empty($operator)) { 00030 return $column; 00031 } 00032 00033 $table = $this->where->get_table(); 00034 $field = $this->prefix_column($column, $table); 00035 $value = $this->where->get_value(); 00036 $ret = ''; 00037 switch ($operator) { 00038 case IDBWhere::OP_IN: 00039 case IDBWhere::OP_NOT_IN: 00040 if ($value instanceof DBQuerySelect) { 00041 $value = $value->get_sql(); 00042 } 00043 else { 00044 $arr_formatted_values = array(); 00045 foreach(Arr::force($value) as $orgvalue) { 00046 $arr_formatted_values[] = DB::format_where($orgvalue, $table, $column); 00047 } 00048 $value = implode(', ', $arr_formatted_values); 00049 } 00050 $value = '(' . $value . ')'; 00051 break; 00052 case IDBWhere::OP_IS_NULL: 00053 case IDBWhere::OP_NOT_NULL: 00054 $value = ''; 00055 break; 00056 case IDBWhere::OP_IN_SET: 00057 $value = DB::format_where($value, $table, $column); 00058 $value = $value . ' = ' . $value; 00059 $operator = '&'; 00060 break; 00061 case IDBWhere::OP_NOT_IN_SET: 00062 $value = DB::format_where($value, $table, $column); 00063 $value = $value . ' = 0'; 00064 $operator = '&'; 00065 break; 00066 default: 00067 $value = DB::format_where($value, $table, $column); 00068 break; 00069 } 00070 return '(' . $field . ' ' . $operator . ' ' . $value . ')'; 00071 }
DBSqlBuilderWhere::prefix_column | ( | $ | column, | |
$ | table | |||
) | [protected] |
Prefix column with table name.
- Parameters:
-
string $column IDBTable|string $table
- Returns:
- string
Definition at line 80 of file dbsqlbuilder.where.cls.php.
00080 { 00081 $ret = $column; 00082 if (!String::contains($column, '.')) { 00083 if ($table instanceof IDBTable) { 00084 $ret = DB::escape_database_entity($column, $table->get_table_driver(), IDBDriver::FIELD); 00085 if ($table->get_table_field($column)) { 00086 $ret = $table->get_table_alias_escaped() . '.' . $ret; 00087 } 00088 } 00089 else { 00090 $ret = DB::escape_database_entity($column, DB::DEFAULT_CONNECTION, IDBDriver::FIELD); 00091 } 00092 } 00093 return $ret; 00094 }
Member Data Documentation
DBSqlBuilderWhere::$where = null
[protected] |
Definition at line 12 of file dbsqlbuilder.where.cls.php.
The documentation for this class was generated from the following file:
- gyro/core/model/base/sqlbuilder/dbsqlbuilder.where.cls.php