00001 <?php
00002
00003
00004
00005
00006
00007
00008 class DBSqlBuilderUpdate extends DBSqlBuilderBase {
00009 protected function get_sql_template() {
00010 return 'UPDATE%ignore %!table SET %!fields_values%where%order_by%limit';
00011 }
00012
00013 protected function get_substitutes() {
00014 $ret = array(
00015 '%!fields_values' => $this->get_fields_values($this->fields, $this->query->get_table()),
00016 '%!table' => $this->get_table_and_alias($this->query->get_table()),
00017 '%where' => $this->get_where($this->query->get_wheres()),
00018 '%ignore' => $this->get_feature_sql($this->params, 'ignore', 'IGNORE'),
00019 '%limit' => $this->get_limit(Arr::get_item($this->params, 'limit', array(0,0))),
00020 '%order_by' => $this->get_order_by(Arr::get_item($this->params, 'order_by', array()))
00021 );
00022 return $ret;
00023 }
00024
00025 protected function get_fields_values($arr_fields, IDBTable $table) {
00026 $fields = array();
00027 foreach($arr_fields as $column => $value) {
00028 $fieldname = $this->prefix_column($column, $table);
00029 $fields[$fieldname] = DB::format($value, $table, $column);;
00030 }
00031 return Arr::implode(', ', $fields, ' = ');
00032 }
00033
00034
00035 protected function get_limit($arr_limit) {
00036 $arr_limit = array_map('intval', $arr_limit);
00037 $ret = '';
00038 if ($arr_limit[1] > 0) {
00039 $ret = ' LIMIT ' . $arr_limit[1];
00040 }
00041 return $ret;
00042 }
00043
00044 }