第112批:修Web收银台下单#1406——detail/reason列从VARCHAR迁移为TEXT
根因:core.php建表 `detail TEXT DEFAULT ''` 在老MySQL(<8.0.13)下被方言层 退化成VARCHAR(500),生产实际是varchar(1059)(灾备快照db_schema_mysql.sql为证), 购物车明细JSON超1059字节报 #1406 Data too long for column 'detail'。 修复: - core.php建表去掉 reason/detail 的 DEFAULT(对齐 sync.php/pay.php 等正确版本) - initTables 加存量迁移:PRAGMA table_info 检测列仍是 varchar 则 ALTER MODIFY 回 TEXT (SQLite 下 type=TEXT 不触发;MODIFY 子句由 sqlMySqlTranslateAlterTable 翻译) - admin.php 两处建表同步去掉 DEFAULT - shop.php 加 detail JSON 超长防御(>60000字节精简 items 明细,完整明细已在 orders.db) - db_schema_mysql.sql 灾备快照同步(防 db_guard 恢复时重建回 VARCHAR)
This commit is contained in:
@@ -1879,18 +1879,40 @@ function initTables($db, $side = null) {
|
||||
)");
|
||||
|
||||
// 交易流水表(Web端记录)
|
||||
// ★ 第112批:reason/detail 不带 DEFAULT —— 老 MySQL(<8.0.13)下 `TEXT DEFAULT ''`
|
||||
// 会被方言层退化成 VARCHAR(500),长购物车明细 JSON 会报 #1406 Data too long。
|
||||
// (sync.php / pay.php / poller_online.php 等建表本来就没 DEFAULT,这里对齐)
|
||||
$db->exec("CREATE TABLE IF NOT EXISTS web_transactions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
player_name TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
operator TEXT DEFAULT '',
|
||||
reason TEXT DEFAULT '',
|
||||
detail TEXT DEFAULT '',
|
||||
reason TEXT,
|
||||
detail TEXT,
|
||||
status TEXT DEFAULT 'pending',
|
||||
created_at INTEGER DEFAULT 0
|
||||
)");
|
||||
|
||||
// ★ 第112批:存量表迁移 —— 老库里 reason/detail 已被退化成 VARCHAR(500),
|
||||
// 检测列类型,仍是 VARCHAR 则 MODIFY 回 TEXT(SQLite 下 type=TEXT 不触发;
|
||||
// MODIFY 子句由 sqlMySqlTranslateAlterTable 翻译)。一次性迁移,之后不再触发。
|
||||
try {
|
||||
$txCols = array();
|
||||
$ci = $db->query("PRAGMA table_info(web_transactions)");
|
||||
while ($c = $ci->fetchArray(SQLITE3_ASSOC)) {
|
||||
$txCols[strtolower($c['name'])] = strtolower($c['type'] ?? '');
|
||||
}
|
||||
foreach (array('detail', 'reason') as $col) {
|
||||
if (isset($txCols[$col]) && strpos($txCols[$col], 'varchar') !== false) {
|
||||
$db->exec("ALTER TABLE web_transactions MODIFY `$col` TEXT");
|
||||
debugLog("initTables: web_transactions.$col 已从 VARCHAR 迁移为 TEXT");
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
debugLog("initTables: web_transactions 列迁移失败: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// 管理员登录会话
|
||||
$db->exec("CREATE TABLE IF NOT EXISTS admin_sessions (
|
||||
session_id TEXT PRIMARY KEY,
|
||||
|
||||
Reference in New Issue
Block a user