Class: TC_Mysql2

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
ext/test.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



97
98
99
100
101
102
103
104
# File 'ext/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

#teardownObject



105
106
107
# File 'ext/test.rb', line 105

def teardown()
  @m.close
end

#test_affected_rowsObject



109
110
111
112
113
# File 'ext/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_autocommitObject



115
116
117
118
119
120
# File 'ext/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_resultObject

def test_ssl_set()

end


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'ext/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_resultObject



160
161
162
163
164
165
166
# File 'ext/test.rb', line 160

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_reconnectObject



168
169
170
171
172
173
174
# File 'ext/test.rb', line 168

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_optionObject



145
146
147
148
149
150
# File 'ext/test.rb', line 145

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_sqlstateObject



152
153
154
155
156
157
158
# File 'ext/test.rb', line 152

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