setSql() public method

The previous SQL execution (if any) will be cancelled, and [[params]] will be cleared as well.
public setSql ( string $sql )
$sql string the SQL statement to be set.
示例#1
0
 /**
  * Указание текста sql запроса
  * @param string $sql текст sql запроса или имя sql-файла.
  * @param array $params параметры для построения sql запроса
  *      (@example [':p1'=>'v1', ':p2' => ['value', 'PDO_SQL_TYPE'], ':p3' => ['value', 'bind'=>'text'], ':p4' => [['v1', 'v2', ...]]])
  * @return static
  */
 public function setSql($sql, array $params = [])
 {
     if (!empty($sql)) {
         $sql = (new Parser($sql, $params))->getSql();
     }
     return parent::setSql($sql);
 }
示例#2
0
 /**
  * Specifies the SQL statement to be executed.
  * The previous SQL execution (if any) will be cancelled, and [[params]] will be cleared as well.
  * @param string $sql the SQL statement to be set.
  * @return static this command instance
  */
 public function setSql($sql)
 {
     $matches = null;
     if (preg_match("/^\\s*DROP TABLE IF EXISTS (['\"]?([^\\s\\;]+)['\"]?);?\\s*\$/i", $sql, $matches)) {
         if ($this->db->getSchema()->getTableSchema($matches[2]) !== null) {
             $sql = $this->db->getQueryBuilder()->dropTable($matches[2]);
         } else {
             $sql = 'select 1 from RDB$DATABASE;';
             //Prevent Drop Table
         }
     }
     return parent::setSql($sql);
 }
 /**
  * Load sample
  * @param string $sample
  * @param \yii\db\Command $command
  * @param boolean $confirm
  */
 public function load($sample, $command, $confirm = true)
 {
     $exists = $command->setSql("select count(*) from {{%{$sample}}}")->queryScalar() > 0;
     if (!$exists || $confirm && Console::confirm("Overwrote {$sample}")) {
         $samples = isset($this->_samples[$sample]) ? $this->_samples[$sample] : [];
         $this->resolveRequired($samples, $command);
         $file = $this->sourcePath . "/{$sample}.php";
         $this->internalLoad($file, ['command' => $command, 'faker' => $this->generator, 'now' => new Expression('NOW()')]);
     }
 }