Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python2.7-SQLite3库输出错误消息;sqlite3.0错误:接近“0”&引用;:语法错误“;_Python_Sqlite - Fatal编程技术网

Python2.7-SQLite3库输出错误消息;sqlite3.0错误:接近“0”&引用;:语法错误“;

Python2.7-SQLite3库输出错误消息;sqlite3.0错误:接近“0”&引用;:语法错误“;,python,sqlite,Python,Sqlite,代码如下。如何用变量值替换?,[表,url] 预期的SQL命令是select*from OTHER_URL,其中URL=”http://a.com/a.jpg“ 此SQL命令在sqlite3命令行界面上不会发生错误 import sqlite3 from contextlib import closing dbname = "ng.db" with closing(sqlite3.connect(dbname)) as conn: c = conn.cursor() c.ex

代码如下。如何用变量值替换
[表,url]

预期的SQL命令是
select*from OTHER_URL,其中URL=”http://a.com/a.jpg“

此SQL命令在sqlite3命令行界面上不会发生错误

import sqlite3
from contextlib import closing

dbname = "ng.db"

with closing(sqlite3.connect(dbname)) as conn:
    c = conn.cursor()
    c.execute("CREATE TABLE IF NOT EXISTS OTHER_URL (url TEXT)")
    conn.commit()

table = "OTHER_URL"
url = "http://a.com/a.jpg"

with closing(sqlite3.connect(dbname)) as conn:
    c = conn.cursor()
    c.execute('select * from ? where url="?"', [table, url])
    print c.fetchone()

这里有两个错误。首先,不能对表名(或列名)使用参数替换,只能对值使用参数替换。您需要对任何其他内容使用字符串插值

其次,不需要在value参数周围加引号;换人会处理好的

因此:


这里有两个错误。首先,不能对表名(或列名)使用参数替换,只能对值使用参数替换。您需要对任何其他内容使用字符串插值

其次,不需要在value参数周围加引号;换人会处理好的

因此:

c.execute('select * from {} where url=?'.format(table), [url])