/** * Looks if the specified table exists and if not create it with the key- * field (uid). Then it syncs the DB-fields with the fields found in the form * with help of template parser */ protected function createTable() { $fields = $this->getFormFields(); $excludeFields = trim($this->utilityFuncs->getSingle($this->settings, 'excludeFields')); if (strlen($excludeFields) > 0) { $excludes = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $excludeFields); foreach ($excludes as $exclude) { unset($fields[$exclude]); } } $globalSettings = $this->globals->getSettings(); $isDebugMode = $this->utilityFuncs->getSingle($globalSettings, 'debug'); if (intval($isDebugMode) === 1) { $this->db->debugOutput = 1; } $res = $this->db->sql_query("SHOW TABLES LIKE '" . $this->table . "'"); if (!$this->db->sql_num_rows($res)) { $query = "CREATE TABLE `" . $this->table . "` (\n\t\t\t\t`" . $this->key . "` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY\n\t\t\t)"; $this->db->sql_query($query); $this->utilityFuncs->debugMessage('sql_request', [$query]); $dbFields = [$this->key]; } else { $dbFields = array_keys($this->db->admin_get_fields($this->table)); } $this->db->sql_free_result($res); $createFields = array_diff($fields, $dbFields); if (count($createFields)) { $sql = 'ALTER TABLE ' . $this->table . ' ADD `'; $sql .= implode('` ' . $this->newFieldsSqlAttribs . ', ADD `', $createFields); $sql .= '` ' . $this->newFieldsSqlAttribs; $this->db->sql_query($sql); $this->utilityFuncs->debugMessage('sql_request', [$sql]); if ($this->db->sql_error()) { $this->utilityFuncs->debugMessage('error', [$this->db->sql_error()], 3); } } }
/** * @test */ public function sqlForSelectMmQuery() { $subject = new \TYPO3\CMS\Core\Database\DatabaseConnection(); $result = $subject->SELECT_mm_query('*', 'sys_category', 'sys_category_record_mm', 'tt_content', 'AND sys_category.uid = 1', '', 'sys_category.title DESC'); $expected = 'SELECT * FROM sys_category,sys_category_record_mm,tt_content WHERE sys_category.uid=sys_category_record_mm.uid_local AND tt_content.uid=sys_category_record_mm.uid_foreign AND sys_category.uid = 1 ORDER BY sys_category.title DESC'; $this->assertEquals($expected, $result); }
/** * @test * @dataProvider cleanIntArrayDataProvider * @param array $exampleData The array to sanitize * @param array $expectedResult The expected result * @return void */ public function cleanIntArray($exampleData, $expectedResult) { /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $subject */ $subject = new \TYPO3\CMS\Core\Database\DatabaseConnection(); $sanitizedArray = $subject->cleanIntArray($exampleData); $this->assertEquals($expectedResult, $sanitizedArray); }