class TC_Mysql2

Public Instance Methods

setup() click to toggle source
# File test.rb, line 97
def setup()
  @host, @user, @pass, db, port, sock, flag = ARGV
  @db = db || "test"
  @port = port.to_i
  @sock = sock.nil? || sock.empty? ? nil : sock
  @flag = flag.to_i
  @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)
end
teardown() click to toggle source
# File test.rb, line 105
def teardown()
  @m.close if @m
end
test_affected_rows() click to toggle source
# File test.rb, line 109
def test_affected_rows()
  @m.query("create temporary table t (id int)")
  @m.query("insert into t values (1)")
  assert_equal(1, @m.affected_rows)
end
test_autocommit() click to toggle source
# File test.rb, line 115
def test_autocommit()
  if @m.methods.include? "autocommit" then
    assert_equal(@m, @m.autocommit(true))
    assert_equal(@m, @m.autocommit(false))
  end
end
test_more_results_next_result() click to toggle source

def test_ssl_set() end

# File test.rb, line 125
def test_more_results_next_result()
  if @m.server_version >= 40100 then
    @m.query_with_result = false
    @m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON) if defined? Mysql::OPTION_MULTI_STATEMENTS_ON
    @m.query("select 1,2,3; select 4,5,6")
    res = @m.store_result
    assert_equal(["1","2","3"], res.fetch_row)
    assert_equal(nil, res.fetch_row)
    assert_equal(true, @m.more_results)
    assert_equal(true, @m.more_results?)
    assert_equal(true, @m.next_result)
    res = @m.store_result
    assert_equal(["4","5","6"], res.fetch_row)
    assert_equal(nil, res.fetch_row)
    assert_equal(false, @m.more_results)
    assert_equal(false, @m.more_results?)
    assert_equal(false, @m.next_result)
  end
end
test_query_with_block() click to toggle source
# File test.rb, line 145
def test_query_with_block()
  if @m.server_version >= 40100 then
    @m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON)
    expect = [["1","2","3"], ["4","5","6"]]
    @m.query("select 1,2,3; select 4,5,6") {|res|
      assert_equal(1, res.num_rows)
      assert_equal(expect.shift, res.fetch_row)
    }
    assert(expect.empty?)
    expect = [["1","2","3"], ["4","5","6"]]
    assert_raises(Mysql::Error) {
      @m.query("select 1,2,3; hoge; select 4,5,6") {|res|
        assert_equal(1, res.num_rows)
        assert_equal(expect.shift, res.fetch_row)
      }
    }
    assert_equal(1, expect.size)
    expect = [["1","2","3"], ["4","5","6"]]
    assert_raises(Mysql::Error) {
      @m.query("select 1,2,3; select 4,5,6; hoge") {|res|
        assert_equal(1, res.num_rows)
        assert_equal(expect.shift, res.fetch_row)
      }
    }
    assert(expect.empty?)
  end
end
test_query_with_block_single() click to toggle source
# File test.rb, line 173
def test_query_with_block_single()
  @m.query("select 1,2,3") {|res|
    assert_equal(1, res.num_rows)
    assert_equal(["1","2","3"], res.fetch_row)
  }
end
test_query_with_result() click to toggle source
# File test.rb, line 195
def test_query_with_result()
  assert_equal(true, @m.query_with_result)
  assert_equal(false, @m.query_with_result = false)
  assert_equal(false, @m.query_with_result)
  assert_equal(true, @m.query_with_result = true)
  assert_equal(true, @m.query_with_result)
end
test_reconnect() click to toggle source
# File test.rb, line 203
def test_reconnect()
  assert_equal(false, @m.reconnect)
  assert_equal(true, @m.reconnect = true)
  assert_equal(true, @m.reconnect)
  assert_equal(false, @m.reconnect = false)
  assert_equal(false, @m.reconnect)
end
test_set_server_option() click to toggle source
# File test.rb, line 180
def test_set_server_option()
  if @m.server_version >= 40101 then
    assert_equal(@m, @m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON))
    assert_equal(@m, @m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_OFF))
  end
end
test_sqlstate() click to toggle source
# File test.rb, line 187
def test_sqlstate()
  if @m.server_version >= 40100 then
    assert_equal("00000", @m.sqlstate)
    assert_raises(Mysql::Error){@m.query("hogehoge")}
    assert_equal("42000", @m.sqlstate)
  end
end