简体   繁体   中英

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. This needs to be done per request. The OCI8 gem we are using has a client_identifier property we could set. 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? Would those attributes be passed with a subsequent ping or sql operation?

Something like this:

ActiveRecord::Base.connection.client_identifier = session[: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. Kinda like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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