skaes-mysql 2.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (10) hide show
  1. data/COPYING +56 -0
  2. data/COPYING.ja +51 -0
  3. data/README.html +1087 -0
  4. data/README_ja.html +1312 -0
  5. data/extconf.rb +73 -0
  6. data/mysql.c.in +2302 -0
  7. data/mysql.gemspec +61 -0
  8. data/test.rb +1442 -0
  9. data/tommy.css +134 -0
  10. metadata +60 -0
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mysql
3
+ version: !ruby/object:Gem::Version
4
+ version: "2.7.7"
5
+ platform: ruby
6
+ authors: [skaes@railsexpress.de]
7
+
8
+ autorequire: mysql
9
+ bindir:
10
+ cert_chain:
11
+ date:
12
+ default_executable:
13
+ dependencies: []
14
+
15
+ description:
16
+ email: skaes@railsexpress.de
17
+ executables: []
18
+
19
+ extensions:
20
+ - extconf.rb
21
+ extra_rdoc_files: []
22
+
23
+ files:
24
+ - COPYING
25
+ - COPYING.ja
26
+ - README.html
27
+ - README_ja.html
28
+ - extconf.rb
29
+ - mysql.c.in
30
+ - test.rb
31
+ - tommy.css
32
+ - mysql.gemspec
33
+ has_rdoc: false
34
+ homepage: http://www.tmtm.org/en/mysql/ruby/
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">"
43
+ - !ruby/object:Gem::Version
44
+ version: 0.0.0
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.2.0
56
+ signing_key:
57
+ specification_version: 1
58
+ summary: MySQL/Ruby provides the same functions for Ruby programs that the MySQL C API provides for C programs.
59
+ test_files: []
60
+
61
+
data/test.rb ADDED
@@ -0,0 +1,1442 @@
1
+ #!/usr/local/bin/ruby
2
+ # $Id: test.rb 236 2008-09-29 14:53:08Z tommy $
3
+
4
+ require "test/unit"
5
+ require "./mysql.o"
6
+
7
+ class TC_Mysql < Test::Unit::TestCase
8
+ def setup()
9
+ @host, @user, @pass, db, port, sock, flag = ARGV
10
+ @db = db || "test"
11
+ @port = port.to_i
12
+ @sock = sock.nil? || sock.empty? ? nil : sock
13
+ @flag = flag.to_i
14
+ end
15
+ def teardown()
16
+ end
17
+
18
+ def test_version()
19
+ assert_equal(20707, Mysql::VERSION)
20
+ end
21
+
22
+ def test_init()
23
+ assert_nothing_raised{@m = Mysql.init}
24
+ assert_nothing_raised{@m.close}
25
+ end
26
+
27
+ def test_real_connect()
28
+ assert_nothing_raised{@m = Mysql.real_connect(@host, @user, @pass, @db, @port, @sock, @flag)}
29
+ assert_nothing_raised{@m.close}
30
+ end
31
+
32
+ def test_connect()
33
+ assert_nothing_raised{@m = Mysql.connect(@host, @user, @pass, @db, @port, @sock, @flag)}
34
+ assert_nothing_raised{@m.close}
35
+ end
36
+
37
+ def test_new()
38
+ assert_nothing_raised{@m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)}
39
+ assert_nothing_raised{@m.close}
40
+ end
41
+
42
+ def test_escape_string()
43
+ assert_equal("abc\\'def\\\"ghi\\0jkl%mno", Mysql.escape_string("abc'def\"ghi\0jkl%mno"))
44
+ end
45
+
46
+ def test_quote()
47
+ assert_equal("abc\\'def\\\"ghi\\0jkl%mno", Mysql.quote("abc'def\"ghi\0jkl%mno"))
48
+ end
49
+
50
+ def test_get_client_info()
51
+ assert_match(/^\d.\d+.\d+[a-z]?(-.*)?$/, Mysql.get_client_info())
52
+ end
53
+
54
+ def test_client_info()
55
+ assert_match(/^\d.\d+.\d+[a-z]?(-.*)?$/, Mysql.client_info())
56
+ end
57
+
58
+ def test_options()
59
+ @m = Mysql.init
60
+ assert_equal(@m, @m.options(Mysql::INIT_COMMAND, "SET AUTOCOMMIT=0"))
61
+ assert_equal(@m, @m.options(Mysql::OPT_COMPRESS))
62
+ assert_equal(@m, @m.options(Mysql::OPT_CONNECT_TIMEOUT, 10))
63
+ assert_equal(@m, @m.options(Mysql::GUESS_CONNECTION)) if defined? Mysql::GUESS_CONNECTION
64
+ assert_equal(@m, @m.options(Mysql::OPT_LOCAL_INFILE, true))
65
+ # assert_equal(@m, @m.options(Mysql::OPT_NAMED_PIPE))
66
+ # assert_equal(@m, @m.options(Mysql::OPT_PROTOCOL, 1))
67
+ assert_equal(@m, @m.options(Mysql::OPT_READ_TIMEOUT, 10)) if defined? Mysql::OPT_READ_TIMEOUT
68
+ assert_equal(@m, @m.options(Mysql::OPT_USE_EMBEDDED_CONNECTION)) if defined? Mysql::OPT_USE_EMBEDDED_CONNECTION
69
+ assert_equal(@m, @m.options(Mysql::OPT_USE_REMOTE_CONNECTION)) if defined? Mysql::OPT_USE_REMOTE_CONNECTION
70
+ assert_equal(@m, @m.options(Mysql::OPT_WRITE_TIMEOUT, 10)) if defined? Mysql::OPT_WRITE_TIMEOUT
71
+ # assert_equal(@m, @m.options(Mysql::READ_DEFAULT_FILE, "/tmp/hoge"))
72
+ assert_equal(@m, @m.options(Mysql::READ_DEFAULT_GROUP, "test"))
73
+ assert_equal(@m, @m.options(Mysql::SECURE_AUTH, true)) if defined? Mysql::SECURE_AUTH
74
+ # assert_equal(@m, @m.options(Mysql::SET_CHARSET_DIR, "??"))
75
+ assert_equal(@m, @m.options(Mysql::SET_CHARSET_NAME, "latin1"))
76
+ assert_equal(@m, @m.options(Mysql::SET_CLIENT_IP, "127.0.0.1")) if defined? Mysql::SET_CLIENT_IP
77
+ # assert_equal(@m, @m.options(Mysql::SHARED_MEMORY_BASE_NAME, "xxx"))
78
+ assert_equal(@m, @m.connect(@host, @user, @pass, @db, @port, @sock, @flag))
79
+ @m.close
80
+ end
81
+
82
+ def test_real_connect2()
83
+ @m = Mysql.init
84
+ assert_equal(@m, @m.real_connect(@host, @user, @pass, @db, @port, @sock, @flag))
85
+ @m.close
86
+ end
87
+
88
+ def test_connect2()
89
+ @m = Mysql.init
90
+ assert_equal(@m, @m.connect(@host, @user, @pass, @db, @port, @sock, @flag))
91
+ @m.close
92
+ end
93
+
94
+ end
95
+
96
+ class TC_Mysql2 < Test::Unit::TestCase
97
+ def setup()
98
+ @host, @user, @pass, db, port, sock, flag = ARGV
99
+ @db = db || "test"
100
+ @port = port.to_i
101
+ @sock = sock.nil? || sock.empty? ? nil : sock
102
+ @flag = flag.to_i
103
+ @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)
104
+ end
105
+ def teardown()
106
+ @m.close if @m
107
+ end
108
+
109
+ def test_affected_rows()
110
+ @m.query("create temporary table t (id int)")
111
+ @m.query("insert into t values (1)")
112
+ assert_equal(1, @m.affected_rows)
113
+ end
114
+
115
+ def test_autocommit()
116
+ if @m.methods.include? "autocommit" then
117
+ assert_equal(@m, @m.autocommit(true))
118
+ assert_equal(@m, @m.autocommit(false))
119
+ end
120
+ end
121
+
122
+ # def test_ssl_set()
123
+ # end
124
+
125
+ def test_more_results_next_result()
126
+ if @m.server_version >= 40100 then
127
+ @m.query_with_result = false
128
+ @m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON) if defined? Mysql::OPTION_MULTI_STATEMENTS_ON
129
+ @m.query("select 1,2,3; select 4,5,6")
130
+ res = @m.store_result
131
+ assert_equal(["1","2","3"], res.fetch_row)
132
+ assert_equal(nil, res.fetch_row)
133
+ assert_equal(true, @m.more_results)
134
+ assert_equal(true, @m.more_results?)
135
+ assert_equal(true, @m.next_result)
136
+ res = @m.store_result
137
+ assert_equal(["4","5","6"], res.fetch_row)
138
+ assert_equal(nil, res.fetch_row)
139
+ assert_equal(false, @m.more_results)
140
+ assert_equal(false, @m.more_results?)
141
+ assert_equal(false, @m.next_result)
142
+ end
143
+ end if Mysql.client_version >= 40100
144
+
145
+ def test_query_with_block()
146
+ if @m.server_version >= 40100 then
147
+ expect = [["1","2","3"], ["4","5","6"]]
148
+ @m.query("select 1,2,3; select 4,5,6") {|res|
149
+ assert_equal(1, res.num_rows)
150
+ assert_equal(expect.shift, res.fetch_row)
151
+ }
152
+ assert(expect.empty?)
153
+ expect = [["1","2","3"], ["4","5","6"]]
154
+ assert_raises(Mysql::Error) {
155
+ @m.query("select 1,2,3; hoge; select 4,5,6") {|res|
156
+ assert_equal(1, res.num_rows)
157
+ assert_equal(expect.shift, res.fetch_row)
158
+ }
159
+ }
160
+ assert_equal(1, expect.size)
161
+ expect = [["1","2","3"], ["4","5","6"]]
162
+ assert_raises(Mysql::Error) {
163
+ @m.query("select 1,2,3; select 4,5,6; hoge") {|res|
164
+ assert_equal(1, res.num_rows)
165
+ assert_equal(expect.shift, res.fetch_row)
166
+ }
167
+ }
168
+ assert(expect.empty?)
169
+ end
170
+ end
171
+
172
+ def test_set_server_option()
173
+ if @m.server_version >= 40101 then
174
+ assert_equal(@m, @m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON))
175
+ assert_equal(@m, @m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_OFF))
176
+ end
177
+ end if Mysql.client_version >= 40101
178
+
179
+ def test_sqlstate()
180
+ if @m.server_version >= 40100 then
181
+ assert_equal("00000", @m.sqlstate)
182
+ assert_raises(Mysql::Error){@m.query("hogehoge")}
183
+ assert_equal("42000", @m.sqlstate)
184
+ end
185
+ end if Mysql.client_version >= 40100
186
+
187
+ def test_query_with_result()
188
+ assert_equal(true, @m.query_with_result)
189
+ assert_equal(false, @m.query_with_result = false)
190
+ assert_equal(false, @m.query_with_result)
191
+ assert_equal(true, @m.query_with_result = true)
192
+ assert_equal(true, @m.query_with_result)
193
+ end
194
+
195
+ def test_reconnect()
196
+ assert_equal(false, @m.reconnect)
197
+ assert_equal(true, @m.reconnect = true)
198
+ assert_equal(true, @m.reconnect)
199
+ assert_equal(false, @m.reconnect = false)
200
+ assert_equal(false, @m.reconnect)
201
+ end
202
+ end
203
+
204
+ class TC_MysqlRes < Test::Unit::TestCase
205
+ def setup()
206
+ @host, @user, @pass, db, port, sock, flag = ARGV
207
+ @db = db || "test"
208
+ @port = port.to_i
209
+ @sock = sock.nil? || sock.empty? ? nil : sock
210
+ @flag = flag.to_i
211
+ @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)
212
+ @m.query("create temporary table t (id int, str char(10), primary key (id))")
213
+ @m.query("insert into t values (1, 'abc'), (2, 'defg'), (3, 'hi'), (4, null)")
214
+ @res = @m.query("select * from t")
215
+ end
216
+ def teardown()
217
+ @res.free
218
+ @m.close
219
+ end
220
+
221
+ def test_num_fields()
222
+ assert_equal(2, @res.num_fields)
223
+ end
224
+
225
+ def test_num_rows()
226
+ assert_equal(4, @res.num_rows)
227
+ end
228
+
229
+ def test_fetch_row()
230
+ assert_equal(["1","abc"], @res.fetch_row)
231
+ assert_equal(["2","defg"], @res.fetch_row)
232
+ assert_equal(["3","hi"], @res.fetch_row)
233
+ assert_equal(["4",nil], @res.fetch_row)
234
+ assert_equal(nil, @res.fetch_row)
235
+ end
236
+
237
+ def test_fetch_hash()
238
+ assert_equal({"id"=>"1", "str"=>"abc"}, @res.fetch_hash)
239
+ assert_equal({"id"=>"2", "str"=>"defg"}, @res.fetch_hash)
240
+ assert_equal({"id"=>"3", "str"=>"hi"}, @res.fetch_hash)
241
+ assert_equal({"id"=>"4", "str"=>nil}, @res.fetch_hash)
242
+ assert_equal(nil, @res.fetch_hash)
243
+ end
244
+
245
+ def test_fetch_hash2()
246
+ assert_equal({"t.id"=>"1", "t.str"=>"abc"}, @res.fetch_hash(true))
247
+ assert_equal({"t.id"=>"2", "t.str"=>"defg"}, @res.fetch_hash(true))
248
+ assert_equal({"t.id"=>"3", "t.str"=>"hi"}, @res.fetch_hash(true))
249
+ assert_equal({"t.id"=>"4", "t.str"=>nil}, @res.fetch_hash(true))
250
+ assert_equal(nil, @res.fetch_hash)
251
+ end
252
+
253
+ def test_each()
254
+ ary = [["1","abc"], ["2","defg"], ["3","hi"], ["4",nil]]
255
+ @res.each do |a|
256
+ assert_equal(ary.shift, a)
257
+ end
258
+ end
259
+
260
+ def test_each_hash()
261
+ hash = [{"id"=>"1","str"=>"abc"}, {"id"=>"2","str"=>"defg"}, {"id"=>"3","str"=>"hi"}, {"id"=>"4","str"=>nil}]
262
+ @res.each_hash do |h|
263
+ assert_equal(hash.shift, h)
264
+ end
265
+ end
266
+
267
+ def test_data_seek()
268
+ assert_equal(["1","abc"], @res.fetch_row)
269
+ assert_equal(["2","defg"], @res.fetch_row)
270
+ assert_equal(["3","hi"], @res.fetch_row)
271
+ @res.data_seek(1)
272
+ assert_equal(["2","defg"], @res.fetch_row)
273
+ end
274
+
275
+ def test_row_seek()
276
+ assert_equal(["1","abc"], @res.fetch_row)
277
+ pos = @res.row_tell
278
+ assert_equal(["2","defg"], @res.fetch_row)
279
+ assert_equal(["3","hi"], @res.fetch_row)
280
+ @res.row_seek(pos)
281
+ assert_equal(["2","defg"], @res.fetch_row)
282
+ end
283
+
284
+ def test_field_seek()
285
+ assert_equal(0, @res.field_tell)
286
+ @res.fetch_field
287
+ assert_equal(1, @res.field_tell)
288
+ @res.fetch_field
289
+ assert_equal(2, @res.field_tell)
290
+ @res.field_seek(1)
291
+ assert_equal(1, @res.field_tell)
292
+ end
293
+
294
+ def test_fetch_field()
295
+ f = @res.fetch_field
296
+ assert_equal("id", f.name)
297
+ assert_equal("t", f.table)
298
+ assert_equal(nil, f.def)
299
+ assert_equal(Mysql::Field::TYPE_LONG, f.type)
300
+ assert_equal(11, f.length)
301
+ assert_equal(1, f.max_length)
302
+ assert_equal(Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG, f.flags)
303
+ assert_equal(0, f.decimals)
304
+ f = @res.fetch_field
305
+ assert_equal("str", f.name)
306
+ assert_equal("t", f.table)
307
+ assert_equal(nil, f.def)
308
+ assert_equal(Mysql::Field::TYPE_STRING, f.type)
309
+ assert_equal(10, f.length)
310
+ assert_equal(4, f.max_length)
311
+ assert_equal(0, f.flags)
312
+ assert_equal(0, f.decimals)
313
+ f = @res.fetch_field
314
+ assert_equal(nil, f)
315
+ end
316
+
317
+ def test_fetch_fields()
318
+ a = @res.fetch_fields
319
+ assert_equal(2, a.size)
320
+ assert_equal("id", a[0].name)
321
+ assert_equal("str", a[1].name)
322
+ end
323
+
324
+ def test_fetch_field_direct()
325
+ f = @res.fetch_field_direct(0)
326
+ assert_equal("id", f.name)
327
+ f = @res.fetch_field_direct(1)
328
+ assert_equal("str", f.name)
329
+ assert_raises(Mysql::Error){@res.fetch_field_direct(-1)}
330
+ assert_raises(Mysql::Error){@res.fetch_field_direct(2)}
331
+ end
332
+
333
+ def test_fetch_lengths()
334
+ assert_equal(nil, @res.fetch_lengths())
335
+ @res.fetch_row
336
+ assert_equal([1, 3], @res.fetch_lengths())
337
+ @res.fetch_row
338
+ assert_equal([1, 4], @res.fetch_lengths())
339
+ @res.fetch_row
340
+ assert_equal([1, 2], @res.fetch_lengths())
341
+ @res.fetch_row
342
+ assert_equal([1, 0], @res.fetch_lengths())
343
+ @res.fetch_row
344
+ assert_equal(nil, @res.fetch_lengths())
345
+ end
346
+
347
+ def test_field_hash()
348
+ f = @res.fetch_field
349
+ h = {
350
+ "name" => "id",
351
+ "table" => "t",
352
+ "def" => nil,
353
+ "type" => Mysql::Field::TYPE_LONG,
354
+ "length" => 11,
355
+ "max_length" => 1,
356
+ "flags" => Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG,
357
+ "decimals" => 0,
358
+ }
359
+ assert_equal(h, f.hash)
360
+ f = @res.fetch_field
361
+ h = {
362
+ "name" => "str",
363
+ "table" => "t",
364
+ "def" => nil,
365
+ "type" => Mysql::Field::TYPE_STRING,
366
+ "length" => 10,
367
+ "max_length" => 4,
368
+ "flags" => 0,
369
+ "decimals" => 0,
370
+ }
371
+ assert_equal(h, f.hash)
372
+ end
373
+
374
+ def test_field_inspect()
375
+ f = @res.fetch_field
376
+ assert_equal("#<Mysql::Field:id>", f.inspect)
377
+ f = @res.fetch_field
378
+ assert_equal("#<Mysql::Field:str>", f.inspect)
379
+ end
380
+
381
+ def test_is_num()
382
+ f = @res.fetch_field
383
+ assert_equal(true, f.is_num?)
384
+ f = @res.fetch_field
385
+ assert_equal(false, f.is_num?)
386
+ end
387
+
388
+ def test_is_not_null()
389
+ f = @res.fetch_field
390
+ assert_equal(true, f.is_not_null?)
391
+ f = @res.fetch_field
392
+ assert_equal(false, f.is_not_null?)
393
+ end
394
+
395
+ def test_is_pri_key()
396
+ f = @res.fetch_field
397
+ assert_equal(true, f.is_pri_key?)
398
+ f = @res.fetch_field
399
+ assert_equal(false, f.is_pri_key?)
400
+ end
401
+
402
+ end
403
+
404
+ class TC_MysqlStmt < Test::Unit::TestCase
405
+ def setup()
406
+ @host, @user, @pass, db, port, sock, flag = ARGV
407
+ @db = db || "test"
408
+ @port = port.to_i
409
+ @sock = sock.nil? || sock.empty? ? nil : sock
410
+ @flag = flag.to_i
411
+ @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)
412
+ end
413
+ def teardown()
414
+ end
415
+
416
+ def test_init()
417
+ if @m.server_version >= 40100 then
418
+ s = @m.stmt_init()
419
+ assert_equal(Mysql::Stmt, s.class)
420
+ s.close
421
+ end
422
+ end
423
+
424
+ def test_prepare()
425
+ if @m.server_version >= 40100 then
426
+ s = @m.prepare("select 1")
427
+ assert_equal(Mysql::Stmt, s.class)
428
+ s.close
429
+ end
430
+ end
431
+
432
+ end if Mysql.client_version >= 40100
433
+
434
+ class TC_MysqlStmt2 < Test::Unit::TestCase
435
+ def setup()
436
+ @host, @user, @pass, db, port, sock, flag = ARGV
437
+ @db = db || "test"
438
+ @port = port.to_i
439
+ @sock = sock.nil? || sock.empty? ? nil : sock
440
+ @flag = flag.to_i
441
+ @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)
442
+ @s = @m.stmt_init()
443
+ end
444
+ def teardown()
445
+ @s.close
446
+ @m.close
447
+ end
448
+
449
+ def test_affected_rows()
450
+ if @m.server_version >= 40100 then
451
+ @m.query("create temporary table t (i int, c char(10))")
452
+ @s.prepare("insert into t values (?,?)")
453
+ @s.execute(1, "hoge")
454
+ assert_equal(1, @s.affected_rows())
455
+ @s.execute(2, "hoge")
456
+ @s.execute(3, "hoge")
457
+ @s.prepare("update t set c=?")
458
+ @s.execute("fuga")
459
+ assert_equal(3, @s.affected_rows())
460
+ end
461
+ end
462
+
463
+ =begin
464
+ def test_attr_get()
465
+ assert_equal(false, @s.attr_get(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH))
466
+ assert_raises(Mysql::Error){@s.attr_get(999)}
467
+ end
468
+
469
+ def test_attr_set()
470
+ @s.attr_set(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH, true)
471
+ assert_equal(true, @s.attr_get(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH))
472
+ @s.attr_set(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH, false)
473
+ assert_equal(false, @s.attr_get(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH))
474
+ assert_raises(Mysql::Error){@s.attr_set(999, true)}
475
+ end
476
+
477
+ def test_bind_param()
478
+ @s.prepare("insert into t values (?,?)")
479
+ @s.bind_param(123, "abc")
480
+ @s.bind_param(Time.now, nil)
481
+ assert_raises(Mysql::Error){@s.bind_param(1, 2, 3)}
482
+ b = @s.bind_param(Bind.new(Mysql::TYPE_TINY, 99, false))
483
+ @s.bind_param(98.765, b)
484
+ end
485
+ =end
486
+
487
+ def test_bind_result_nil()
488
+ if @m.server_version >= 40100 then
489
+ @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
490
+ @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
491
+ @s.prepare("select * from t")
492
+ @s.bind_result(nil,nil,nil,nil)
493
+ @s.execute
494
+ a = @s.fetch
495
+ assert_equal([123, "9abcdefg", 1.2345, Mysql::Time.new(2005,8,2,23,50,11)], a)
496
+ end
497
+ end
498
+
499
+ def test_bind_result_numeric()
500
+ if @m.server_version >= 40100 then
501
+ @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
502
+ @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
503
+ @s.prepare("select * from t")
504
+ @s.bind_result(Numeric, Numeric, Numeric, Numeric)
505
+ @s.execute
506
+ a = @s.fetch
507
+ if Mysql.client_version < 50000 then
508
+ assert_equal([123, 9, 1, 2005], a)
509
+ else
510
+ assert_equal([123, 9, 1, 20050802235011], a)
511
+ end
512
+ end
513
+ end
514
+
515
+ def test_bind_result_integer()
516
+ if @m.server_version >= 40100 then
517
+ @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
518
+ @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
519
+ @s.prepare("select * from t")
520
+ @s.bind_result(Integer, Integer, Integer, Integer)
521
+ @s.execute
522
+ a = @s.fetch
523
+ if Mysql.client_version < 50000 then
524
+ assert_equal([123, 9, 1, 2005], a)
525
+ else
526
+ assert_equal([123, 9, 1, 20050802235011], a)
527
+ end
528
+ end
529
+ end
530
+
531
+ def test_bind_result_fixnum()
532
+ if @m.server_version >= 40100 then
533
+ @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
534
+ @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
535
+ @s.prepare("select * from t")
536
+ @s.bind_result(Fixnum, Fixnum, Fixnum, Fixnum)
537
+ @s.execute
538
+ a = @s.fetch
539
+ if Mysql.client_version < 50000 then
540
+ assert_equal([123, 9, 1, 2005], a)
541
+ else
542
+ assert_equal([123, 9, 1, 20050802235011.0], a)
543
+ end
544
+ end
545
+ end
546
+
547
+ def test_bind_result_string()
548
+ if @m.server_version >= 40100 then
549
+ @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
550
+ @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
551
+ @s.prepare("select * from t")
552
+ @s.bind_result(String, String, String, String)
553
+ @s.execute
554
+ a = @s.fetch
555
+ assert_equal(["123", "9abcdefg", "1.2345", "2005-08-02 23:50:11"], a)
556
+ end
557
+ end
558
+
559
+ def test_bind_result_float()
560
+ if @m.server_version >= 40100 then
561
+ @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
562
+ @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
563
+ @s.prepare("select * from t")
564
+ @s.bind_result(Float, Float, Float, Float)
565
+ @s.execute
566
+ a = @s.fetch
567
+ if Mysql.client_version < 50000 then
568
+ assert_equal([123.0, 9.0, 1.2345, 2005.0], a)
569
+ else
570
+ assert_equal([123.0, 9.0, 1.2345, 20050802235011.0], a)
571
+ end
572
+ end
573
+ end
574
+
575
+ def test_bind_result_mysqltime()
576
+ if @m.server_version >= 40100 then
577
+ @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
578
+ @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
579
+ @s.prepare("select * from t")
580
+ @s.bind_result(Mysql::Time, Mysql::Time, Mysql::Time, Mysql::Time)
581
+ @s.execute
582
+ a = @s.fetch
583
+ if Mysql.client_version < 50000 then
584
+ assert_equal([Mysql::Time.new, Mysql::Time.new, Mysql::Time.new, Mysql::Time.new(2005,8,2,23,50,11)], a)
585
+ else
586
+ assert_equal([Mysql::Time.new(2000,1,23), Mysql::Time.new, Mysql::Time.new, Mysql::Time.new(2005,8,2,23,50,11)], a)
587
+ end
588
+ end
589
+ end
590
+
591
+ def test_bind_result_unknown()
592
+ if @m.server_version >= 40100 then
593
+ @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
594
+ @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
595
+ @s.prepare("select * from t")
596
+ assert_raises(TypeError){@s.bind_result(Time, nil, nil, nil)}
597
+ end
598
+ end
599
+
600
+ def test_bind_result_unmatch_count()
601
+ if @m.server_version >= 40100 then
602
+ @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
603
+ @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
604
+ @s.prepare("select * from t")
605
+ assert_raises(Mysql::Error){@s.bind_result(nil, nil)}
606
+ end
607
+ end
608
+
609
+ def test_data_seek()
610
+ if @m.server_version >= 40100 then
611
+ @m.query("create temporary table t (i int)")
612
+ @m.query("insert into t values (0),(1),(2),(3),(4),(5)")
613
+ @s.prepare("select i from t")
614
+ @s.execute
615
+ assert_equal([0], @s.fetch)
616
+ assert_equal([1], @s.fetch)
617
+ assert_equal([2], @s.fetch)
618
+ @s.data_seek(5)
619
+ assert_equal([5], @s.fetch)
620
+ @s.data_seek(1)
621
+ assert_equal([1], @s.fetch)
622
+ end
623
+ end
624
+
625
+ =begin
626
+ def test_errno()
627
+ @s.errno()
628
+ end
629
+
630
+ def test_error()
631
+ @s.error()
632
+ end
633
+ =end
634
+
635
+ def test_execute()
636
+ if @m.server_version >= 40100 then
637
+ @m.query("create temporary table t (i int)")
638
+ @s.prepare("insert into t values (123)")
639
+ @s.execute()
640
+ assert_equal(1, @s.affected_rows)
641
+ @s.execute()
642
+ assert_equal(1, @s.affected_rows)
643
+ assert_equal(2, @m.query("select count(*) from t").fetch_row[0].to_i)
644
+ end
645
+ end
646
+
647
+ def test_execute2()
648
+ if @m.server_version >= 40100 then
649
+ @m.query("create temporary table t (i int)")
650
+ @s.prepare("insert into t values (?)")
651
+ @s.execute(123)
652
+ @s.execute("456")
653
+ @s.prepare("select * from t")
654
+ @s.execute
655
+ assert_equal([123], @s.fetch)
656
+ assert_equal([456], @s.fetch)
657
+ end
658
+ end
659
+
660
+ def test_execute3()
661
+ if @m.server_version >= 40100 then
662
+ @m.query("create temporary table t (i int, c char(255), t timestamp)")
663
+ @s.prepare("insert into t values (?,?,?)")
664
+ @s.execute(123, "hoge", Time.local(2005,7,19,23,53,0));
665
+ assert_raises(Mysql::Error){@s.execute(123, "hoge")}
666
+ assert_raises(Mysql::Error){@s.execute(123, "hoge", 0, "fuga")}
667
+ @s.prepare("select * from t")
668
+ @s.execute
669
+ assert_equal([123, "hoge", Mysql::Time.new(2005,7,19,23,53,0)], @s.fetch)
670
+ end
671
+ end
672
+
673
+ def test_execute4()
674
+ if @m.server_version >= 40100 then
675
+ @m.query("create temporary table t (i int, c char(255), t timestamp)")
676
+ @s.prepare("insert into t values (?,?,?)")
677
+ @s.execute(nil, "hoge", Mysql::Time.new(2005,7,19,23,53,0));
678
+ @s.prepare("select * from t")
679
+ @s.execute
680
+ assert_equal([nil, "hoge", Mysql::Time.new(2005,7,19,23,53,0)], @s.fetch)
681
+ end
682
+ end
683
+
684
+ def test_execute5()
685
+ if @m.server_version >= 40100 then
686
+ [30, 31, 32, 62, 63].each do |i|
687
+ v, = @m.prepare("select cast(? as signed)").execute(2**i-1).fetch
688
+ assert_equal(2**i-1, v)
689
+ v, = @m.prepare("select cast(? as signed)").execute(-(2**i)).fetch
690
+ assert_equal(-(2**i), v)
691
+ end
692
+ end
693
+ end
694
+
695
+ def test_fetch()
696
+ if @m.server_version >= 40100 then
697
+ @s.prepare("select 123, 'abc', null")
698
+ @s.execute()
699
+ assert_equal([123, "abc", nil], @s.fetch())
700
+ end
701
+ end
702
+
703
+ def test_fetch_bit()
704
+ if @m.client_version >= 50003 and @m.server_version >= 50003 then
705
+ @m.query("create temporary table t (i bit(8))")
706
+ @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255),(256)")
707
+ @s.prepare("select i from t")
708
+ @s.execute
709
+ assert_equal(["\x00"], @s.fetch)
710
+ assert_equal(["\xff"], @s.fetch)
711
+ assert_equal(["\x7f"], @s.fetch)
712
+ assert_equal(["\xff"], @s.fetch)
713
+ assert_equal(["\xff"], @s.fetch)
714
+ assert_equal(["\xff"], @s.fetch)
715
+ assert_equal(["\xff"], @s.fetch)
716
+ @m.query("create temporary table t2 (i bit(64))")
717
+ @m.query("insert into t2 values (0),(-1),(4294967296),(18446744073709551615),(18446744073709551616)")
718
+ @s.prepare("select i from t2")
719
+ @s.execute
720
+ assert_equal(["\x00\x00\x00\x00\x00\x00\x00\x00"], @s.fetch)
721
+ assert_equal(["\xff\xff\xff\xff\xff\xff\xff\xff"], @s.fetch)
722
+ assert_equal(["\x00\x00\x00\x01\x00\x00\x00\x00"], @s.fetch)
723
+ assert_equal(["\xff\xff\xff\xff\xff\xff\xff\xff"], @s.fetch)
724
+ assert_equal(["\xff\xff\xff\xff\xff\xff\xff\xff"], @s.fetch)
725
+ end
726
+ end
727
+
728
+ def test_fetch_tinyint()
729
+ if @m.server_version >= 40100 then
730
+ @m.query("create temporary table t (i tinyint)")
731
+ @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255)")
732
+ @s.prepare("select i from t")
733
+ @s.execute
734
+ assert_equal([0], @s.fetch)
735
+ assert_equal([-1], @s.fetch)
736
+ assert_equal([127], @s.fetch)
737
+ assert_equal([-128], @s.fetch)
738
+ assert_equal([127], @s.fetch)
739
+ assert_equal([-128], @s.fetch)
740
+ end
741
+ end
742
+
743
+ def test_fetch_tinyint_unsigned()
744
+ if @m.server_version >= 40100 then
745
+ @m.query("create temporary table t (i tinyint unsigned)")
746
+ @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255),(256)")
747
+ @s.prepare("select i from t")
748
+ @s.execute
749
+ assert_equal([0], @s.fetch)
750
+ assert_equal([0], @s.fetch)
751
+ assert_equal([127], @s.fetch)
752
+ assert_equal([0], @s.fetch)
753
+ assert_equal([255], @s.fetch)
754
+ assert_equal([0], @s.fetch)
755
+ assert_equal([255], @s.fetch)
756
+ end
757
+ end
758
+
759
+ def test_fetch_smallint()
760
+ if @m.server_version >= 40100 then
761
+ @m.query("create temporary table t (i smallint)")
762
+ @m.query("insert into t values (0),(-1),(32767),(-32768),(65535),(-65535),(65536)")
763
+ @s.prepare("select i from t")
764
+ @s.execute
765
+ assert_equal([0], @s.fetch)
766
+ assert_equal([-1], @s.fetch)
767
+ assert_equal([32767], @s.fetch)
768
+ assert_equal([-32768], @s.fetch)
769
+ assert_equal([32767], @s.fetch)
770
+ assert_equal([-32768], @s.fetch)
771
+ end
772
+ end
773
+
774
+ def test_fetch_smallint_unsigned()
775
+ if @m.server_version >= 40100 then
776
+ @m.query("create temporary table t (i smallint unsigned)")
777
+ @m.query("insert into t values (0),(-1),(32767),(-32768),(65535),(-65535),(65536)")
778
+ @s.prepare("select i from t")
779
+ @s.execute
780
+ assert_equal([0], @s.fetch)
781
+ assert_equal([0], @s.fetch)
782
+ assert_equal([32767], @s.fetch)
783
+ assert_equal([0], @s.fetch)
784
+ assert_equal([65535], @s.fetch)
785
+ assert_equal([0], @s.fetch)
786
+ assert_equal([65535], @s.fetch)
787
+ end
788
+ end
789
+
790
+ def test_fetch_mediumint()
791
+ if @m.server_version >= 40100 then
792
+ @m.query("create temporary table t (i mediumint)")
793
+ @m.query("insert into t values (0),(-1),(8388607),(-8388608),(16777215),(-16777215),(16777216)")
794
+ @s.prepare("select i from t")
795
+ @s.execute
796
+ assert_equal([0], @s.fetch)
797
+ assert_equal([-1], @s.fetch)
798
+ assert_equal([8388607], @s.fetch)
799
+ assert_equal([-8388608], @s.fetch)
800
+ assert_equal([8388607], @s.fetch)
801
+ assert_equal([-8388608], @s.fetch)
802
+ end
803
+ end
804
+
805
+ def test_fetch_mediumint_unsigned()
806
+ if @m.server_version >= 40100 then
807
+ @m.query("create temporary table t (i mediumint unsigned)")
808
+ @m.query("insert into t values (0),(-1),(8388607),(-8388608),(16777215),(-16777215),(16777216)")
809
+ @s.prepare("select i from t")
810
+ @s.execute
811
+ assert_equal([0], @s.fetch)
812
+ assert_equal([0], @s.fetch)
813
+ assert_equal([8388607], @s.fetch)
814
+ assert_equal([0], @s.fetch)
815
+ assert_equal([16777215], @s.fetch)
816
+ assert_equal([0], @s.fetch)
817
+ assert_equal([16777215], @s.fetch)
818
+ end
819
+ end
820
+
821
+ def test_fetch_int()
822
+ if @m.server_version >= 40100 then
823
+ @m.query("create temporary table t (i int)")
824
+ @m.query("insert into t values (0),(-1),(2147483647),(-2147483648),(4294967295),(-4294967295),(4294967296)")
825
+ @s.prepare("select i from t")
826
+ @s.execute
827
+ assert_equal([0], @s.fetch)
828
+ assert_equal([-1], @s.fetch)
829
+ assert_equal([2147483647], @s.fetch)
830
+ assert_equal([-2147483648], @s.fetch)
831
+ assert_equal([2147483647], @s.fetch)
832
+ assert_equal([-2147483648], @s.fetch)
833
+ end
834
+ end
835
+
836
+ def test_fetch_int_unsigned()
837
+ if @m.server_version >= 40100 then
838
+ @m.query("create temporary table t (i int unsigned)")
839
+ @m.query("insert into t values (0),(-1),(2147483647),(-2147483648),(4294967295),(-4294967295),(4294967296)")
840
+ @s.prepare("select i from t")
841
+ @s.execute
842
+ assert_equal([0], @s.fetch)
843
+ assert_equal([0], @s.fetch)
844
+ assert_equal([2147483647], @s.fetch)
845
+ assert_equal([0], @s.fetch)
846
+ assert_equal([4294967295], @s.fetch)
847
+ assert_equal([0], @s.fetch)
848
+ assert_equal([4294967295], @s.fetch)
849
+ end
850
+ end
851
+
852
+ def test_fetch_bigint()
853
+ if @m.server_version >= 40100 then
854
+ @m.query("create temporary table t (i bigint)")
855
+ @m.query("insert into t values (0),(-1),(9223372036854775807),(-9223372036854775808),(18446744073709551615),(-18446744073709551615),(18446744073709551616)")
856
+ @s.prepare("select i from t")
857
+ @s.execute
858
+ assert_equal([0], @s.fetch)
859
+ assert_equal([-1], @s.fetch)
860
+ assert_equal([9223372036854775807], @s.fetch)
861
+ assert_equal([-9223372036854775808], @s.fetch)
862
+ if @m.server_version >= 50000 then
863
+ assert_equal([9223372036854775807], @s.fetch)
864
+ else
865
+ assert_equal([-1], @s.fetch) # MySQL problem
866
+ end
867
+ assert_equal([-9223372036854775808], @s.fetch)
868
+ assert_equal([9223372036854775807], @s.fetch)
869
+ end
870
+ end
871
+
872
+ def test_fetch_bigint_unsigned()
873
+ if @m.server_version >= 40100 then
874
+ @m.query("create temporary table t (i bigint unsigned)")
875
+ @m.query("insert into t values (0),(-1),(9223372036854775807),(-9223372036854775808),(18446744073709551615),(-18446744073709551615),(18446744073709551616)")
876
+ @s.prepare("select i from t")
877
+ @s.execute
878
+ assert_equal([0], @s.fetch)
879
+ if @m.server_version >= 50000 then
880
+ assert_equal([0], @s.fetch)
881
+ else
882
+ assert_equal([18446744073709551615], @s.fetch) # MySQL problem
883
+ end
884
+ assert_equal([9223372036854775807], @s.fetch)
885
+ if @m.server_version >= 50000 then
886
+ assert_equal([0], @s.fetch)
887
+ else
888
+ assert_equal([9223372036854775808], @s.fetch) # MySQL problem
889
+ end
890
+ assert_equal([18446744073709551615], @s.fetch)
891
+ assert_equal([0], @s.fetch)
892
+ assert_equal([18446744073709551615], @s.fetch)
893
+ end
894
+ end
895
+
896
+ def test_fetch_float()
897
+ if @m.server_version >= 40100 then
898
+ @m.query("create temporary table t (i float)")
899
+ @m.query("insert into t values (0),(-3.402823466E+38),(-1.175494351E-38),(1.175494351E-38),(3.402823466E+38)")
900
+ @s.prepare("select i from t")
901
+ @s.execute
902
+ assert_equal([0], @s.fetch)
903
+ assert_in_delta(-3.402823466E+38, @s.fetch[0], 0.000000001E+38)
904
+ assert_in_delta(-1.175494351E-38, @s.fetch[0], 0.000000001E-38)
905
+ assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38)
906
+ assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38)
907
+ end
908
+ end
909
+
910
+ def test_fetch_float_unsigned()
911
+ if @m.server_version >= 40100 then
912
+ @m.query("create temporary table t (i float unsigned)")
913
+ @m.query("insert into t values (0),(-3.402823466E+38),(-1.175494351E-38),(1.175494351E-38),(3.402823466E+38)")
914
+ @s.prepare("select i from t")
915
+ @s.execute
916
+ assert_equal([0], @s.fetch)
917
+ assert_equal([0], @s.fetch)
918
+ assert_equal([0], @s.fetch)
919
+ assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38)
920
+ assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38)
921
+ end
922
+ end
923
+
924
+ def test_fetch_double()
925
+ if @m.server_version >= 40100 then
926
+ @m.query("create temporary table t (i double)")
927
+ @m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)")
928
+ @s.prepare("select i from t")
929
+ @s.execute
930
+ assert_equal([0], @s.fetch)
931
+ assert_in_delta(-Float::MAX, @s.fetch[0], Float::EPSILON)
932
+ assert_in_delta(-Float::MIN, @s.fetch[0], Float::EPSILON)
933
+ assert_in_delta(Float::MIN, @s.fetch[0], Float::EPSILON)
934
+ assert_in_delta(Float::MAX, @s.fetch[0], Float::EPSILON)
935
+ end
936
+ end
937
+
938
+ def test_fetch_double_unsigned()
939
+ if @m.server_version >= 40100 then
940
+ @m.query("create temporary table t (i double unsigned)")
941
+ @m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)")
942
+ @s.prepare("select i from t")
943
+ @s.execute
944
+ assert_equal([0], @s.fetch)
945
+ assert_equal([0], @s.fetch)
946
+ assert_equal([0], @s.fetch)
947
+ assert_in_delta(Float::MIN, @s.fetch[0], Float::EPSILON)
948
+ assert_in_delta(Float::MAX, @s.fetch[0], Float::EPSILON)
949
+ end
950
+ end
951
+
952
+ def test_fetch_decimal()
953
+ if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then
954
+ @m.query("create temporary table t (i decimal)")
955
+ @m.query("insert into t values (0),(9999999999),(-9999999999),(10000000000),(-10000000000)")
956
+ @s.prepare("select i from t")
957
+ @s.execute
958
+ assert_equal(["0"], @s.fetch)
959
+ assert_equal(["9999999999"], @s.fetch)
960
+ assert_equal(["-9999999999"], @s.fetch)
961
+ if @m.server_version < 50000 then
962
+ assert_equal(["10000000000"], @s.fetch) # MySQL problem
963
+ else
964
+ assert_equal(["9999999999"], @s.fetch)
965
+ end
966
+ assert_equal(["-9999999999"], @s.fetch)
967
+ end
968
+ end
969
+
970
+ def test_fetch_decimal_unsigned()
971
+ if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then
972
+ @m.query("create temporary table t (i decimal unsigned)")
973
+ @m.query("insert into t values (0),(9999999998),(9999999999),(-9999999998),(-9999999999),(10000000000),(-10000000000)")
974
+ @s.prepare("select i from t")
975
+ @s.execute
976
+ assert_equal(["0"], @s.fetch)
977
+ assert_equal(["9999999998"], @s.fetch)
978
+ assert_equal(["9999999999"], @s.fetch)
979
+ assert_equal(["0"], @s.fetch)
980
+ assert_equal(["0"], @s.fetch)
981
+ assert_equal(["9999999999"], @s.fetch)
982
+ assert_equal(["0"], @s.fetch)
983
+ end
984
+ end
985
+
986
+ def test_fetch_date()
987
+ if @m.server_version >= 40100 then
988
+ @m.query("create temporary table t (i date)")
989
+ @m.query("insert into t values ('0000-00-00'),('1000-01-01'),('9999-12-31')")
990
+ @s.prepare("select i from t")
991
+ @s.execute
992
+ assert_equal([Mysql::Time.new(0,0,0)], @s.fetch)
993
+ assert_equal([Mysql::Time.new(1000,1,1)], @s.fetch)
994
+ assert_equal([Mysql::Time.new(9999,12,31)], @s.fetch)
995
+ end
996
+ end
997
+
998
+ def test_fetch_datetime()
999
+ if @m.server_version >= 40100 then
1000
+ @m.query("create temporary table t (i datetime)")
1001
+ @m.query("insert into t values ('0000-00-00 00:00:00'),('1000-01-01 00:00:00'),('9999-12-31 23:59:59')")
1002
+ @s.prepare("select i from t")
1003
+ @s.execute
1004
+ assert_equal([Mysql::Time.new(0,0,0,0,0,0)], @s.fetch)
1005
+ assert_equal([Mysql::Time.new(1000,1,1,0,0,0)], @s.fetch)
1006
+ assert_equal([Mysql::Time.new(9999,12,31,23,59,59)], @s.fetch)
1007
+ end
1008
+ end
1009
+
1010
+ def test_fetch_timestamp()
1011
+ if @m.server_version >= 40100 then
1012
+ @m.query("create temporary table t (i timestamp)")
1013
+ @m.query("insert into t values ('1970-01-02 00:00:00'),('2037-12-30 23:59:59')")
1014
+ @s.prepare("select i from t")
1015
+ @s.execute
1016
+ assert_equal([Mysql::Time.new(1970,1,2,0,0,0)], @s.fetch)
1017
+ assert_equal([Mysql::Time.new(2037,12,30,23,59,59)], @s.fetch)
1018
+ end
1019
+ end
1020
+
1021
+ def test_fetch_time()
1022
+ if @m.server_version >= 40100 then
1023
+ @m.query("create temporary table t (i time)")
1024
+ @m.query("insert into t values ('-838:59:59'),(0),('838:59:59')")
1025
+ @s.prepare("select i from t")
1026
+ @s.execute
1027
+ assert_equal([Mysql::Time.new(0,0,0,838,59,59,true)], @s.fetch)
1028
+ assert_equal([Mysql::Time.new(0,0,0,0,0,0,false)], @s.fetch)
1029
+ assert_equal([Mysql::Time.new(0,0,0,838,59,59,false)], @s.fetch)
1030
+ end
1031
+ end
1032
+
1033
+ def test_fetch_year()
1034
+ if @m.server_version >= 40100 then
1035
+ @m.query("create temporary table t (i year)")
1036
+ @m.query("insert into t values (0),(70),(69),(1901),(2155)")
1037
+ @s.prepare("select i from t")
1038
+ @s.execute
1039
+ assert_equal([0], @s.fetch)
1040
+ assert_equal([1970], @s.fetch)
1041
+ assert_equal([2069], @s.fetch)
1042
+ assert_equal([1901], @s.fetch)
1043
+ assert_equal([2155], @s.fetch)
1044
+ end
1045
+ end
1046
+
1047
+ def test_fetch_char()
1048
+ if @m.server_version >= 40100 then
1049
+ @m.query("create temporary table t (i char(10))")
1050
+ @m.query("insert into t values (null),('abc')")
1051
+ @s.prepare("select i from t")
1052
+ @s.execute
1053
+ assert_equal([nil], @s.fetch)
1054
+ assert_equal(["abc"], @s.fetch)
1055
+ end
1056
+ end
1057
+
1058
+ def test_fetch_varchar()
1059
+ if @m.server_version >= 40100 then
1060
+ @m.query("create temporary table t (i varchar(10))")
1061
+ @m.query("insert into t values (null),('abc')")
1062
+ @s.prepare("select i from t")
1063
+ @s.execute
1064
+ assert_equal([nil], @s.fetch)
1065
+ assert_equal(["abc"], @s.fetch)
1066
+ end
1067
+ end
1068
+
1069
+ def test_fetch_binary()
1070
+ if @m.server_version >= 40100 then
1071
+ @m.query("create temporary table t (i binary(10))")
1072
+ @m.query("insert into t values (null),('abc')")
1073
+ @s.prepare("select i from t")
1074
+ @s.execute
1075
+ assert_equal([nil], @s.fetch)
1076
+ if @m.server_version >= 50000 then
1077
+ assert_equal(["abc\0\0\0\0\0\0\0"], @s.fetch)
1078
+ else
1079
+ assert_equal(["abc"], @s.fetch)
1080
+ end
1081
+ end
1082
+ end
1083
+
1084
+ def test_fetch_varbinary()
1085
+ if @m.server_version >= 40100 then
1086
+ @m.query("create temporary table t (i varbinary(10))")
1087
+ @m.query("insert into t values (null),('abc')")
1088
+ @s.prepare("select i from t")
1089
+ @s.execute
1090
+ assert_equal([nil], @s.fetch)
1091
+ assert_equal(["abc"], @s.fetch)
1092
+ end
1093
+ end
1094
+
1095
+ def test_fetch_tinyblob()
1096
+ if @m.server_version >= 40100 then
1097
+ @m.query("create temporary table t (i tinyblob)")
1098
+ @m.query("insert into t values (null),('abc')")
1099
+ @s.prepare("select i from t")
1100
+ @s.execute
1101
+ assert_equal([nil], @s.fetch)
1102
+ assert_equal(["abc"], @s.fetch)
1103
+ end
1104
+ end
1105
+
1106
+ def test_fetch_tinytext()
1107
+ if @m.server_version >= 40100 then
1108
+ @m.query("create temporary table t (i tinytext)")
1109
+ @m.query("insert into t values (null),('abc')")
1110
+ @s.prepare("select i from t")
1111
+ @s.execute
1112
+ assert_equal([nil], @s.fetch)
1113
+ assert_equal(["abc"], @s.fetch)
1114
+ end
1115
+ end
1116
+
1117
+ def test_fetch_blob()
1118
+ if @m.server_version >= 40100 then
1119
+ @m.query("create temporary table t (i blob)")
1120
+ @m.query("insert into t values (null),('abc')")
1121
+ @s.prepare("select i from t")
1122
+ @s.execute
1123
+ assert_equal([nil], @s.fetch)
1124
+ assert_equal(["abc"], @s.fetch)
1125
+ end
1126
+ end
1127
+
1128
+ def test_fetch_text()
1129
+ if @m.server_version >= 40100 then
1130
+ @m.query("create temporary table t (i text)")
1131
+ @m.query("insert into t values (null),('abc')")
1132
+ @s.prepare("select i from t")
1133
+ @s.execute
1134
+ assert_equal([nil], @s.fetch)
1135
+ assert_equal(["abc"], @s.fetch)
1136
+ end
1137
+ end
1138
+
1139
+ def test_fetch_mediumblob()
1140
+ if @m.server_version >= 40100 then
1141
+ @m.query("create temporary table t (i mediumblob)")
1142
+ @m.query("insert into t values (null),('abc')")
1143
+ @s.prepare("select i from t")
1144
+ @s.execute
1145
+ assert_equal([nil], @s.fetch)
1146
+ assert_equal(["abc"], @s.fetch)
1147
+ end
1148
+ end
1149
+
1150
+ def test_fetch_mediumtext()
1151
+ if @m.server_version >= 40100 then
1152
+ @m.query("create temporary table t (i mediumtext)")
1153
+ @m.query("insert into t values (null),('abc')")
1154
+ @s.prepare("select i from t")
1155
+ @s.execute
1156
+ assert_equal([nil], @s.fetch)
1157
+ assert_equal(["abc"], @s.fetch)
1158
+ end
1159
+ end
1160
+
1161
+ def test_fetch_longblob()
1162
+ if @m.server_version >= 40100 then
1163
+ @m.query("create temporary table t (i longblob)")
1164
+ @m.query("insert into t values (null),('abc')")
1165
+ @s.prepare("select i from t")
1166
+ @s.execute
1167
+ assert_equal([nil], @s.fetch)
1168
+ assert_equal(["abc"], @s.fetch)
1169
+ end
1170
+ end
1171
+
1172
+ def test_fetch_longtext()
1173
+ if @m.server_version >= 40100 then
1174
+ @m.query("create temporary table t (i longtext)")
1175
+ @m.query("insert into t values (null),('abc')")
1176
+ @s.prepare("select i from t")
1177
+ @s.execute
1178
+ assert_equal([nil], @s.fetch)
1179
+ assert_equal(["abc"], @s.fetch)
1180
+ end
1181
+ end
1182
+
1183
+ def test_fetch_enum()
1184
+ if @m.server_version >= 40100 then
1185
+ @m.query("create temporary table t (i enum('abc','def'))")
1186
+ @m.query("insert into t values (null),(0),(1),(2),('abc'),('def'),('ghi')")
1187
+ @s.prepare("select i from t")
1188
+ @s.execute
1189
+ assert_equal([nil], @s.fetch)
1190
+ assert_equal([""], @s.fetch)
1191
+ assert_equal(["abc"], @s.fetch)
1192
+ assert_equal(["def"], @s.fetch)
1193
+ assert_equal(["abc"], @s.fetch)
1194
+ assert_equal(["def"], @s.fetch)
1195
+ assert_equal([""], @s.fetch)
1196
+ end
1197
+ end
1198
+
1199
+ def test_fetch_set()
1200
+ if @m.server_version >= 40100 then
1201
+ @m.query("create temporary table t (i set('abc','def'))")
1202
+ @m.query("insert into t values (null),(0),(1),(2),(3),('abc'),('def'),('abc,def'),('ghi')")
1203
+ @s.prepare("select i from t")
1204
+ @s.execute
1205
+ assert_equal([nil], @s.fetch)
1206
+ assert_equal([""], @s.fetch)
1207
+ assert_equal(["abc"], @s.fetch)
1208
+ assert_equal(["def"], @s.fetch)
1209
+ assert_equal(["abc,def"], @s.fetch)
1210
+ assert_equal(["abc"], @s.fetch)
1211
+ assert_equal(["def"], @s.fetch)
1212
+ assert_equal(["abc,def"], @s.fetch)
1213
+ assert_equal([""], @s.fetch)
1214
+ end
1215
+ end
1216
+
1217
+ def test_each()
1218
+ if @m.server_version >= 40100 then
1219
+ @m.query("create temporary table t (i int, c char(255), d datetime)")
1220
+ @m.query("insert into t values (1,'abc','19701224235905'),(2,'def','21120903123456'),(3,'123',null)")
1221
+ @s.prepare("select * from t")
1222
+ @s.execute
1223
+ c = 0
1224
+ @s.each do |a|
1225
+ case c
1226
+ when 0
1227
+ assert_equal([1,"abc",Mysql::Time.new(1970,12,24,23,59,05)], a)
1228
+ when 1
1229
+ assert_equal([2,"def",Mysql::Time.new(2112,9,3,12,34,56)], a)
1230
+ when 2
1231
+ assert_equal([3,"123",nil], a)
1232
+ else
1233
+ raise
1234
+ end
1235
+ c += 1
1236
+ end
1237
+ end
1238
+ end
1239
+
1240
+ def test_field_count()
1241
+ if @m.server_version >= 40100 then
1242
+ @s.prepare("select 1,2,3")
1243
+ @s.execute()
1244
+ assert_equal(3, @s.field_count())
1245
+ @s.prepare("set @a=1")
1246
+ @s.execute()
1247
+ assert_equal(0, @s.field_count())
1248
+ end
1249
+ end
1250
+
1251
+ def test_free_result()
1252
+ if @m.server_version >= 40100 then
1253
+ @s.free_result()
1254
+ @s.prepare("select 1,2,3")
1255
+ @s.execute()
1256
+ @s.free_result()
1257
+ end
1258
+ end
1259
+
1260
+ def test_insert_id()
1261
+ if @m.server_version >= 40100 then
1262
+ @m.query("create temporary table t (i int auto_increment, unique(i))")
1263
+ @s.prepare("insert into t values (0)")
1264
+ @s.execute()
1265
+ assert_equal(1, @s.insert_id())
1266
+ @s.execute()
1267
+ assert_equal(2, @s.insert_id())
1268
+ end
1269
+ end
1270
+
1271
+ def test_num_rows()
1272
+ if @m.server_version >= 40100 then
1273
+ @m.query("create temporary table t (i int)")
1274
+ @m.query("insert into t values (1),(2),(3),(4)")
1275
+ @s.prepare("select * from t")
1276
+ @s.execute
1277
+ assert_equal(4, @s.num_rows())
1278
+ end
1279
+ end
1280
+
1281
+ def test_param_count()
1282
+ if @m.server_version >= 40100 then
1283
+ @m.query("create temporary table t (a int, b int, c int)")
1284
+ @s.prepare("select * from t")
1285
+ assert_equal(0, @s.param_count())
1286
+ @s.prepare("insert into t values (?,?,?)")
1287
+ assert_equal(3, @s.param_count())
1288
+ end
1289
+ end
1290
+
1291
+ =begin
1292
+ def test_param_metadata()
1293
+ @s.param_metadata()
1294
+ end
1295
+ =end
1296
+
1297
+ def test_prepare()
1298
+ if @m.server_version >= 40100 then
1299
+ @s.prepare("select 1")
1300
+ assert_raises(Mysql::Error){@s.prepare("invalid syntax")}
1301
+ end
1302
+ end
1303
+
1304
+ =begin
1305
+ def test_reset()
1306
+ @s.reset()
1307
+ end
1308
+ =end
1309
+
1310
+ def test_result_metadata()
1311
+ if @m.server_version >= 40100 then
1312
+ @s.prepare("select 1 foo, 2 bar")
1313
+ res = @s.result_metadata()
1314
+ f = res.fetch_fields
1315
+ assert_equal("foo", f[0].name)
1316
+ assert_equal("bar", f[1].name)
1317
+ end
1318
+ end
1319
+
1320
+ def test_result_metadata_nodata()
1321
+ if @m.server_version >= 40100 then
1322
+ @m.query("create temporary table t (i int)")
1323
+ @s.prepare("insert into t values (1)")
1324
+ assert_equal(nil, @s.result_metadata())
1325
+ end
1326
+ end
1327
+
1328
+ def test_row_seek_tell()
1329
+ if @m.server_version >= 40100 then
1330
+ @m.query("create temporary table t (i int)")
1331
+ @m.query("insert into t values (0),(1),(2),(3),(4)")
1332
+ @s.prepare("select * from t")
1333
+ @s.execute
1334
+ row0 = @s.row_tell
1335
+ assert_equal([0], @s.fetch)
1336
+ assert_equal([1], @s.fetch)
1337
+ row2 = @s.row_seek(row0)
1338
+ assert_equal([0], @s.fetch)
1339
+ @s.row_seek(row2)
1340
+ assert_equal([2], @s.fetch)
1341
+ end
1342
+ end
1343
+
1344
+ =begin
1345
+ def test_send_long_data()
1346
+ @m.query("create temporary table t (i int, t text)")
1347
+ @s.prepare("insert into t values (?,?)")
1348
+ @s.send_long_data(1, "long long data ")
1349
+ @s.send_long_data(1, "long long data2")
1350
+ assert_raises(Mysql::Error){@s.send_long_data(9, "invalid param number")}
1351
+ @s.execute(99, "hoge")
1352
+ assert_equal("long long data long long data2", @m.query("select t from t").fetch_row[0])
1353
+ end
1354
+ =end
1355
+
1356
+ def test_sqlstate()
1357
+ if @m.server_version >= 40100 then
1358
+ @s.prepare("select 1")
1359
+ if @m.client_version >= 50000 then
1360
+ assert_equal("00000", @s.sqlstate)
1361
+ else
1362
+ assert_equal("", @s.sqlstate)
1363
+ end
1364
+ assert_raises(Mysql::Error){@s.prepare("hogehoge")}
1365
+ assert_equal("42000", @s.sqlstate)
1366
+ end
1367
+ end
1368
+
1369
+ =begin
1370
+ def test_store_result()
1371
+ @s.store_result()
1372
+ end
1373
+ =end
1374
+
1375
+ end if Mysql.client_version >= 40100
1376
+
1377
+ class TC_MysqlTime < Test::Unit::TestCase
1378
+ def setup()
1379
+ end
1380
+ def teardown()
1381
+ end
1382
+
1383
+ def test_init()
1384
+ t = Mysql::Time.new
1385
+ assert_equal(0, t.year);
1386
+ assert_equal(0, t.month);
1387
+ assert_equal(0, t.day);
1388
+ assert_equal(0, t.hour);
1389
+ assert_equal(0, t.minute);
1390
+ assert_equal(0, t.second);
1391
+ assert_equal(false, t.neg);
1392
+ assert_equal(0, t.second_part);
1393
+ end
1394
+
1395
+ def test_year()
1396
+ t = Mysql::Time.new
1397
+ assert_equal(2005, t.year = 2005)
1398
+ assert_equal(2005, t.year)
1399
+ end
1400
+
1401
+ def test_month()
1402
+ t = Mysql::Time.new
1403
+ assert_equal(11, t.month = 11)
1404
+ assert_equal(11, t.month)
1405
+ end
1406
+
1407
+ def test_day()
1408
+ t = Mysql::Time.new
1409
+ assert_equal(23, t.day = 23)
1410
+ assert_equal(23, t.day)
1411
+ end
1412
+
1413
+ def test_hour()
1414
+ t = Mysql::Time.new
1415
+ assert_equal(15, t.hour = 15)
1416
+ assert_equal(15, t.hour)
1417
+ end
1418
+
1419
+ def test_minute()
1420
+ t = Mysql::Time.new
1421
+ assert_equal(58, t.month = 58)
1422
+ assert_equal(58, t.month)
1423
+ end
1424
+
1425
+ def test_second()
1426
+ t = Mysql::Time.new
1427
+ assert_equal(34, t.second = 34)
1428
+ assert_equal(34, t.second)
1429
+ end
1430
+
1431
+ def test_tos()
1432
+ t = Mysql::Time.new(2005, 7, 19, 10, 15, 49)
1433
+ assert_equal("2005-07-19 10:15:49", t.to_s)
1434
+ end
1435
+
1436
+ def test_eql()
1437
+ t1 = Mysql::Time.new(2005,7,19,23,56,13)
1438
+ t2 = Mysql::Time.new(2005,7,19,23,56,13)
1439
+ assert_equal(t1, t2)
1440
+ end
1441
+
1442
+ end if Mysql.client_version >= 40100