1--source include/have_innodb.inc
2--disable_abort_on_error
3--source include/have_myisam.inc
4
5if (`SELECT HEX(@commands) = HEX('configure')`)
6{
7  connection master;
8
9  #
10  # Index that is used as an Id to tables that trigger errors.
11  #
12  --let $tt_error_counter=0
13  --let $nt_error_counter=0
14
15  #
16  # Creates a T-table that is never dropped.
17  #
18  --eval CREATE TABLE tt_xx_1 ( id INT ) ENGINE = Innodb
19
20  #
21  # Creates a N-table that is never dropped.
22  #
23  --eval CREATE TABLE nt_xx_1 ( id INT ) ENGINE = MyIsam
24
25  #
26  # Creates a T-table that is never dropped.
27  #
28  --eval CREATE TABLE tt_error_1 ( id INT, PRIMARY KEY (id) ) ENGINE = Innodb
29
30  #
31  # Creates a N-table that is never dropped.
32  #
33  --eval CREATE TABLE nt_error_1 ( id INT, PRIMARY KEY (id) ) ENGINE = MyIsam
34
35  #
36  # Creates a T-table that is never dropped.
37  #
38  --eval CREATE TABLE tt_error_2 ( id INT, PRIMARY KEY (id) ) ENGINE = Innodb
39
40  #
41  # Creates a N-table that is never dropped.
42  #
43  --eval CREATE TABLE nt_error_2 ( id INT, PRIMARY KEY (id) ) ENGINE = MyIsam
44
45  #
46  # Create a trigger nt_error_2 --> tt_error_2
47  #
48  DELIMITER |;
49  CREATE TRIGGER tr_i_nt_2_to_tt_2 AFTER INSERT ON nt_error_2 FOR EACH ROW
50  BEGIN
51    DECLARE in_stmt_id INTEGER;
52    INSERT INTO tt_error_2(id) VALUES (NEW.id);
53  END|
54  DELIMITER ;|
55
56  #
57  # Creates a Temporary N-table that is never dropped.
58  #
59  --eval CREATE TEMPORARY TABLE nt_tmp_xx_1 ( id INT ) ENGINE = MyIsam
60
61  #
62  # Creates a Temporary N-table that is never dropped.
63  #
64  --eval CREATE TEMPORARY TABLE tt_tmp_xx_1 ( id INT ) ENGINE = Innodb
65
66  #
67  # In what follows, we create a set of tables that are used
68  # throughout this test case. The number of tables to be
69  # created is give by the variable $tot_table.
70  #
71  #
72  # Creates Temporay N-tables that are automatically dropped and recreated
73  # when a command ends.
74  #
75  --let $n= $tot_table
76  while ($n)
77  {
78    --eval DROP TEMPORARY TABLE IF EXISTS nt_tmp_$n
79    --eval CREATE TEMPORARY TABLE nt_tmp_$n ( id INT ) ENGINE = MyIsam
80    --disable_query_log
81    --eval SET @check_temp='$available_n_temp'
82    --enable_query_log
83    #
84    # Updates the $available_n_temp that keeps track of the created
85    # temporary N-tables.
86    #
87    if (`SELECT HEX(@check_temp) != HEX('')`)
88    {
89      --let $available_n_temp= $available_n_temp,nt_tmp_$n
90    }
91    if (`SELECT HEX(@check_temp) = HEX('')`)
92    {
93      --let $available_n_temp= nt_tmp_$n
94    }
95    --dec $n
96  }
97
98  #
99  # Creates Temporay T-tables that are automatically dropped and recreated
100  # when a command ends.
101  #
102  --let $n= $tot_table
103  while ($n)
104  {
105    --eval DROP TEMPORARY TABLE IF EXISTS tt_tmp_$n
106    --eval CREATE TEMPORARY TABLE tt_tmp_$n ( id INT ) ENGINE = Innodb
107    --disable_query_log
108    --eval SET @check_temp='$available_t_temp'
109    --enable_query_log
110    #
111    # Updates the $available_t_temp that keeps track of the created
112    # temporary T-tables.
113    #
114    if (`SELECT HEX(@check_temp) != HEX('')`)
115    {
116      --let $available_t_temp= $available_t_temp,tt_tmp_$n
117    }
118    if (`SELECT HEX(@check_temp) = HEX('')`)
119    {
120      --let $available_t_temp= tt_tmp_$n
121    }
122    --dec $n
123  }
124
125  #
126  # Creates N-tables that are automatically dropped and recreated
127  # when a command ends.
128  #
129  --let $n= $tot_table
130  while ($n)
131  {
132    --eval DROP TABLE IF EXISTS nt_$n
133    --eval CREATE TABLE nt_$n ( id INT ) ENGINE = MyIsam
134    --disable_query_log
135    --eval SET @check_temp='$available_n'
136    --enable_query_log
137    #
138    # Updates the $available_n that keeps track of the created
139    # N-tables.
140    #
141    if (`SELECT HEX(@check_temp) != HEX('')`)
142    {
143      --let $available_n= $available_n,nt_$n
144    }
145    if (`SELECT HEX(@check_temp) = HEX('')`)
146    {
147      --let $available_n= nt_$n
148    }
149    --dec $n
150  }
151
152  #
153  # Creates T-tables that are automatically dropped and recreated
154  # when a command ends.
155  #
156  --let $n= $tot_table
157  while ($n)
158  {
159    --eval DROP TABLE IF EXISTS tt_$n
160    --eval CREATE TABLE tt_$n ( id INT ) ENGINE = Innodb
161    --disable_query_log
162    --eval SET @check_temp='$available_t'
163    --enable_query_log
164    #
165    # Updates the $available_t that keeps track of the created
166    # T-tables.
167    #
168    if (`SELECT HEX(@check_temp) != HEX('')`)
169    {
170      --let $available_t= $available_t,tt_$n
171    }
172    if (`SELECT HEX(@check_temp) = HEX('')`)
173    {
174      --let $available_t= tt_$n
175    }
176    --dec $n
177  }
178
179  --let $dropped_t_temp=
180  --let $dropped_n_temp=
181
182  --let $dropped_t=
183  --let $dropped_n=
184
185  let $pos_trans_command= query_get_value("SHOW MASTER STATUS", Position, 1);
186
187  SET @commands= '';
188}
189
190#
191# Drops tables and synchronizes master and slave.
192#
193
194if (`SELECT HEX(@commands) = HEX('clean')`)
195{
196  connection master;
197
198  DROP TABLE IF EXISTS tt_xx_1;
199
200  DROP TABLE IF EXISTS nt_xx_1;
201
202  DROP TABLE IF EXISTS tt_error_1;
203
204  DROP TABLE IF EXISTS nt_error_1;
205
206  DROP TABLE IF EXISTS tt_error_2;
207
208  DROP TABLE IF EXISTS nt_error_2;
209
210  DROP TEMPORARY TABLE IF EXISTS tt_tmp_xx_1;
211  DROP TEMPORARY TABLE IF EXISTS nt_tmp_xx_1;
212
213  --let $n= $tot_table
214  while ($n)
215  {
216    --eval DROP TABLE IF EXISTS nt_$n
217    --eval DROP TEMPORARY TABLE IF EXISTS tt_tmp_$n
218    --eval DROP TEMPORARY TABLE IF EXISTS nt_tmp_$n
219    --dec $n
220  }
221
222  --let $n= $tot_table
223  while ($n)
224  {
225    --eval DROP TABLE IF EXISTS tt_$n
226    --dec $n
227  }
228
229  sync_slave_with_master;
230
231  SET @commands= '';
232}
233
234#
235# This is the core of the test is responsible for processing
236# the following commands:
237#
238# B - Begin
239# C - Commit
240# R - Rollback
241#
242#
243# T - Inserts a row into a T-table
244# N-Temp - Inserts a row into a temporary N-table.
245#
246#
247# T-SELECT-N-Temp - Selects from a temporary N-table and inserts
248#                   into a T-table.
249# N-SELECT-N-Temp - Selects from a temporary N-table and inserts
250#                   into a N-table.
251# T-SELECT-T-Temp - Selects from a temporary T-table and inserts
252#                   into a T-table.
253# N-SELECT-T-Temp - Selects from a temporary T-table and inserts
254#                   into a N-table.
255#
256#
257# Create-N-Temp - Creates a temporary N-table if a temporary N-table
258#                 was dropped before
259# Create-T-Temp - Creates a temporary T-table if a temporary T-table
260#                 was dropped before
261#
262#
263# Drop-Temp-T-Temp - Drops a temporary T-table if there is any
264# Drop-Temp-N-Temp - Drops a temporary N-table if there is any
265# Drop-Temp-TN-Temp - Drops both a temporary T-table and N-table if there
266#                     is any
267# Drop-Temp-TT-Temp - Drops two temporary T-tables if there is any
268# Drop-Temp-NN-Temp - Drops two temporary N-tables if there is any
269# Drop-Temp-Xe-Temp - Tries to drop a temporary table that does not exist
270# Drop-Temp-NXe-Temp - Drops a temporary N-table if there is any and
271#                      a temporary table that does not exist
272# Drop-Temp-TXe-Temp - Drops a temporary T-table if there is any and
273#                      a temporary table that does not exist
274#
275#
276# Drop-Temp-If-Xe-Temp - Tries to drop a temporary table that does not exist
277# Drop-Temp-If-TXe-Temp - Drops a temporary T-table if there is any and
278#                         a temporary table that does not exist
279#
280#
281# Drop-T - Drops a T-table if there is any
282# Drop-N - Drops a  N-table if there is any
283# Drop-Xe - Tries to drop a table that does not exist
284# Drop-TXe - Drops a T-table if there is any and a table that does
285#            not exist
286# Drop-NXe - Drops a N-table if there is any and a table that does
287#            not exist
288# Drop-TN - Drops both a T-table and N-table if there is any
289# Drop-TT - Drops two T-tables if there is any
290# Drop-NN - Drops two N-tables if there is any
291# Drop-N-TN-Temp - Drops a N-table and both a temporary T-table and
292#                  N-table if there is any
293#
294#
295# Drop-If-Xe - Tries to drop a table that does not exist
296# Drop-If-TXe - Drops a T-table if there is any and a table that does
297#               not exist
298# Drop-If-NXe - Drops a N-table if there is any and a table that does
299#               not exist
300#
301while (`SELECT HEX(@commands) != HEX('')`)
302{
303  --disable_query_log
304  SET @command= SUBSTRING_INDEX(@commands, ' ', 1);
305  let $command= `SELECT @command`;
306  --eval SET @check_commands= '$commands'
307  if (`SELECT HEX(@check_commands) = HEX('''')`)
308  {
309    let $commands= `SELECT @commands`;
310  }
311
312  if (`SELECT HEX(@command) = HEX('B')`)
313  {
314    --enable_query_log
315    eval BEGIN;
316   --disable_query_log
317  }
318
319  if (`SELECT HEX(@command) = HEX('T')`)
320  {
321    --enable_query_log
322    eval INSERT INTO tt_xx_1() VALUES (1);
323   --disable_query_log
324  }
325
326  if (`SELECT HEX(@command) = HEX('N')`)
327  {
328    --enable_query_log
329    eval INSERT INTO nt_xx_1() VALUES (1);
330   --disable_query_log
331  }
332
333  if (`SELECT HEX(@command) = HEX('Te')`)
334  {
335    --enable_query_log
336    --inc $tt_error_counter
337    eval INSERT INTO tt_error_1() VALUES ($tt_error_counter), ($tt_error_counter);
338   --disable_query_log
339  }
340
341  if (`SELECT HEX(@command) = HEX('Ne')`)
342  {
343    --enable_query_log
344    --inc $nt_error_counter
345    eval INSERT INTO nt_error_1() VALUES ($nt_error_counter), ($nt_error_counter);
346   --disable_query_log
347  }
348
349  if (`SELECT HEX(@command) = HEX('NeT-trig')`)
350  {
351    --enable_query_log
352    --inc $nt_error_counter
353    eval INSERT INTO nt_error_1() VALUES ($nt_error_counter), ($nt_error_counter);
354   --disable_query_log
355  }
356
357  if (`SELECT HEX(@command) = HEX('N-Temp')`)
358  {
359    --enable_query_log
360    eval INSERT INTO nt_tmp_xx_1() VALUES (1);
361   --disable_query_log
362  }
363
364  if (`SELECT HEX(@command) = HEX('N-SELECT-N-Temp')`)
365  {
366    --enable_query_log
367    eval INSERT INTO nt_xx_1 SELECT * FROM nt_tmp_xx_1;
368   --disable_query_log
369  }
370
371  if (`SELECT HEX(@command) = HEX('N-SELECT-T-Temp')`)
372  {
373    --enable_query_log
374    eval INSERT INTO nt_xx_1 SELECT * FROM tt_tmp_xx_1;
375   --disable_query_log
376  }
377
378  if (`SELECT HEX(@command) = HEX('T-SELECT-N-Temp')`)
379  {
380    --enable_query_log
381    eval INSERT INTO tt_xx_1 SELECT * FROM nt_tmp_xx_1;
382   --disable_query_log
383  }
384
385  if (`SELECT HEX(@command) = HEX('T-SELECT-T-Temp')`)
386  {
387    --enable_query_log
388    eval INSERT INTO tt_xx_1 SELECT * FROM tt_tmp_xx_1;
389   --disable_query_log
390  }
391
392  if (`SELECT HEX(@command) = HEX('Create-N-Temp') || HEX(@command) = HEX('Create-T-Temp')`)
393  {
394    if (`SELECT HEX(@command) = HEX('Create-N-Temp')`)
395    {
396      --let $dropped_temp=$dropped_n_temp
397      --let $available_temp=$available_n_temp
398    }
399    if (`SELECT HEX(@command) = HEX('Create-T-Temp')`)
400    {
401      --let $dropped_temp=$dropped_t_temp
402      --let $available_temp=$available_t_temp
403    }
404
405    --eval SET @check_temp='$dropped_temp'
406    if (`SELECT HEX(@check_temp) != HEX('')`)
407    {
408      SET @temp= SUBSTRING_INDEX(@check_temp, ',', 1);
409      let $table=`SELECT @temp`;
410      --eval SET @check_temp='$available_temp'
411      if (`SELECT HEX(@check_temp) != HEX('')`)
412      {
413        --let $available_temp= $available_temp,$table
414      }
415      if (`SELECT HEX(@check_temp) = HEX('')`)
416      {
417        --let $available_temp= $table
418      }
419      --eval SET @check_temp='$dropped_temp'
420      --eval SET @table_temp='$table'
421      SET @check_temp= LTRIM(SUBSTRING(@check_temp, LENGTH(@table_temp) + 2));
422      --let $dropped_temp= `SELECT @check_temp`
423
424      if (`SELECT HEX(@command) = HEX('Create-N-Temp')`)
425      {
426        --enable_query_log
427        --eval CREATE TEMPORARY TABLE $table ( id INT ) engine= MyIsam
428        --disable_query_log
429
430        --let $available_n_temp= $available_temp
431        --let $dropped_n_temp= $dropped_temp
432      }
433      if (`SELECT HEX(@command) = HEX('Create-T-Temp')`)
434      {
435        --enable_query_log
436        --eval CREATE TEMPORARY TABLE $table ( id INT ) engine= Innodb
437        --disable_query_log
438
439        --let $available_t_temp= $available_temp
440        --let $dropped_t_temp= $dropped_temp
441      }
442    }
443  }
444
445  if (`SELECT HEX(@command) = HEX('Drop-Temp-N-Temp') || HEX(@command) = HEX('Drop-Temp-T-Temp') || HEX(@command) = HEX('Drop-T') || HEX(@command) = HEX('Drop-N')`)
446  {
447    if (`SELECT HEX(@command) = HEX('Drop-Temp-N-Temp')`)
448    {
449      --let $dropped_temp=$dropped_n_temp
450      --let $available_temp=$available_n_temp
451    }
452    if (`SELECT HEX(@command) = HEX('Drop-Temp-T-Temp')`)
453    {
454      --let $dropped_temp=$dropped_t_temp
455      --let $available_temp=$available_t_temp
456    }
457    if (`SELECT HEX(@command) = HEX('Drop-N')`)
458    {
459      --let $dropped_temp=$dropped_n
460      --let $available_temp=$available_n
461    }
462    if (`SELECT HEX(@command) = HEX('Drop-T')`)
463    {
464      --let $dropped_temp=$dropped_t
465      --let $available_temp=$available_t
466    }
467
468    --eval SET @check_temp='$available_temp'
469    if (`SELECT HEX(@check_temp) != HEX('')`)
470    {
471      SET @temp= SUBSTRING_INDEX(@check_temp, ',', 1);
472      let $table=`SELECT @temp`;
473      --eval SET @check_temp='$dropped_temp'
474      if (`SELECT HEX(@check_temp) != HEX('')`)
475      {
476        --let $dropped_temp= $dropped_temp,$table
477      }
478      if (`SELECT HEX(@check_temp) = HEX('')`)
479      {
480        --let $dropped_temp= $table
481      }
482      --eval SET @check_temp='$available_temp'
483      --eval SET @table_temp='$table'
484      SET @check_temp= LTRIM(SUBSTRING(@check_temp, LENGTH(@table_temp) + 2));
485      --let $available_temp= `SELECT @check_temp`
486
487      if (`SELECT HEX(@command) = HEX('Drop-Temp-N-Temp')`)
488      {
489        --enable_query_log
490        --eval DROP TEMPORARY TABLE $table
491        --disable_query_log
492
493        --let $available_n_temp= $available_temp
494        --let $dropped_n_temp= $dropped_temp
495      }
496      if (`SELECT HEX(@command) = HEX('Drop-Temp-T-Temp')`)
497      {
498        --enable_query_log
499        --eval DROP TEMPORARY TABLE $table
500        --disable_query_log
501
502        --let $available_t_temp= $available_temp
503        --let $dropped_t_temp= $dropped_temp
504      }
505      if (`SELECT HEX(@command) = HEX('Drop-N')`)
506      {
507        --enable_query_log
508        --eval DROP TABLE $table
509        --disable_query_log
510
511        --let $available_n= $available_temp
512        --let $dropped_n= $dropped_temp
513      }
514      if (`SELECT HEX(@command) = HEX('Drop-T')`)
515      {
516        --enable_query_log
517        --eval DROP TABLE $table
518        --disable_query_log
519
520        --let $available_t= $available_temp
521        --let $dropped_t= $dropped_temp
522      }
523    }
524  }
525
526  if (`SELECT HEX(@command) = HEX('Drop-Temp-Xe-Temp')`)
527  {
528    --enable_query_log
529    --eval DROP TEMPORARY TABLE tt_xx_1
530    --disable_query_log
531  }
532
533  if (`SELECT HEX(@command) = HEX('Drop-Temp-If-Xe-Temp')`)
534  {
535    --enable_query_log
536    --eval DROP TEMPORARY TABLE IF EXISTS tt_xx_1
537    --disable_query_log
538  }
539
540  if (`SELECT HEX(@command) = HEX('Drop-Xe')`)
541  {
542    --enable_query_log
543    --eval DROP TABLE xx_1
544    --disable_query_log
545  }
546
547  if (`SELECT HEX(@command) = HEX('Drop-If-Xe')`)
548  {
549    --enable_query_log
550    --eval DROP TABLE IF EXISTS xx_1
551    --disable_query_log
552  }
553
554  if (`SELECT HEX(@command) = HEX('Drop-Temp-NXe-Temp') || HEX(@command) = HEX('Drop-Temp-TXe-Temp') || HEX(@command) = HEX('Drop-NXe') || HEX(@command) = HEX('Drop-TXe') || HEX(@command) = HEX('Drop-Temp-If-NXe-Temp') || HEX(@command) = HEX('Drop-Temp-If-TXe-Temp') || HEX(@command) = HEX('Drop-If-NXe') || HEX(@command) = HEX('Drop-If-TXe')`)
555  {
556    if (`SELECT HEX(@command) = HEX('Drop-Temp-NXe-Temp') || HEX(@command) = HEX('Drop-Temp-If-NXe-Temp')`)
557    {
558      --let $dropped_temp=$dropped_n_temp
559      --let $available_temp=$available_n_temp
560    }
561    if (`SELECT HEX(@command) = HEX('Drop-Temp-TXe-Temp') || HEX(@command) = HEX('Drop-Temp-If-TXe-Temp')`)
562    {
563      --let $dropped_temp=$dropped_t_temp
564      --let $available_temp=$available_t_temp
565    }
566    if (`SELECT HEX(@command) = HEX('Drop-NXe') || HEX(@command) = HEX('Drop-If-NXe')`)
567    {
568      --let $dropped_temp=$dropped_n
569      --let $available_temp=$available_n
570    }
571    if (`SELECT HEX(@command) = HEX('Drop-TXe') || HEX(@command) = HEX('Drop-If-TXe')`)
572    {
573      --let $dropped_temp=$dropped_t
574      --let $available_temp=$available_t
575    }
576
577    --eval SET @check_temp='$available_temp'
578    if (`SELECT HEX(@check_temp) != HEX('')`)
579    {
580      SET @temp= SUBSTRING_INDEX(@check_temp, ',', 1);
581      let $table=`SELECT @temp`;
582      --eval SET @check_temp='$dropped_temp'
583      if (`SELECT HEX(@check_temp) != HEX('')`)
584      {
585        --let $dropped_temp= $dropped_temp,$table
586      }
587      if (`SELECT HEX(@check_temp) = HEX('')`)
588      {
589        --let $dropped_n_temp= $table
590      }
591      --eval SET @check_temp='$available_temp'
592      --eval SET @table_temp='$table'
593      SET @check_temp= LTRIM(SUBSTRING(@check_temp, LENGTH(@table_temp) + 2));
594      --let $available_temp= `SELECT @check_temp`
595
596      if (`SELECT HEX(@command) = HEX('Drop-Temp-NXe-Temp')`)
597      {
598        --enable_query_log
599        --eval DROP TEMPORARY TABLE $table, tt_1
600        --disable_query_log
601
602        --let $available_n_temp= $available_temp
603        --let $dropped_n_temp= $dropped_temp
604      }
605      if (`SELECT HEX(@command) = HEX('Drop-Temp-If-NXe-Temp')`)
606      {
607        --enable_query_log
608        --eval DROP TEMPORARY TABLE IF EXISTS $table, tt_1
609        --disable_query_log
610
611        --let $available_n_temp= $available_temp
612        --let $dropped_n_temp= $dropped_temp
613      }
614      if (`SELECT HEX(@command) = HEX('Drop-Temp-TXe-Temp')`)
615      {
616        --enable_query_log
617        --eval DROP TEMPORARY TABLE $table, tt_1
618        --disable_query_log
619
620        --let $available_t_temp= $available_temp
621        --let $dropped_t_temp= $dropped_temp
622      }
623      if (`SELECT HEX(@command) = HEX('Drop-Temp-If-TXe-Temp')`)
624      {
625        --enable_query_log
626        --eval DROP TEMPORARY TABLE IF EXISTS $table, tt_1
627        --disable_query_log
628
629        --let $available_t_temp= $available_temp
630        --let $dropped_t_temp= $dropped_temp
631      }
632      if (`SELECT HEX(@command) = HEX('Drop-NXe')`)
633      {
634        --enable_query_log
635        --eval DROP TABLE $table, xx_1
636        --disable_query_log
637
638        --let $available_n= $available_temp
639        --let $dropped_n= $dropped_temp
640      }
641      if (`SELECT HEX(@command) = HEX('Drop-If-NXe')`)
642      {
643        --enable_query_log
644        --eval DROP TABLE IF EXISTS $table, xx_1
645        --disable_query_log
646
647        --let $available_n= $available_temp
648        --let $dropped_n= $dropped_temp
649      }
650      if (`SELECT HEX(@command) = HEX('Drop-TXe')`)
651      {
652        --enable_query_log
653        --eval DROP TABLE $table, xx_1
654        --disable_query_log
655
656        --let $available_t= $available_temp
657        --let $dropped_t= $dropped_temp
658      }
659      if (`SELECT HEX(@command) = HEX('Drop-If-TXe')`)
660      {
661        --enable_query_log
662        --eval DROP TABLE IF EXISTS $table, xx_1
663        --disable_query_log
664
665        --let $available_t= $available_temp
666        --let $dropped_t= $dropped_temp
667      }
668    }
669  }
670
671  if (`SELECT HEX(@command) = HEX('Drop-Temp-NN-Temp') || HEX(@command) = HEX('Drop-Temp-TT-Temp') || HEX(@command) = HEX('Drop-NN') || HEX(@command) = HEX('Drop-TT')`)
672  {
673    if (`SELECT HEX(@command) = HEX('Drop-Temp-NN-Temp')`)
674    {
675      --let $dropped_temp=$dropped_n_temp
676      --let $available_temp=$available_n_temp
677    }
678    if (`SELECT HEX(@command) = HEX('Drop-Temp-TT-Temp')`)
679    {
680      --let $dropped_temp=$dropped_t_temp
681      --let $available_temp=$available_t_temp
682    }
683    if (`SELECT HEX(@command) = HEX('Drop-NN')`)
684    {
685      --let $dropped_temp=$dropped_n
686      --let $available_temp=$available_n
687    }
688    if (`SELECT HEX(@command) = HEX('Drop-TT')`)
689    {
690      --let $dropped_temp=$dropped_t
691      --let $available_temp=$available_t
692    }
693
694    --eval SET @check_temp='$available_temp'
695    if (`SELECT HEX(@check_temp) != HEX('')`)
696    {
697      --let $n= 2
698      while (`SELECT HEX(@check_temp) != HEX('') && $n != 0`)
699      {
700        SET @temp= SUBSTRING_INDEX(@check_temp, ',', 1);
701        let $table=`SELECT @temp`;
702        --eval SET @check_temp='$dropped_temp'
703        if (`SELECT HEX(@check_temp) != HEX('')`)
704        {
705          --let $dropped_temp= $dropped_temp,$table
706        }
707        if (`SELECT HEX(@check_temp) = HEX('')`)
708        {
709          --let $dropped_temp= $table
710        }
711        if ($n == 1)
712        {
713          --let $table_1= $table
714        }
715        if ($n == 2)
716        {
717          --let $table_2= $table
718        }
719
720        --dec $n
721        --eval SET @check_temp='$available_temp'
722        --eval SET @table_temp='$table'
723        SET @check_temp= LTRIM(SUBSTRING(@check_temp, LENGTH(@table_temp) + 2));
724        --let $available_temp= `SELECT @check_temp`
725      }
726
727      if (`SELECT HEX(@command) = HEX('Drop-Temp-NN-Temp') && $n = 0`)
728      {
729        --enable_query_log
730        --eval DROP TEMPORARY TABLE $table_1, $table_2
731        --disable_query_log
732
733        --let $available_n_temp= $available_temp
734        --let $dropped_n_temp= $dropped_temp
735      }
736      if (`SELECT HEX(@command) = HEX('Drop-Temp-TT-Temp') && $n= 0`)
737      {
738        --enable_query_log
739        --eval DROP TEMPORARY TABLE $table_1, $table_2
740        --disable_query_log
741
742        --let $available_t_temp= $available_temp
743        --let $dropped_t_temp= $dropped_temp
744      }
745      if (`SELECT HEX(@command) = HEX('Drop-NN') && $n = 0`)
746      {
747        --enable_query_log
748        --eval DROP TABLE $table_1, $table_2
749        --disable_query_log
750
751        --let $available_n= $available_temp
752        --let $dropped_n= $dropped_temp
753      }
754      if (`SELECT HEX(@command) = HEX('Drop-TT') && $n= 0`)
755      {
756        --enable_query_log
757        --eval DROP TABLE $table_1, $table_2
758        --disable_query_log
759
760        --let $available_t= $available_temp
761        --let $dropped_t= $dropped_temp
762      }
763    }
764  }
765
766  if (`SELECT HEX(@command) = HEX('Drop-Temp-TN-Temp')`)
767  {
768    --eval SET @check_temp_t='$available_t_temp'
769    --eval SET @check_temp_n='$available_n_temp'
770    if (`SELECT HEX(@check_temp_t) != HEX('') && HEX(@check_temp_n) != HEX('')`)
771    {
772      SET @temp_t= SUBSTRING_INDEX(@check_temp_t, ',', 1);
773      let $table_t=`SELECT @temp_t`;
774      --eval SET @check_temp_t='$dropped_t_temp'
775      if (`SELECT HEX(@check_temp_t) != HEX('')`)
776      {
777        --let $dropped_t_temp= $dropped_t_temp,$table_t
778      }
779      if (`SELECT HEX(@check_temp_t) = HEX('')`)
780      {
781        --let $dropped_t_temp= $table_t
782      }
783      --eval SET @check_temp='$available_t_temp'
784      --eval SET @table_temp='$table_t'
785      SET @check_temp= LTRIM(SUBSTRING(@check_temp, LENGTH(@table_temp) + 2));
786      --let $available_t_temp= `SELECT @check_temp`
787
788      SET @temp_n= SUBSTRING_INDEX(@check_temp_n, ',', 1);
789      let $table_n=`SELECT @temp_n`;
790      --eval SET @check_temp_n='$dropped_n_temp'
791      if (`SELECT HEX(@check_temp_n) != HEX('')`)
792      {
793        --let $dropped_n_temp= $dropped_n_temp,$table_n
794      }
795      if (`SELECT HEX(@check_temp_n) = HEX('')`)
796      {
797        --let $dropped_n_temp= $table_n
798      }
799      --eval SET @check_temp='$available_n_temp'
800      --eval SET @table_temp='$table_n'
801      SET @check_temp= LTRIM(SUBSTRING(@check_temp, LENGTH(@table_temp) + 2));
802      --let $available_n_temp= `SELECT @check_temp`
803
804      --enable_query_log
805      --eval DROP TEMPORARY TABLE $table_t, $table_n
806      --disable_query_log
807    }
808  }
809
810  if (`SELECT HEX(@command) = HEX('Drop-TN')`)
811  {
812    --eval SET @check_temp_t='$available_t'
813    --eval SET @check_temp_n='$available_n'
814    if (`SELECT HEX(@check_temp_t) != HEX('') && HEX(@check_temp_n) != HEX('')`)
815    {
816      SET @temp_t= SUBSTRING_INDEX(@check_temp_t, ',', 1);
817      let $table_t=`SELECT @temp_t`;
818      --eval SET @check_temp_t='$dropped_t'
819      if (`SELECT HEX(@check_temp_t) != HEX('')`)
820      {
821        --let $dropped_t= $dropped_t,$table_t
822      }
823      if (`SELECT HEX(@check_temp_t) = HEX('')`)
824      {
825        --let $dropped_t= $table_t
826      }
827      --eval SET @check_temp='$available_t'
828      --eval SET @table_temp='$table_t'
829      SET @check_temp= LTRIM(SUBSTRING(@check_temp, LENGTH(@table_temp) + 2));
830      --let $available_t= `SELECT @check_temp`
831
832      SET @temp_n= SUBSTRING_INDEX(@check_temp_n, ',', 1);
833      let $table_n=`SELECT @temp_n`;
834      --eval SET @check_temp_n='$dropped_n'
835      if (`SELECT HEX(@check_temp_n) != HEX('')`)
836      {
837        --let $dropped_n= $dropped_n,$table_n
838      }
839      if (`SELECT HEX(@check_temp_n) = HEX('')`)
840      {
841        --let $dropped_n= $table_n
842      }
843      --eval SET @check_temp='$available_n'
844      --eval SET @table_temp='$table_n'
845      SET @check_temp= LTRIM(SUBSTRING(@check_temp, LENGTH(@table_temp) + 2));
846      --let $available_t= `SELECT @check_temp`
847
848      --enable_query_log
849      --eval DROP TABLE $table_t, $table_n
850      --disable_query_log
851    }
852  }
853
854  if (`SELECT HEX(@command) = HEX('Drop-N-TN-Temp') || HEX(@command) = HEX('Drop-TN-Temp')`)
855  {
856    --eval SET @check_temp_t='$available_t_temp'
857    --eval SET @check_temp_n='$available_n_temp'
858    if (`SELECT HEX(@command) = HEX('Drop-N-TN-Temp')`)
859    {
860      --eval SET @check_n='$available_n'
861    }
862    if (`SELECT HEX(@command) = HEX('Drop-TN-Temp')`)
863    {
864      #
865      # Just to be possible to go through the next if...
866      #
867      --eval SET @check_n='...'
868    }
869    if (`SELECT HEX(@check_temp_t) != HEX('') && HEX(@check_temp_n) != HEX('') && HEX(@check_n) != HEX('')`)
870    {
871      SET @temp_t= SUBSTRING_INDEX(@check_temp_t, ',', 1);
872      let $table_temp_t=`SELECT @temp_t`;
873      --eval SET @check_temp_t='$dropped_t_temp'
874      if (`SELECT HEX(@check_temp_t) != HEX('')`)
875      {
876        --let $dropped_t_temp= $dropped_t_temp,$table_temp_t
877      }
878      if (`SELECT HEX(@check_temp_t) = HEX('')`)
879      {
880        --let $dropped_t_temp= $table_temp_t
881      }
882      --eval SET @check_temp='$available_t_temp'
883      --eval SET @table_temp='$table_temp_t'
884      SET @check_temp= LTRIM(SUBSTRING(@check_temp, LENGTH(@table_temp) + 2));
885      --let $available_t_temp= `SELECT @check_temp`
886
887      SET @temp_n= SUBSTRING_INDEX(@check_temp_n, ',', 1);
888      let $table_temp_n=`SELECT @temp_n`;
889      --eval SET @check_temp_n='$dropped_n_temp'
890      if (`SELECT HEX(@check_temp_n) != HEX('')`)
891      {
892        --let $dropped_n_temp= $dropped_n_temp,$table_temp_n
893      }
894      if (`SELECT HEX(@check_temp_n) = HEX('')`)
895      {
896        --let $dropped_n_temp= $table_temp_n
897      }
898      --eval SET @check_temp='$available_n_temp'
899      --eval SET @table_temp='$table_temp_n'
900      SET @check_temp= LTRIM(SUBSTRING(@check_temp, LENGTH(@table_temp) + 2));
901      --let $available_n_temp= `SELECT @check_temp`
902
903      if (`SELECT HEX(@command) = HEX('Drop-N-TN-Temp')`)
904      {
905        SET @temp_n= SUBSTRING_INDEX(@check_n, ',', 1);
906        let $table_n=`SELECT @temp_n`;
907        --eval SET @check_n='$dropped_n'
908        if (`SELECT HEX(@check_n) != HEX('')`)
909        {
910          --let $dropped_n= $dropped_n,$table_n
911        }
912        if (`SELECT HEX(@check_n) = HEX('')`)
913        {
914          --let $dropped_n= $table_n
915        }
916        --eval SET @check_temp='$available_n'
917        --eval SET @table_temp='$table_n'
918        SET @check_temp= LTRIM(SUBSTRING(@check_temp, LENGTH(@table_temp) + 2));
919        --let $available_n= `SELECT @check_temp`
920
921        --enable_query_log
922        --eval DROP TABLE $table_temp_t, $table_temp_n, $table_n
923        --disable_query_log
924      }
925      if (`SELECT HEX(@command) = HEX('Drop-TN-Temp')`)
926      {
927        --enable_query_log
928        --eval DROP TABLE $table_temp_t, $table_temp_n
929        --disable_query_log
930      }
931    }
932  }
933
934  if (`SELECT HEX(@command) = HEX('C')`)
935  {
936    --enable_query_log
937    --error 0, ER_GET_ERRMSG
938    eval COMMIT;
939    --disable_query_log
940  }
941
942  if (`SELECT HEX(@command) = HEX('R')`)
943  {
944    --enable_query_log
945    --error 0, ER_GET_ERRMSG
946    --replace_column 2 #
947    eval ROLLBACK;
948    --disable_query_log
949  }
950
951  SET @commands= LTRIM(SUBSTRING(@commands, LENGTH(@command) + 1));
952  if (`SELECT HEX(@commands) = HEX('')`)
953  {
954    let $binlog_start= $pos_trans_command;
955    --echo -b-b-b-b-b-b-b-b-b-b-b- >> $commands << -b-b-b-b-b-b-b-b-b-b-b-
956    # Use other connection because include/show_binlog_events.inc
957    # executes SELECT UUID(), which switches to row-logging when
958    # binlog_format=mixed, if there are open temporary tables. This is
959    # due to BUG#13692513.
960    --connection server_1
961    --source include/show_binlog_events.inc
962    --connection master
963    --echo -e-e-e-e-e-e-e-e-e-e-e- >> $commands << -e-e-e-e-e-e-e-e-e-e-e-
964    --echo
965
966    --disable_warnings
967    --let $available_n_temp=
968    --let $dropped_n_temp=
969    --let $n= $tot_table
970    while ($n)
971    {
972      --eval DROP TEMPORARY TABLE IF EXISTS nt_tmp_$n
973      --eval CREATE TEMPORARY TABLE nt_tmp_$n ( id INT ) ENGINE = MyIsam
974      --eval SET @check_temp='$available_n_temp'
975      if (`SELECT HEX(@check_temp) != HEX('')`)
976      {
977        --let $available_n_temp= $available_n_temp,nt_tmp_$n
978      }
979      if (`SELECT HEX(@check_temp) = HEX('')`)
980      {
981        --let $available_n_temp= nt_tmp_$n
982      }
983      --dec $n
984    }
985
986    --let $available_t_temp=
987    --let $dropped_t_temp=
988    --let $n= $tot_table
989    while ($n)
990    {
991      --eval DROP TEMPORARY TABLE IF EXISTS tt_tmp_$n
992      --eval CREATE TEMPORARY TABLE tt_tmp_$n ( id INT ) ENGINE = Innodb
993      --eval SET @check_temp='$available_t_temp'
994      if (`SELECT HEX(@check_temp) != HEX('')`)
995      {
996        --let $available_t_temp= $available_t_temp,tt_tmp_$n
997      }
998      if (`SELECT HEX(@check_temp) = HEX('')`)
999      {
1000        --let $available_t_temp= tt_tmp_$n
1001      }
1002      --dec $n
1003    }
1004
1005    --let $available_t=
1006    --let $dropped_t=
1007    --let $n= $tot_table
1008    while ($n)
1009    {
1010      --eval DROP TABLE IF EXISTS tt_$n
1011      --eval CREATE TABLE tt_$n ( id INT ) ENGINE = Innodb
1012      --eval SET @check_temp='$available_t'
1013      if (`SELECT HEX(@check_temp) != HEX('')`)
1014      {
1015        --let $available_t= $available_t,tt_$n
1016      }
1017      if (`SELECT HEX(@check_temp) = HEX('')`)
1018      {
1019        --let $available_t= tt_$n
1020      }
1021      --dec $n
1022    }
1023
1024    --let $available_n=
1025    --let $dropped_n=
1026    --let $n= $tot_table
1027    while ($n)
1028    {
1029      --eval DROP TABLE IF EXISTS nt_$n
1030      --eval CREATE TABLE nt_$n ( id INT ) ENGINE = MyIsam
1031      --eval SET @check_temp='$available_n'
1032      if (`SELECT HEX(@check_temp) != HEX('')`)
1033      {
1034        --let $available_n= $available_n,nt_$n
1035      }
1036      if (`SELECT HEX(@check_temp) = HEX('')`)
1037      {
1038        --let $available_n= nt_$n
1039      }
1040      --dec $n
1041    }
1042    --enable_warnings
1043
1044    let $pos_trans_command= query_get_value("SHOW MASTER STATUS", Position, 1);
1045    let $commands= '';
1046  }
1047  --enable_query_log
1048}
1049