@@ -391,12 +391,10 @@ mysqlnd_stmt_prepare_read_eof(MYSQLND_STMT * s)
391391
392392/* {{{ mysqlnd_stmt::prepare */
393393static enum_func_status
394- MYSQLND_METHOD (mysqlnd_stmt , prepare )(MYSQLND_STMT * const s , const char * const query , const size_t query_len )
394+ MYSQLND_METHOD (mysqlnd_stmt , prepare )(MYSQLND_STMT * s , const char * const query , const size_t query_len )
395395{
396396 MYSQLND_STMT_DATA * stmt = s ? s -> data : NULL ;
397397 MYSQLND_CONN_DATA * conn = stmt ? stmt -> conn : NULL ;
398- MYSQLND_STMT * s_to_prepare = s ;
399- MYSQLND_STMT_DATA * stmt_to_prepare = stmt ;
400398
401399 DBG_ENTER ("mysqlnd_stmt::prepare" );
402400 if (!stmt || !conn ) {
@@ -412,25 +410,15 @@ MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const s, const char * const
412410 SET_EMPTY_ERROR (conn -> error_info );
413411
414412 if (stmt -> state > MYSQLND_STMT_INITTED ) {
415- /* See if we have to clean the wire */
416- if (stmt -> state == MYSQLND_STMT_WAITING_USE_OR_STORE ) {
417- /* Do implicit use_result and then flush the result */
418- stmt -> default_rset_handler = s -> m -> use_result ;
419- stmt -> default_rset_handler (s );
420- }
421- /* No 'else' here please :) */
422- if (stmt -> state > MYSQLND_STMT_WAITING_USE_OR_STORE && stmt -> result ) {
423- stmt -> result -> m .skip_result (stmt -> result );
424- }
425413 /*
426- Create a new test statement, which we will prepare, but if anything
427- fails, we will scrap it.
414+ Create a new prepared statement and destroy the previous one.
428415 */
429- s_to_prepare = conn -> m -> stmt_init (conn );
430- if (!s_to_prepare ) {
416+ s -> m -> dtor (s , TRUE);
417+ s = conn -> m -> stmt_init (conn );
418+ if (!s ) {
431419 goto fail ;
432420 }
433- stmt_to_prepare = s_to_prepare -> data ;
421+ stmt = s -> data ;
434422 }
435423
436424 {
@@ -444,13 +432,13 @@ MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const s, const char * const
444432 }
445433 }
446434
447- if (FAIL == mysqlnd_stmt_read_prepare_response (s_to_prepare )) {
435+ if (FAIL == mysqlnd_stmt_read_prepare_response (s )) {
448436 goto fail ;
449437 }
450438
451- if (stmt_to_prepare -> param_count ) {
452- if (FAIL == mysqlnd_stmt_skip_metadata (s_to_prepare ) ||
453- FAIL == mysqlnd_stmt_prepare_read_eof (s_to_prepare ))
439+ if (stmt -> param_count ) {
440+ if (FAIL == mysqlnd_stmt_skip_metadata (s ) ||
441+ FAIL == mysqlnd_stmt_prepare_read_eof (s ))
454442 {
455443 goto fail ;
456444 }
@@ -461,51 +449,31 @@ MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const s, const char * const
461449 Beware that SHOW statements bypass the PS framework and thus they send
462450 no metadata at prepare.
463451 */
464- if (stmt_to_prepare -> field_count ) {
465- MYSQLND_RES * result = conn -> m -> result_init (stmt_to_prepare -> field_count );
452+ if (stmt -> field_count ) {
453+ MYSQLND_RES * result = conn -> m -> result_init (stmt -> field_count );
466454 if (!result ) {
467455 SET_OOM_ERROR (conn -> error_info );
468456 goto fail ;
469457 }
470458 /* Allocate the result now as it is needed for the reading of metadata */
471- stmt_to_prepare -> result = result ;
459+ stmt -> result = result ;
472460
473461 result -> conn = conn -> m -> get_reference (conn );
474462
475463 result -> type = MYSQLND_RES_PS_BUF ;
476464
477465 if (FAIL == result -> m .read_result_metadata (result , conn ) ||
478- FAIL == mysqlnd_stmt_prepare_read_eof (s_to_prepare ))
466+ FAIL == mysqlnd_stmt_prepare_read_eof (s ))
479467 {
480468 goto fail ;
481469 }
482470 }
483471
484- if (stmt_to_prepare != stmt ) {
485- /* swap */
486- size_t real_size = sizeof (MYSQLND_STMT ) + mysqlnd_plugin_count () * sizeof (void * );
487- char * tmp_swap = mnd_malloc (real_size );
488- memcpy (tmp_swap , s , real_size );
489- memcpy (s , s_to_prepare , real_size );
490- memcpy (s_to_prepare , tmp_swap , real_size );
491- mnd_free (tmp_swap );
492- {
493- MYSQLND_STMT_DATA * tmp_swap_data = stmt_to_prepare ;
494- stmt_to_prepare = stmt ;
495- stmt = tmp_swap_data ;
496- }
497- s_to_prepare -> m -> dtor (s_to_prepare , TRUE);
498- }
499472 stmt -> state = MYSQLND_STMT_PREPARED ;
500473 DBG_INF ("PASS" );
501474 DBG_RETURN (PASS );
502475
503476fail :
504- if (stmt_to_prepare != stmt && s_to_prepare ) {
505- s_to_prepare -> m -> dtor (s_to_prepare , TRUE);
506- }
507- stmt -> state = MYSQLND_STMT_INITTED ;
508-
509477 DBG_INF ("FAIL" );
510478 DBG_RETURN (FAIL );
511479}
0 commit comments