Class: DataObject::Sqlite3::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_string) ⇒ Connection

Returns a new instance of Connection.



14
15
16
17
18
# File 'lib/do_sqlite3.rb', line 14

def initialize(connection_string)
  @state = STATE_CLOSED        
  @connection_string = connection_string
  @conn = Hash[*connection_string.split(" ").map {|x| x.split("=")}.flatten]["dbname"]
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



12
13
14
# File 'lib/do_sqlite3.rb', line 12

def db
  @db
end

Instance Method Details

#closeObject



31
32
33
34
35
# File 'lib/do_sqlite3.rb', line 31

def close
  Sqlite3_c.sqlite3_close(@db)
  @state = STATE_CLOSED
  true
end

#create_command(text) ⇒ Object



37
38
39
# File 'lib/do_sqlite3.rb', line 37

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

#openObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/do_sqlite3.rb', line 20

def open
  r, d = Sqlite3_c.sqlite3_open(@conn)
  unless r == Sqlite3_c::SQLITE_OK
    raise ConnectionFailed, "Unable to connect to database with provided connection string. \n#{Sqlite3_c.sqlite3_errmsg(d)}"
  else
    @db = d
  end
  @state = STATE_OPEN
  true
end