SMF icon indicating copy to clipboard operation
SMF copied to clipboard

[3.0]: Cannot install to database with `.` in it

Open Daaaav opened this issue 2 months ago • 7 comments

Basic Information

(Split off from #8961)

If the database name contains a ., the installer will report an SQL syntax error.

Steps to reproduce

  1. Run the 3.0 installer
  2. Enter a database name with a . in it (such as testforum_smf_3.0_a2025)
  3. Get to step 4: Forum Settings, and click Continue

Expected result

The database gets populated.

Actual result

The installer fails with 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 '.`0_a2025`' at line 2

Version/Git revision

3.0 Alpha 4, 9d4dfaff41b06b84c668098c63d4938bee4ba4df

Database Engine

MySQL

Database Version

10.11.13-MariaDB-0ubuntu0.24.04.1

PHP Version

8.1.33

Logs

PHP Fatal error:  Uncaught mysqli_sql_exception: 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 '.`0_a2025`' at line 2 in .../SMF3/Sources/Db/APIs/MySQL.php:219
Stack trace:
#0 .../SMF3/Sources/Db/APIs/MySQL.php(219): mysqli_query(Object(mysqli), 'SHOW TABLES\n\t\t\t...', 0)
#1 .../SMF3/Sources/Db/APIs/MySQL.php(1227): SMF\Db\APIs\MySQL->query('SHOW TABLES\n\t\t\t...', Array)
#2 .../SMF3/Sources/Maintenance/Tools/Install.php(688): SMF\Db\APIs\MySQL->list_tables()
#3 .../SMF3/Sources/Maintenance/Maintenance.php(294): SMF\Maintenance\Tools\Install->databasePopulation()
#4 .../SMF3/install.php(31): SMF\Maintenance\Maintenance->execute(1)
#5 {main}
  thrown in .../SMF3/Sources/Db/APIs/MySQL.php on line 219

Additional Information

No response

Daaaav avatar Oct 26 '25 19:10 Daaaav

Seems to be this code: https://github.com/SimpleMachines/SMF/blob/b3418252a1c3d2a68604abcbde8a7c71afb263ec/Sources/Db/APIs/MySQL.php#L1221-L1229

Which was changed in #8906

The problem is that we are stripping out the escapes around the identifier, which causes the period to not be accepted for ad database name.

@Sesquipedalian Your thoughts here. The original code didn't make much sense in that we strip out the backtick

But it has been this way for 14+ years: https://github.com/SimpleMachines/SMF/blame/d6dbdbdc3f9fd101201b06e668d9fc21ed00a819/Sources/DbExtra-mysql.php#L242

I didn't test, but I suspect the problem has existed for all these years and only now that we are making full use of our database abstraction layer for installs, do we see the problem.

jdarwood007 avatar Oct 26 '25 20:10 jdarwood007

I agree with your assessment, @jdarwood007. This looks like an old bug we are only finding now.

I suspect that similar issues might also exist in some or all of the following methods:

  • MySQL::list_tables()
  • MySQL::create_table()
  • MySQL::drop_table()
  • MySQL::rename_table()
  • MySQL::table_structure()
  • MySQL::list_columns()
  • MySQL::list_indexes()

Sesquipedalian avatar Oct 26 '25 20:10 Sesquipedalian

Thought I should mention in case it helps, I've used similar names containing "2.0" and "2.1" in the database name for other test installs, and never noticed any problems running and playing around with them - but I haven't installed any big mods in them that would create their own tables or anything like that.

Daaaav avatar Oct 26 '25 20:10 Daaaav

but I haven't installed any big mods in them that would create their own tables or anything like that.

Yeah, this issue wouldn't show up in 2.0 and 2.1 unless and until a mod tried to call list_tables().

Sesquipedalian avatar Oct 26 '25 20:10 Sesquipedalian

my pov, just remove or just not allow . in the name.

albertlast avatar Oct 27 '25 19:10 albertlast

If we change that line to allow it, things are still broken because of the identifier call here: https://github.com/SimpleMachines/SMF/blob/a7d14f68df4aa70a32ea54c3d8d9cae1efe11063/Sources/Db/APIs/MySQL.php#L2776-L2779

As such, I recommend we no longer support periods in the database name. Easy enough to do for the installer. The upgrader can warn that it is unsupported, and renaming the database is recommended.

Thoughts?

jdarwood007 avatar Nov 22 '25 00:11 jdarwood007

How common is it for people to use periods in the database name?

Oldiesmann avatar Nov 28 '25 05:11 Oldiesmann