.

DBSqlBuilderInsert Class Reference
[Model]

Build an insert query. More...

Inheritance diagram for DBSqlBuilderInsert:
DBSqlBuilderBase IDBSqlBuilder DBSqlBuilderInsertMysql DBSqlBuilderReplaceMysql

List of all members.

Protected Member Functions

  get_fieldnames ($arr_fields, IDBTable $table)
  get_select ($query)
  get_sql_template ()
  get_substitutes ()
  get_table (IDBTable $table)
  get_values ($arr_fields, IDBTable $table)

Detailed Description

Build an insert query.

Author:
Gerd Riesselmann

Definition at line 8 of file dbsqlbuilder.insert.cls.php.


Member Function Documentation

DBSqlBuilderInsert::get_fieldnames ( arr_fields,
IDBTable table  
) [protected]

Definition at line 28 of file dbsqlbuilder.insert.cls.php.

00028                                                                         {
00029                 $conn = $table->get_table_driver();
00030                 $ret = array();
00031                 foreach($arr_fields as $key => $field) {
00032                         if (!is_numeric($key)) {
00033                                 // FOrm array('col1' => val1, 'col2' => val2): Used with INSERT VALUES
00034                                 $ret[] = DB::escape_database_entity($key, $conn, IDBDriver::FIELD);
00035                         }
00036                         else {
00037                                 // Form array("col1", "col2", ...): Used with INSERT SELECT only
00038                                 $ret[] = DB::escape_database_entity($field, $conn, IDBDriver::FIELD); 
00039                         }
00040                 }
00041                 return implode(', ', $ret);
00042         }
DBSqlBuilderInsert::get_select ( query  )  [protected]

Definition at line 53 of file dbsqlbuilder.insert.cls.php.

00053                                               {
00054                 if ($query) {
00055                         return $query->get_sql();
00056                 }
00057                 return '';
00058         }
DBSqlBuilderInsert::get_sql_template (  )  [protected]

Reimplemented from DBSqlBuilderBase.

Reimplemented in DBSqlBuilderReplaceMysql.

Definition at line 9 of file dbsqlbuilder.insert.cls.php.

00009                                               {         
00010                 return 'INSERT%delayed%ignore INTO %!table (%fields) %!values_or_select';               
00011         }
DBSqlBuilderInsert::get_substitutes (  )  [protected]

Reimplemented from DBSqlBuilderBase.

Reimplemented in DBSqlBuilderReplaceMysql.

Definition at line 13 of file dbsqlbuilder.insert.cls.php.

00013                                              {
00014                 $value_or_select = $this->get_select(Arr::get_item($this->params, 'select', null));
00015                 if (empty($value_or_select)) {
00016                         $value_or_select = $this->get_values($this->fields, $this->query->get_table());
00017                 }
00018                 $ret = array(
00019                         '%fields' => $this->get_fieldnames($this->fields, $this->query->get_table()),
00020                         '%!table' => $this->get_table($this->query->get_table()),
00021                         '%!values_or_select' => $value_or_select,
00022                         '%delayed' => $this->get_feature_sql($this->params, 'delayed', 'DELAYED'),
00023                         '%ignore' => $this->get_feature_sql($this->params, 'ignore', 'IGNORE'),
00024                 );      
00025                 return $ret;
00026         }
DBSqlBuilderInsert::get_table ( IDBTable table  )  [protected]

Reimplemented from DBSqlBuilderBase.

Definition at line 60 of file dbsqlbuilder.insert.cls.php.

00060                                                       {
00061                 return $table->get_table_name_escaped();
00062         }
DBSqlBuilderInsert::get_values ( arr_fields,
IDBTable table  
) [protected]

Definition at line 44 of file dbsqlbuilder.insert.cls.php.

00044                                                                     {
00045                 $values = array();
00046                 foreach($arr_fields as $column => $value) {
00047                         $values[] = DB::format($value, $table, $column);                        
00048                 }
00049                 $values = 'VALUES (' . implode(', ', $values) . ')';
00050                 return $values;
00051         }

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