🐛 修复当数据库文件不存在时的异常报错

This commit is contained in:
Art_Sakura 2025-05-19 00:56:17 +08:00
parent ff5b446b52
commit 2fbaf5d54f
10 changed files with 5 additions and 6 deletions

View File

@ -2,6 +2,7 @@ import math
import os
import re
from contextlib import asynccontextmanager
from pathlib import Path
import aiosqlite
@ -12,10 +13,9 @@ from ..config import g_sDBFilePath, g_sDBPath
class CSqlManager:
def __init__(self):
try:
os.mkdir(g_sDBFilePath)
except FileExistsError:
pass
dbPath = Path(g_sDBPath)
if dbPath and not dbPath.exists():
os.makedirs(dbPath, exist_ok=True)
@classmethod
async def cleanup(cls):
@ -25,8 +25,7 @@ class CSqlManager:
@classmethod
async def init(cls) -> bool:
try:
_ = os.path.exists(g_sDBFilePath)
cls.m_pDB = await aiosqlite.connect(str(g_sDBFilePath))
cls.m_pDB = await aiosqlite.connect(g_sDBFilePath)
cls.m_pDB.row_factory = aiosqlite.Row
return True
except Exception as e:

BIN
resource/soil/浇水.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
resource/soil/浇水2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
resource/soil/黑土.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB