/**
  * Inserts new relations in the mm table if related records have been submitted
  *
  * @param array $insertArray
  */
 public function insertNewRelations($insertArray)
 {
     if (!count($insertArray)) {
         return;
     }
     $insertQuery = $this->typo3Db->INSERTmultipleRows($this->table, array($this->uidLocalField, $this->uidForeignField), $insertArray);
     $this->utilityFuncs->debugMessage('sql_request', array($insertQuery));
     $insertResult = $this->typo3Db->sql_query($insertQuery);
     if (!$insertResult) {
         $this->utilityFuncs->throwException('Error in SQL query for inserting new relations: ' . $this->typo3Db->sql_error());
     }
 }
 /**
  * @test
  *
  * @return void
  */
 public function insertMultipleRowsCreateValidQuery()
 {
     $this->subject = $this->getAccessibleMock(DatabaseConnection::class, ['fullQuoteStr'], [], '', false);
     $this->subject->expects($this->any())->method('fullQuoteStr')->will($this->returnCallback(function ($data) {
         return '\'' . (string) $data . '\'';
     }));
     $fields = [$this->testField, $this->anotherTestField];
     $values = [['Foo', 100], ['Bar', 200], ['Baz', 300]];
     $queryExpected = "INSERT INTO {$this->testTable} ({$this->testField}, {$this->anotherTestField}) " . "VALUES ('Foo', '100'), ('Bar', '200'), ('Baz', '300')";
     $queryGenerated = $this->subject->INSERTmultipleRows($this->testTable, $fields, $values);
     $this->assertSame($queryExpected, $queryGenerated);
 }
Пример #3
0
 /**
  * Creates an INSERT SQL-statement for $table with multiple rows.
  *
  * @param string $table Table name
  * @param array $fields Field names
  * @param array $rows Table rows. Each row should be an array with field values mapping to $fields
  * @param bool|array|string $no_quote_fields See fullQuoteArray()
  * @return string|array Full SQL query for INSERT (unless $rows does not contain any elements in which case it will be FALSE)
  */
 public function INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE)
 {
     if ((string) $this->handlerCfg[$this->lastHandlerKey]['type'] === 'native') {
         return parent::INSERTmultipleRows($table, $fields, $rows, $no_quote_fields);
     }
     $result = array();
     foreach ($rows as $row) {
         $fields_values = array();
         foreach ($fields as $key => $value) {
             $fields_values[$value] = $row[$key];
         }
         $rowQuery = $this->INSERTquery($table, $fields_values, $no_quote_fields);
         if (is_array($rowQuery)) {
             $result[] = $rowQuery;
         } else {
             $result[][0] = $rowQuery;
         }
     }
     return $result;
 }