Class: DataObject::Postgres::Connection

Inherits:
Connection
  • Object
show all
Defined in:
lib/do_postgres.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_string) ⇒ Connection

Returns a new instance of Connection.



13
14
15
16
# File 'lib/do_postgres.rb', line 13

def initialize(connection_string)
  @state = STATE_CLOSED        
  @connection_string = connection_string
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



11
12
13
# File 'lib/do_postgres.rb', line 11

def db
  @db
end

Instance Method Details

#closeObject



27
28
29
30
31
# File 'lib/do_postgres.rb', line 27

def close
  Postgres_c.PQfinish(@db)
  @state = STATE_CLOSED
  true
end

#create_command(text) ⇒ Object



33
34
35
# File 'lib/do_postgres.rb', line 33

def create_command(text)
  Command.new(self, text)
end

#openObject



18
19
20
21
22
23
24
25
# File 'lib/do_postgres.rb', line 18

def open
  @db = Postgres_c.PQconnectdb(@connection_string)
  if Postgres_c.PQstatus(@db) != Postgres_c::CONNECTION_OK
    raise ConnectionFailed, "The connection with connection string #{@connection_string} failed\n#{Postgres_c.PQerrorMessage(@db)}"
  end
  @state = STATE_OPEN
  true
end