File: test_result_set.rb

package info (click to toggle)
ruby-sqlite3 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 680 kB
  • sloc: ruby: 4,827; ansic: 1,868; sh: 91; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 1,062 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require "helper"

module SQLite3
  class TestResultSet < SQLite3::TestCase
    def setup
      @db = SQLite3::Database.new ":memory:"
      super
    end

    def teardown
      super
      @db.close
    end

    def test_each_hash
      @db.execute "create table foo ( a integer primary key, b text )"
      list = ("a".."z").to_a
      list.each do |t|
        @db.execute "insert into foo (b) values (\"#{t}\")"
      end

      rs = @db.prepare("select * from foo").execute
      rs.each_hash do |hash|
        assert_equal list[hash["a"] - 1], hash["b"]
      end
      rs.close
    end

    def test_next_hash
      @db.execute "create table foo ( a integer primary key, b text )"
      list = ("a".."z").to_a
      list.each do |t|
        @db.execute "insert into foo (b) values (\"#{t}\")"
      end

      rs = @db.prepare("select * from foo").execute
      rows = []
      while (row = rs.next_hash)
        rows << row
      end
      rows.each do |hash|
        assert_equal list[hash["a"] - 1], hash["b"]
      end
      rs.close
    end
  end
end