See also: MySQL Insert Statement http://dev.mysql.com/doc/refman/5.7/en/insert.html
Inheritance: implements SQLBuilder\ToSqlInterface, use trait SQLBuilder\Universal\Traits\OptionTrait, use trait SQLBuilder\MySQL\Traits\PartitionTrait
Example #1
0
 public function testInsertWithQuestionMark()
 {
     $driver = new MySQLDriver();
     $driver->setQMarkParamMarker();
     $args = new ArgumentArray();
     $query = new InsertQuery();
     $query->option('LOW_PRIORITY', 'IGNORE');
     $query->insert(['name' => new Bind('name', 'John'), 'confirmed' => new Bind('confirmed', true)])->into('users');
     $query->returning('id');
     $sql = $query->toSql($driver, $args);
     $this->assertEquals('INSERT LOW_PRIORITY IGNORE INTO users (name,confirmed) VALUES (?,?)', $sql);
 }
Example #2
0
 /**
  * Simply create record without validation and triggers.
  *
  * @param array $args
  */
 public function rawCreate(array $args)
 {
     $dsId = $this->writeSourceId;
     $conn = $this->getWriteConnection();
     $k = static::PRIMARY_KEY;
     $driver = $this->getWriteQueryDriver();
     $query = new InsertQuery();
     $query->insert($args);
     $query->into($this->table);
     $query->returning($k);
     $arguments = new ArgumentArray();
     $sql = $query->toSql($driver, $arguments);
     $stm = $conn->prepare($sql);
     $stm->execute($arguments->toArray());
     $pkId = null;
     if ($driver instanceof PDOPgSQLDriver) {
         $pkId = $stm->fetchColumn();
     } else {
         // lastInsertId is supported in SQLite and MySQL
         $pkId = $conn->lastInsertId();
     }
     $this->_data = $args;
     $this->_data[$k] = $pkId;
     return $this->reportSuccess('Create success', array('sql' => $sql, 'type' => Result::TYPE_CREATE));
 }
Example #3
0
 /**
  * Simply create record without validation and triggers.
  *
  * @param array $args
  */
 public function rawCreate(array $args)
 {
     $dsId = $this->getWriteSourceId();
     $conn = $this->getConnection($dsId);
     $k = static::primary_key;
     $driver = $conn->createQueryDriver();
     $query = new InsertQuery();
     $query->insert($args);
     $query->into($this->getTable());
     $query->returning($k);
     $arguments = new ArgumentArray();
     $sql = $query->toSql($driver, $arguments);
     $stm = $this->dbPrepareAndExecute($conn, $sql, $arguments->toArray());
     $pkId = null;
     if ($driver instanceof PDOPgSQLDriver) {
         $pkId = $stm->fetchColumn();
     } else {
         // lastInsertId is supported in SQLite and MySQL
         $pkId = $conn->lastInsertId();
     }
     $this->_data = $args;
     $this->_data[$k] = $pkId;
     return $this->reportSuccess('Create success', array('sql' => $sql));
 }