.

DBSqlBuilderReplaceMysql Class Reference
[Model]

Implementation of Replace for MySQL. More...

Inheritance diagram for DBSqlBuilderReplaceMysql:
DBSqlBuilderInsertMysql DBSqlBuilderInsert DBSqlBuilderBase IDBSqlBuilder

List of all members.

Protected Member Functions

  get_fields_values ($arr_fields, IDBTable $table)
  get_sql_template ()
  get_substitutes ()

Detailed Description

Implementation of Replace for MySQL.

Does not use REPLACE but INSERT ... ON DUPLICATED KEY UPDATE, since REPLACE means to DELETE and then INSERT, which is a pain

Author:
Gerd Riesselmann

Definition at line 15 of file dbsqlbuilder.replace.mysql.cls.php.


Member Function Documentation

DBSqlBuilderReplaceMysql::get_fields_values ( arr_fields,
IDBTable table  
) [protected]

Definition at line 30 of file dbsqlbuilder.replace.mysql.cls.php.

00030                                                                            {
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                 // This is wrong (Duplicated key)
00040 //              foreach($keyfields as $column => $dbfield) { 
00041 //                      if ($dbfield instanceof DBFieldInt && $dbfield->has_policy(DBFieldInt::AUTOINCREMENT)) {
00042 //                              // LAst isnert id fix
00043 //                              $fieldname = $this->prefix_column($column, $table);
00044 //                              $fields[$fieldname] = 'LAST_INSERT_ID(' . DB::format($value, $table, $column) . ')';
00045 //                      }
00046 //              }
00047                 return Arr::implode(', ', $fields, ' = ');
00048         }
DBSqlBuilderReplaceMysql::get_sql_template (  )  [protected]

Reimplemented from DBSqlBuilderInsert.

Definition at line 16 of file dbsqlbuilder.replace.mysql.cls.php.

00016                                               {         
00017                 return 'INSERT INTO %!table (%fields) %!values ON DUPLICATE KEY UPDATE %!fields_values';                
00018         }       
DBSqlBuilderReplaceMysql::get_substitutes (  )  [protected]

Reimplemented from DBSqlBuilderInsert.

Definition at line 20 of file dbsqlbuilder.replace.mysql.cls.php.

00020                                              {
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         }

The documentation for this class was generated from the following file: