任何方式*不*在Postgresql中使用服务器端预处理语句?
发布时间:2020-12-13 15:59:33 所属栏目:百科 来源:网络整理
导读:在(比方说) Python中,我可以发出: psycopg2.connect(...).cursor().execute("select * from account where id='00100000006ONCrAAO'") 在服务器上导致以下日志条目: 2011-07-18 18:56:08 PDT LOG: duration: 6.112 ms statement: select * from account wh
在(比方说)
Python中,我可以发出:
psycopg2.connect(...).cursor().execute("select * from account where id='00100000006ONCrAAO'") 在服务器上导致以下日志条目: 2011-07-18 18:56:08 PDT LOG: duration: 6.112 ms statement: select * from account where id='00100000006ONCrAAO' 但是,在Java中,发布: conn.createStatement().executeQuery("select * from account where id = '00100000006ONCrAAO'"); 结果是: 2011-07-18 18:44:59 PDT LOG: duration: 4.353 ms parse <unnamed>: select * from account where id = '00100000006ONCrAAO' 2011-07-18 18:44:59 PDT LOG: duration: 0.230 ms bind <unnamed>: select * from account where id = '00100000006ONCrAAO' 2011-07-18 18:44:59 PDT LOG: duration: 0.246 ms execute <unnamed>: select * from account where id = '00100000006ONCrAAO' 一些搜索显示PG JDBC驱动程序始终使用预准备语句:http://postgresql.1045698.n5.nabble.com/JDBC-prepared-statements-amp-server-side-prepared-statements-td1919506.html 有没有办法绕过服务器准备好的语句?如果它有所作为,我问的是PG 8.4和9.0. 解决方法
JDBC驱动程序文档包含
gory details何时以及如何使用服务器端预处理语句.
无论如何,您显示的日志输出并不表示存在问题,因为任何查询都将被解析,绑定和执行. JDBC驱动程序只选择执行这些步骤作为单独的协议步骤,而不是像Python驱动程序那样执行一个步骤. (我想你可以争论网络开销.)大多数人关于预备语句的问题是在计划之后参数被替换,但这不是这里发生的事情,因为< unnamed>准备好的语句是在绑定步骤之后计划的(与命名的预准备语句不同,后者是在解析步骤之后计划的).您可以在protocol documentation中了解这些详细信息. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |