newQuery() public method

Create a new Query instance for this connection.
public newQuery ( ) : Query
return Query
 /**
  * Test executing "mark_migration"
  *
  * @return void
  */
 public function testExecute()
 {
     $commandTester = new CommandTester($this->command);
     $commandTester->execute(['command' => $this->command->getName(), 'version' => '20150416223600', '--connection' => 'test']);
     $this->assertContains('Migration successfully marked migrated !', $commandTester->getDisplay());
     $result = $this->Connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetch('assoc');
     $this->assertEquals('20150416223600', $result['version']);
 }
 /**
  * Imports all records of the given fixture.
  *
  * @param string $fixtureClassName Fixture class name
  * @param \Cake\Database\Schema\Table $schema Table schema for which records
  *  will be imported
  * @param \Cake\Database\Connection $connection Database connection to use
  * @return bool True on success
  */
 protected function _importRecords($fixtureClassName, TableSchema $schema, Connection $connection)
 {
     $fixture = new $fixtureClassName();
     if (!isset($fixture->records) || empty($fixture->records)) {
         return true;
     }
     $fixture->records = (array) $fixture->records;
     if (count($fixture->records) > 100) {
         $chunk = array_chunk($fixture->records, 100);
     } else {
         $chunk = [0 => $fixture->records];
     }
     foreach ($chunk as $records) {
         list($fields, $values, $types) = $this->_getRecords($records, $schema);
         $query = $connection->newQuery()->insert($fields, $types)->into($schema->name());
         foreach ($values as $row) {
             $query->values($row);
         }
         try {
             $statement = $query->execute();
             $statement->closeCursor();
         } catch (\Exception $ex) {
             $this->error(__d('installer', 'Error while importing data for table "{0}". Details: {1}', $schema->name(), $ex->getMessage()));
             return false;
         }
     }
     return true;
 }
Beispiel #3
-1
 /**
  * Run before each tests is executed, should return a set of SQL statements to insert records for the table
  * of this fixture could be executed successfully.
  *
  * @param Connection $db An instance of the database into which the records will be inserted
  * @return bool on success or if there are no records to insert, or false on failure
  */
 public function insert(Connection $db)
 {
     if (isset($this->records) && !empty($this->records)) {
         list($fields, $values, $types) = $this->_getRecords();
         $query = $db->newQuery()->insert($fields, $types)->into($this->table);
         foreach ($values as $row) {
             $query->values($row);
         }
         $statement = $query->execute();
         $statement->closeCursor();
         return $statement;
     }
     return true;
 }