【问题标题】:Inserting data into SQLite database fails with sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type将数据插入 SQLite 数据库失败并出现 sqlite3.InterfaceError: Error binding parameter 0 - 可能是不受支持的类型
【发布时间】:2021-05-14 20:23:41
【问题描述】:

我已经浏览了很多在这个网站上提出的问题,除非我很密集(谁知道),我不认为他们完全复制了我的问题。

首先让我从一些代码 sn-ps 开始

表格

         CREATE TABLE IF NOT EXISTS moves(
               ID INTEGER PRIMARY KEY AUTOINCREMENT,
               name char(20),
               type char(10),
               category char(10),
               desc char(200),
               share char(3),
               priority char(5),
               damage_dice char(5),
               cool_down char(8),
               accuracy char(100),
               effect char(200),
               move_target char(50),
               makes_contact char(3),
               contest_cat char(10)
         )''')

插入函数

def insert_moves(move):
    c = dbConn.cursor()
    statement = '''insert into moves values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)'''
    try:
        c.execute(statement,(move[0], str(move[1]), str(move[2]), str(move[3]), str(move[4]),
         str(move[5]), str(move[6]), str(move[7]), str(move[8]), str(move[9]), str(move[10]),
         str(move[11]), str(move[12]), str(move[13]),))
        dbConn.commit()
        return True, ''
    except Exception as e:
        return False, e

现在,让我向您展示堆栈跟踪,作为其中的一部分,您将看到 move 在传递到 datebase 函数之前的打印输出。

现在,这是输出

[1, 'Attack Order', 'Bug', 'Physical', 'The user calls out its underlings to pummel the target.', 'Yes', '-', '1d6', '1 Turn', '100', 'Attack Order deals damage and has an increased critical hit ratio of 50 percent', 'Targets a single adjacent Pokemon.', 'No', 'Clever']
Ignoring exception in command update_moves:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/projects/pokebot/gsheet.py", line 59, in update_moves
    result, error2 = db.insert_moves(moves)
  File "/projects/pokebot/db.py", line 103, in insert_moves
    c.execute(statement,(move[0], str(move[1]), str(move[2]), str(move[3]), str(move[4]), str(move[5]), str(move[6]), str(move[7]), str(move[8]), str(move[9]), str(move[10]), str(move[11]), str(move[12]), str(move[13]),))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: InterfaceError: Error binding parameter 0 - probably unsupported type.

我尝试了一些方法,例如删除随机百分号以防万一,或者将 Pokémon 更改为 Pokemon。但我不明白问题是什么。其他很多都是关于人们发送诸如列表或对象之类的东西来插入而不是一些字符串/整数对象,我不认为这是这里的问题。有什么突出的吗?

【问题讨论】:

  • 什么是move?它是在哪里定义的?
  • move 是一个列表,其内容在堆栈跟踪之前打印出来。
  • 你的代码适合我。
  • 可以简化为:c.execute(statement,move)
  • @forpas 是的,我试图把它弄好……但现在我发现了我的问题,那肯定是干净多了。我一直忘记这一点,但它是一种优雅的处理方式。谢谢。

标签: sqlite python-3.6


【解决方案1】:

所以……这绝对是我的错。如果我发布了调用插入的函数,我会看到它。我想这只是一个星期五的下午,我的大脑很累。

    print(move)
    result, error2 = db.insert_moves(move)

这是写成

    print(move)
    result, error2 = db.insert_moves(moves)

在哪里迭代移动,以便我可以做一些工作。老实说,这完全是我的错。哦,好吧,我认为教训是......关于插入功能,如果您收到此错误,请检查传递的值的类型。老实说,我现在应该已经完成​​了..但我会把它写到星期五下午。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-07
    • 2021-05-30
    • 2013-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多