<tfoot id='aWdWF'></tfoot>
    <legend id='aWdWF'><style id='aWdWF'><dir id='aWdWF'><q id='aWdWF'></q></dir></style></legend>

    1. <small id='aWdWF'></small><noframes id='aWdWF'>

      <i id='aWdWF'><tr id='aWdWF'><dt id='aWdWF'><q id='aWdWF'><span id='aWdWF'><b id='aWdWF'><form id='aWdWF'><ins id='aWdWF'></ins><ul id='aWdWF'></ul><sub id='aWdWF'></sub></form><legend id='aWdWF'></legend><bdo id='aWdWF'><pre id='aWdWF'><center id='aWdWF'></center></pre></bdo></b><th id='aWdWF'></th></span></q></dt></tr></i><div id='aWdWF'><tfoot id='aWdWF'></tfoot><dl id='aWdWF'><fieldset id='aWdWF'></fieldset></dl></div>
      • <bdo id='aWdWF'></bdo><ul id='aWdWF'></ul>
      1. 在sqlite中插入int时不支持参数

        parameter unsupported when inserting int in sqlite(在sqlite中插入int时不支持参数)
          <tbody id='a2Obn'></tbody>
        • <small id='a2Obn'></small><noframes id='a2Obn'>

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

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

                  <bdo id='a2Obn'></bdo><ul id='a2Obn'></ul>
                  本文介绍了在sqlite中插入int时不支持参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在反复在 SQLite3 中存储日期和时间,目的是稍后使用比较检索记录,例如SELECT * WHERE date1 <日期2

                  I have been going around and around with storing date and time in SQLite3 with the intention of retrieving the records using comparisons later e.g. SELECT * WHERE date1 < date2

                  我终于放弃了存储 datetime.datetime 对象的尝试,并决定使用 UNIX 时间戳,因为它们只是一个 int 且易于操作,但我仍然遇到错误.

                  I finally gave up trying to store datetime.datetime objects and decided to use a UNIX timestamp instead as they are just an int and easy to manipulate but I am still getting errors.

                  import sqlite3 as lite
                  import datetime
                  import time
                  
                  conn = lite.connect('dispatcher.db')
                  cur = conn.cursor()
                  query = "create table if not exists new_test (curent_dt)"
                  cur.execute(query)
                  conn.commit()
                  now = datetime.datetime.now() - datetime.timedelta(minutes=60)
                  temp = int(time.mktime(now.timetuple()))
                  cur.execute('insert into new_test (curent_dt) values (? )', (temp))
                  conn.commit()
                  conn.close()
                  

                  返回以下错误:

                  cur.execute('insert into new_test (curent_dt) values (? )', (temp))ValueError: 参数的类型不受支持

                  cur.execute('insert into new_test (curent_dt) values (? )', (temp)) ValueError: parameters are of unsupported type

                  在进一步调查问题后,我发现您必须使用尾随逗号来创建单个元素元组,例如(temp,)

                  After investigating the problem a little further I found that you have to use a trailing comma to create a single element tuple e.g. (temp,)

                  推荐答案

                  注意下面temp"后添加的逗号:

                  Note the added comma after "temp" below:

                  cur.execute('insert into new_test (curent_dt) values (?)', (temp,))
                  

                  发生这种情况的原因是 (temp) 是一个整数,而 (temp,) 是一个包含 temp 的长度为 1 的元组.

                  The reason this happens is that (temp) is an integer but (temp,) is a tuple of length one containing temp.

                  这篇关于在sqlite中插入int时不支持参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  SQLite loop statements?(SQLite 循环语句?)
                  Can I use parameters for the table name in sqlite3?(我可以在 sqlite3 中使用表名的参数吗?)
                  SQL - Inserting a row and returning primary key(SQL - 插入一行并返回主键)
                  How to get the number of rows of the selected result from sqlite3?(如何从sqlite3中获取所选结果的行数?)
                  Python : How to insert a dictionary to a sqlite database?(Python:如何将字典插入到 sqlite 数据库中?)
                  What are the advantages of VistaDB(VistaDB有什么优势)

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

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

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

                      • <tfoot id='Iia8y'></tfoot>