sqlite3在使用checkpoint时未知的数据库模式问题

2024-05-23 14:57:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到:

sqlite3.OperationalError: unknown database schema

conn = sqlite3.connect('tick.db', detect_types=sqlite3.PARSE_DECLTYPES, timeout=20,isolation_level=None)
# conn1 = sqlite3.connect('nifty_tick.db', detect_types=sqlite3.PARSE_DECLTYPES, timeout=20,isolation_level=None)

c = conn.cursor()
# c1 = conn1.cursor()

c.execute('PRAGMA journal_mode=wal')

def tick_entry1(inst,timestamp,ltp, bid, ask):
    if inst == 12335874:
        c.execute('INSERT INTO niftyfut (timestamp, close, bid, ask) VALUES (?,?,?,?)',
                  (timestamp, ltp, bid, ask))

def on_ticks(ws, ticks):
    global c, conn
    for t in ticks:
        if t['instrument_token'] == 12335874:
            timestamp = t['timestamp']
            ltp = t['last_price']
            inst = t['instrument_token']

            try:
                tick_entry1(inst,timestamp,ltp)
            except:
                # print('problem with db')
                pass
    c.execute('PRAGMA schema.wal_checkpoint(FULL);')

我试过:

c.execute('PRAGMA schema.wal_checkpoint(FULL);')

以及

c.execute('PRAGMA schema.wal_checkpoint(FULL)')

短暂性脑缺血发作

----编辑----

我刚试过:

c.execute('PRAGMA wal_checkpoint(FULL)')

好像有用。现在想知道是否应该在开始时执行以下操作:

c.execute("PRAGMA wal_autocheckpoint = 0")


Tags: executedbschemaconnsqlite3timestampfullask
1条回答
网友
1楼 · 发布于 2024-05-23 14:57:37

消息说没有数据库具有名为schema的模式。你知道吗

在文档中,模式是斜体的,这表示它是符号而不是实际值,并将替换为适当的值,该值用于区分附加的数据库。你知道吗

例如,如果您使用

ATTACH DATABASE the_database_path AS database2 /*<<<<<<<<<< THE SCHEMA is database2 */; 

那你可以用

PRAGMA database2.wal_checkpoint(FULL); 

检查附加的数据库。你知道吗

初始数据库的模式是main,但不是必需的,因为如果没有提供模式,它是默认的。你知道吗

因此c.execute('PRAGMA wal_checkpoint(FULL)')起作用的原因(正如c.execute('PRAGMA main.wal_checkpoint(FULL)'))。i、 e.有效的方法是相同的。你知道吗

如果使用c.execute("PRAGMA wal_autocheckpoint = 0"),则必须管理所有检查点,因为自动检查点将被关闭(请注意,关闭所有数据库连接检查点)。你知道吗

您不妨考虑:

Disabling the automatic checkpoint mechanism. In its default configuration, SQLite will checkpoint the WAL file at the conclusion of any transaction when the WAL file is more than 1000 pages long. However, compile-time and run-time options exist that can disable or defer this automatic checkpoint. If an application disables the automatic checkpoint, then there is nothing to prevent the WAL file from growing excessively. Write-Ahead Logging - 6. Avoiding Excessively Large WAL Files

我建议不要使用PRAGMA wal_autocheckpoint = 0autocheckpointing并不妨碍强制检查点,除非强制检查点发生在自动检查点之后(并且所有页面都被写入),并且没有任何更新,那么它将什么也不做(优雅地),否则会有更多的页面被写入数据库文件。你知道吗

相关问题 更多 >