Skip to content

Commit 6e662e7

Browse files
committed
also bind return code for dbuse?
1 parent ac9bc43 commit 6e662e7

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

ext/tiny_tds/client.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,8 @@ static void *
944944
dbuse_without_gvl(void *ptr)
945945
{
946946
struct dbuse_args *args = (struct dbuse_args *)ptr;
947-
dbuse(args->dbproc, args->name);
948-
return NULL;
947+
RETCODE rc = dbuse(args->dbproc, args->name);
948+
return (void *)(intptr_t)rc;
949949
}
950950

951951
static VALUE rb_tinytds_connect(VALUE self)
@@ -1060,14 +1060,18 @@ static VALUE rb_tinytds_connect(VALUE self)
10601060
use_args.dbproc = cwrap->client;
10611061
use_args.name = StringValueCStr(database);
10621062

1063-
// in case of any errors, the tinytds_err_handler will be called
1064-
// so we do not have to check the return code here
1065-
rb_thread_call_without_gvl(
1066-
dbuse_without_gvl,
1067-
&use_args,
1068-
NULL,
1069-
NULL
1070-
);
1063+
nogvl_setup(cwrap->client);
1064+
RETCODE retcode = (RETCODE)(intptr_t)rb_thread_call_without_gvl(
1065+
dbuse_without_gvl,
1066+
&use_args,
1067+
NULL,
1068+
NULL
1069+
);
1070+
nogvl_cleanup(cwrap->client);
1071+
1072+
if (retcode == FAIL) {
1073+
rb_raise(cTinyTdsError, "Unable to change to database %s.", use_args.name);
1074+
}
10711075
}
10721076

10731077
transposed_encoding = rb_funcall(cTinyTdsClient, intern_transpose_iconv_encoding, 1, charset);

0 commit comments

Comments
 (0)