/**
  * 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);
         }
     }
 }