Closed harsimranrajpal21 closed 6 years ago
any other way to run oracle code if i dont have oci8 with ruby
I cannot guess what you say by the sentence. If it means you want to access Oracle without ruby-oci8, use jruby and jdbc or any other languages instead. Ruby-oci8 is the only way to access Oracle when you use MRI ruby. If it means you want to access Oracle with more higher-level API, use oracle-enhanced or sequel. They use ruby-oci8 internally when the ruby is MRI.
Why did you post the code? What is your request?
In addition, could you check Preview
before you make an issue or add a comment?
The code you posted is garbled and hard to read.
See https://help.github.com/articles/creating-and-highlighting-code-blocks/
actually i am not able to load oci8, while running code getting below error
inspec exec test12.rb
/opt/inspec/embedded/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- oci8 (LoadError) from /opt/inspec/embedded/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in
require'
from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/lib/inspec/dsl_shared.rb:14:in require' from test12.rb:1:in
load_with_context'
from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/lib/inspec/profile_context.rb:158:in instance_eval' from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/lib/inspec/profile_context.rb:158:in
load_with_context'
from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/lib/inspec/profile_context.rb:142:in load_control_file' from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/lib/inspec/profile.rb:170:in
block in collect_tests'
from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/lib/inspec/profile.rb:167:in each' from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/lib/inspec/profile.rb:167:in
collect_tests'
from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/lib/inspec/runner.rb:93:in block in load' from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/lib/inspec/runner.rb:82:in
each'
from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/lib/inspec/runner.rb:82:in load' from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/lib/inspec/runner.rb:103:in
run'
from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/lib/inspec/cli.rb:168:in exec' from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in
run'
from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in invoke_command' from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in
dispatch'
from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/base.rb:466:in start' from /opt/inspec/embedded/lib/ruby/gems/2.4.0/gems/inspec-2.1.83/bin/inspec:12:in
<top (required)>'
from /bin/inspec:137:in load' from /bin/inspec:137:in
First of all, could you fix your previous two comments to display code and error messages correctly? Your comments are hard to read. See https://help.github.com/articles/creating-and-highlighting-code-blocks/
Edit Comment
icon.
your code or error messages
Write
to Preview
and check whether the code is displayed correctly.
Secondly, you should cut down your code and make minimum code to reproduce your issue. In this case, the minimum code will be the following one line.
require 'oci8'
Thirdly, you should write enough information to run the code when you post code. What is Inspec.resource(1)
?
Fourthly, you should provide information about your environment such as ruby version, OS version, Oracle version and so on.
Finally, could you check whether ruby-oci8 is installed? Run gem list
command or check Gemfile
if your project or tool uses bundler.
Closed because of no reply.
any other way to run oracle code if i dont have oci8 with ruby
code is like below:
require 'oci8'
class Oraclexe < Inspec.resource(1) name 'oraclexe'
desc "oracle resource class to verify any assessment related oracledb"
Roles / Priviledges => [:SYSDBA, :SYSOPER, :SYSASM, :SYSBACKUP, :SYSDG, or :SYSKM]
params = {
:host => '127.0.0.1',
:port => '1521',
:user => 'sys',
:pass => 'password',
:service => 'XE',
:role => 'SYSDBA',
:db_name => nil
}
def initialize(params={}) @param ||= params conn_string = "#{@param[:user]}/#{@param[:pass]}@#{@param[:host]}:#{@param[:port]}/#{@param[:service]}"
end
def ping? return @db.ping end
def select_username_scheme_from_dba_users begin cursor = connect.exec('SELECT username, expiry_date, account_status FROM dba_users') row = cursor.fetch() cursor.close connect.logoff rescue OCIError row = $!.code.to_s + " " + $!.message end
end
def db_user_exist?(user)
return select_username_scheme_from_dba_users.include? user
end
private def connect return @db end
def logoff return @db.logoff end end