简体   繁体   English

Ruby Rails:将线程中的会话信息传递给Oracle数据库连接

[英]Ruby Rails: passing session info in a thread to a Oracle db connection

Our app holds a user id in the session and we need to pass that along to an oracle connection so that the user id can be logged in oracle with each user operation. 我们的应用程序在会话中保留一个用户ID,我们需要将该用户ID传递给oracle连接,以便可以使用每个用户操作将用户ID登录到oracle中。 This needs to be done per request. 这需要根据请求完成。 The OCI8 gem we are using has a client_identifier property we could set. 我们正在使用的OCI8 gem具有我们可以设置的client_identifier属性。 We just need to know how and where. 我们只需要知道如何以及在哪里。

Can we access a threads database connection in a method in the application controller (triggered in a before_filter) and if we did would the connection expose its adapter's methods and/or attributes? 我们是否可以在应用程序控制器中的方法(在before_filter中触发)中访问线程数据库连接,并且如果这样做,该连接将公开其适配器的方法和/或属性? Would those attributes be passed with a subsequent ping or sql operation? 这些属性会在随后的ping或sql操作中传递吗?

Something like this: 像这样:

ActiveRecord::Base.connection.client_identifier = session[:user] ActiveRecord :: Base.connection.client_identifier =会话[:user]

Maybe? 也许?

Thanks 谢谢

Looks like we needed to grab the raw connection which allowed us to set the client id in a before filter in the application controller. 看起来我们需要获取原始连接,这使我们能够在应用程序控制器中的before过滤器中设置客户端ID。 Kinda like this: 有点像这样:

ActiveRecord::Base.connection.raw_connection.client_identifier=user_id ActiveRecord :: Base.connection.raw_connection.client_identifier = user_id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM