Module: Sequel::Pervasive::DatabaseMethods
- Defined in:
- lib/sequel/pervasive_adapter.rb
Instance Method Summary collapse
-
#database_type ⇒ Object
Pervasive SQL Server uses the :psql type.
- #dataset(opts = nil) ⇒ Object
-
#do_transaction(&block) ⇒ Object
special transaction method since pervasive does not support transactions through sql “start transaction” statement.
-
#execute(sql, opts = {}) ⇒ Object
overriding execute to be able to thow a DatabaseDisconnectError when the ODBC::Error is code 08S01.
- #select_fields(table, *fields) ⇒ Object
Instance Method Details
#database_type ⇒ Object
Pervasive SQL Server uses the :psql type.
5 6 7 |
# File 'lib/sequel/pervasive_adapter.rb', line 5 def database_type :psql end |
#dataset(opts = nil) ⇒ Object
9 10 11 12 13 |
# File 'lib/sequel/pervasive_adapter.rb', line 9 def dataset(opts = nil) ds = super ds.extend(DatasetMethods) ds end |
#do_transaction(&block) ⇒ Object
special transaction method since pervasive does not support transactions through sql “start transaction” statement. be sure to use begin/rescue if you want to recover from failure since this method throws errors
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sequel/pervasive_adapter.rb', line 18 def do_transaction(&block) synchronize do |conn| begin conn.autocommit = false yield conn r = conn.run("commit"); r.drop rescue Exception,Error => se r = conn.run("rollback"); r.drop raise se ensure conn.autocommit = true end end end |
#execute(sql, opts = {}) ⇒ Object
overriding execute to be able to thow a DatabaseDisconnectError when the ODBC::Error is code 08S01.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sequel/pervasive_adapter.rb', line 38 def execute(sql, opts={}) log_info(sql) synchronize(opts[:server]) do |conn| begin r = conn.run(sql) yield(r) if block_given? rescue Sequel::DatabaseConnectionError => se raise Sequel.convert_exception_class(se, Sequel::DatabaseDisconnectError) rescue Sequel::DatabaseError => se se = Sequel.convert_exception_class(se, Sequel::DatabaseDisconnectError) if se..match(/08S01/) raise_error(se) rescue ::ODBC::Error => e e = Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError) if e..match(/08S01/) raise_error(e) ensure r.drop if r end nil end end |
#select_fields(table, *fields) ⇒ Object
33 34 35 |
# File 'lib/sequel/pervasive_adapter.rb', line 33 def select_fields(table, *fields) dataset.select_fields(table, *fields) end |