Class: PLSQL::Connection
- Inherits:
-
Object
- Object
- PLSQL::Connection
- Defined in:
- lib/plsql/connection.rb
Direct Known Subclasses
Defined Under Namespace
Modules: CursorCommon
Instance Attribute Summary collapse
-
#activerecord_class ⇒ Object
readonly
Returns the value of attribute activerecord_class.
-
#raw_driver ⇒ Object
readonly
Returns the value of attribute raw_driver.
Class Method Summary collapse
Instance Method Summary collapse
-
#autocommit=(value) ⇒ Object
Set autocommit mode (true or false).
-
#autocommit? ⇒ Boolean
Current autocommit mode (true or false).
-
#commit ⇒ Object
:nodoc:.
-
#database_version ⇒ Object
Returns array with major and minor version of database (e.g. [10, 2]).
-
#describe_synonym(schema_name, synonym_name) ⇒ Object
all_synonyms view is quite slow therefore this implementation is overriden in OCI connection with faster native OCI method.
-
#exec(sql, *bindvars) ⇒ Object
:nodoc:.
-
#initialize(raw_drv, raw_conn, ar_class = nil) ⇒ Connection
constructor
:nodoc:.
-
#jdbc? ⇒ Boolean
Is it JDBC connection.
-
#logoff ⇒ Object
:nodoc:.
-
#oci? ⇒ Boolean
Is it OCI8 connection.
-
#parse(sql) ⇒ Object
:nodoc:.
-
#prefetch_rows=(value) ⇒ Object
Set number of rows to be prefetched.
-
#raw_connection ⇒ Object
Returns OCI8 or JDBC connection.
-
#rollback ⇒ Object
:nodoc:.
-
#select_all(sql, *bindvars, &block) ⇒ Object
:nodoc:.
-
#select_first(sql, *bindvars) ⇒ Object
:nodoc:.
-
#select_hash_all(sql, *bindvars, &block) ⇒ Object
:nodoc:.
-
#select_hash_first(sql, *bindvars) ⇒ Object
:nodoc:.
Constructor Details
#initialize(raw_drv, raw_conn, ar_class = nil) ⇒ Connection
:nodoc:
6 7 8 9 10 |
# File 'lib/plsql/connection.rb', line 6 def initialize(raw_drv, raw_conn, ar_class = nil) #:nodoc: @raw_driver = raw_drv @raw_connection = raw_conn @activerecord_class = ar_class end |
Instance Attribute Details
#activerecord_class ⇒ Object (readonly)
Returns the value of attribute activerecord_class.
4 5 6 |
# File 'lib/plsql/connection.rb', line 4 def activerecord_class @activerecord_class end |
#raw_driver ⇒ Object (readonly)
Returns the value of attribute raw_driver.
3 4 5 |
# File 'lib/plsql/connection.rb', line 3 def raw_driver @raw_driver end |
Class Method Details
.create(raw_conn, ar_class = nil) ⇒ Object
:nodoc:
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/plsql/connection.rb', line 12 def self.create(raw_conn, ar_class = nil) #:nodoc: if ar_class && !(defined?(::ActiveRecord) && [ar_class, ar_class.superclass].include?(::ActiveRecord::Base)) raise ArgumentError, "Wrong ActiveRecord class" end # MRI 1.8.6 or YARV 1.9.1 if (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby") && defined?(OCI8) OCIConnection.new(:oci, raw_conn, ar_class) # JRuby elsif (defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby") JDBCConnection.new(:jdbc, raw_conn, ar_class) else raise ArgumentError, "Unknown raw driver" end end |
Instance Method Details
#autocommit=(value) ⇒ Object
Set autocommit mode (true or false)
64 65 66 |
# File 'lib/plsql/connection.rb', line 64 def autocommit=(value) raise NoMethodError, "Not implemented for this raw driver" end |
#autocommit? ⇒ Boolean
Current autocommit mode (true or false)
59 60 61 |
# File 'lib/plsql/connection.rb', line 59 def autocommit? raise NoMethodError, "Not implemented for this raw driver" end |
#commit ⇒ Object
:nodoc:
50 51 52 |
# File 'lib/plsql/connection.rb', line 50 def commit #:nodoc: raise NoMethodError, "Not implemented for this raw driver" end |
#database_version ⇒ Object
Returns array with major and minor version of database (e.g. [10, 2])
164 165 166 |
# File 'lib/plsql/connection.rb', line 164 def database_version raise NoMethodError, "Not implemented for this raw driver" end |
#describe_synonym(schema_name, synonym_name) ⇒ Object
all_synonyms view is quite slow therefore this implementation is overriden in OCI connection with faster native OCI method
157 158 159 160 161 |
# File 'lib/plsql/connection.rb', line 157 def describe_synonym(schema_name, synonym_name) #:nodoc: select_first( "SELECT table_owner, table_name FROM all_synonyms WHERE owner = :owner AND synonym_name = :synonym_name", schema_name.to_s.upcase, synonym_name.to_s.upcase) end |
#exec(sql, *bindvars) ⇒ Object
:nodoc:
122 123 124 |
# File 'lib/plsql/connection.rb', line 122 def exec(sql, *bindvars) #:nodoc: raise NoMethodError, "Not implemented for this raw driver" end |
#jdbc? ⇒ Boolean
Is it JDBC connection
42 43 44 |
# File 'lib/plsql/connection.rb', line 42 def jdbc? @raw_driver == :jdbc end |
#logoff ⇒ Object
:nodoc:
46 47 48 |
# File 'lib/plsql/connection.rb', line 46 def logoff #:nodoc: raise NoMethodError, "Not implemented for this raw driver" end |
#oci? ⇒ Boolean
Is it OCI8 connection
37 38 39 |
# File 'lib/plsql/connection.rb', line 37 def oci? @raw_driver == :oci end |
#parse(sql) ⇒ Object
:nodoc:
126 127 128 |
# File 'lib/plsql/connection.rb', line 126 def parse(sql) #:nodoc: raise NoMethodError, "Not implemented for this raw driver" end |
#prefetch_rows=(value) ⇒ Object
Set number of rows to be prefetched. This can reduce the number of network round trips when fetching many rows. The default value is one. (If ActiveRecord oracle_enhanced connection is used then default is 100)
70 71 72 |
# File 'lib/plsql/connection.rb', line 70 def prefetch_rows=(value) raise NoMethodError, "Not implemented for this raw driver" end |
#raw_connection ⇒ Object
Returns OCI8 or JDBC connection
28 29 30 31 32 33 34 |
# File 'lib/plsql/connection.rb', line 28 def raw_connection if @activerecord_class @activerecord_class.connection.raw_connection else @raw_connection end end |
#rollback ⇒ Object
:nodoc:
54 55 56 |
# File 'lib/plsql/connection.rb', line 54 def rollback #:nodoc: raise NoMethodError, "Not implemented for this raw driver" end |
#select_all(sql, *bindvars, &block) ⇒ Object
:nodoc:
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/plsql/connection.rb', line 88 def select_all(sql, *bindvars, &block) #:nodoc: cursor = cursor_from_query(sql, bindvars) results = [] row_count = 0 while row = cursor.fetch if block_given? yield(row) row_count += 1 else results << row end end block_given? ? row_count : results ensure cursor.close rescue nil end |
#select_first(sql, *bindvars) ⇒ Object
:nodoc:
74 75 76 77 78 79 |
# File 'lib/plsql/connection.rb', line 74 def select_first(sql, *bindvars) #:nodoc: cursor = cursor_from_query(sql, bindvars, :prefetch_rows => 1) cursor.fetch ensure cursor.close rescue nil end |
#select_hash_all(sql, *bindvars, &block) ⇒ Object
:nodoc:
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/plsql/connection.rb', line 105 def select_hash_all(sql, *bindvars, &block) #:nodoc: cursor = cursor_from_query(sql, bindvars) results = [] row_count = 0 while row = cursor.fetch_hash if block_given? yield(row) row_count += 1 else results << row end end block_given? ? row_count : results ensure cursor.close rescue nil end |
#select_hash_first(sql, *bindvars) ⇒ Object
:nodoc:
81 82 83 84 85 86 |
# File 'lib/plsql/connection.rb', line 81 def select_hash_first(sql, *bindvars) #:nodoc: cursor = cursor_from_query(sql, bindvars, :prefetch_rows => 1) cursor.fetch_hash ensure cursor.close rescue nil end |