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

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

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

        Python 和 SQLite:插入表

        时间:2023-10-10

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

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

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

                <tfoot id='c9pR8'></tfoot>

                  本文介绍了Python 和 SQLite:插入表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个包含 3 行的列表,每行代表一个表格行:

                  <预><代码>>>>打印清单[湖,444,M][锦,445,M][锦,445,M]

                  如何将这个列表插入到表格中?

                  我的表结构是:

                  <前>表名(名称 varchar[100],年龄整数,性别字符 [1])

                  或者我应该使用列表以外的其他东西吗?

                  这是实际的代码部分:

                   在 self.server 中记录:打印--->",记录t=记录self.cursor.execute("插入服务器(服务器)值(?)",(t[0],));self.cursor.execute("插入服务器(id)值(?)",(t[1],))self.cursor.execute("插入服务器(状态)值(?)",(t[2],));

                  单独插入三个字段有效,但使用单行

                  self.cursor.execute("insert into server(server,c_id,status) values (?,?,?)",(t[0],),(t[1],),(t[2],))

                  self.cursor.execute("insert into server(server,c_id,status) values (?,?,?)",(t),)

                  没有.

                  解决方案

                  conn = sqlite3.connect('/path/to/your/sqlite_file.db')c = conn.cursor()对于 my_list 中的项目:c.execute('插入表名值(?,?,?)', item)

                  I have a list that has 3 rows each representing a table row:

                  >>> print list
                  [laks,444,M]
                  [kam,445,M]
                  [kam,445,M]
                  

                  How to insert this list into a table?

                  My table structure is:

                  tablename(name varchar[100], age int, sex char[1])
                  

                  Or should I use something other than list?

                  Here is the actual code part:

                      for record in self.server:
                          print "--->",record
                          t=record
                          self.cursor.execute("insert into server(server) values (?)",(t[0],));
                          self.cursor.execute("insert into server(id) values (?)",(t[1],))
                          self.cursor.execute("insert into server(status) values (?)",(t[2],));
                  

                  Inserting the three fields separately works, but using a single line like

                  self.cursor.execute("insert into server(server,c_id,status) values (?,?,?)",(t[0],),(t[1],),(t[2],))

                  or

                  self.cursor.execute("insert into server(server,c_id,status) values (?,?,?)",(t),)

                  does not.

                  解决方案

                  conn = sqlite3.connect('/path/to/your/sqlite_file.db')
                  c = conn.cursor()
                  for item in my_list:
                    c.execute('insert into tablename values (?,?,?)', item)
                  

                  这篇关于Python 和 SQLite:插入表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:sqlite中是否有自动增量? 下一篇:SQLite 中区分大小写和不区分大小写

                  相关文章

                  <tfoot id='qIrgw'></tfoot>

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

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

                      • <bdo id='qIrgw'></bdo><ul id='qIrgw'></ul>
                    1. <legend id='qIrgw'><style id='qIrgw'><dir id='qIrgw'><q id='qIrgw'></q></dir></style></legend>