我正在使用Python 2.7和SQLite。我正在建立一个有数百万行的数据库。我只想偶尔写入磁盘,这样可以提高性能。我的想法是只不时地调用commit()。我用下面的代码试过了。中间的选择表明我们得到了一致的读取。但是,当我在光盘上看到一个文件example.db-journal。必须在此处缓存数据。在这种情况下,我的表现将一无所获。有没有办法把插入的内容收集到内存中,然后刷新到光盘上?有更好的办法吗?
这是我的示例代码:import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
c.execute('CREATE TABLE if not exists stocks (date text, trans text, symbol text, qty real, price real)')
c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
t = ('RHAT',)
c.execute('SELECT date, symbol, trans FROM stocks WHERE symbol=?', t)
# Here, we get 2 rows as expected.
print c.fetchall()
c.execute("INSERT I