<legend id='jitqv'><style id='jitqv'><dir id='jitqv'><q id='jitqv'></q></dir></style></legend>
    • <bdo id='jitqv'></bdo><ul id='jitqv'></ul>

        <i id='jitqv'><tr id='jitqv'><dt id='jitqv'><q id='jitqv'><span id='jitqv'><b id='jitqv'><form id='jitqv'><ins id='jitqv'></ins><ul id='jitqv'></ul><sub id='jitqv'></sub></form><legend id='jitqv'></legend><bdo id='jitqv'><pre id='jitqv'><center id='jitqv'></center></pre></bdo></b><th id='jitqv'></th></span></q></dt></tr></i><div id='jitqv'><tfoot id='jitqv'></tfoot><dl id='jitqv'><fieldset id='jitqv'></fieldset></dl></div>

        <small id='jitqv'></small><noframes id='jitqv'>

      1. <tfoot id='jitqv'></tfoot>

      2. 如何在 Python sqlite3 中将现有的 db 文件加载到内存中?

        时间:2023-09-18
          <bdo id='KqguG'></bdo><ul id='KqguG'></ul>

            <small id='KqguG'></small><noframes id='KqguG'>

          • <legend id='KqguG'><style id='KqguG'><dir id='KqguG'><q id='KqguG'></q></dir></style></legend>
          • <i id='KqguG'><tr id='KqguG'><dt id='KqguG'><q id='KqguG'><span id='KqguG'><b id='KqguG'><form id='KqguG'><ins id='KqguG'></ins><ul id='KqguG'></ul><sub id='KqguG'></sub></form><legend id='KqguG'></legend><bdo id='KqguG'><pre id='KqguG'><center id='KqguG'></center></pre></bdo></b><th id='KqguG'></th></span></q></dt></tr></i><div id='KqguG'><tfoot id='KqguG'></tfoot><dl id='KqguG'><fieldset id='KqguG'></fieldset></dl></div>

              <tbody id='KqguG'></tbody>

                <tfoot id='KqguG'></tfoot>

                  本文介绍了如何在 Python sqlite3 中将现有的 db 文件加载到内存中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个现有的 sqlite3 db 文件,我需要对其进行一些广泛的计算.从文件中进行计算非常缓慢,而且由于文件不大(~10 MB),因此将其加载到内存中应该没有问题.

                  I have an existing sqlite3 db file, on which I need to make some extensive calculations. Doing the calculations from the file is painfully slow, and as the file is not large (~10 MB), so there should be no problem to load it into memory.

                  是否有一种 Pythonic 的方法可以将现有文件加载到内存中以加快计算速度?

                  Is there a Pythonic way to load the existing file into memory in order to speed up the calculations?

                  推荐答案

                  这是我为我的 Flask 应用程序编写的代码片段:

                  Here is the snippet that I wrote for my flask application:

                  import sqlite3
                  from io import StringIO
                  
                  def init_sqlite_db(app):
                      # Read database to tempfile
                      con = sqlite3.connect(app.config['SQLITE_DATABASE'])
                      tempfile = StringIO()
                      for line in con.iterdump():
                          tempfile.write('%s
                  ' % line)
                      con.close()
                      tempfile.seek(0)
                  
                      # Create a database in memory and import from tempfile
                      app.sqlite = sqlite3.connect(":memory:")
                      app.sqlite.cursor().executescript(tempfile.read())
                      app.sqlite.commit()
                      app.sqlite.row_factory = sqlite3.Row
                  

                  这篇关于如何在 Python sqlite3 中将现有的 db 文件加载到内存中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 SQL Server 上使用 varchar(MAX) 与 TEXT 下一篇:如何使用 Python 批量插入 Oracle 数据库?

                  相关文章

                  <small id='KJU7o'></small><noframes id='KJU7o'>

                    <bdo id='KJU7o'></bdo><ul id='KJU7o'></ul>

                  <i id='KJU7o'><tr id='KJU7o'><dt id='KJU7o'><q id='KJU7o'><span id='KJU7o'><b id='KJU7o'><form id='KJU7o'><ins id='KJU7o'></ins><ul id='KJU7o'></ul><sub id='KJU7o'></sub></form><legend id='KJU7o'></legend><bdo id='KJU7o'><pre id='KJU7o'><center id='KJU7o'></center></pre></bdo></b><th id='KJU7o'></th></span></q></dt></tr></i><div id='KJU7o'><tfoot id='KJU7o'></tfoot><dl id='KJU7o'><fieldset id='KJU7o'></fieldset></dl></div>

                1. <tfoot id='KJU7o'></tfoot><legend id='KJU7o'><style id='KJU7o'><dir id='KJU7o'><q id='KJU7o'></q></dir></style></legend>