Class: Cubrid2::Client
- Inherits:
-
Object
- Object
- Cubrid2::Client
- Defined in:
- lib/cubrid2/client.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#query_options ⇒ Object
readonly
Returns the value of attribute query_options.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
Class Method Summary collapse
Instance Method Summary collapse
- #_query(sql, _options) ⇒ Object
- #auto_commit ⇒ Object
- #auto_commit=(flag) ⇒ Object
- #close ⇒ Object
- #info ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #ping ⇒ Object
- #query(sql, options = {}) ⇒ Object
- #query_info ⇒ Object
- #server_version ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cubrid2/client.rb', line 13 def initialize(opts = {}) raise Cubrid2::Error, 'Options parameter must be a Hash' unless opts.is_a? Hash opts = Cubrid2::Util.key_hash_as_symbols(opts) @read_timeout = nil @query_options = self.class..dup @query_options.merge! opts %i[auto_commit].each do |key| next unless opts.key?(key) case key when :auto_commit send(:"#{key}=", !!opts[key]) # rubocop:disable Style/DoubleNegation else send(:"#{key}=", opts[key]) end end flags = 0 user = opts[:username] || opts[:user] pass = opts[:password] || opts[:pass] host = opts[:host] || opts[:hostname] port = opts[:port] database = opts[:database] || opts[:dbname] || opts[:db] # Correct the data types before passing these values down to the C level user = user.to_s unless user.nil? pass = pass.to_s unless pass.nil? host = host.to_s unless host.nil? port = port.to_i unless port.nil? database = database.to_s unless database.nil? @conn = Cubrid.connect database, host, port, user, pass end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
5 6 7 |
# File 'lib/cubrid2/client.rb', line 5 def conn @conn end |
#query_options ⇒ Object (readonly)
Returns the value of attribute query_options.
5 6 7 |
# File 'lib/cubrid2/client.rb', line 5 def @query_options end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
5 6 7 |
# File 'lib/cubrid2/client.rb', line 5 def read_timeout @read_timeout end |
Class Method Details
.default_query_options ⇒ Object
7 8 9 10 11 |
# File 'lib/cubrid2/client.rb', line 7 def self. @default_query_options ||= { auto_commit: true } end |
Instance Method Details
#_query(sql, _options) ⇒ Object
56 57 58 |
# File 'lib/cubrid2/client.rb', line 56 def _query(sql, ) @conn.query(sql) end |
#auto_commit ⇒ Object
85 86 87 |
# File 'lib/cubrid2/client.rb', line 85 def auto_commit @conn.auto_commit end |
#auto_commit=(flag) ⇒ Object
89 90 91 |
# File 'lib/cubrid2/client.rb', line 89 def auto_commit=(flag) @conn.auto_commit = flag end |
#close ⇒ Object
81 82 83 |
# File 'lib/cubrid2/client.rb', line 81 def close @conn.close end |
#info ⇒ Object
69 70 71 |
# File 'lib/cubrid2/client.rb', line 69 def info self.class.info end |
#ping ⇒ Object
73 74 75 |
# File 'lib/cubrid2/client.rb', line 73 def ping @conn.server_version.present? end |
#query(sql, options = {}) ⇒ Object
50 51 52 53 54 |
# File 'lib/cubrid2/client.rb', line 50 def query(sql, = {}) Thread.handle_interrupt(::Cubrid2::Util::TIMEOUT_ERROR_CLASS => :never) do _query(sql, @query_options.merge()) end end |
#query_info ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/cubrid2/client.rb', line 60 def query_info info = query_info_string return {} unless info info_hash = {} info.split.each_slice(2) { |s| info_hash[s[0].downcase.delete(':').to_sym] = s[1].to_i } info_hash end |
#server_version ⇒ Object
77 78 79 |
# File 'lib/cubrid2/client.rb', line 77 def server_version @conn.server_version end |