File: test_statement_execute.rb

package info (click to toggle)
ruby-sqlite3 1.3.9-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 468 kB
  • ctags: 769
  • sloc: ruby: 3,824; ansic: 1,198; makefile: 10
file content (35 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download | duplicates (6)
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
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 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