Skip to content

feat(CrazyShop): support MySQL - #62

Merged
Rushaway merged 1 commit into
mainfrom
feat/crazyshop-mysql
Nov 4, 2026
Merged

Rushaway merged 1 commit into
mainfrom
feat/crazyshop-mysql

Conversation

@Rushaway

@Rushaway Rushaway commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Summary

  • MySQL for CrazyShop (Fun_Modes/CrazyShop.sp): CrazyShop_DB_CreateTables() only accepted the sqlite driver. With a mysql entry for FM_CrazyShop it logged "Only SQLITE is supported", deleted the handle, and credits and items were never saved. Both drivers are now supported:
    • MySQL tables with the same columns: clients_data keyed on client_steamid, shop_items_data keyed on (client_steamid, item) (a primary key instead of the SQLite UNIQUE constraint). The columns are signed INT like the SQLite INTEGER ones, because the account id is formatted with %d;
    • the credits and items upserts use ON DUPLICATE KEY UPDATE ... VALUES() on MySQL and keep ON CONFLICT ... excluded on SQLite. The SELECT and DELETE queries already run on both;
    • the table creation log lines name the driver.
  • The SQLite schema and queries are unchanged.
  • An unknown driver is still rejected, with the driver name in the error.
  • README: new "Database" section under CrazyShop with databases.cfg examples for both drivers. It recommends a dedicated database, because the table names are generic (SelfMute also has a clients_data table).
  • Version 3.1.4 -> 3.2.0.

Test plan

  • Compiles with spcomp 1.12.0.7260 (same deps as CI), 0 warnings (same as before)
  • MySQL 8.0.46 and MariaDB 11.8: table creation run twice, then credits and items inserted, updated, deleted and read back with the plugin's queries, including a negative account id
  • SQLite 3.50: same sequence with the unchanged SQLite queries
  • CI build passes
  • "driver" "mysql" entry, sm_crazyshop_savecredits 1: credits and items survive a reconnect and a map change
  • Existing "driver" "sqlite" entry: data kept, no error

The credits database only accepted the sqlite driver ("Only SQLITE is
supported"): with a mysql entry for FM_CrazyShop the handle was dropped and
nothing was saved. The tables are now created for MySQL too (same columns,
primary keys instead of the SQLite UNIQUE constraint) and the two upserts
use ON DUPLICATE KEY UPDATE on MySQL, ON CONFLICT on SQLite. The SELECT
and DELETE queries already run on both.

Unknown drivers are still rejected, with the driver name in the error.
README: databases.cfg examples for both drivers.
Version 3.1.4 -> 3.2.0.

@WareZ57 WareZ57 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested the MySQL path on a throwaway MySQL 8.0.44 with the exact statements: tables created, a second INSERT … ON DUPLICATE KEY UPDATE updates credits (100 → 250) and item count (1 → 4), load SELECTs and the item DELETE work, a negative account id is accepted (signed INT, matching the %d formatting). The SQLite path is unchanged. Compiled on spcomp 1.12: 0 errors, 0 warnings.

FYI only: MySQL 8.0.20+ warns that VALUES() in ON DUPLICATE KEY UPDATE is deprecated (warning 1287). It still works, and the replacement (… AS new … new.col) isn't supported by MariaDB, so keeping VALUES() is the right choice for now.

@Rushaway
Rushaway merged commit 2da74dd into main Nov 4, 2026
9 checks passed
@Rushaway
Rushaway deleted the feat/crazyshop-mysql branch November 4, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants