sql 注入缓解的参数化查询 Postgres

parameterized query Postgres for sql injection mitigation

stmt = "SELECT filecontent FROM filecontent WHERE filecontent_id = %d AND filecontent LIKE '%% %s %%'"%(int(result_file_pri[0]),str(myjson['recordType']))
curs.execute(stmt)

尝试将以上 postgres 查询转换为参数化查询以启动 sql 注入。我在互联网上找到的解决方案是在执行语句中包含 stmt 并从引号中取出 %s 即

curs.execute("SELECT filecontent FROM filecontent WHERE filecontent_id = %s AND filecontent LIKE %% %s %%",(int(result_file_pri[0]),str(myjson['recordType'])))

以上对我 %% %s %% 不起作用,我该如何解决这个问题?

应该是百分号的参数:

curs.execute("SELECT filecontent FROM filecontent WHERE filecontent_id = %s AND filecontent LIKE %s",
             (int(result_file_pri[0]), str("%" + myjson['recordType'] + "%")))
                                            ^----------------------------^
                                                    so the wildcard is the
                                                     part of the parameter