Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9705df5c
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,发现更多精彩内容 >>
提交
9705df5c
编写于
12月 24, 2013
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13469 from schneems/schneems/no-database-errors-all
Raise NoDatabaseError when db does not exist
上级
959cfcef
f0311c24
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
41 addition
and
2 deletion
+41
-2
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+2
-2
activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
...d/lib/active_record/connection_adapters/mysql2_adapter.rb
+6
-0
activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
...rd/lib/active_record/connection_adapters/mysql_adapter.rb
+6
-0
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
.../lib/active_record/connection_adapters/sqlite3_adapter.rb
+6
-0
activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
+14
-0
activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
...ecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
+7
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
9705df5c
...
...
@@ -27,10 +27,10 @@
*Carlos Antonio da Silva*
*
When connecting to a non-existant
postgresql
database, the error:
*
When connecting to a non-existant database, the error:
`ActiveRecord::NoDatabaseError`
will now be raised. When being used with Rails
the error message will include information on how to create a database:
`rake db:create`
`rake db:create`
. Supported adapters: postgresql, mysql, mysql2, sqlite3
*Richard Schneeman*
...
...
activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
浏览文件 @
9705df5c
...
...
@@ -18,6 +18,12 @@ def mysql2_connection(config)
client
=
Mysql2
::
Client
.
new
(
config
)
options
=
[
config
[
:host
],
config
[
:username
],
config
[
:password
],
config
[
:database
],
config
[
:port
],
config
[
:socket
],
0
]
ConnectionAdapters
::
Mysql2Adapter
.
new
(
client
,
logger
,
options
,
config
)
rescue
Mysql2
::
Error
=>
error
if
error
.
message
.
include?
(
"Unknown database"
)
raise
ActiveRecord
::
NoDatabaseError
.
new
(
error
.
message
)
else
raise
error
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
浏览文件 @
9705df5c
...
...
@@ -34,6 +34,12 @@ def mysql_connection(config)
default_flags
|=
Mysql
::
CLIENT_FOUND_ROWS
if
Mysql
.
const_defined?
(
:CLIENT_FOUND_ROWS
)
options
=
[
host
,
username
,
password
,
database
,
port
,
socket
,
default_flags
]
ConnectionAdapters
::
MysqlAdapter
.
new
(
mysql
,
logger
,
options
,
config
)
rescue
Mysql
::
Error
=>
error
if
error
.
message
.
include?
(
"Unknown database"
)
raise
ActiveRecord
::
NoDatabaseError
.
new
(
error
.
message
)
else
raise
error
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
浏览文件 @
9705df5c
...
...
@@ -31,6 +31,12 @@ def sqlite3_connection(config)
db
.
busy_timeout
(
ConnectionAdapters
::
SQLite3Adapter
.
type_cast_config_to_integer
(
config
[
:timeout
]))
if
config
[
:timeout
]
ConnectionAdapters
::
SQLite3Adapter
.
new
(
db
,
logger
,
config
)
rescue
Errno
::
ENOENT
=>
error
if
error
.
message
.
include?
(
"No such file or directory"
)
raise
ActiveRecord
::
NoDatabaseError
.
new
(
error
.
message
)
else
raise
error
end
end
end
...
...
activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
浏览文件 @
9705df5c
...
...
@@ -16,6 +16,20 @@ def setup
eosql
end
def
test_bad_connection_mysql
assert_raise
ActiveRecord
::
NoDatabaseError
do
connection
=
ActiveRecord
::
Base
.
mysql_connection
(
adapter:
"mysql"
,
database:
"should_not_exist-cinco-dog-db"
)
connection
.
exec_query
(
'drop table if exists ex'
)
end
end
def
test_bad_connection_mysql2
assert_raise
ActiveRecord
::
NoDatabaseError
do
connection
=
ActiveRecord
::
Base
.
mysql2_connection
(
adapter:
"mysql2"
,
database:
"should_not_exist-cinco-dog-db"
)
connection
.
exec_query
(
'drop table if exists ex'
)
end
end
def
test_valid_column
column
=
@conn
.
columns
(
'ex'
).
find
{
|
col
|
col
.
name
==
'id'
}
assert
@conn
.
valid_type?
(
column
.
type
)
...
...
activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
浏览文件 @
9705df5c
...
...
@@ -26,6 +26,13 @@ def setup
ActiveSupport
::
Notifications
.
subscribe
(
'sql.active_record'
,
@subscriber
)
end
def
test_bad_connection
assert_raise
ActiveRecord
::
NoDatabaseError
do
connection
=
ActiveRecord
::
Base
.
sqlite3_connection
(
adapter:
"sqlite3"
,
database:
"/tmp/should/_not/_exist/-cinco-dog.db"
)
connection
.
exec_query
(
'drop table if exists ex'
)
end
end
def
test_connect_with_url
original_connection
=
ActiveRecord
::
Base
.
remove_connection
tf
=
Tempfile
.
open
'whatever'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录