使用 python fdb 模块从 firebird 数据库中提取数据

Extract data from a firebird database with python fdb module

我正在尝试使用 Python 中的 FDB 模块从 Firebird 2.5 版创建的 Firebird 数据库中读取数据。不成功。 我在 Windows10 64 位系统上有一个 Python v3.7.3。

我能够连接到数据库并读取其 table 的名称:

con_1 = fdb.connect(dsn='C:/Prova_Archi.eft', user='sysdba', password='masterkey')  
schema_1 = fdb.schema.Schema()  
schema_1.bind(con2)  
print (schema_1.tables[57].name)  ===>  TUtenti

对于给定的 table,我还能够读取其列名和索引:

print ([i.name for i in con_1.schema.get_table(schema_1.tables[57].name).columns][0]) ===> ...  
print ([i.name for i in con_1.schema.get_table(schema_1.tables[n].name).indices][r]) ===> ...  

但是,我无法提取数据!

当我尝试这个时:

cur_1 = con_1.cursor()  
cur_1.execute("select * from 'TUtenti'")  

我收到以下错误:

===> DatabaseError: ("Error while preparing SQL statement:\n- SQLCODE: -104\n- Dynamic SQL Error\n- SQL error code = -104\n- Token unknown - line 1, column 15\n- 'TUtenti'", -104, 335544569)

非常欢迎提出建议。

问题是单引号分隔了字符串文字,而不是对象名称(例如 table 名称)。要引用对象名称,您需要使用双引号,因此请使用:

cur_1.execute('select * from "TUtenti"')