yii\db\Connection::quoteTableName PHP Method

quoteTableName() public method

If the table name contains schema prefix, the prefix will also be properly quoted. If the table name is already quoted or contains special characters including '(', '[[' and '{{', then this method will do nothing.
public quoteTableName ( string $name ) : string
$name string table name
return string the properly quoted table name
    public function quoteTableName($name)
    {
        return $this->getSchema()->quoteTableName($name);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param integer $count
  * @return \Generator
  * @throws Exception
  */
 public function export($count)
 {
     if (!$this->table) {
         throw new Exception("table name is required");
     }
     if (is_null($this->db)) {
         $this->db = \Yii::$app->get($this->db_component);
     }
     $this->table_quoted = $this->db->quoteTableName($this->table);
     $this->truncate();
     $first_row = $this->generator->generate()->current();
     // prepare quoted fileds name list
     $fields = array_map(function ($i) {
         return $this->db->quoteColumnName($i);
     }, array_keys($first_row));
     $fields_str = implode(",", $fields);
     // prepare values section, repeat values block $rows_per_request number
     $rows_per_request = 1;
     if ($this->multirow) {
         $rows_per_request = (int) max(floor($this->placeholder_limit / count($fields)), 1);
     }
     $placeholders = "(" . implode(",", array_fill(1, count($fields), '?')) . ")";
     $value_placeholders = implode(",", array_fill(1, $rows_per_request, $placeholders));
     // finally sql request
     $prepare = $this->db->createCommand("INSERT INTO {$this->table_quoted}({$fields_str}) VALUES {$value_placeholders}");
     // first row of data, lets save it
     $insert_values = $this->array1based($first_row);
     $prepared_rows = 1;
     foreach ($this->generator->generate() as $item) {
         if ($prepared_rows === $rows_per_request) {
             unset($insert_values[0]);
             $prepare->bindValues($insert_values);
             $prepare->execute();
             $count = $count - $rows_per_request;
             if ($count <= 0) {
                 break;
             }
             (yield $count);
             $insert_values = $this->array1based($item);
             $prepared_rows = 1;
         } else {
             $insert_values = array_merge($insert_values, array_values($item));
             $prepared_rows++;
         }
     }
 }