|
5 | 5 | VALUE cTinyTdsClient; |
6 | 6 | extern VALUE mTinyTds, cTinyTdsError; |
7 | 7 | static ID intern_source_eql, intern_severity_eql, intern_db_error_number_eql, intern_os_error_number_eql; |
8 | | -static ID intern_new, intern_dup, intern_transpose_iconv_encoding, intern_local_offset, intern_gsub, intern_call; |
| 8 | +static ID intern_new, intern_dup, intern_transpose_iconv_encoding, intern_local_offset, intern_gsub, intern_call, intern_active, intern_connect; |
9 | 9 | VALUE opt_escape_regex, opt_escape_dblquote; |
10 | 10 |
|
11 | 11 | static ID id_ivar_fields, id_ivar_rows, id_ivar_return_code, id_ivar_affected_rows, id_ivar_default_query_options, intern_bigd, intern_divide; |
@@ -468,11 +468,15 @@ static VALUE allocate(VALUE klass) |
468 | 468 |
|
469 | 469 |
|
470 | 470 | // TinyTds::Client (public) |
471 | | - |
472 | 471 | static VALUE rb_tinytds_server_version(VALUE self) |
473 | 472 | { |
474 | 473 | GET_CLIENT_WRAPPER(self); |
475 | | - return INT2FIX(dbtds(cwrap->client)); |
| 474 | + |
| 475 | + if (rb_funcall(self, intern_active, 0) == Qtrue) { |
| 476 | + return INT2FIX(dbtds(cwrap->client)); |
| 477 | + } else { |
| 478 | + return Qnil; |
| 479 | + } |
476 | 480 | } |
477 | 481 |
|
478 | 482 | static VALUE rb_tinytds_close(VALUE self) |
@@ -745,6 +749,11 @@ static VALUE rb_tinytds_execute(int argc, VALUE *argv, VALUE self) |
745 | 749 | } |
746 | 750 |
|
747 | 751 | GET_CLIENT_WRAPPER(self); |
| 752 | + |
| 753 | + if (rb_funcall(self, intern_active, 0) == Qfalse) { |
| 754 | + rb_funcall(self, intern_connect, 0); |
| 755 | + } |
| 756 | + |
748 | 757 | rb_tinytds_send_sql_to_server(cwrap, sql); |
749 | 758 |
|
750 | 759 | VALUE result = rb_obj_alloc(cTinyTdsResult); |
@@ -856,6 +865,11 @@ static VALUE rb_tiny_tds_insert(VALUE self, VALUE sql) |
856 | 865 | { |
857 | 866 | VALUE identity = Qnil; |
858 | 867 | GET_CLIENT_WRAPPER(self); |
| 868 | + |
| 869 | + if (rb_funcall(self, intern_active, 0) == Qfalse) { |
| 870 | + rb_funcall(self, intern_connect, 0); |
| 871 | + } |
| 872 | + |
859 | 873 | rb_tinytds_send_sql_to_server(cwrap, sql); |
860 | 874 | rb_tinytds_result_exec_helper(cwrap->client); |
861 | 875 |
|
@@ -885,6 +899,11 @@ static VALUE rb_tiny_tds_insert(VALUE self, VALUE sql) |
885 | 899 | static VALUE rb_tiny_tds_do(VALUE self, VALUE sql) |
886 | 900 | { |
887 | 901 | GET_CLIENT_WRAPPER(self); |
| 902 | + |
| 903 | + if (rb_funcall(self, intern_active, 0) == Qfalse) { |
| 904 | + rb_funcall(self, intern_connect, 0); |
| 905 | + } |
| 906 | + |
888 | 907 | rb_tinytds_send_sql_to_server(cwrap, sql); |
889 | 908 | rb_tinytds_result_exec_helper(cwrap->client); |
890 | 909 |
|
@@ -1054,8 +1073,7 @@ void init_tinytds_client() |
1054 | 1073 | rb_define_method(cTinyTdsClient, "escape", rb_tinytds_escape, 1); |
1055 | 1074 | rb_define_method(cTinyTdsClient, "return_code", rb_tinytds_return_code, 0); |
1056 | 1075 | rb_define_method(cTinyTdsClient, "identity_sql", rb_tinytds_identity_sql, 0); |
1057 | | - /* Define TinyTds::Client Protected Methods */ |
1058 | | - rb_define_protected_method(cTinyTdsClient, "connect", rb_tinytds_connect, 0); |
| 1076 | + rb_define_method(cTinyTdsClient, "connect", rb_tinytds_connect, 0); |
1059 | 1077 | /* Intern TinyTds::Error Accessors */ |
1060 | 1078 | intern_source_eql = rb_intern("source="); |
1061 | 1079 | intern_severity_eql = rb_intern("severity="); |
@@ -1088,6 +1106,8 @@ void init_tinytds_client() |
1088 | 1106 | intern_timezone = rb_intern("timezone"); |
1089 | 1107 | intern_utc = rb_intern("utc"); |
1090 | 1108 | intern_local = rb_intern("local"); |
| 1109 | + intern_active = rb_intern("active?"); |
| 1110 | + intern_connect = rb_intern("connect"); |
1091 | 1111 |
|
1092 | 1112 | cTinyTdsClient = rb_const_get(mTinyTds, rb_intern("Client")); |
1093 | 1113 | cTinyTdsResult = rb_const_get(mTinyTds, rb_intern("Result")); |
|
0 commit comments