Class: Sequel::Oracle::Database
- Defined in:
- lib/sequel_core/adapters/oracle.rb
Constant Summary
Constants inherited from Database
Database::ADAPTERS, Database::SQL_BEGIN, Database::SQL_COMMIT, Database::SQL_ROLLBACK
Constants included from Schema::SQL
Schema::SQL::AUTOINCREMENT, Schema::SQL::CASCADE, Schema::SQL::COMMA_SEPARATOR, Schema::SQL::NOT_NULL, Schema::SQL::NO_ACTION, Schema::SQL::NULL, Schema::SQL::PRIMARY_KEY, Schema::SQL::RESTRICT, Schema::SQL::SET_DEFAULT, Schema::SQL::SET_NULL, Schema::SQL::TYPES, Schema::SQL::UNDERSCORE, Schema::SQL::UNIQUE, Schema::SQL::UNSIGNED
Instance Attribute Summary
Attributes inherited from Database
#loggers, #opts, #pool, #quote_identifiers
Instance Method Summary collapse
-
#connect ⇒ Object
AUTO_INCREMENT = ‘IDENTITY(1,1)’.freeze.
- #dataset(opts = nil) ⇒ Object
- #disconnect ⇒ Object
- #execute(sql) ⇒ Object (also: #do)
- #table_exists?(name) ⇒ Boolean
- #tables ⇒ Object
- #transaction ⇒ Object
Methods inherited from Database
#<<, #[], adapter_class, adapter_scheme, #add_column, #add_index, #alter_table, connect, #create_or_replace_view, #create_table, #create_table!, #create_view, #drop_column, #drop_index, #drop_table, #drop_view, #fetch, #from, #get, #initialize, #inspect, #log_info, #logger, #logger=, #multi_threaded?, #query, quote_identifiers=, #quote_identifiers?, #rename_column, #rename_table, #select, #serial_primary_key_options, #set_column_default, #set_column_type, single_threaded=, #single_threaded?, #synchronize, #test_connection, #typecast_value, #uri, uri_to_options
Methods included from Schema::SQL
#alter_table_sql, #alter_table_sql_list, #auto_increment_sql, #column_definition_sql, #column_list_sql, #constraint_definition_sql, #create_table_sql_list, #default_index_name, #drop_table_sql, #filter_expr, #index_definition_sql, #index_list_sql_list, #literal, #on_delete_clause, #quote_identifier, #rename_table_sql, #schema, #schema_utility_dataset, #type_literal
Constructor Details
This class inherits a constructor from Sequel::Database
Instance Method Details
#connect ⇒ Object
AUTO_INCREMENT = ‘IDENTITY(1,1)’.freeze
def auto_increment_sql
AUTO_INCREMENT
end
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sequel_core/adapters/oracle.rb', line 14 def connect if @opts[:database] dbname = @opts[:host] ? \ "//#{@opts[:host]}/#{@opts[:database]}" : @opts[:database] else dbname = @opts[:host] end conn = OCI8.new(@opts[:user], @opts[:password], dbname, @opts[:privilege]) conn.autocommit = true conn.non_blocking = true conn end |
#dataset(opts = nil) ⇒ Object
31 32 33 |
# File 'lib/sequel_core/adapters/oracle.rb', line 31 def dataset(opts = nil) Oracle::Dataset.new(self, opts) end |
#disconnect ⇒ Object
27 28 29 |
# File 'lib/sequel_core/adapters/oracle.rb', line 27 def disconnect @pool.disconnect {|c| c.logoff} end |
#execute(sql) ⇒ Object Also known as: do
35 36 37 38 |
# File 'lib/sequel_core/adapters/oracle.rb', line 35 def execute(sql) log_info(sql) @pool.hold {|conn| conn.exec(sql)} end |
#table_exists?(name) ⇒ Boolean
48 49 50 |
# File 'lib/sequel_core/adapters/oracle.rb', line 48 def table_exists?(name) from(:tab).filter(:tname => name.to_s.upcase, :tabtype => 'TABLE').count > 0 end |
#tables ⇒ Object
42 43 44 45 46 |
# File 'lib/sequel_core/adapters/oracle.rb', line 42 def tables from(:tab).select(:tname).filter(:tabtype => 'TABLE').map do |r| r[:tname].downcase.to_sym end end |
#transaction ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sequel_core/adapters/oracle.rb', line 52 def transaction @pool.hold do |conn| @transactions ||= [] if @transactions.include? Thread.current return yield(conn) end conn.autocommit = false begin @transactions << Thread.current yield(conn) rescue => e conn.rollback raise e unless Error::Rollback === e ensure conn.commit unless e conn.autocommit = true @transactions.delete(Thread.current) end end end |