Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.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
Python sqlite3搜索数据库_Python_Sql_Sqlite - Fatal编程技术网

Python sqlite3搜索数据库

Python sqlite3搜索数据库,python,sql,sqlite,Python,Sql,Sqlite,我的数据库最初是一个sql文件,转换为sqlite文件data.sqlite。 数据库,是一本有章节和诗句编号的书。桌子是空的 `#INSERT INTO `booktext` (`index`, `chapter`, `verse`, `text`) VALUES` def read_from_db(): table='booktext' chapter =100 sql = '''SELECT * FROM {0} WHERE chapter= {1}'''.form

我的数据库最初是一个sql文件,转换为sqlite文件data.sqlite。 数据库,是一本有章节和诗句编号的书。桌子是空的

`#INSERT INTO `booktext` (`index`, `chapter`, `verse`, `text`) VALUES`
def read_from_db():
    table='booktext'
    chapter =100
    sql = '''SELECT * FROM {0} WHERE chapter= {1}'''.format(table,chapter)
    c.execute(sql)
    data = c.fetchall()
    print (data) #returns emty list
return data 
返回一个空列表。然而,当我不选择章节时,为了获取章节中的所有诗句,而是写:

c.execute("SELECT * FROM 'booktext'")
如预期的那样,所有带有文本的章节和诗句编号都会出现。我不知道我的代码出了什么问题。可能在我将sql文件转换为data.sqlite(数据表)的过程中发生了更改。有没有办法查看当前的数据表

在我的原始sql文件中,使用数据库的指南是

DROP TABLE IF EXISTS `booktext`;
CREATE TABLE `booktext` ('index` int(4) NOT NULL auto_increment,
`chapter` int(3) NOT NULL default '0',
`verse` int(3) NOT NULL default '0',
`text` text NOT NULL,
PRIMARY KEY  (`index`)
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

无法参数化表名。您需要使用字符串连接或插值(两者都有潜在的危险-SQL注入);这样地;c、 执行(“从'booktext'中选择*,其中章节='100')),但仍然存在相同的问题。