helhum / TYPO3-Distribution

A distribution package for TYPO3 CMS with added typo3_console support
81 stars 19 forks source link

Escape column fields in installation #7

Closed adimit closed 7 years ago

adimit commented 7 years ago

Description

Installation doesn't work with mariadb 10.2+, because recursive has been made a keword. Currently, issuing install:setup will fail with the following output:

  ERROR: Database query failed!
  Query:
   CREATE TABLE sys_file_collection (
  uid int(11) NOT NULL auto_increment,
  pid int(11) NOT NULL default '0',
  tstamp int(11) NOT NULL default '0',
  crdate int(11) NOT NULL default '0',
  cruser_id int(11) NOT NULL default '0',
  t3ver_oid int(11) NOT NULL default '0',
  t3ver_id int(11) NOT NULL default '0',
  t3ver_wsid int(11) NOT NULL default '0',
  t3ver_label varchar(30) NOT NULL default '',
  t3ver_state tinyint(4) NOT NULL default '0',
  t3ver_stage int(11) NOT NULL default '0',
  t3ver_count int(11) NOT NULL default '0',
  t3ver_tstamp int(11) NOT NULL default '0',
  t3ver_move_id int(11) NOT NULL default '0',
  t3_origuid int(11) NOT NULL default '0',
  sys_language_uid int(11) NOT NULL default '0',
  l10n_parent int(11) NOT NULL default '0',
  l10n_diffsource mediumtext,
  deleted tinyint(4) NOT NULL default '0',
  hidden tinyint(4) NOT NULL default '0',
  starttime int(11) NOT NULL default '0',
  endtime int(11) NOT NULL default '0',
  title tinytext,
  description text,
  type varchar(30) NOT NULL default 'static',
  files int(11) NOT NULL default '0',
  storage int(11) NOT NULL default '0',
  folder text,
  recursive tinyint(4) NOT NULL default '0',
  category int(11) NOT NULL default '0',
  PRIMARY KEY (uid),
  KEY parent (pid,deleted),
  KEY t3ver_oid (t3ver_oid,t3ver_wsid)
  );
  Error:
   You have an error in your SQL syntax; check the manual that corresponds to
  your MariaDB server version for the right syntax to use near 'recursive
  tinyint(4) NOT NULL default '0',
  category int(11) NOT NULL default '0'' at line 30
  ERROR: Database query failed!
  Query:
   CREATE TABLE tt_content (
  uid int(11) NOT NULL auto_increment,
  pid int(11) NOT NULL default '0',
  t3ver_oid int(11) NOT NULL default '0',
  t3ver_id int(11) NOT NULL default '0',
  t3ver_wsid int(11) NOT NULL default '0',
  t3ver_label varchar(255) NOT NULL default '',
  t3ver_state tinyint(4) NOT NULL default '0',
  t3ver_stage int(11) NOT NULL default '0',
  t3ver_count int(11) NOT NULL default '0',
  t3ver_tstamp int(11) NOT NULL default '0',
  t3ver_move_id int(11) NOT NULL default '0',
  t3_origuid int(11) NOT NULL default '0',
  tstamp int(11) unsigned NOT NULL default '0',
  crdate int(11) unsigned NOT NULL default '0',
  cruser_id int(11) unsigned NOT NULL default '0',
  editlock tinyint(4) unsigned NOT NULL default '0',
  hidden tinyint(4) unsigned NOT NULL default '0',
  sorting int(11) unsigned NOT NULL default '0',
  CType varchar(255) NOT NULL default '',
  header varchar(255) NOT NULL default '',
  rowDescription text,
  bodytext mediumtext,
  image int(11) unsigned NOT NULL default '0',
  imagewidth mediumint(11) unsigned NOT NULL default '0',
  imageorient tinyint(4) unsigned NOT NULL default '0',
  imagecols tinyint(4) unsigned NOT NULL default '0',
  imageborder tinyint(4) unsigned NOT NULL default '0',
  media int(11) unsigned NOT NULL default '0',
  layout int(11) unsigned NOT NULL default '0',
  deleted tinyint(4) unsigned NOT NULL default '0',
  cols int(11) unsigned NOT NULL default '0',
  records text,
  pages text,
  starttime int(11) unsigned NOT NULL default '0',
  endtime int(11) unsigned NOT NULL default '0',
  colPos int(11) unsigned NOT NULL default '0',
  subheader varchar(255) NOT NULL default '',
  fe_group varchar(100) NOT NULL default '0',
  header_link varchar(1024) NOT NULL default '',
  image_zoom tinyint(3) unsigned NOT NULL default '0',
  header_layout varchar(30) NOT NULL default '0',
  menu_type varchar(30) NOT NULL default '0',
  list_type varchar(255) NOT NULL default '',
  select_key varchar(80) NOT NULL default '',
  sectionIndex tinyint(3) unsigned NOT NULL default '0',
  linkToTop tinyint(3) unsigned NOT NULL default '0',
  file_collections text,
  filelink_size tinyint(3) unsigned NOT NULL default '0',
  filelink_sorting varchar(10) NOT NULL default '',
  target varchar(30) NOT NULL default '',
  date int(10) unsigned NOT NULL default '0',
  recursive tinyint(3) unsigned NOT NULL default '0',
  imageheight mediumint(8) unsigned NOT NULL default '0',
  sys_language_uid int(11) NOT NULL default '0',
  tx_impexp_origuid int(11) NOT NULL default '0',
  pi_flexform mediumtext,
  accessibility_title varchar(30) NOT NULL default '',
  accessibility_bypass tinyint(3) unsigned NOT NULL default '0',
  accessibility_bypass_text varchar(30) NOT NULL default '',
  l18n_parent int(11) NOT NULL default '0',
  l18n_diffsource mediumblob,
  selected_categories text,
  category_field varchar(64) NOT NULL default '',
  table_caption varchar(255) default NULL,
  table_delimiter smallint(6) unsigned NOT NULL default '0',
  table_enclosure smallint(6) unsigned NOT NULL default '0',
  table_header_position tinyint(3) unsigned NOT NULL default '0',
  table_tfoot tinyint(1) unsigned NOT NULL default '0',
  bullets_type tinyint(3) unsigned NOT NULL default '0',
  uploads_description tinyint(1) unsigned NOT NULL default '0',
  uploads_type tinyint(3) unsigned NOT NULL default '0',
  assets int(11) unsigned NOT NULL default '0',
  categories int(11) NOT NULL default '0',
  PRIMARY KEY (uid),
  KEY t3ver_oid (t3ver_oid,t3ver_wsid),
  KEY parent (pid,sorting),
  KEY language (l18n_parent,sys_language_uid)
  );
  Error:
   You have an error in your SQL syntax; check the manual that corresponds to
  your MariaDB server version for the right syntax to use near 'recursive
  tinyint(3) unsigned NOT NULL default '0',
  imageheight mediumint(8) uns' at line 53

Exact mariadb version:

  mysql  Ver 15.1 Distrib 10.2.7-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Test

You can use the official mariadb:10.2 docker image to reproduce this result with a query like:

  CREATE TABLE foo (recursive tinyint(4));

See also this bug on typo forge.

Proposed solution:

Put the recursive column for sys_file_collection and tt_content in backticks; my guess is that this will affect other commands as well, not just the installation command.

It might be a good idea to put all column names in backticks, as that will future-proof the code — there are other common word column names, such as type, category or storage that could become reserved words.

Proposed workaround:

Downgrading to mariadb:5, or 10.1.

helhum commented 7 years ago

since I call only TYPO3 API, this cannot be fixed here but must be fixed within TYPO3. Please report the bug in the TYPO3 tracker

https://forge.typo3.org/projects/typo3cms-core/issues