00001 <?php
00002
00003 Load::classes_in_directory("model/base/sqlbuilder/", "dbsqlbuilder.insert", 'cls');
00004 Load::classes_in_directory("model/drivers/mysql/sqlbuilder/", "dbsqlbuilder.insert.mysql", 'cls');
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 class DBSqlBuilderReplaceMysql extends DBSqlBuilderInsertMysql {
00016 protected function get_sql_template() {
00017 return 'INSERT INTO %!table (%fields) %!values ON DUPLICATE KEY UPDATE %!fields_values';
00018 }
00019
00020 protected function get_substitutes() {
00021 $ret = array(
00022 '%fields' => $this->get_fieldnames($this->fields, $this->query->get_table()),
00023 '%!table' => $this->get_table($this->query->get_table()),
00024 '%!values' => $this->get_values($this->fields, $this->query->get_table()),
00025 '%!fields_values' => $this->get_fields_values($this->fields, $this->query->get_table()),
00026 );
00027 return $ret;
00028 }
00029
00030 protected function get_fields_values($arr_fields, IDBTable $table) {
00031 $fields = array();
00032 $keyfields = $table->get_table_keys();
00033 foreach($arr_fields as $column => $value) {
00034 if (!array_key_exists($column, $keyfields)) {
00035 $fieldname = $this->prefix_column($column, $table);
00036 $fields[$fieldname] = DB::format($value, $table, $column);
00037 }
00038 }
00039
00040
00041
00042
00043
00044
00045
00046
00047 return Arr::implode(', ', $fields, ' = ');
00048 }
00049
00050 }