1. <small id='5BQ23'></small><noframes id='5BQ23'>

    <legend id='5BQ23'><style id='5BQ23'><dir id='5BQ23'><q id='5BQ23'></q></dir></style></legend><tfoot id='5BQ23'></tfoot>

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

      Sqlite 插入查询不适用于python?

      时间:2023-10-10

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

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

              • <bdo id='jQGQ6'></bdo><ul id='jQGQ6'></ul>
                <legend id='jQGQ6'><style id='jQGQ6'><dir id='jQGQ6'><q id='jQGQ6'></q></dir></style></legend>
                本文介绍了Sqlite 插入查询不适用于python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我一直在尝试使用 python 中的以下代码将数据插入数据库:

                I have been trying to insert data into the database using the following code in python:

                import sqlite3 as db
                conn = db.connect('insertlinks.db')
                cursor = conn.cursor()
                db.autocommit(True)
                a="asd"
                b="adasd"
                cursor.execute("Insert into links (link,id) values (?,?)",(a,b))
                conn.close()
                

                代码运行没有任何错误.但是不会对数据库进行更新.我尝试添加 conn.commit() 但它给出了一个错误,说找不到模块.请帮忙?

                The code runs without any errors. But no updation to the database takes place. I tried adding the conn.commit() but it gives an error saying module not found. Please help?

                推荐答案

                插入后必须提交:

                cursor.execute("Insert into links (link,id) values (?,?)",(a,b))
                conn.commit()
                

                或使用 连接作为上下文管理器:

                with conn:
                    cursor.execute("Insert into links (link,id) values (?,?)", (a, b))
                

                或通过将 isolation_level 关键字参数设置为 connect() 方法为 None 来正确设置自动提交:

                or set autocommit correctly by setting the isolation_level keyword parameter to the connect() method to None:

                conn = db.connect('insertlinks.db', isolation_level=None)
                

                请参阅控制事务.

                这篇关于Sqlite 插入查询不适用于python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:数据库先创建实体框架6.1.1模型使用system.data.sqlite 1.0.93 下一篇:如何获得 Sqlite 中的前 5 条记录?

                相关文章

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

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

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

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