I am trying to pass the name of the table and information to be inserted into the table as parameters. The query I have come up with is below:

我试图将表的名称和信息作为参数传递到表中。我提出的查询如下:

sql = """INSERT INTO `%s` (title,link,description) VALUES(%%s,%%s,%%s)""" % (feed,title_xml,link_xml,description_xml)
cursor.execute(sql)

However, I am getting the following error:

但是,我收到以下错误:

Traceback (most recent call last):
  File "slicer_1.py", line 41, in <module>
    sql = """INSERT INTO `%s` (title,link,description) VALUES(%%s,%%s,%%s)""" %(feed,title_xml,link_xml,description_xml)
TypeError: not all arguments converted during string formatting

What could be wrong here?

这可能有什么问题?

1 个解决方案

#1


1

You have double %% on the last three %s. This means that only the first %s will be substituted in the string substitution, which means you can only pass one value to be substituted. Perhaps you meant to pass the other three to the execute call to be handled by the SQL library's safe substitution? Either that or you need to make all four have just one % so they all get substituted in the first step. (I'm not sure if things like MySQLdb let you parameterize VALUES data.)

你在最后三个%s上有两倍的%%。这意味着只有第一个%s将在字符串替换中被替换,这意味着您只能传递一个要替换的值。也许你打算将其他三个传递给执行调用,由SQL库的安全替换处理?无论是那个还是你需要使所有四个只有一个百分点,所以他们都在第一步中被替换。 (我不确定像MySQLdb这样的东西是否允许你参数化VALUES数据。)

Edit: If you take the second suggestion, you probably want to do it like this:

编辑:如果你采取第二个建议,你可能想这样做:

"""INSERT INTO `%s` (title,link,description) VALUES("%s","%s","%s")""" % (feed,title_xml,link_xml,description_xml)

更多相关文章

  1. SQL 函数如何设置参数默认值
  2. sql语句,order by后加参数问题
  3. 检索SQL语句的输出参数
  4. android-exploitme(四):参数篡改
  5. 如何在函数中将两个参数从1个类传递给另一个?
  6. Android的startActivityForResult()与onActivityResult()与setRe
  7. Android开发入门之为应用添加多个Activity与参数传递
  8. java socket参数详解:TcpNoDelay
  9. 在spring 中如何注入map,set,list,property等参数

随机推荐

  1. Android中的CheckBox
  2. 【Android】 ListView之setEmptyView的问
  3. react native之修改APP的名称和图标
  4. 关于声明文件中android:process属性说明
  5. android 文件系统(
  6. Android学习笔记:框架模式
  7. android - 5大UI设计技巧
  8. Android 八款开源 Android 游戏引擎
  9. 在Android中查看和管理sqlite数据库
  10. ImageView通过matrix实现手势缩放