提交 a9e8554b 编写于 作者: A Aaron Patterson

use prepared statements for primary key queries

上级 5df072d6
......@@ -796,8 +796,21 @@ def pk_and_sequence_for(table) #:nodoc:
# Returns just a table's primary key
def primary_key(table)
pk_and_sequence = pk_and_sequence_for(table)
pk_and_sequence && pk_and_sequence.first
row = exec_query(<<-end_sql, 'SCHEMA', [[nil, table]]).rows.first
SELECT DISTINCT(attr.attname)
FROM pg_attribute attr,
pg_depend dep,
pg_namespace name,
pg_constraint cons
WHERE attr.attrelid = dep.refobjid
AND attr.attnum = dep.refobjsubid
AND attr.attrelid = cons.conrelid
AND attr.attnum = cons.conkey[1]
AND cons.contype = 'p'
AND dep.refobjid = $1::regclass
end_sql
row && row.first
end
# Renames a table.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册