如何连接到使用甲骨文轨道后运行特定的脚本? [英] How to run specific script after connected to oracle using rails?
问题描述
我需要后运行Oracle脚本中使用ActiveRecord的连接到Oracle数据库。
我知道存在的初始化,但只有在应用程序的启动这些运行。我需要一个写点运行每一个新的数据库连接建立后,code。
这是必要的初始化与使用相同的遗留数据库等应用程序共享一些Oracle环境变量。
I need to run an oracle script after connect to oracle database using ActiveRecord.
I know that exists the initializers, but these run only in the application's start. I need a point to write a code that runs after every new database connection be established.
This is needed to initialize some oracle environments variables shared with others applications that uses the same legacy database.
任何想法?
在此先感谢。
推荐答案
我找到了解决办法:
创建文件/config/initializers/oracle.rb,并把它放在这个code:
I found the solution:
Create the file /config/initializers/oracle.rb and put into it this code:
ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
def new_connection_with_initialization
result = new_connection_without_initialization
result.execute('begin Base_Pck.ConfigSession; end;')
result
end
alias_method_chain :new_connection, :initialization
end
在 alias_method_chain
允许您更改的方法(new_connection)没有覆盖它,但延长它。
然后,我们只需要改变脚本到 result.execute
电话。
The alias_method_chain
allows you to change a method (new_connection) without override it, but extending it.
Then we need only to change the script into the result.execute
call.
这篇关于如何连接到使用甲骨文轨道后运行特定的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!