mysql 2.6 → 2.7

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