Class: DataObject::Sqlite3::Connection
- Inherits:
-
Connection
- Object
- Connection
- DataObject::Sqlite3::Connection
- Defined in:
- lib/do_sqlite3.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
- #close ⇒ Object
- #create_command(text) ⇒ Object
-
#initialize(connection_string) ⇒ Connection
constructor
A new instance of Connection.
- #open ⇒ Object
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
#db ⇒ Object (readonly)
Returns the value of attribute db.
12 13 14 |
# File 'lib/do_sqlite3.rb', line 12 def db @db end |
Instance Method Details
#close ⇒ Object
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 |
#open ⇒ Object
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 |