From bde13f359feea5d084e43afe072ce54460cabcb7 Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Mon, 31 Aug 2026 22:24:31 +0800 Subject: [PATCH] fix: avoid schema writes on readonly bills sqlite --- .../Repositories/StoreReportRepository.php | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/EcommerceFinance/Repositories/StoreReportRepository.php b/modules/EcommerceFinance/Repositories/StoreReportRepository.php index aeaaf6ab..a93ae39b 100644 --- a/modules/EcommerceFinance/Repositories/StoreReportRepository.php +++ b/modules/EcommerceFinance/Repositories/StoreReportRepository.php @@ -103,7 +103,7 @@ class StoreReportRepository /** @return array>> */ private function lifecycles(array $names): array { - if (! $this->connection->getSchemaBuilder()->hasTable('store_lifecycles')) { + if (! $this->hasTable('store_lifecycles')) { return []; } @@ -133,8 +133,8 @@ class StoreReportRepository private function lifecycleSales(array $names): array { if ($names === [] - || ! $this->connection->getSchemaBuilder()->hasTable('store_lifecycles') - || ! $this->connection->getSchemaBuilder()->hasTable('bills')) { + || ! $this->hasTable('store_lifecycles') + || ! $this->hasTable('bills')) { return []; } @@ -168,7 +168,7 @@ class StoreReportRepository /** @return array}> */ private function fallbackSales(array $names): array { - if ($names === [] || ! $this->connection->getSchemaBuilder()->hasTable('bills')) { + if ($names === [] || ! $this->hasTable('bills')) { return []; } @@ -195,6 +195,18 @@ class StoreReportRepository return $result; } + /** + * 判断 SQLite 表是否存在。使用普通只读查询,避免 Schema Builder + * 在只读/WAL 挂载下探测表结构时尝试写入数据库。 + */ + private function hasTable(string $table): bool + { + return $this->connection->select( + "SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ? LIMIT 1", + [$table], + ) !== []; + } + private function date(mixed $value, string $fallback): string { $value = trim((string) ($value ?? ''));