SQLite3 - 数据库的位置

问题描述 投票:0回答:1

我已经在我的discord bot中实现了SQLite3,一切似乎都正常,我可以将行提交到我的数据库,进行选择并检索它们,但是在我的项目的本地目录中我看不到数据库本身。

我尝试寻找命令将位置记录到我的日志文件中,但似乎也不起作用。

我错过了什么吗?

更新:

这是我目前的职责:

def add_replay_to_db(filename: str, gamejson: str, playerjson: str, resultjson: str, replaysource: str, messageauthor: str, md5: str):
    try:
        db_path = '/database/yesman.db'

        # Ensure the directory exists
        if not os.path.exists(os.path.dirname(db_path)):
            fullpath = os.path.dirname(db_path)
            os.makedirs(fullpath)
            logger.info(f'Database created: {fullpath}')


        logger.info(f'Adding {filename} to the SQL database')

        connection = sqlite3.connect(db_path)
        cursor = connection.cursor()

        cursor.execute('''CREATE TABLE IF NOT EXISTS replay_raw_data (
                            id INTEGER PRIMARY KEY,
                            filename TEXT,
                            game_json TEXT,
                            player_json TEXT,
                            result_json TEXT,
                            replay_source TEXT,
                            user TEXT,
                            md5 TEXT
                          )''')

        # INSERT INTO
        cursor.execute('INSERT INTO replay_raw_data (filename, game_json, player_json, result_json, replay_source, user, md5) VALUES (?, ?, ?, ?, ?, ?, ?)',
                       (str(filename), str(gamejson), str(playerjson), str(resultjson), str(replaysource), str(messageauthor), str(md5)))

        connection.commit()

        # Fetch and print data
        cursor.execute('SELECT * FROM replay_raw_data')
        rows = cursor.fetchall()
        for row in rows:
            print(row)

    except sqlite3.Error as er:
            logger.error(f'{er}')

    finally:
        if connection:
            connection.close()
python sqlite sqlite3-python
1个回答
0
投票

更新2:

我安装了“Everything”来搜索文件,结果是设置

db_path = '/database/yesman.db'

将该文件安装到我的根 C:\database 目录。我把它改成了

db_path = './database/yesman.db'

它会在正确的项目位置重新创建数据库。

© www.soinside.com 2019 - 2024. All rights reserved.