title: Is it okay not to close db for sqlite3
body: <p>Here is my method </p>
  
  <pre><code>def convertElsToMass(symbol)
      begin
         db = SQLite3::Database.open("test.db")
  
         rs = db.prepare("SELECT * FROM Elements WHERE symbol = '#{symbol}    '")
         temp = rs.execute
         mass = temp.first
  
         rescue SQLite3::Exeption =&gt; e
              puts e
  
         ensure
              db.close if db
      end       
      return mass[3]   
  end
  </code></pre>
  
  <p>When I test this method using rspec I get this error message: </p>
  
  <pre><code> 1) PeriodicTable should change Elements to mass of Elements
   Failure/Error: expect(table.convertElsToMass("Na")).to eq(22.9898)
   SQLite3::BusyException:
     unable to close due to unfinalized statements or unfinished backups
   # ./lib/formatel.rb:42:in `close'
   # ./lib/formatel.rb:42:in `convertElsToMass'
   # ./spec/lib/pt_spec.rb:13:in `block (2 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>I notice I if I don't put the line <code>db.close if db</code> this method does exactly as I expect. However I'm worried what the consequences are if I don't close the db after I execute a query. How can I fix this so that I close the db after I execute a query?</p>