<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 文件加载到内存中?

        How to load existing db file to memory in Python sqlite3?(如何在 Python sqlite3 中将现有的 db 文件加载到内存中?)
          <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 group by versus distinct(sql group by 与不同)
                  What is best performance for Retrieving MySQL EAV results as Relational Table(将 MySQL EAV 结果作为关系表检索的最佳性能是什么)
                  How to connect MySQL database using Python+SQLAlchemy remotely?(如何使用Python+SQLAlchemy远程连接MySQL数据库?)
                  Group by month in SQLite(在 SQLite 中按月分组)
                  When to consider Solr(何时考虑 Solr)
                  Are there any Sql Server Full-Text Search (FTS) performance improvements since version 2008 R2?(自 2008 R2 版本以来,是否有任何 Sql Server 全文搜索 (FTS) 性能改进?)

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

                    <tbody id='KJU7o'></tbody>
                    <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>

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