Class: Sequel::Postgres::Adapter
- Defined in:
- lib/sequel/adapters/postgres.rb
Overview
PGconn subclass for connection specific methods used with the pg, postgres, or postgres-pr driver.
Constant Summary collapse
- DISCONNECT_ERROR_RE =
/\Acould not receive data from server/
Instance Attribute Summary collapse
-
#prepared_statements ⇒ Object
readonly
Hash of prepared statements for this connection.
Instance Method Summary collapse
-
#check_disconnect_errors ⇒ Object
Raise a Sequel::DatabaseDisconnectError if a PGError is raised and the connection status cannot be determined or it is not OK.
-
#execute(sql, args = nil) ⇒ Object
Execute the given SQL with this connection.
Instance Attribute Details
#prepared_statements ⇒ Object (readonly)
Hash of prepared statements for this connection. Keys are string names of the server side prepared statement, and values are SQL strings.
105 106 107 |
# File 'lib/sequel/adapters/postgres.rb', line 105 def prepared_statements @prepared_statements end |
Instance Method Details
#check_disconnect_errors ⇒ Object
Raise a Sequel::DatabaseDisconnectError if a PGError is raised and the connection status cannot be determined or it is not OK.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/sequel/adapters/postgres.rb', line 109 def check_disconnect_errors begin yield rescue PGError => e disconnect = false begin s = status rescue PGError disconnect = true end status_ok = (s == Adapter::CONNECTION_OK) disconnect ||= !status_ok disconnect ||= e. =~ DISCONNECT_ERROR_RE disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise ensure block if status_ok && !disconnect end end |
#execute(sql, args = nil) ⇒ Object
Execute the given SQL with this connection. If a block is given, yield the results, otherwise, return the number of changed rows.
130 131 132 133 134 135 136 137 138 |
# File 'lib/sequel/adapters/postgres.rb', line 130 def execute(sql, args=nil) args = args.map{|v| @db.bound_variable_arg(v, self)} if args q = check_disconnect_errors{execute_query(sql, args)} begin block_given? ? yield(q) : q.cmd_tuples ensure q.clear if q && q.respond_to?(:clear) end end |