Overview

Namespaces

  • Alchemy
    • core
      • query
      • schema
    • dialect
    • engine
    • orm
    • tests
    • util
      • promise
  • PHP

Classes

  • ColumnRef
  • DDLQuery
  • Expression
  • Insert
  • Join
  • Predicate
  • Query
  • Scalar
  • TableRef

Interfaces

  • IQuery
  • IQueryFragment
  • IQueryValue
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace Alchemy\core\query;
 4: use Exception;
 5: 
 6: 
 7: /**
 8:  * Represent an INSERT statement
 9:  */
10: class Insert extends Query {
11:     protected $rows = array();
12: 
13: 
14:     /**
15:      * Add a row to insert. Each parameter corresponds to
16:      * a column set with {@see Query::columns()}. Optionally
17:      * Send all columns as a single array.
18:      */
19:     public function row() {
20:         $columns = func_get_args();
21:         $columns = is_array($columns[0]) ? $columns[0] : $columns;
22:         $row = array();
23:         foreach ($columns as $column) {
24:             if (!$column instanceof Scalar) {
25:                 $column = new Scalar($column);
26:             }
27: 
28:             $row[] = $column;
29:         }
30: 
31:         $this->rows[] = $row;
32:         return $this;
33:     }
34: 
35: 
36:     /**
37:      * Get the rows to insert
38:      *
39:      * @return array
40:      */
41:     public function rows() {
42:         $default = array();
43:         foreach (array_values($this->columns) as $index => $column) {
44:             if ($column instanceof Scalar) {
45:                 $default[$index] = $column;
46:             }
47:         }
48: 
49:         $rows = array();
50:         foreach ($this->rows as $row) {
51:             $rows[] = $row + $default;
52:         }
53: 
54:         return $rows;
55:     }
56: 
57: 
58:     /**
59:      * Recursively get all scalar parameters used by this expression
60:      *
61:      * @return array array(Scalar, Scalar, ...)
62:      */
63:     public function parameters() {
64:         $params = parent::parameters();
65:         foreach ($this->rows as $row) {
66:             foreach ($row as $value) {
67:                 $params[] = $value;
68:             }
69:         }
70: 
71:         return $params;
72:     }
73: }
74: 
API documentation generated by ApiGen 2.8.0