File: test_statement_execute.rb

package info (click to toggle)
ruby-sqlite3 2.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 684 kB
  • sloc: ruby: 4,827; ansic: 1,868; sh: 91; makefile: 7
file content (40 lines) | stat: -rw-r--r-- 1,110 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
require "helper"

module SQLite3
  class TestStatementExecute < SQLite3::TestCase
    def setup
      @db = SQLite3::Database.new(":memory:")
      @db.execute_batch(
        "CREATE TABLE items (id integer PRIMARY KEY, number integer)"
      )
    end

    def teardown
      @db.close
    end

    def test_execute_insert
      ps = @db.prepare("INSERT INTO items (number) VALUES (:n)")
      ps.execute("n" => 10)
      assert_equal 1, @db.get_first_value("SELECT count(*) FROM items")
      ps.close
    end

    def test_execute_update
      @db.execute("INSERT INTO items (number) VALUES (?)", [10])

      ps = @db.prepare("UPDATE items SET number = :new WHERE number = :old")
      ps.execute("old" => 10, "new" => 20)
      assert_equal 20, @db.get_first_value("SELECT number FROM items")
      ps.close
    end

    def test_execute_delete
      @db.execute("INSERT INTO items (number) VALUES (?)", [20])
      ps = @db.prepare("DELETE FROM items WHERE number = :n")
      ps.execute("n" => 20)
      assert_equal 0, @db.get_first_value("SELECT count(*) FROM items")
      ps.close
    end
  end
end