• <legend id='ZOlTA'><style id='ZOlTA'><dir id='ZOlTA'><q id='ZOlTA'></q></dir></style></legend>

        <bdo id='ZOlTA'></bdo><ul id='ZOlTA'></ul>
    1. <small id='ZOlTA'></small><noframes id='ZOlTA'>

        <tfoot id='ZOlTA'></tfoot>

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

        Python:如何将字典插入到 sqlite 数据库中?

        时间:2023-10-10

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

            <legend id='M0pIE'><style id='M0pIE'><dir id='M0pIE'><q id='M0pIE'></q></dir></style></legend>

                • <bdo id='M0pIE'></bdo><ul id='M0pIE'></ul>

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

                • 本文介绍了Python:如何将字典插入到 sqlite 数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个带有以下列表的 sqlite 数据库:

                  I have a sqlite database with a table with following columns :

                  id(int) , name(text) , dob(text)
                  

                  我想插入以下字典:

                  {"id":"100","name":"xyz","dob":"12/12/12"}
                  

                  字典键是列名.我怎样才能实现它?

                  Dictionary keys are the column names. How can i achieve it ?

                  推荐答案

                  这是一种保持参数安全的方法.(可能需要在表名部门打磨)

                  Here's a way which preserves parameter safety. (Might need polishing in the tablename department)

                  def post_row(conn, tablename, rec):
                      keys = ','.join(rec.keys())
                      question_marks = ','.join(list('?'*len(rec)))
                      values = tuple(rec.values())
                      conn.execute('INSERT INTO '+tablename+' ('+keys+') VALUES ('+question_marks+')', values)
                  
                  row = {"id":"100","name":"xyz","dob":"12/12/12"}
                  post_row(my_db, 'my_table', row)
                  

                  这篇关于Python:如何将字典插入到 sqlite 数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:VistaDB有什么优势 下一篇:如何从sqlite3中获取所选结果的行数?

                  相关文章

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

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

                      <legend id='Ko2MK'><style id='Ko2MK'><dir id='Ko2MK'><q id='Ko2MK'></q></dir></style></legend>

                    1. <tfoot id='Ko2MK'></tfoot>
                        <bdo id='Ko2MK'></bdo><ul id='Ko2MK'></ul>