Skip to content

Commit ec36692

Browse files
nyaxtjustincase
authored andcommitted
check is_stream
1 parent a7db7a9 commit ec36692

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

ext/mysql2/statement.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
VALUE cMysql2Statement;
44
extern VALUE mMysql2, cMysql2Error, cBigDecimal, cDateTime, cDate;
5+
static VALUE sym_stream;
56

67
static void rb_mysql_stmt_mark(void * ptr) {
78
mysql_stmt_wrapper* stmt_wrapper = (mysql_stmt_wrapper *)ptr;
@@ -150,6 +151,7 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
150151
VALUE resultObj;
151152
VALUE *params_enc = alloca(sizeof(VALUE) * argc);
152153
unsigned long* length_buffers = NULL;
154+
int is_streaming = 0;
153155
#ifdef HAVE_RUBY_ENCODING_H
154156
rb_encoding *conn_enc;
155157
#endif
@@ -160,6 +162,12 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
160162
conn_enc = rb_to_encoding(wrapper->encoding);
161163
}
162164
#endif
165+
{
166+
VALUE valStreaming = rb_hash_aref(rb_iv_get(stmt_wrapper->client, "@query_options"), sym_stream);
167+
if(valStreaming == Qtrue) {
168+
is_streaming = 1;
169+
}
170+
}
163171

164172
stmt = stmt_wrapper->stmt;
165173

@@ -284,11 +292,15 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
284292
current = rb_hash_dup(rb_iv_get(stmt_wrapper->client, "@query_options"));
285293
GET_CLIENT(stmt_wrapper->client);
286294

287-
// FIXME: don't do this if streaming opt.
288-
if (mysql_stmt_store_result(stmt)) {
289-
rb_raise(cMysql2Error, "%s", mysql_stmt_error(stmt));
295+
if(is_streaming) {
296+
rb_raise(cMysql2Error, "TODO: streaming stmt execute not yet impl.");
297+
} else {
298+
// recieve the whole result set from ther server
299+
if (mysql_stmt_store_result(stmt)) {
300+
rb_raise(cMysql2Error, "%s", mysql_stmt_error(stmt));
301+
}
302+
MARK_CONN_INACTIVE(stmt_wrapper->client);
290303
}
291-
MARK_CONN_INACTIVE(stmt_wrapper->client);
292304

293305
resultObj = rb_mysql_result_to_obj(stmt_wrapper->client, wrapper->encoding, current, metadata, stmt);
294306

@@ -360,4 +372,6 @@ void init_mysql2_statement() {
360372
rb_define_method(cMysql2Statement, "field_count", field_count, 0);
361373
rb_define_method(cMysql2Statement, "execute", execute, -1);
362374
rb_define_method(cMysql2Statement, "fields", fields, 0);
375+
376+
sym_stream = ID2SYM(rb_intern("stream"));
363377
}

0 commit comments

Comments
 (0)