Class: Sequel::Fdbsql::Connection

Inherits:
PG::Connection
  • Object
show all
Defined in:
lib/sequel/adapters/fdbsql.rb

Overview

Connection specific methods for Fdbsql with pg

Constant Summary collapse

DISCONNECT_ERROR_RE =

Regular expression for error messages that note that the connection is closed.

/\A(?:could not receive data from server|no connection to the server|connection not open|connection is closed)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, opts) ⇒ Connection

Create a new connection to the FoundationDB SQL Layer. See Database#connect.



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/sequel/adapters/fdbsql.rb', line 213

def initialize(db, opts)
  connect_opts = {
    :host => opts[:host] || 'localhost',
    :port => opts[:port] || 15432,
    :dbname => opts[:database],
    :user => opts[:user],
    :password => opts[:password],
    :hostaddr => opts[:hostaddr],
    :connect_timeout => opts[:connect_timeout] || 20,
    :sslmode => opts[:sslmode]
  }.delete_if{|key, value| value.nil? or (value.respond_to?(:empty?) and value.empty?)}
	super(connect_opts)

  @db = db
  @prepared_statements = {}

  if opts[:notice_receiver]
    set_notice_receiver(opts[:notice_receiver])
  else
    # Swallow warnings
    set_notice_receiver{|proc| }
  end
end

Instance Attribute Details

#prepared_statementsObject

Hash of prepared statements for this connection. Keys are string names of the server side prepared statement, and values are SQL strings.



210
211
212
# File 'lib/sequel/adapters/fdbsql.rb', line 210

def prepared_statements
  @prepared_statements
end

Instance Method Details

#closeObject

Close the connection.



238
239
240
241
# File 'lib/sequel/adapters/fdbsql.rb', line 238

def close
  super
rescue PGError, IOError
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.



245
246
247
248
# File 'lib/sequel/adapters/fdbsql.rb', line 245

def execute(sql, args=nil)
  q = query(sql, args)
  block_given? ? yield(q) : q.cmd_tuples
end

#execute_prepared_statement(name, args) ⇒ Object

Execute the prepared statement of the given name, binding the given args.



252
253
254
# File 'lib/sequel/adapters/fdbsql.rb', line 252

def execute_prepared_statement(name, args)
  check_disconnect_errors{exec_prepared(name, args)}
end

#prepare(name, sql) ⇒ Object

Prepare a statement for later use.



257
258
259
# File 'lib/sequel/adapters/fdbsql.rb', line 257

def prepare(name, sql)
  check_disconnect_errors{super}
end

#query(sql, args = nil) ⇒ Object

Execute the given query and return the results.



262
263
264
265
# File 'lib/sequel/adapters/fdbsql.rb', line 262

def query(sql, args=nil)
  args = args.map{|v| @db.bound_variable_arg(v, self)} if args
  check_disconnect_errors{super}
end