convert over to mysql_send_query/mysql_read_query_result non-blocking API
This commit is contained in:
parent
4974ec4a6e
commit
c2fd214cb4
@ -105,10 +105,38 @@ void rb_mysql_client_free(void * client) {
|
|||||||
static VALUE rb_mysql_client_query(VALUE self, VALUE sql) {
|
static VALUE rb_mysql_client_query(VALUE self, VALUE sql) {
|
||||||
MYSQL * client;
|
MYSQL * client;
|
||||||
MYSQL_RES * result;
|
MYSQL_RES * result;
|
||||||
|
fd_set fdset;
|
||||||
|
int fd, retval;
|
||||||
Check_Type(sql, T_STRING);
|
Check_Type(sql, T_STRING);
|
||||||
|
|
||||||
GetMysql2Client(self, client);
|
GetMysql2Client(self, client);
|
||||||
if (mysql_real_query(client, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0) {
|
if (mysql_send_query(client, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0) {
|
||||||
|
rb_raise(cMysql2Error, "%s", mysql_error(client));
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the below code is largely from do_mysql
|
||||||
|
fd = client->net.fd;
|
||||||
|
for(;;) {
|
||||||
|
FD_ZERO(&fdset);
|
||||||
|
FD_SET(fd, &fdset);
|
||||||
|
|
||||||
|
retval = rb_thread_select(fd + 1, &fdset, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
if (retval < 0) {
|
||||||
|
rb_sys_fail(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (retval == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client->status == MYSQL_STATUS_READY) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mysql_read_query_result(client) != 0) {
|
||||||
rb_raise(cMysql2Error, "%s", mysql_error(client));
|
rb_raise(cMysql2Error, "%s", mysql_error(client));
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user