我有一个网络服务器,我将用户数据添加到我的SQL查询中。它适用于psycopg但不适用于cx_Oracle。
...
class grid:
def GET(self):
web.header('Access-Control-Allow-Origin', '*')
web.header('Access-Control-Allow-Credentials', 'true')
web.header('Content-Type', 'application/json')
data = web.input(ID='')
ido = int(data.ID)
a = [ido]
cur = connection.cursor()
cur.arraysize = 10000
query = "SELECT a.id AS building_nr, c.geometry.sdo_ordinates AS geometry, d.Classname AS polygon_typ FROM building a, THEMATIC_SURFACE b, SURFACE_GEOMETRY c, OBJECTCLASS d WHERE a.id = b.BUILDING_ID AND b.LOD2_MULTI_SURFACE_ID = c.ROOT_ID AND c.GEOMETRY IS NOT NULL AND b.OBJECTCLASS_ID = d.ID AND a.grid_id_500 = %s;"
cur.execute(query, a)
直到execute语句才有效。我收到错误消息: 'ascii'编解码器无法解码位置36的字节0xfc:序数不在范围内(128)
如何将数据添加到我的查询中?
答案 0 :(得分:1)
我知道出了什么问题。我不应该使用%s作为数据。显然,cx_Oracle默认为“命名”paramstyle。
data = web.input(ID='')
query = "SELECT ... FROM... WHERE a.id =:grid_id "
cursor.execute(query, {'grid_id':data.ID})