Class: Libis::Services::OracleClient
- Inherits:
-
Object
- Object
- Libis::Services::OracleClient
- Defined in:
- lib/libis/services/oracle_client.rb
Instance Attribute Summary collapse
-
#oci ⇒ Object
readonly
Returns the value of attribute oci.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #blocking=(value) ⇒ Object
- #blocking? ⇒ Boolean
- #call(procedure, parameters = []) ⇒ Object
- #execute(statement, *bindvars, &block) ⇒ Object
-
#initialize(url) ⇒ OracleClient
constructor
A new instance of OracleClient.
- #run(script, parameters = []) ⇒ Object
- #table(name) ⇒ Object
Constructor Details
#initialize(url) ⇒ OracleClient
Returns a new instance of OracleClient.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/libis/services/oracle_client.rb', line 18 def initialize(url) @url = url @oci = if RUBY_PLATFORM == 'java' raise RuntimeError, 'Malformed database URL' unless url =~ /^(.*)\/(.*)@(.*)$/ user, pass, db = $1, $2, $3 uri = "jdbc:oracle:thin:@#{db}" ods = OracleDataSource.new ods.set_url(uri) ods.set_user(user) ods.set_password(pass) ods.get_connection else OCI8.new(url) end ObjectSpace.define_finalizer(self, self.class.finalize(@oci)) end |
Instance Attribute Details
#oci ⇒ Object (readonly)
Returns the value of attribute oci.
16 17 18 |
# File 'lib/libis/services/oracle_client.rb', line 16 def oci @oci end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
16 17 18 |
# File 'lib/libis/services/oracle_client.rb', line 16 def url @url end |
Class Method Details
.finalize(oci) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/libis/services/oracle_client.rb', line 35 def self.finalize(oci) if RUBY_PLATFORM == 'java' proc { oci.close } else proc { oci.logoff } end end |
Instance Method Details
#blocking=(value) ⇒ Object
44 45 46 47 |
# File 'lib/libis/services/oracle_client.rb', line 44 def blocking=(value) oci.non_blocking = !value blocking? end |
#blocking? ⇒ Boolean
49 50 51 |
# File 'lib/libis/services/oracle_client.rb', line 49 def blocking? !oci.non_blocking? end |
#call(procedure, parameters = []) ⇒ Object
53 54 55 56 57 |
# File 'lib/libis/services/oracle_client.rb', line 53 def call(procedure, parameters = []) params = '' params = "'" + parameters.map(&:to_s).join("','") + "'" if parameters and parameters.size > 0 oci.exec("call #{procedure}(#{params})") end |
#execute(statement, *bindvars, &block) ⇒ Object
59 60 61 |
# File 'lib/libis/services/oracle_client.rb', line 59 def execute(statement, *bindvars, &block) oci.exec(statement, *bindvars, &block) end |
#run(script, parameters = []) ⇒ Object
84 85 86 87 88 |
# File 'lib/libis/services/oracle_client.rb', line 84 def run(script, parameters = []) params = '' params = "\"" + parameters.join("\" \"") + "\"" if parameters&.size.to_i > 0 process_result `sqlplus -S #{url} @#{script} #{params}` end |
#table(name) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/libis/services/oracle_client.rb', line 63 def table(name) = oci.describe_table(name) { columns: .columns.map do |column| { name: column.name, type: column.data_type, size: case column.data_type when :number column.precision when :varchar2 column.char_size else column.data_size end, required: !column.nullable? } end } end |