Skip to content

[3.0] Writes a column type MySQL knows in the SQL that rebuilds a table - #9653

Open
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/mysql-table-sql-column-type
Open

[3.0] Writes a column type MySQL knows in the SQL that rebuilds a table#9653
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/mysql-table-sql-column-type

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

On MySQL, table_sql() returns SQL naming a column type MySQL does not have:

ERROR 1064 (42000): You have an error in your SQL syntax; ... near 'inet DEFAULT NULL'

SMF has its own names for a couple of types, and list_columns() reports those rather than the ones the database uses: a varbinary(16) holding an address comes back as an inet, and a binary(16) holding an id comes back as a uuid. Everywhere else that writes DDL turns them back first, with calculate_type(). table_sql() did not, and wrote SMF's name into its CREATE TABLE:

$line = '  `' . $column['name'] . '` ' . $column['type'];

Ten tables on a forum with nothing added to it carry such a column, and they are the ones that record an address: ban_items, log_actions, log_banned, log_errors, log_floodcontrol, log_online, log_reported_comments, member_logins, members and messages.

Nothing in SMF calls table_sql(), which is why this has gone unnoticed. It is public API, reachable through the db_table_sql alias in DatabaseApi::$db_function_map.

PostgreSQL is unaffected: inet is a type it has.

How this was verified

By taking the definition of every table on a MySQL forum upgraded from the 2.1.7 baseline and running each into an empty database, which is the only thing the output is for.

before after
definitions that replay 57 of 72 72 of 72
failing on a type MySQL lacks 10 0
failing on an index prefix (#9652) 5 0

The two faults are independent and were counted separately: with only #9652 applied the ten type failures remain, and with only this one the five index failures do. Both were applied together for the 72 of 72.

The rebuilt database was then compared against the original: 72 tables and 539 columns on each side.

Not reachable from the unit suite

table_sql() is a database driver method and needs a connection.

Issues References (Fixes|Related|Closes)

  1. Related: [3.0] Puts an index prefix length outside the column's quoting #9652, the other reason the same method's output would not run.
  2. Related: [3.0] Lets table_sql read a column that has no default #9651, the same method failing on PostgreSQL.

list_columns() reports SMF's own name for a type the database spells
differently: a varbinary(16) holding an address comes back as an inet.
table_sql() wrote that name straight into its CREATE TABLE, so MySQL
was asked for a column of a type it does not have.

  ERROR 1064 (42000): ... near 'inet DEFAULT NULL'

Ten tables on a stock forum carry such a column, all of them the ones
that record an address.

Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant