@@ -31,6 +31,7 @@ VALUE rb_raise_mysql2_stmt_error2(MYSQL_STMT *stmt
3131 ) {
3232 VALUE rb_error_msg = rb_str_new2 (mysql_stmt_error (stmt ));
3333 VALUE rb_sql_state = rb_tainted_str_new2 (mysql_stmt_sqlstate (stmt ));
34+ VALUE e = rb_exc_new3 (cMysql2Error , rb_error_msg );
3435#ifdef HAVE_RUBY_ENCODING_H
3536 rb_encoding * default_internal_enc = rb_default_internal_encoding ();
3637
@@ -41,8 +42,6 @@ VALUE rb_raise_mysql2_stmt_error2(MYSQL_STMT *stmt
4142 rb_sql_state = rb_str_export_to_enc (rb_sql_state , default_internal_enc );
4243 }
4344#endif
44-
45- VALUE e = rb_exc_new3 (cMysql2Error , rb_error_msg );
4645 rb_funcall (e , intern_error_number_eql , 1 , UINT2NUM (mysql_stmt_errno (stmt )));
4746 rb_funcall (e , intern_sql_state_eql , 1 , rb_sql_state );
4847 rb_exc_raise (e );
@@ -209,19 +208,15 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
209208 long i ;
210209 MYSQL_STMT * stmt ;
211210 MYSQL_RES * metadata ;
211+ VALUE current ;
212212 VALUE resultObj ;
213213 VALUE * params_enc = alloca (sizeof (VALUE ) * argc );
214214 unsigned long * length_buffers = NULL ;
215215 int is_streaming = 0 ;
216- #ifdef HAVE_RUBY_ENCODING_H
217- rb_encoding * conn_enc ;
218- #endif
219216 GET_STATEMENT (self );
217+ GET_CLIENT (stmt_wrapper -> client );
220218#ifdef HAVE_RUBY_ENCODING_H
221- {
222- GET_CLIENT (stmt_wrapper -> client );
223- conn_enc = rb_to_encoding (wrapper -> encoding );
224- }
219+ rb_encoding * conn_enc = rb_to_encoding (wrapper -> encoding );
225220#endif
226221 {
227222 VALUE valStreaming = rb_hash_aref (rb_iv_get (stmt_wrapper -> client , "@query_options" ), sym_stream );
@@ -287,11 +282,12 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
287282 default :
288283 // TODO: what Ruby type should support MYSQL_TYPE_TIME
289284 if (CLASS_OF (argv [i ]) == rb_cTime || CLASS_OF (argv [i ]) == cDateTime ) {
285+ MYSQL_TIME t ;
286+ VALUE rb_time = argv [i ];
287+
290288 bind_buffers [i ].buffer_type = MYSQL_TYPE_DATETIME ;
291289 bind_buffers [i ].buffer = xmalloc (sizeof (MYSQL_TIME ));
292290
293- MYSQL_TIME t ;
294- VALUE rb_time = argv [i ];
295291 memset (& t , 0 , sizeof (MYSQL_TIME ));
296292 t .neg = 0 ;
297293 t .second_part = FIX2INT (rb_funcall (rb_time , rb_intern ("usec" ), 0 ));
@@ -304,13 +300,12 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
304300
305301 * (MYSQL_TIME * )(bind_buffers [i ].buffer ) = t ;
306302 } else if (CLASS_OF (argv [i ]) == cDate ) {
303+ MYSQL_TIME t ;
304+ VALUE rb_time = argv [i ];
307305
308306 bind_buffers [i ].buffer_type = MYSQL_TYPE_DATE ;
309-
310307 bind_buffers [i ].buffer = xmalloc (sizeof (MYSQL_TIME ));
311308
312- MYSQL_TIME t ;
313- VALUE rb_time = argv [i ];
314309 memset (& t , 0 , sizeof (MYSQL_TIME ));
315310 t .second_part = 0 ;
316311 t .neg = 0 ;
@@ -352,9 +347,7 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
352347 return Qnil ;
353348 }
354349
355- VALUE current ;
356350 current = rb_hash_dup (rb_iv_get (stmt_wrapper -> client , "@query_options" ));
357- GET_CLIENT (stmt_wrapper -> client );
358351
359352 if (!is_streaming ) {
360353 // recieve the whole result set from the server
0 commit comments