mysql 2.5.1 → 2.6
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.
- data/README.html +86 -17
- data/README_ja.html +88 -10
- data/mysql.c.in +153 -11
- data/mysql.gemspec +11 -0
- data/test.rb +353 -27
- metadata +5 -17
- data/mysql-compat.rb +0 -62
- data/mysql-ruby-2.5.1.gem +0 -0
- data/mysql-ruby.gemspec +0 -20
- data/t/00connect.rb +0 -1
- data/t/10create_db.rb +0 -3
- data/t/20create_table.rb +0 -1
- data/t/30insert.rb +0 -2
- data/t/40select.rb +0 -4
- data/t/50update.rb +0 -2
- data/t/60drop_table.rb +0 -1
- data/t/70drop_db.rb +0 -2
- data/t/80close.rb +0 -1
data/README.html
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
2
|
-
<!-- $Id: README.html,v 1.
|
2
|
+
<!-- $Id: README.html,v 1.9 2005/04/25 14:34:19 tommy Exp $ -->
|
3
3
|
<html>
|
4
4
|
<head>
|
5
5
|
<meta http-equiv="content-style-type" content="text/css">
|
@@ -17,10 +17,20 @@
|
|
17
17
|
It provides the same functions for Ruby programs that the MySQL C API provides for C programs.
|
18
18
|
</p>
|
19
19
|
|
20
|
+
<!--
|
21
|
+
<h2>Download</h2>
|
22
|
+
<ul>
|
23
|
+
<li><a href="mysql-ruby-2.6.tar.gz">mysql-ruby-2.6.tar.gz</a>
|
24
|
+
<li><a href="mysql-ruby-2.5.2.tar.gz">mysql-ruby-2.5.2.tar.gz</a>
|
25
|
+
<li><a href="mysql-ruby-2.5.1.tar.gz">mysql-ruby-2.5.1.tar.gz</a>
|
26
|
+
<li><a href="mysql-ruby-2.5.tar.gz">mysql-ruby-2.5.tar.gz</a>
|
27
|
+
</ul>
|
28
|
+
-->
|
29
|
+
|
20
30
|
<h2>Requirement</h2>
|
21
31
|
<ul>
|
22
|
-
<li>MySQL
|
23
|
-
<li>Ruby 1.
|
32
|
+
<li>MySQL 4.1.9 +
|
33
|
+
<li>Ruby 1.8.2 +
|
24
34
|
</ul>
|
25
35
|
<p>
|
26
36
|
The module may work for other versions, but that has not been verified.
|
@@ -81,17 +91,9 @@
|
|
81
91
|
2nd:
|
82
92
|
</p>
|
83
93
|
<pre class="code">
|
84
|
-
% ruby
|
94
|
+
% ruby ./test.rb [<i>hostname</i> [<i>user</i> [<i>passwd</i> [<i>dbname</i> [<i>port</i> [<i>socket</i> [<i>flag</i>]]]]]]]
|
85
95
|
</pre>
|
86
96
|
|
87
|
-
<p>
|
88
|
-
test.rb should be invoked with three arguments that indicate the
|
89
|
-
MySQL server hostname, and the username and password for a MySQL
|
90
|
-
account that can create a database named "rubytest". An
|
91
|
-
optional fourth argument is allowed, to specify a database name
|
92
|
-
to use rather than "rubytest". The database should not already
|
93
|
-
exist.
|
94
|
-
</p>
|
95
97
|
<p>
|
96
98
|
3rd:
|
97
99
|
</p>
|
@@ -352,6 +354,19 @@
|
|
352
354
|
return table list Array.
|
353
355
|
</p>
|
354
356
|
|
357
|
+
<dt>more_results?()
|
358
|
+
<dd>
|
359
|
+
<p>
|
360
|
+
returns true if more results exist from the currently executed query.
|
361
|
+
</p>
|
362
|
+
|
363
|
+
<dt>next_result()
|
364
|
+
<dd>
|
365
|
+
<p>
|
366
|
+
returns true if more results exist from the currently executed query.
|
367
|
+
after this, you do store_result() to get result table of query.
|
368
|
+
</p>
|
369
|
+
|
355
370
|
<dt>ping()
|
356
371
|
<dd>
|
357
372
|
<p>
|
@@ -359,12 +374,22 @@
|
|
359
374
|
</p>
|
360
375
|
|
361
376
|
<dt>query(q)
|
377
|
+
<dt>real_query(q)
|
362
378
|
<dd>
|
363
379
|
<p>
|
364
380
|
do query and store_result(). return Mysql::Result object.
|
365
381
|
If query_with_result is false, it does not store_result().
|
366
382
|
</p>
|
367
383
|
|
384
|
+
<dt>query(q) {|res| ...}
|
385
|
+
<dt>real_query(q) {|res| ...}
|
386
|
+
<dd>
|
387
|
+
<p>
|
388
|
+
do query and execute block with Mysql::Result object.
|
389
|
+
if you specify multiple query, then repeat block.
|
390
|
+
set_server_option(Mysql::OPTION_MULTI_STATEMENTS) is executed automatically.
|
391
|
+
</p>
|
392
|
+
|
368
393
|
<dt>refresh(r)
|
369
394
|
<dd>
|
370
395
|
<p>
|
@@ -389,6 +414,13 @@
|
|
389
414
|
select database.
|
390
415
|
</p>
|
391
416
|
|
417
|
+
<dt>set_server_option(opt)
|
418
|
+
<dd>
|
419
|
+
<p>
|
420
|
+
set option to server.
|
421
|
+
options is one of Mysql::OPTION_MULTI_STATEMENTS_ON, Mysql::OPTION_MULTI_STATEMENTS_OFF.
|
422
|
+
</p>
|
423
|
+
|
392
424
|
<dt>shutdown()
|
393
425
|
<dd>
|
394
426
|
<p>
|
@@ -437,9 +469,18 @@
|
|
437
469
|
<dl>
|
438
470
|
<dt>query_with_result
|
439
471
|
<dd>
|
440
|
-
|
441
|
-
|
442
|
-
|
472
|
+
<p>
|
473
|
+
If true, query() also invokes store_result() and returns a
|
474
|
+
Mysql::Result object. Default is true.
|
475
|
+
</p>
|
476
|
+
|
477
|
+
<dt>reconnect
|
478
|
+
<dd>
|
479
|
+
<p>
|
480
|
+
If true, reconnect to server automatically when disconect to server.
|
481
|
+
Default is false.
|
482
|
+
</p>
|
483
|
+
|
443
484
|
</dl>
|
444
485
|
|
445
486
|
<h2>Mysql::Result class</h2>
|
@@ -607,8 +648,36 @@
|
|
607
648
|
<dd>error number
|
608
649
|
</dl>
|
609
650
|
|
610
|
-
<h2>
|
651
|
+
<h2>History</h2>
|
611
652
|
<dl>
|
653
|
+
<dt>2005-04-25
|
654
|
+
<dd>
|
655
|
+
version 2.6
|
656
|
+
<ul>
|
657
|
+
<li>add constants for Mysql#option():
|
658
|
+
Mysql::OPT_PROTOCOL, Mysql::OPT_READ_TIMEOUT,
|
659
|
+
Mysql::OPT_WRITE_TIMEOUT, Mysql::SET_CHARSET_DIR,
|
660
|
+
Mysql::SET_CHARSET_NAME, Mysql::SHARED_MEMORY_BASE_NAME,
|
661
|
+
Mysql::SECURE_AUTH
|
662
|
+
<li>add methods: Mysql#more_results?(), Mysql#next_result(),
|
663
|
+
Mysql#set_server_option(), Mysql#sqlstate()
|
664
|
+
<li>add constants for Mysql#connect():
|
665
|
+
Mysql::CLIENT_MULTI_STATEMENTS, Mysql::CLIENT_MULTI_RESULTS
|
666
|
+
<li>add constants for Mysql#set_server_option():
|
667
|
+
Mysql::OPTION_MULTI_STATEMENTS_ON,
|
668
|
+
Mysql::OPTION_MULTI_STATEMENTS_OFF
|
669
|
+
<li>add Mysql#query() with block
|
670
|
+
<li>add Mysql#reconnect(), Mysql#reconnect=()
|
671
|
+
<li>When connection was closed, it don't try to reconnect by default.
|
672
|
+
</ul>
|
673
|
+
|
674
|
+
<dt>2005-02-12
|
675
|
+
<dd>
|
676
|
+
version 2.5.2
|
677
|
+
<ul>
|
678
|
+
<li>BUG: Mysql#connect make object to not close. (Thanks Andres Salomon)
|
679
|
+
</ul>
|
680
|
+
|
612
681
|
<dt>2004-09-20
|
613
682
|
<dd>
|
614
683
|
version 2.5.1
|
@@ -719,7 +788,7 @@
|
|
719
788
|
<address><a href="mailto:tommy@tmtm.org">TOMITA Masahiro</a></address>
|
720
789
|
<!-- Created: Sun Aug 29 11:52:09 JST 2004 -->
|
721
790
|
<!-- hhmts start -->
|
722
|
-
Last modified: Mon
|
791
|
+
Last modified: Mon Apr 25 23:33:21 JST 2005
|
723
792
|
<!-- hhmts end -->
|
724
793
|
</body>
|
725
794
|
</html>
|
data/README_ja.html
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
2
|
-
<!-- $Id: README_ja.html,v 1.
|
2
|
+
<!-- $Id: README_ja.html,v 1.13 2005/04/25 14:34:19 tommy Exp $ -->
|
3
3
|
<html>
|
4
4
|
<head>
|
5
5
|
<meta http-equiv="content-style-type" content="text/css">
|
@@ -10,16 +10,26 @@
|
|
10
10
|
|
11
11
|
<body>
|
12
12
|
<h1>MySQL/Ruby</h1>
|
13
|
-
<p><a href="
|
13
|
+
<p><a href="README.html">[English]</a></p>
|
14
14
|
<hr>
|
15
15
|
<p>
|
16
16
|
����� <a href="http://www.mysql.com">MySQL</a> �� Ruby API �Ǥ���MySQL �� C API �Ȥۤ�Ʊ���ε�ǽ������ޤ���
|
17
17
|
</p>
|
18
18
|
|
19
|
+
<!--
|
20
|
+
<h2>�����������</h2>
|
21
|
+
<ul>
|
22
|
+
<li><a href="mysql-ruby-2.6.tar.gz">mysql-ruby-2.6.tar.gz</a>
|
23
|
+
<li><a href="mysql-ruby-2.5.2.tar.gz">mysql-ruby-2.5.2.tar.gz</a>
|
24
|
+
<li><a href="mysql-ruby-2.5.1.tar.gz">mysql-ruby-2.5.1.tar.gz</a>
|
25
|
+
<li><a href="mysql-ruby-2.5.tar.gz">mysql-ruby-2.5.tar.gz</a>
|
26
|
+
</ul>
|
27
|
+
-->
|
28
|
+
|
19
29
|
<h2>ɬ�פʤ��</h2>
|
20
30
|
<ul>
|
21
|
-
<li>MySQL
|
22
|
-
<li>Ruby 1.
|
31
|
+
<li>MySQL 4.1.9 �ʾ�
|
32
|
+
<li>Ruby 1.8.2 �ʾ�
|
23
33
|
</ul>
|
24
34
|
<p>
|
25
35
|
�����ʳ��Ǥ� make �Ǥ��뤫�⤷��ޤ�����ǧ���Ƥޤ���
|
@@ -77,11 +87,11 @@
|
|
77
87
|
���Ǵ�ñ�ʥƥ��Ȥ��Ǥ��ޤ���
|
78
88
|
</p>
|
79
89
|
<pre class="code">
|
80
|
-
% ruby
|
90
|
+
% ruby ./test.rb [<i>hostname</i> [<i>user</i> [<i>passwd</i> [<i>dbname</i> [<i>port</i> [<i>socket</i> [<i>flag</i>]]]]]]]
|
81
91
|
</pre>
|
82
92
|
|
83
93
|
<p>
|
84
|
-
test.rb
|
94
|
+
test.rb ��Ϳ��������� Mysql.real_connect() �ΰ�����Ʊ���Ǥ���
|
85
95
|
</p>
|
86
96
|
<p>
|
87
97
|
����ʤ���С������ѡ��桼���ǥ��ȡ��뤷�Ƥ���������
|
@@ -346,6 +356,19 @@
|
|
346
356
|
�ơ��֥�ΰ�����������֤��ޤ���
|
347
357
|
</p>
|
348
358
|
|
359
|
+
<dt>more_results?()
|
360
|
+
<dd>
|
361
|
+
<p>
|
362
|
+
�������Ƥ��ʤ��������̤�������Ͽ����֤��ޤ���
|
363
|
+
</p>
|
364
|
+
|
365
|
+
<dt>next_result()
|
366
|
+
<dd>
|
367
|
+
<p>
|
368
|
+
�������Ƥ��ʤ��������̤�������Ͽ����֤��ޤ���
|
369
|
+
���θ�� store_result() ��¹Ԥ���ȥ������̤�����Ǥ��ޤ���
|
370
|
+
</p>
|
371
|
+
|
349
372
|
<dt>ping()
|
350
373
|
<dd>
|
351
374
|
<p>
|
@@ -353,13 +376,24 @@
|
|
353
376
|
</p>
|
354
377
|
|
355
378
|
<dt>query(q)
|
379
|
+
<dt>real_query(q)
|
356
380
|
<dd>
|
357
381
|
<p>
|
358
|
-
�������¹Ԥ��ޤ���
|
382
|
+
�������¹Ԥ��ޤ���
|
359
383
|
�����꤬��̤��֤���硢��ưŪ�� store_result() ��¹Ԥ��ơ�Mysql::Result ���饹���֥������Ȥ��֤��ޤ���
|
360
384
|
query_with_result �� false �����ꤵ��Ƥ���С�store_result() �ϼ¹Ԥ��ޤ���
|
361
385
|
</p>
|
362
386
|
|
387
|
+
<dt>query(q) {|res| ...}
|
388
|
+
<dt>real_query(q) {|res| ...}
|
389
|
+
<dd>
|
390
|
+
<p>
|
391
|
+
�������¹Ԥ��ޤ���
|
392
|
+
�����꤬��̤��֤���硢Mysql::Result ���֥������Ȥ�����Ȥ��ƥ֥��å���¹Ԥ��ޤ���
|
393
|
+
�����ˡ�;�פǶ��ڤ�줿ʣ���Υ��������ꤷ�����ϡ�������ο������֥��å����֤��ޤ���
|
394
|
+
��ưŪ�� set_server_option(Mysql::OPTION_MULTI_STATEMENTS) ���¹Ԥ���ޤ���
|
395
|
+
</p>
|
396
|
+
|
363
397
|
<dt>refresh(r)
|
364
398
|
<dd>
|
365
399
|
<p>
|
@@ -384,6 +418,13 @@
|
|
384
418
|
�ǡ����١��������ޤ���
|
385
419
|
</p>
|
386
420
|
|
421
|
+
<dt>set_server_option(opt)
|
422
|
+
<dd>
|
423
|
+
<p>
|
424
|
+
�����ǻ��ꤷ�����ץ������Ф����ꤷ�ޤ���
|
425
|
+
�����ˤϡ�Mysql::OPTION_MULTI_STATEMENTS_ON, Mysql::OPTION_MULTI_STATEMENTS_OFF ������Ǥ��ޤ���
|
426
|
+
</p>
|
427
|
+
|
387
428
|
<dt>shutdown()
|
388
429
|
<dd>
|
389
430
|
<p>
|
@@ -432,8 +473,17 @@
|
|
432
473
|
<dl>
|
433
474
|
<dt>query_with_result
|
434
475
|
<dd>
|
435
|
-
|
436
|
-
|
476
|
+
<p>
|
477
|
+
true �����ꤹ��� query() ���� store_result() ��¹Ԥ��ơ�Mysql::Result ���饹���֥������Ȥ��֤��ޤ���
|
478
|
+
false �����ꤹ��Ȥ���ư��ϹԤ��ޤ��ǥե���Ȥ� true �Ǥ���
|
479
|
+
</p>
|
480
|
+
|
481
|
+
<dt>reconnect
|
482
|
+
<dd>
|
483
|
+
<p>
|
484
|
+
true �����ꤹ��� MySQL �����ФȤ���³���ڤ줿�Ȥ��˼�ưŪ�˺���³���ޤ���
|
485
|
+
�ǥե���Ȥ� false �Ǥ���
|
486
|
+
</p>
|
437
487
|
</dl>
|
438
488
|
|
439
489
|
<h2>Mysql::Result ���饹</h2>
|
@@ -637,6 +687,34 @@
|
|
637
687
|
|
638
688
|
<h2>����</h2>
|
639
689
|
<dl>
|
690
|
+
<dt>2005-04-25
|
691
|
+
<dd>
|
692
|
+
version 2.6
|
693
|
+
<ul>
|
694
|
+
<li>Mysql#option() �Ѥ�����ɲ�
|
695
|
+
Mysql::OPT_PROTOCOL, Mysql::OPT_READ_TIMEOUT,
|
696
|
+
Mysql::OPT_WRITE_TIMEOUT, Mysql::SET_CHARSET_DIR,
|
697
|
+
Mysql::SET_CHARSET_NAME, Mysql::SHARED_MEMORY_BASE_NAME,
|
698
|
+
Mysql::SECURE_AUTH
|
699
|
+
<li>Mysql#more_results?(), Mysql#next_result(),
|
700
|
+
Mysql#set_server_option(), Mysql#sqlstate() �ɲ�
|
701
|
+
<li>Mysql#connect() �Υե饰������ɲ�
|
702
|
+
Mysql::CLIENT_MULTI_STATEMENTS, Mysql::CLIENT_MULTI_RESULTS
|
703
|
+
<li>Mysql#set_server_option() �Ѥ�����ɲ�
|
704
|
+
Mysql::OPTION_MULTI_STATEMENTS_ON,
|
705
|
+
Mysql::OPTION_MULTI_STATEMENTS_OFF
|
706
|
+
<li>�֥��å��դ� Mysql#query()
|
707
|
+
<li>Mysql#reconnect(), Mysql#reconnect=() �ɲ�
|
708
|
+
<li>MySQL �Ȥ���³���ڤ줿�Ȥ��ˡ��ǥե���ȤǤϺ���³���ʤ��褦�ˤ�����
|
709
|
+
</ul>
|
710
|
+
|
711
|
+
<dt>2005-02-12
|
712
|
+
<dd>
|
713
|
+
version 2.5.2
|
714
|
+
<ul>
|
715
|
+
<li>BUG: Mysql#connect ����³�������³�����Ǥ���ʤ���(Andres Salomon �˴���)
|
716
|
+
</ul>
|
717
|
+
|
640
718
|
<dt>2004-09-20
|
641
719
|
<dd>
|
642
720
|
version 2.5.1
|
@@ -891,7 +969,7 @@
|
|
891
969
|
<address><a href="mailto:tommy@tmtm.org">TOMITA Masahiro</a></address>
|
892
970
|
<!-- Created: Sun Aug 29 11:52:09 JST 2004 -->
|
893
971
|
<!-- hhmts start -->
|
894
|
-
Last modified: Mon
|
972
|
+
Last modified: Mon Apr 25 23:30:04 JST 2005
|
895
973
|
<!-- hhmts end -->
|
896
974
|
</body>
|
897
975
|
</html>
|
data/mysql.c.in
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/* ruby mysql module
|
2
|
-
* $Id: mysql.c.in,v 1.
|
2
|
+
* $Id: mysql.c.in,v 1.16 2005/04/19 14:20:03 tommy Exp $
|
3
3
|
*/
|
4
4
|
|
5
5
|
#include "ruby.h"
|
@@ -36,7 +36,7 @@
|
|
36
36
|
#define mysql_field_count mysql_num_fields
|
37
37
|
#endif
|
38
38
|
|
39
|
-
#define NILorSTRING(obj) (NIL_P(obj)? NULL:
|
39
|
+
#define NILorSTRING(obj) (NIL_P(obj)? NULL: StringValuePtr(obj))
|
40
40
|
#define NILorINT(obj) (NIL_P(obj)? 0: NUM2INT(obj))
|
41
41
|
|
42
42
|
#define GetMysqlStruct(obj) (Check_Type(obj, T_DATA), (struct mysql*)DATA_PTR(obj))
|
@@ -172,6 +172,7 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass)
|
|
172
172
|
#endif
|
173
173
|
mysql_raise(&myp->handler);
|
174
174
|
|
175
|
+
myp->handler.reconnect = 0;
|
175
176
|
myp->connection = Qtrue;
|
176
177
|
myp->query_with_result = Qtrue;
|
177
178
|
rb_obj_call_init(obj, argc, argv);
|
@@ -199,7 +200,7 @@ static VALUE client_info(VALUE klass)
|
|
199
200
|
/* my_debug(string) */
|
200
201
|
static VALUE my_debug(VALUE obj, VALUE str)
|
201
202
|
{
|
202
|
-
mysql_debug(
|
203
|
+
mysql_debug(StringValuePtr(str));
|
203
204
|
return obj;
|
204
205
|
}
|
205
206
|
#endif
|
@@ -235,6 +236,8 @@ static VALUE real_connect2(int argc, VALUE* argv, VALUE obj)
|
|
235
236
|
|
236
237
|
if (mysql_real_connect(m, h, u, p, d, pp, s, f) == NULL)
|
237
238
|
mysql_raise(m);
|
239
|
+
m->reconnect = 0;
|
240
|
+
GetMysqlStruct(obj)->connection = Qtrue;
|
238
241
|
|
239
242
|
return obj;
|
240
243
|
}
|
@@ -244,12 +247,20 @@ static VALUE options(int argc, VALUE* argv, VALUE obj)
|
|
244
247
|
{
|
245
248
|
VALUE opt, val;
|
246
249
|
int n;
|
250
|
+
my_bool b;
|
247
251
|
char* v;
|
248
252
|
MYSQL* m = GetHandler(obj);
|
249
253
|
|
250
254
|
rb_scan_args(argc, argv, "11", &opt, &val);
|
251
255
|
switch(NUM2INT(opt)) {
|
252
256
|
case MYSQL_OPT_CONNECT_TIMEOUT:
|
257
|
+
#if MYSQL_VERSION_ID >= 40100
|
258
|
+
case MYSQL_OPT_PROTOCOL:
|
259
|
+
#endif
|
260
|
+
#if MYSQL_VERSION_ID >= 40101
|
261
|
+
case MYSQL_OPT_READ_TIMEOUT:
|
262
|
+
case MYSQL_OPT_WRITE_TIMEOUT:
|
263
|
+
#endif
|
253
264
|
if (val == Qnil)
|
254
265
|
rb_raise(rb_eArgError, "wrong # of arguments(1 for 2)");
|
255
266
|
n = NUM2INT(val);
|
@@ -258,10 +269,26 @@ static VALUE options(int argc, VALUE* argv, VALUE obj)
|
|
258
269
|
case MYSQL_INIT_COMMAND:
|
259
270
|
case MYSQL_READ_DEFAULT_FILE:
|
260
271
|
case MYSQL_READ_DEFAULT_GROUP:
|
272
|
+
#if MYSQL_VERSION_ID >= 32349
|
273
|
+
case MYSQL_SET_CHARSET_DIR:
|
274
|
+
case MYSQL_SET_CHARSET_NAME:
|
275
|
+
#endif
|
276
|
+
#if MYSQL_VERSION_ID >= 40100
|
277
|
+
case MYSQL_SHARED_MEMORY_BASE_NAME:
|
278
|
+
#endif
|
261
279
|
if (val == Qnil)
|
262
280
|
rb_raise(rb_eArgError, "wrong # of arguments(1 for 2)");
|
263
|
-
v =
|
281
|
+
v = StringValuePtr(val);
|
264
282
|
break;
|
283
|
+
#if MYSQL_VERSION_ID >= 40101
|
284
|
+
case MYSQL_SECURE_AUTH:
|
285
|
+
if (val == Qnil || val == Qfalse)
|
286
|
+
b = 1;
|
287
|
+
else
|
288
|
+
b = 0;
|
289
|
+
v = (char*)&b;
|
290
|
+
break;
|
291
|
+
#endif
|
265
292
|
#if MYSQL_VERSION_ID >= 32349
|
266
293
|
case MYSQL_OPT_LOCAL_INFILE:
|
267
294
|
if (val == Qnil || val == Qfalse)
|
@@ -348,7 +375,7 @@ static VALUE my_close(VALUE obj)
|
|
348
375
|
static VALUE create_db(VALUE obj, VALUE db)
|
349
376
|
{
|
350
377
|
MYSQL* m = GetHandler(obj);
|
351
|
-
if (mysql_create_db(m,
|
378
|
+
if (mysql_create_db(m, StringValuePtr(db)) != 0)
|
352
379
|
mysql_raise(m);
|
353
380
|
return obj;
|
354
381
|
}
|
@@ -357,7 +384,7 @@ static VALUE create_db(VALUE obj, VALUE db)
|
|
357
384
|
static VALUE drop_db(VALUE obj, VALUE db)
|
358
385
|
{
|
359
386
|
MYSQL* m = GetHandler(obj);
|
360
|
-
if (mysql_drop_db(m,
|
387
|
+
if (mysql_drop_db(m, StringValuePtr(db)) != 0)
|
361
388
|
mysql_raise(m);
|
362
389
|
return obj;
|
363
390
|
}
|
@@ -461,7 +488,7 @@ static VALUE list_fields(int argc, VALUE* argv, VALUE obj)
|
|
461
488
|
MYSQL* m = GetHandler(obj);
|
462
489
|
MYSQL_RES* res;
|
463
490
|
rb_scan_args(argc, argv, "11", &table, &field);
|
464
|
-
res = mysql_list_fields(m,
|
491
|
+
res = mysql_list_fields(m, StringValuePtr(table), NILorSTRING(field));
|
465
492
|
if (res == NULL)
|
466
493
|
mysql_raise(m);
|
467
494
|
return mysqlres2obj(res);
|
@@ -530,7 +557,7 @@ static VALUE reload(VALUE obj)
|
|
530
557
|
static VALUE select_db(VALUE obj, VALUE db)
|
531
558
|
{
|
532
559
|
MYSQL* m = GetHandler(obj);
|
533
|
-
if (mysql_select_db(m,
|
560
|
+
if (mysql_select_db(m, StringValuePtr(db)) != 0)
|
534
561
|
mysql_raise(m);
|
535
562
|
return obj;
|
536
563
|
}
|
@@ -592,6 +619,31 @@ static VALUE query(VALUE obj, VALUE sql)
|
|
592
619
|
{
|
593
620
|
MYSQL* m = GetHandler(obj);
|
594
621
|
Check_Type(sql, T_STRING);
|
622
|
+
if (rb_block_given_p()) {
|
623
|
+
#if MYSQL_VERSION_ID >= 40101
|
624
|
+
if (mysql_set_server_option(m, MYSQL_OPTION_MULTI_STATEMENTS_ON) != 0)
|
625
|
+
mysql_raise(m);
|
626
|
+
#endif
|
627
|
+
if (mysql_real_query(m, RSTRING(sql)->ptr, RSTRING(sql)->len) != 0)
|
628
|
+
mysql_raise(m);
|
629
|
+
do {
|
630
|
+
MYSQL_RES* res = mysql_store_result(m);
|
631
|
+
if (res == NULL) {
|
632
|
+
if (mysql_field_count(m) != 0)
|
633
|
+
mysql_raise(m);
|
634
|
+
} else {
|
635
|
+
static VALUE res_free(VALUE);
|
636
|
+
VALUE robj = mysqlres2obj(res);
|
637
|
+
rb_ensure(rb_yield, robj, res_free, robj);
|
638
|
+
}
|
639
|
+
}
|
640
|
+
#if MYSQL_VERSION_ID >= 40101
|
641
|
+
while (mysql_next_result(m) == 0);
|
642
|
+
#else
|
643
|
+
while (0);
|
644
|
+
#endif
|
645
|
+
return obj;
|
646
|
+
}
|
595
647
|
if (mysql_real_query(m, RSTRING(sql)->ptr, RSTRING(sql)->len) != 0)
|
596
648
|
mysql_raise(m);
|
597
649
|
if (GetMysqlStruct(obj)->query_with_result == Qfalse)
|
@@ -637,7 +689,7 @@ static VALUE autocommit(VALUE obj, VALUE mode)
|
|
637
689
|
{
|
638
690
|
MYSQL* m = GetHandler(obj);
|
639
691
|
int f;
|
640
|
-
f = (mode == Qnil || mode == Qfalse || NUM2INT(mode) == 0) ? 0 : 1;
|
692
|
+
f = (mode == Qnil || mode == Qfalse || (rb_type(mode) == T_FIXNUM && NUM2INT(mode) == 0)) ? 0 : 1;
|
641
693
|
if (mysql_autocommit(m, f) != 0)
|
642
694
|
mysql_raise(m);
|
643
695
|
return obj;
|
@@ -662,6 +714,47 @@ static VALUE ssl_set(int argc, VALUE* argv, VALUE obj)
|
|
662
714
|
}
|
663
715
|
#endif
|
664
716
|
|
717
|
+
#if MYSQL_VERSION_ID >= 40100
|
718
|
+
/* more_results() */
|
719
|
+
static VALUE more_results(VALUE obj)
|
720
|
+
{
|
721
|
+
if (mysql_more_results(GetHandler(obj)) == 0)
|
722
|
+
return Qfalse;
|
723
|
+
else
|
724
|
+
return Qtrue;
|
725
|
+
}
|
726
|
+
|
727
|
+
static VALUE next_result(VALUE obj)
|
728
|
+
{
|
729
|
+
MYSQL* m = GetHandler(obj);
|
730
|
+
int ret;
|
731
|
+
ret = mysql_next_result(m);
|
732
|
+
if (ret > 0)
|
733
|
+
mysql_raise(m);
|
734
|
+
if (ret == 0)
|
735
|
+
return Qtrue;
|
736
|
+
return Qfalse;
|
737
|
+
}
|
738
|
+
#endif
|
739
|
+
|
740
|
+
#if MYSQL_VERSION_ID >= 40101
|
741
|
+
/* set_server_option(option) */
|
742
|
+
static VALUE set_server_option(VALUE obj, VALUE option)
|
743
|
+
{
|
744
|
+
MYSQL *m = GetHandler(obj);
|
745
|
+
if (mysql_set_server_option(m, NUM2INT(option)) != 0)
|
746
|
+
mysql_raise(m);
|
747
|
+
return obj;
|
748
|
+
}
|
749
|
+
|
750
|
+
/* sqlstate() */
|
751
|
+
static VALUE sqlstate(VALUE obj)
|
752
|
+
{
|
753
|
+
MYSQL *m = GetHandler(obj);
|
754
|
+
return rb_tainted_str_new2(mysql_sqlstate(m));
|
755
|
+
}
|
756
|
+
#endif
|
757
|
+
|
665
758
|
/* query_with_result() */
|
666
759
|
static VALUE query_with_result(VALUE obj)
|
667
760
|
{
|
@@ -681,6 +774,19 @@ static VALUE query_with_result_set(VALUE obj, VALUE flag)
|
|
681
774
|
return flag;
|
682
775
|
}
|
683
776
|
|
777
|
+
/* reconnect() */
|
778
|
+
static VALUE reconnect(VALUE obj)
|
779
|
+
{
|
780
|
+
return GetHandler(obj)->reconnect ? Qtrue : Qfalse;
|
781
|
+
}
|
782
|
+
|
783
|
+
/* reconnect=(flag) */
|
784
|
+
static VALUE reconnect_set(VALUE obj, VALUE flag)
|
785
|
+
{
|
786
|
+
GetHandler(obj)->reconnect = (flag == Qnil || flag == Qfalse) ? 0 : 1;
|
787
|
+
return flag;
|
788
|
+
}
|
789
|
+
|
684
790
|
/*-------------------------------
|
685
791
|
* Mysql::Result object method
|
686
792
|
*/
|
@@ -931,7 +1037,7 @@ static VALUE field_hash(VALUE obj)
|
|
931
1037
|
static VALUE field_inspect(VALUE obj)
|
932
1038
|
{
|
933
1039
|
VALUE n = rb_iv_get(obj, "name");
|
934
|
-
VALUE s = rb_str_new(0, RSTRING(n)->len +
|
1040
|
+
VALUE s = rb_str_new(0, RSTRING(n)->len + 16);
|
935
1041
|
sprintf(RSTRING(s)->ptr, "#<Mysql::Field:%s>", RSTRING(n)->ptr);
|
936
1042
|
return s;
|
937
1043
|
}
|
@@ -973,7 +1079,6 @@ static VALUE field_is_pri_key(VALUE obj)
|
|
973
1079
|
}
|
974
1080
|
#endif
|
975
1081
|
|
976
|
-
|
977
1082
|
/*-------------------------------
|
978
1083
|
* Mysql::Error object method
|
979
1084
|
*/
|
@@ -1075,6 +1180,7 @@ void Init_mysql(void)
|
|
1075
1180
|
rb_define_method(cMysql, "ping", ping, 0);
|
1076
1181
|
#endif
|
1077
1182
|
rb_define_method(cMysql, "query", query, 1);
|
1183
|
+
rb_define_method(cMysql, "real_query", query, 1);
|
1078
1184
|
rb_define_method(cMysql, "refresh", refresh, 1);
|
1079
1185
|
rb_define_method(cMysql, "reload", reload, 0);
|
1080
1186
|
rb_define_method(cMysql, "select_db", select_db, 1);
|
@@ -1093,10 +1199,22 @@ void Init_mysql(void)
|
|
1093
1199
|
#endif
|
1094
1200
|
#ifdef HAVE_MYSQL_SSL_SET
|
1095
1201
|
rb_define_method(cMysql, "ssl_set", ssl_set, -1);
|
1202
|
+
#endif
|
1203
|
+
#if MYSQL_VERSION_ID >= 40100
|
1204
|
+
rb_define_method(cMysql, "more_results", more_results, 0);
|
1205
|
+
rb_define_method(cMysql, "more_results?", more_results, 0);
|
1206
|
+
rb_define_method(cMysql, "next_result", next_result, 0);
|
1207
|
+
#endif
|
1208
|
+
#if MYSQL_VERSION_ID >= 40101
|
1209
|
+
rb_define_method(cMysql, "set_server_option", set_server_option, 1);
|
1210
|
+
rb_define_method(cMysql, "sqlstate", sqlstate, 0);
|
1096
1211
|
#endif
|
1097
1212
|
rb_define_method(cMysql, "query_with_result", query_with_result, 0);
|
1098
1213
|
rb_define_method(cMysql, "query_with_result=", query_with_result_set, 1);
|
1099
1214
|
|
1215
|
+
rb_define_method(cMysql, "reconnect", reconnect, 0);
|
1216
|
+
rb_define_method(cMysql, "reconnect=", reconnect_set, 1);
|
1217
|
+
|
1100
1218
|
/* Mysql constant */
|
1101
1219
|
#if MYSQL_VERSION_ID >= 32200
|
1102
1220
|
rb_define_const(cMysql, "OPT_CONNECT_TIMEOUT", INT2NUM(MYSQL_OPT_CONNECT_TIMEOUT));
|
@@ -1107,7 +1225,18 @@ void Init_mysql(void)
|
|
1107
1225
|
rb_define_const(cMysql, "READ_DEFAULT_GROUP", INT2NUM(MYSQL_READ_DEFAULT_GROUP));
|
1108
1226
|
#endif
|
1109
1227
|
#if MYSQL_VERSION_ID >= 32349
|
1228
|
+
rb_define_const(cMysql, "SET_CHARSET_DIR", INT2NUM(MYSQL_SET_CHARSET_DIR));
|
1229
|
+
rb_define_const(cMysql, "SET_CHARSET_NAME", INT2NUM(MYSQL_SET_CHARSET_NAME));
|
1110
1230
|
rb_define_const(cMysql, "OPT_LOCAL_INFILE", INT2NUM(MYSQL_OPT_LOCAL_INFILE));
|
1231
|
+
#endif
|
1232
|
+
#if MYSQL_VERSION_ID >= 40100
|
1233
|
+
rb_define_const(cMysql, "OPT_PROTOCOL", INT2NUM(MYSQL_OPT_PROTOCOL));
|
1234
|
+
rb_define_const(cMysql, "SHARED_MEMORY_BASE_NAME", INT2NUM(MYSQL_SHARED_MEMORY_BASE_NAME));
|
1235
|
+
#endif
|
1236
|
+
#if MYSQL_VERSION_ID >= 40101
|
1237
|
+
rb_define_const(cMysql, "OPT_READ_TIMEOUT", INT2NUM(MYSQL_OPT_READ_TIMEOUT));
|
1238
|
+
rb_define_const(cMysql, "OPT_WRITE_TIMEOUT", INT2NUM(MYSQL_OPT_WRITE_TIMEOUT));
|
1239
|
+
rb_define_const(cMysql, "SECURE_AUTH", INT2NUM(MYSQL_SECURE_AUTH));
|
1111
1240
|
#endif
|
1112
1241
|
rb_define_const(cMysql, "REFRESH_GRANT", INT2NUM(REFRESH_GRANT));
|
1113
1242
|
rb_define_const(cMysql, "REFRESH_LOG", INT2NUM(REFRESH_LOG));
|
@@ -1166,6 +1295,16 @@ void Init_mysql(void)
|
|
1166
1295
|
#ifdef CLIENT_TRANSACTIONS
|
1167
1296
|
rb_define_const(cMysql, "CLIENT_TRANSACTIONS", INT2NUM(CLIENT_TRANSACTIONS));
|
1168
1297
|
#endif
|
1298
|
+
#ifdef CLIENT_MULTI_STATEMENTS
|
1299
|
+
rb_define_const(cMysql, "CLIENT_MULTI_STATEMENTS", INT2NUM(CLIENT_MULTI_STATEMENTS));
|
1300
|
+
#endif
|
1301
|
+
#ifdef CLIENT_MULTI_RESULTS
|
1302
|
+
rb_define_const(cMysql, "CLIENT_MULTI_RESULTS", INT2NUM(CLIENT_MULTI_RESULTS));
|
1303
|
+
#endif
|
1304
|
+
#if MYSQL_VERSION_ID >= 40101
|
1305
|
+
rb_define_const(cMysql, "OPTION_MULTI_STATEMENTS_ON", INT2NUM(MYSQL_OPTION_MULTI_STATEMENTS_ON));
|
1306
|
+
rb_define_const(cMysql, "OPTION_MULTI_STATEMENTS_OFF", INT2NUM(MYSQL_OPTION_MULTI_STATEMENTS_OFF));
|
1307
|
+
#endif
|
1169
1308
|
|
1170
1309
|
/* Mysql::Result object method */
|
1171
1310
|
rb_define_method(cMysqlRes, "data_seek", data_seek, 1);
|
@@ -1258,6 +1397,9 @@ void Init_mysql(void)
|
|
1258
1397
|
#ifdef NUM_FLAG
|
1259
1398
|
rb_define_const(cMysqlField, "NUM_FLAG", INT2NUM(NUM_FLAG));
|
1260
1399
|
#endif
|
1400
|
+
#ifdef PART_KEY_FLAG
|
1401
|
+
rb_define_const(cMysqlField, "PART_KEY_FLAG", INT2NUM(PART_KEY_FLAG));
|
1402
|
+
#endif
|
1261
1403
|
|
1262
1404
|
/* Mysql::Error object method */
|
1263
1405
|
rb_define_method(eMysql, "error", error_error, 0);
|
data/mysql.gemspec
ADDED
@@ -0,0 +1,11 @@
|
|
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
|
data/test.rb
CHANGED
@@ -1,33 +1,359 @@
|
|
1
|
-
|
2
|
-
# $Id: test.rb,v 1.
|
3
|
-
#
|
4
|
-
# Execute in mysql-ruby top directory.
|
5
|
-
# Modify following $host, $user, $passwd and $db if needed.
|
6
|
-
# $host: hostname mysql running
|
7
|
-
# $user: mysql username (not unix login user)
|
8
|
-
# $passwd: mysql access passwd for $user
|
9
|
-
# $db: database name for this test. it must not exist before testing.
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
# $Id: test.rb,v 1.6 2005/04/25 14:34:19 tommy Exp $
|
10
3
|
|
4
|
+
require "test/unit"
|
11
5
|
require "./mysql.o"
|
12
6
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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_init()
|
19
|
+
assert_nothing_raised{@m = Mysql.init}
|
20
|
+
assert_nothing_raised{@m.close}
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_real_connect()
|
24
|
+
assert_nothing_raised{@m = Mysql.real_connect(@host, @user, @pass, @db, @port, @sock, @flag)}
|
25
|
+
assert_nothing_raised{@m.close}
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_connect()
|
29
|
+
assert_nothing_raised{@m = Mysql.connect(@host, @user, @pass, @db, @port, @sock, @flag)}
|
30
|
+
assert_nothing_raised{@m.close}
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_new()
|
34
|
+
assert_nothing_raised{@m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)}
|
35
|
+
assert_nothing_raised{@m.close}
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_escape_string()
|
39
|
+
assert_equal("abc\\'def\\\"ghi\\0jkl%mno", Mysql.escape_string("abc'def\"ghi\0jkl%mno"))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_quote()
|
43
|
+
assert_equal("abc\\'def\\\"ghi\\0jkl%mno", Mysql.quote("abc'def\"ghi\0jkl%mno"))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_get_client_info()
|
47
|
+
assert_match(/^\d.\d+.\d+$/, Mysql.get_client_info())
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_client_info()
|
51
|
+
assert_match(/^\d.\d+.\d+$/, Mysql.client_info())
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_options()
|
55
|
+
@m = Mysql.init
|
56
|
+
assert_equal(@m, @m.options(Mysql::INIT_COMMAND, "SET AUTOCOMMIT=0"))
|
57
|
+
assert_equal(@m, @m.options(Mysql::OPT_COMPRESS))
|
58
|
+
assert_equal(@m, @m.options(Mysql::OPT_CONNECT_TIMEOUT, 10))
|
59
|
+
assert_equal(@m, @m.options(Mysql::OPT_LOCAL_INFILE, true))
|
60
|
+
# assert_equal(@m, @m.options(Mysql::OPT_NAMED_PIPE))
|
61
|
+
# 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))
|
64
|
+
# assert_equal(@m, @m.options(Mysql::READ_DEFAULT_FILE, "/tmp/hoge"))
|
65
|
+
assert_equal(@m, @m.options(Mysql::READ_DEFAULT_GROUP, "test"))
|
66
|
+
assert_equal(@m, @m.options(Mysql::SECURE_AUTH, true))
|
67
|
+
# assert_equal(@m, @m.options(Mysql::SET_CHARSET_DIR, "??"))
|
68
|
+
assert_equal(@m, @m.options(Mysql::SET_CHARSET_NAME, "latin1"))
|
69
|
+
# assert_equal(@m, @m.options(Mysql::SHARED_MEMORY_BASE_NAME, "xxx"))
|
70
|
+
assert_equal(@m, @m.connect(@host, @user, @pass, @db, @port, @sock, @flag))
|
71
|
+
@m.close
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_real_connect()
|
75
|
+
@m = Mysql.init
|
76
|
+
assert_equal(@m, @m.real_connect(@host, @user, @pass, @db, @port, @sock, @flag))
|
77
|
+
@m.close
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_connect()
|
81
|
+
@m = Mysql.init
|
82
|
+
assert_equal(@m, @m.connect(@host, @user, @pass, @db, @port, @sock, @flag))
|
83
|
+
@m.close
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
class TC_Mysql2 < Test::Unit::TestCase
|
89
|
+
def setup()
|
90
|
+
@host, @user, @pass, db, port, sock, flag = ARGV
|
91
|
+
@db = db || "test"
|
92
|
+
@port = port.to_i
|
93
|
+
@sock = sock.nil? || sock.empty? ? nil : sock
|
94
|
+
@flag = flag.to_i
|
95
|
+
@m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)
|
96
|
+
end
|
97
|
+
def teardown()
|
98
|
+
@m.close
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_affected_rows()
|
102
|
+
@m.query("create temporary table t (id int)")
|
103
|
+
@m.query("insert into t values (1)")
|
104
|
+
assert_equal(1, @m.affected_rows)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_autocommit()
|
108
|
+
if @m.methods.include? "autocommit" then
|
109
|
+
assert_equal(@m, @m.autocommit(true))
|
110
|
+
assert_equal(@m, @m.autocommit(false))
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# def test_ssl_set()
|
115
|
+
# end
|
116
|
+
|
117
|
+
def test_more_results_next_result()
|
118
|
+
if @m.methods.include? "more_results" then
|
119
|
+
@m.query_with_result = false
|
120
|
+
@m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON)
|
121
|
+
@m.query("select 1,2,3; select 4,5,6")
|
122
|
+
res = @m.store_result
|
123
|
+
assert_equal(["1","2","3"], res.fetch_row)
|
124
|
+
assert_equal(nil, res.fetch_row)
|
125
|
+
assert_equal(true, @m.more_results)
|
126
|
+
assert_equal(true, @m.more_results?)
|
127
|
+
assert_equal(true, @m.next_result)
|
128
|
+
res = @m.store_result
|
129
|
+
assert_equal(["4","5","6"], res.fetch_row)
|
130
|
+
assert_equal(nil, res.fetch_row)
|
131
|
+
assert_equal(false, @m.more_results)
|
132
|
+
assert_equal(false, @m.more_results?)
|
133
|
+
assert_equal(false, @m.next_result)
|
31
134
|
end
|
32
135
|
end
|
136
|
+
|
137
|
+
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
|
141
|
+
|
142
|
+
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
|
147
|
+
|
148
|
+
def test_query_with_result()
|
149
|
+
assert_equal(true, @m.query_with_result)
|
150
|
+
assert_equal(false, @m.query_with_result = false)
|
151
|
+
assert_equal(false, @m.query_with_result)
|
152
|
+
assert_equal(true, @m.query_with_result = true)
|
153
|
+
assert_equal(true, @m.query_with_result)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_reconnect()
|
157
|
+
assert_equal(false, @m.reconnect)
|
158
|
+
assert_equal(true, @m.reconnect = true)
|
159
|
+
assert_equal(true, @m.reconnect)
|
160
|
+
assert_equal(false, @m.reconnect = false)
|
161
|
+
assert_equal(false, @m.reconnect)
|
162
|
+
end
|
33
163
|
end
|
164
|
+
|
165
|
+
class TC_MysqlRes < Test::Unit::TestCase
|
166
|
+
def setup()
|
167
|
+
@host, @user, @pass, db, port, sock, flag = ARGV
|
168
|
+
@db = db || "test"
|
169
|
+
@port = port.to_i
|
170
|
+
@sock = sock.nil? || sock.empty? ? nil : sock
|
171
|
+
@flag = flag.to_i
|
172
|
+
@m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)
|
173
|
+
@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')")
|
175
|
+
@res = @m.query("select * from t")
|
176
|
+
end
|
177
|
+
def teardown()
|
178
|
+
@res.free
|
179
|
+
@m.close
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_num_fields()
|
183
|
+
assert_equal(2, @res.num_fields)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_num_rows()
|
187
|
+
assert_equal(3, @res.num_rows)
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_fetch_row()
|
191
|
+
assert_equal(["1","abc"], @res.fetch_row)
|
192
|
+
assert_equal(["2","defg"], @res.fetch_row)
|
193
|
+
assert_equal(["3","hi"], @res.fetch_row)
|
194
|
+
assert_equal(nil, @res.fetch_row)
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_fetch_hash()
|
198
|
+
assert_equal({"id"=>"1", "str"=>"abc"}, @res.fetch_hash)
|
199
|
+
assert_equal({"id"=>"2", "str"=>"defg"}, @res.fetch_hash)
|
200
|
+
assert_equal({"id"=>"3", "str"=>"hi"}, @res.fetch_hash)
|
201
|
+
assert_equal(nil, @res.fetch_hash)
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_fetch_hash2()
|
205
|
+
assert_equal({"t.id"=>"1", "t.str"=>"abc"}, @res.fetch_hash(true))
|
206
|
+
assert_equal({"t.id"=>"2", "t.str"=>"defg"}, @res.fetch_hash(true))
|
207
|
+
assert_equal({"t.id"=>"3", "t.str"=>"hi"}, @res.fetch_hash(true))
|
208
|
+
assert_equal(nil, @res.fetch_hash)
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_each()
|
212
|
+
ary = [["1","abc"], ["2","defg"], ["3","hi"]]
|
213
|
+
@res.each do |a|
|
214
|
+
assert_equal(ary.shift, a)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_each_hash()
|
219
|
+
hash = [{"id"=>"1","str"=>"abc"}, {"id"=>"2","str"=>"defg"}, {"id"=>"3","str"=>"hi"}]
|
220
|
+
@res.each_hash do |h|
|
221
|
+
assert_equal(hash.shift, h)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_data_seek()
|
226
|
+
assert_equal(["1","abc"], @res.fetch_row)
|
227
|
+
assert_equal(["2","defg"], @res.fetch_row)
|
228
|
+
assert_equal(["3","hi"], @res.fetch_row)
|
229
|
+
@res.data_seek(1)
|
230
|
+
assert_equal(["2","defg"], @res.fetch_row)
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_row_seek()
|
234
|
+
assert_equal(["1","abc"], @res.fetch_row)
|
235
|
+
pos = @res.row_tell
|
236
|
+
assert_equal(["2","defg"], @res.fetch_row)
|
237
|
+
assert_equal(["3","hi"], @res.fetch_row)
|
238
|
+
@res.row_seek(pos)
|
239
|
+
assert_equal(["2","defg"], @res.fetch_row)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_field_seek()
|
243
|
+
assert_equal(0, @res.field_tell)
|
244
|
+
@res.fetch_field
|
245
|
+
assert_equal(1, @res.field_tell)
|
246
|
+
@res.fetch_field
|
247
|
+
assert_equal(2, @res.field_tell)
|
248
|
+
@res.field_seek(1)
|
249
|
+
assert_equal(1, @res.field_tell)
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_fetch_field()
|
253
|
+
f = @res.fetch_field
|
254
|
+
assert_equal("id", f.name)
|
255
|
+
assert_equal("t", f.table)
|
256
|
+
assert_equal(nil, f.def)
|
257
|
+
assert_equal(Mysql::Field::TYPE_LONG, f.type)
|
258
|
+
assert_equal(11, f.length)
|
259
|
+
assert_equal(1, f.max_length)
|
260
|
+
assert_equal(Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG, f.flags)
|
261
|
+
assert_equal(0, f.decimals)
|
262
|
+
f = @res.fetch_field
|
263
|
+
assert_equal("str", f.name)
|
264
|
+
assert_equal("t", f.table)
|
265
|
+
assert_equal(nil, f.def)
|
266
|
+
assert_equal(Mysql::Field::TYPE_STRING, f.type)
|
267
|
+
assert_equal(10, f.length)
|
268
|
+
assert_equal(4, f.max_length)
|
269
|
+
assert_equal(0, f.flags)
|
270
|
+
assert_equal(0, f.decimals)
|
271
|
+
f = @res.fetch_field
|
272
|
+
assert_equal(nil, f)
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_fetch_fields()
|
276
|
+
a = @res.fetch_fields
|
277
|
+
assert_equal(2, a.size)
|
278
|
+
assert_equal("id", a[0].name)
|
279
|
+
assert_equal("str", a[1].name)
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_fetch_field_direct()
|
283
|
+
f = @res.fetch_field_direct(0)
|
284
|
+
assert_equal("id", f.name)
|
285
|
+
f = @res.fetch_field_direct(1)
|
286
|
+
assert_equal("str", f.name)
|
287
|
+
assert_raises(Mysql::Error){@res.fetch_field_direct(-1)}
|
288
|
+
assert_raises(Mysql::Error){@res.fetch_field_direct(2)}
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_fetch_lengths()
|
292
|
+
assert_equal(nil, @res.fetch_lengths())
|
293
|
+
@res.fetch_row
|
294
|
+
assert_equal([1, 3], @res.fetch_lengths())
|
295
|
+
@res.fetch_row
|
296
|
+
assert_equal([1, 4], @res.fetch_lengths())
|
297
|
+
@res.fetch_row
|
298
|
+
assert_equal([1, 2], @res.fetch_lengths())
|
299
|
+
@res.fetch_row
|
300
|
+
assert_equal(nil, @res.fetch_lengths())
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_field_hash()
|
304
|
+
f = @res.fetch_field
|
305
|
+
h = {
|
306
|
+
"name" => "id",
|
307
|
+
"table" => "t",
|
308
|
+
"def" => nil,
|
309
|
+
"type" => Mysql::Field::TYPE_LONG,
|
310
|
+
"length" => 11,
|
311
|
+
"max_length" => 1,
|
312
|
+
"flags" => Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG,
|
313
|
+
"decimals" => 0,
|
314
|
+
}
|
315
|
+
assert_equal(h, f.hash)
|
316
|
+
f = @res.fetch_field
|
317
|
+
h = {
|
318
|
+
"name" => "str",
|
319
|
+
"table" => "t",
|
320
|
+
"def" => nil,
|
321
|
+
"type" => Mysql::Field::TYPE_STRING,
|
322
|
+
"length" => 10,
|
323
|
+
"max_length" => 4,
|
324
|
+
"flags" => 0,
|
325
|
+
"decimals" => 0,
|
326
|
+
}
|
327
|
+
assert_equal(h, f.hash)
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_field_inspect()
|
331
|
+
f = @res.fetch_field
|
332
|
+
assert_equal("#<Mysql::Field:id>", f.inspect)
|
333
|
+
f = @res.fetch_field
|
334
|
+
assert_equal("#<Mysql::Field:str>", f.inspect)
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_is_num()
|
338
|
+
f = @res.fetch_field
|
339
|
+
assert_equal(true, f.is_num?)
|
340
|
+
f = @res.fetch_field
|
341
|
+
assert_equal(false, f.is_num?)
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_is_not_null()
|
345
|
+
f = @res.fetch_field
|
346
|
+
assert_equal(true, f.is_not_null?)
|
347
|
+
f = @res.fetch_field
|
348
|
+
assert_equal(false, f.is_not_null?)
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_is_pri_key()
|
352
|
+
f = @res.fetch_field
|
353
|
+
assert_equal(true, f.is_pri_key?)
|
354
|
+
f = @res.fetch_field
|
355
|
+
assert_equal(false, f.is_pri_key?)
|
356
|
+
end
|
357
|
+
|
358
|
+
end
|
359
|
+
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version:
|
2
|
+
rubygems_version: 0.8.10
|
3
3
|
specification_version: 1
|
4
4
|
name: mysql
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 2.
|
7
|
-
date:
|
6
|
+
version: "2.6"
|
7
|
+
date: 2005-06-23
|
8
8
|
summary: MySQL/Ruby provides the same functions for Ruby programs that the MySQL C API provides for C programs.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
author: TOMITA Masahiro
|
12
11
|
email: tommy@tmtm.org
|
13
12
|
homepage: http://www.tmtm.org/en/mysql/ruby/
|
14
13
|
rubyforge_project:
|
@@ -25,28 +24,17 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
25
24
|
version: 0.0.0
|
26
25
|
version:
|
27
26
|
platform: ruby
|
27
|
+
authors: []
|
28
28
|
files:
|
29
|
-
- t
|
30
29
|
- COPYING
|
31
30
|
- COPYING.ja
|
32
31
|
- README.html
|
33
32
|
- README_ja.html
|
34
33
|
- extconf.rb
|
35
|
-
- mysql-compat.rb
|
36
34
|
- mysql.c.in
|
37
35
|
- test.rb
|
38
36
|
- tommy.css
|
39
|
-
- mysql
|
40
|
-
- mysql-ruby.gemspec
|
41
|
-
- t/00connect.rb
|
42
|
-
- t/10create_db.rb
|
43
|
-
- t/20create_table.rb
|
44
|
-
- t/30insert.rb
|
45
|
-
- t/40select.rb
|
46
|
-
- t/50update.rb
|
47
|
-
- t/60drop_table.rb
|
48
|
-
- t/70drop_db.rb
|
49
|
-
- t/80close.rb
|
37
|
+
- mysql.gemspec
|
50
38
|
test_files: []
|
51
39
|
rdoc_options: []
|
52
40
|
extra_rdoc_files: []
|
data/mysql-compat.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# for compatibility with 1.x
|
2
|
-
# $Id: mysql-compat.rb,v 1.2 1998/11/29 13:02:15 tommy Exp $
|
3
|
-
|
4
|
-
require 'mysql.o'
|
5
|
-
|
6
|
-
class Mysql
|
7
|
-
def Mysql.connect(host=nil, db=nil, user=nil, pass=nil)
|
8
|
-
Mysql.real_connect(host, user, pass, db)
|
9
|
-
end
|
10
|
-
def Mysql.new(host=nil, db=nil, user=nil, pass=nil)
|
11
|
-
Mysql.real_connect(host, user, pass, db)
|
12
|
-
end
|
13
|
-
|
14
|
-
alias selectdb select_db
|
15
|
-
alias affectedrows affected_rows
|
16
|
-
alias insertid insert_id
|
17
|
-
alias createdb create_db
|
18
|
-
alias dropdb drop_db
|
19
|
-
|
20
|
-
def listdbs()
|
21
|
-
ret = []
|
22
|
-
query("show databases").each {|x| ret << x[0]}
|
23
|
-
ret
|
24
|
-
end
|
25
|
-
|
26
|
-
def listtables()
|
27
|
-
ret = []
|
28
|
-
query("show tables").each {|x| ret << x[0]}
|
29
|
-
ret
|
30
|
-
end
|
31
|
-
|
32
|
-
def listfields(table)
|
33
|
-
query("show fields from #{table}")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class MysqlRes
|
38
|
-
alias numrows num_rows
|
39
|
-
alias numfields num_fields
|
40
|
-
alias fetchrow fetch_row
|
41
|
-
alias dataseek data_seek
|
42
|
-
|
43
|
-
def fetchfields()
|
44
|
-
ret = []
|
45
|
-
fetch_fields.each{|f| ret << f.name}
|
46
|
-
ret
|
47
|
-
end
|
48
|
-
|
49
|
-
def fetchhash()
|
50
|
-
row = fetchrow or return nil
|
51
|
-
fields = fetchfields
|
52
|
-
ret = {}
|
53
|
-
fields.each_index {|i| ret[fields[i]] = row[i]}
|
54
|
-
ret
|
55
|
-
end
|
56
|
-
|
57
|
-
def each_hash()
|
58
|
-
while hash = fetchhash
|
59
|
-
yield hash
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/mysql-ruby-2.5.1.gem
DELETED
Binary file
|
data/mysql-ruby.gemspec
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
SPEC = Gem::Specification.new do |s|
|
4
|
-
s.name = "mysql"
|
5
|
-
s.version = "2.5.1"
|
6
|
-
s.author = "TOMITA Masahiro"
|
7
|
-
s.email = "tommy@tmtm.org"
|
8
|
-
s.homepage = "http://www.tmtm.org/en/mysql/ruby/"
|
9
|
-
s.platform = Gem::Platform::RUBY
|
10
|
-
s.summary = "MySQL/Ruby provides the same functions for Ruby programs that the MySQL C API provides for C programs."
|
11
|
-
s.extensions = %w{extconf.rb}
|
12
|
-
s.has_rdoc = false
|
13
|
-
s.autorequire = "mysql"
|
14
|
-
s.files = Dir.glob('**/*')
|
15
|
-
end
|
16
|
-
|
17
|
-
if $0 == __FILE__
|
18
|
-
Gem::manage_gems
|
19
|
-
Gem::Builder.new(spec).build
|
20
|
-
end
|
data/t/00connect.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
$my = Mysql.connect($host, $user, $passwd)
|
data/t/10create_db.rb
DELETED
data/t/20create_table.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
$my.query("create table test (id int not null, str char(32) not null)")
|
data/t/30insert.rb
DELETED
data/t/40select.rb
DELETED
data/t/50update.rb
DELETED
data/t/60drop_table.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
$my.query("drop table test")
|
data/t/70drop_db.rb
DELETED
data/t/80close.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
$my.close
|