Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
dac80f77
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
dac80f77
编写于
4月 24, 2010
作者:
J
Jeremy Kemper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PostgreSQL: use standard-conforming strings if possible
上级
72a3e4b7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
30 deletion
+14
-30
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+14
-30
未找到文件。
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
dac80f77
...
...
@@ -263,20 +263,12 @@ def supports_primary_key? #:nodoc:
true
end
# Does PostgreSQL support standard conforming strings?
def
supports_standard_conforming_strings?
# Temporarily set the client message level above error to prevent unintentional
# error messages in the logs when working on a PostgreSQL database server that
# does not support standard conforming strings.
client_min_messages_old
=
client_min_messages
self
.
client_min_messages
=
'panic'
# postgres-pr does not raise an exception when client_min_messages is set higher
# than error and "SHOW standard_conforming_strings" fails, but returns an empty
# PGresult instead.
has_support
=
query
(
'SHOW standard_conforming_strings'
)[
0
][
0
]
rescue
false
self
.
client_min_messages
=
client_min_messages_old
has_support
# Enable standard-conforming strings if available.
def
set_standard_conforming_strings
old
,
self
.
client_min_messages
=
client_min_messages
,
'panic'
execute
(
'SET standard_conforming_strings = on'
)
rescue
nil
ensure
self
.
client_min_messages
=
old
end
def
supports_insert_with_returning?
...
...
@@ -376,9 +368,9 @@ def unescape_bytea(original_value)
# Quotes PostgreSQL-specific data types for SQL input.
def
quote
(
value
,
column
=
nil
)
#:nodoc:
if
value
.
kind_of?
(
String
)
&&
column
&&
column
.
type
==
:binary
"
#{
quoted_string_prefix
}
'
#{
escape_bytea
(
value
)
}
'"
"'
#{
escape_bytea
(
value
)
}
'"
elsif
value
.
kind_of?
(
String
)
&&
column
&&
column
.
sql_type
==
'xml'
"xml
E
'
#{
quote_string
(
value
)
}
'"
"xml '
#{
quote_string
(
value
)
}
'"
elsif
value
.
kind_of?
(
Numeric
)
&&
column
&&
column
.
sql_type
==
'money'
# Not truly string input, so doesn't require (or allow) escape string syntax.
"'
#{
value
.
to_s
}
'"
...
...
@@ -991,22 +983,11 @@ def connect
# Ignore async_exec and async_query when using postgres-pr.
@async
=
@config
[
:allow_concurrency
]
&&
@connection
.
respond_to?
(
:async_exec
)
# Use escape string syntax if available. We cannot do this lazily when encountering
# the first string, because that could then break any transactions in progress.
# See: http://www.postgresql.org/docs/current/static/runtime-config-compatible.html
# If PostgreSQL doesn't know the standard_conforming_strings parameter then it doesn't
# support escape string syntax. Don't override the inherited quoted_string_prefix.
if
supports_standard_conforming_strings?
self
.
class
.
instance_eval
do
define_method
(
:quoted_string_prefix
)
{
'E'
}
end
end
# Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
# PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision
# should know about this but can't detect it there, so deal with it here.
PostgreSQLColumn
.
money_precision
=
(
postgresql_version
>=
80300
)
?
19
:
10
PostgreSQLColumn
.
money_precision
=
(
postgresql_version
>=
80300
)
?
19
:
10
configure_connection
end
...
...
@@ -1022,7 +1003,10 @@ def configure_connection
end
self
.
client_min_messages
=
@config
[
:min_messages
]
if
@config
[
:min_messages
]
self
.
schema_search_path
=
@config
[
:schema_search_path
]
||
@config
[
:schema_order
]
# Use standard-conforming strings if available so we don't have to do the E'...' dance.
set_standard_conforming_strings
# If using ActiveRecord's time zone support configure the connection to return
# TIMESTAMP WITH ZONE types in UTC.
execute
(
"SET time zone 'UTC'"
)
if
ActiveRecord
::
Base
.
default_timezone
==
:utc
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录