Class: PLSQL::Schema
- Inherits:
-
Object
- Object
- PLSQL::Schema
- Includes:
- SQLStatements
- Defined in:
- lib/plsql/schema.rb
Constant Summary collapse
- DBMS_OUTPUT_MAX_LINES =
Maximum line numbers for DBMS_OUTPUT in one PL/SQL call (from DBMSOUTPUT_LINESARRAY type)
2147483647- @@schemas =
{}
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns connection wrapper object (this is not raw OCI8 or JDBC connection!).
Class Method Summary collapse
Instance Method Summary collapse
-
#activerecord_class=(ar_class) ⇒ Object
Set connection to current ActiveRecord connection (use in initializer file):.
-
#dbms_output_buffer_size ⇒ Object
DBMS_OUTPUT buffer size (default is 20_000).
-
#dbms_output_buffer_size=(value) ⇒ Object
Seet DBMS_OUTPUT buffer size (default is 20_000).
-
#dbms_output_stream ⇒ Object
IO stream where to log DBMS_OUTPUT from PL/SQL procedures.
-
#dbms_output_stream=(stream) ⇒ Object
Specify IO stream where to log DBMS_OUTPUT from PL/SQL procedures.
-
#default_timezone ⇒ Object
Default timezone to which database values will be converted - :utc or :local.
-
#default_timezone=(value) ⇒ Object
Set default timezone to which database values will be converted - :utc or :local.
-
#initialize(raw_conn = nil, schema = nil, original_schema = nil) ⇒ Schema
constructor
:nodoc:.
-
#local_timezone_offset ⇒ Object
Same implementation as for ActiveRecord DateTimes aren’t aware of DST rules, so use a consistent non-DST offset when creating a DateTime with an offset in the local zone.
-
#logoff ⇒ Object
Disconnect from Oracle.
-
#raw_connection=(raw_conn) ⇒ Object
:nodoc:.
-
#schema_name ⇒ Object
Current Oracle schema name.
Methods included from SQLStatements
#commit, #execute, #rollback, #select, #select_all, #select_first, #select_one
Constructor Details
#initialize(raw_conn = nil, schema = nil, original_schema = nil) ⇒ Schema
:nodoc:
19 20 21 22 23 |
# File 'lib/plsql/schema.rb', line 19 def initialize(raw_conn = nil, schema = nil, original_schema = nil) #:nodoc: self.connection = raw_conn @schema_name = schema ? schema.to_s.upcase : nil @original_schema = original_schema end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/plsql/schema.rb', line 155 def method_missing(method, *args, &block) raise ArgumentError, "No database connection" unless connection # search in database if not in cache at first object = (@schema_objects[method] ||= find_database_object(method) || find_other_schema(method) || find_public_synonym(method)) || find_standard_procedure(method) raise ArgumentError, "No database object '#{method.to_s.upcase}' found" unless object if object.is_a?(Procedure) object.exec(*args, &block) else object end end |
Instance Attribute Details
#connection ⇒ Object
Returns connection wrapper object (this is not raw OCI8 or JDBC connection!)
26 27 28 |
# File 'lib/plsql/schema.rb', line 26 def connection @connection end |
Class Method Details
.find_or_new(connection_alias) ⇒ Object
:nodoc:
8 9 10 11 12 13 14 15 |
# File 'lib/plsql/schema.rb', line 8 def find_or_new(connection_alias) #:nodoc: connection_alias ||= :default if @@schemas[connection_alias] @@schemas[connection_alias] else @@schemas[connection_alias] = self.new end end |
Instance Method Details
#activerecord_class=(ar_class) ⇒ Object
Set connection to current ActiveRecord connection (use in initializer file):
plsql.activerecord_class = ActiveRecord::Base
57 58 59 60 61 |
# File 'lib/plsql/schema.rb', line 57 def activerecord_class=(ar_class) @connection = ar_class ? Connection.create(nil, ar_class) : nil reset_instance_variables ar_class end |
#dbms_output_buffer_size ⇒ Object
DBMS_OUTPUT buffer size (default is 20_000)
104 105 106 107 108 109 110 |
# File 'lib/plsql/schema.rb', line 104 def dbms_output_buffer_size if @original_schema @original_schema.dbms_output_buffer_size else @dbms_output_buffer_size || 20_000 end end |
#dbms_output_buffer_size=(value) ⇒ Object
Seet DBMS_OUTPUT buffer size (default is 20_000). Example:
plsql.dbms_output_buffer_size = 100_000
116 117 118 |
# File 'lib/plsql/schema.rb', line 116 def dbms_output_buffer_size=(value) @dbms_output_buffer_size = value end |
#dbms_output_stream ⇒ Object
IO stream where to log DBMS_OUTPUT from PL/SQL procedures.
135 136 137 138 139 140 141 |
# File 'lib/plsql/schema.rb', line 135 def dbms_output_stream if @original_schema @original_schema.dbms_output_stream else @dbms_output_stream end end |
#dbms_output_stream=(stream) ⇒ Object
Specify IO stream where to log DBMS_OUTPUT from PL/SQL procedures. Example:
plsql.dbms_output_stream = STDOUT
127 128 129 130 131 132 |
# File 'lib/plsql/schema.rb', line 127 def dbms_output_stream=(stream) @dbms_output_stream = stream if @dbms_output_stream.nil? && @connection sys.dbms_output.disable end end |
#default_timezone ⇒ Object
Default timezone to which database values will be converted - :utc or :local
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/plsql/schema.rb', line 76 def default_timezone if @original_schema @original_schema.default_timezone else @default_timezone || # Use ActiveRecord class default_timezone when ActiveRecord connection is used (@connection && (ar_class = @connection.activerecord_class) && ar_class.default_timezone) || # default to local timezone :local end end |
#default_timezone=(value) ⇒ Object
Set default timezone to which database values will be converted - :utc or :local
89 90 91 92 93 94 95 |
# File 'lib/plsql/schema.rb', line 89 def default_timezone=(value) if [:local, :utc].include?(value) @default_timezone = value else raise ArgumentError, "default timezone should be :local or :utc" end end |
#local_timezone_offset ⇒ Object
Same implementation as for ActiveRecord DateTimes aren’t aware of DST rules, so use a consistent non-DST offset when creating a DateTime with an offset in the local zone
99 100 101 |
# File 'lib/plsql/schema.rb', line 99 def local_timezone_offset #:nodoc: ::Time.local(2007).utc_offset.to_r / 86400 end |
#logoff ⇒ Object
Disconnect from Oracle
64 65 66 67 |
# File 'lib/plsql/schema.rb', line 64 def logoff @connection.logoff self.connection = nil end |
#raw_connection=(raw_conn) ⇒ Object
:nodoc:
28 29 30 31 |
# File 'lib/plsql/schema.rb', line 28 def raw_connection=(raw_conn) #:nodoc: @connection = raw_conn ? Connection.create(raw_conn) : nil reset_instance_variables end |
#schema_name ⇒ Object
Current Oracle schema name
70 71 72 73 |
# File 'lib/plsql/schema.rb', line 70 def schema_name return nil unless connection @schema_name ||= select_first("SELECT SYS_CONTEXT('userenv','session_user') FROM dual")[0] end |