Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TSqlMultiInsert.php

Documentation is available at TSqlMultiInsert.php

  1. <?php
  2. namespace Adianti\Database;
  3.  
  4. use Adianti\Database\TSqlStatement;
  5. use Adianti\Database\TTransaction;
  6. use Adianti\Database\TCriteria;
  7. use Exception;
  8.  
  9. /**
  10.  * Provides an Interface to create an MULTI INSERT statement
  11.  *
  12.  * @version    7.4
  13.  * @package    database
  14.  * @author     Pablo Dall'Oglio
  15.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  16.  * @license    http://www.adianti.com.br/framework-license
  17.  */
  18. {
  19.     protected $sql;
  20.     private $rows;
  21.     
  22.     /**
  23.      * Constructor method
  24.      */
  25.     public function __construct()
  26.     {
  27.         $this->rows [];
  28.     }
  29.     
  30.     /**
  31.      * Add a row data
  32.      * @param $row Row data
  33.      */
  34.     public function addRowValues($row)
  35.     {
  36.         $this->rows[$row;
  37.     }
  38.     
  39.     /**
  40.      * Transform the value according to its PHP type before send it to the database
  41.      * @param $value    Value to be transformed
  42.      * @return       Transformed Value
  43.      */
  44.     private function transform($value)
  45.     {
  46.         // store just scalar values (string, integer, ...)
  47.         if (is_scalar($value))
  48.         {
  49.             // if is a string
  50.             if (is_string($valueand (!empty($value)))
  51.             {
  52.                 $conn TTransaction::get();
  53.                 $result $conn->quote($value);
  54.             }
  55.             else if (is_bool($value)) // if is a boolean
  56.             {
  57.                 $result $value 'TRUE''FALSE';
  58.             }
  59.             else if ($value !== ''// if its another data type
  60.             {
  61.                 $result $value;
  62.             }
  63.             else
  64.             {
  65.                 $result "NULL";
  66.             }
  67.         }
  68.         else if (is_null($value))
  69.         {
  70.             $result "NULL";
  71.         }
  72.         
  73.         return $result;
  74.     }
  75.     
  76.     /**
  77.      * this method doesn't exist in this class context
  78.      * @param $criteria A TCriteria object, specifiyng the filters
  79.      * @exception       Exception in any case
  80.      */
  81.     public function setCriteria(TCriteria $criteria)
  82.     {
  83.         throw new Exception("Cannot call setCriteria from " . __CLASS__);
  84.     }
  85.     
  86.     /**
  87.      * Returns the INSERT plain statement
  88.      * @param $prepared Return a prepared Statement
  89.      */
  90.     public function getInstruction$prepared FALSE )
  91.     {
  92.         if ($this->rows)
  93.         {
  94.             $buffer [];
  95.             $target_columns implode(','array_keys($this->rows[0]));
  96.             
  97.             foreach ($this->rows as $row)
  98.             {
  99.                 foreach ($row as $key => $value)
  100.                 {
  101.                     $row[$key$this->transform($value);
  102.                 }
  103.                 
  104.                 $values_list implode(','$row);
  105.                 $buffer["($values_list)";
  106.             }
  107.             
  108.             $this->sql = "INSERT INTO {$this->entity} ($target_columns) VALUES " . implode(',', $buffer);
  109.             return $this->sql;
  110.         }
  111.     }