PageRenderTime 54ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/mysql-test/t/mysqltest.test

https://bitbucket.org/Habibutsu/mysql
Unknown | 2939 lines | 2445 code | 494 blank | 0 comment | 0 complexity | 101d155ce8b33bb2ddbd458ab7f76fdb MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. # ----------------------------------------------------------------------------
  2. # $mysql_errno contains the return code of the last command
  3. # sent to the server.
  4. # ----------------------------------------------------------------------------
  5. # get $mysql_errno before the first statement
  6. # $mysql_errno should be -1
  7. # get $mysql_errname as well
  8. echo $mysql_errno before test;
  9. echo $mysql_errname before test;
  10. -- source include/have_log_bin.inc
  11. # This test should work in embedded server after mysqltest is fixed
  12. -- source include/not_embedded.inc
  13. # This test uses chmod, can't be run with root permissions
  14. -- source include/not_as_root.inc
  15. # Save the initial number of concurrent sessions
  16. --source include/count_sessions.inc
  17. # ============================================================================
  18. #
  19. # Test of mysqltest itself
  20. #
  21. # There are three rules that determines what belong to each command
  22. # 1. A normal command is delimited by the <delimiter> which by default is
  23. # set to ';'
  24. #
  25. # ex: | select *
  26. # | from t1;
  27. # |
  28. # Command: "select * from t1"
  29. #
  30. # 2. Special case is a line that starts with "--", this is a comment
  31. # ended when the new line character is reached. But the first word
  32. # in the comment may contain a valid command, which then will be
  33. # executed. This can be useful when sending commands that
  34. # contains <delimiter>
  35. #
  36. # 3. Special case is also a line that starts with '#' which is treated
  37. # as a comment and will be ended by new line character
  38. #
  39. # ============================================================================
  40. # ----------------------------------------------------------------------------
  41. # Positive case(statement)
  42. # ----------------------------------------------------------------------------
  43. select otto from (select 1 as otto) as t1;
  44. # expectation = response
  45. --error 0
  46. select otto from (select 1 as otto) as t1;
  47. # ----------------------------------------------------------------------------
  48. # Negative case(statement):
  49. # The derived table t1 does not contain a column named 'friedrich' .
  50. # --> ERROR 42S22: Unknown column 'friedrich' in 'field list and
  51. # --> 1054: Unknown column 'friedrich' in 'field list'
  52. # ----------------------------------------------------------------------------
  53. # expectation <> response
  54. #--error 0
  55. #select friedrich from (select 1 as otto) as t1
  56. --error 1
  57. --exec echo "select friedrich from (select 1 as otto) as t1;" | $MYSQL_TEST 2>&1
  58. # expectation = response
  59. --error ER_BAD_FIELD_ERROR
  60. select friedrich from (select 1 as otto) as t1;
  61. # The following unmasked unsuccessful statement must give
  62. # 1. mysqltest gives a 'failed'
  63. # 2. does not produce a r/<test case>.reject file !!!
  64. # PLEASE uncomment it and check its effect
  65. #select friedrich from (select 1 as otto) as t1;
  66. # ----------------------------------------------------------------------------
  67. # Tests for the new feature - SQLSTATE error code matching
  68. # Positive case(statement)
  69. # ----------------------------------------------------------------------------
  70. # This syntax not allowed anymore, use --error S00000, see below
  71. # expectation = response
  72. #!S00000 select otto from (select 1 as otto) as t1;
  73. --error S00000
  74. select otto from (select 1 as otto) as t1;
  75. # expectation <> response
  76. #!S42S22 select otto from (select 1 as otto) as t1;
  77. #--error S42S22
  78. #select otto from (select 1 as otto) as t1;
  79. --error 1
  80. --exec echo "error S42S22; select otto from (select 1 as otto) as t1;" | $MYSQL_TEST 2>&1
  81. # expecting a SQL-state for a command that can't give one should fail
  82. --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
  83. --error 1
  84. --exec echo "error S00000; remove_file $MYSQLTEST_VARDIR/tmp/test_nonexistent.tmp;" | $MYSQL_TEST 2>&1
  85. # ----------------------------------------------------------------------------
  86. # Negative case(statement)
  87. # ----------------------------------------------------------------------------
  88. # This syntax not allowed anymore, use --error S42S22, see below
  89. # expectation = response
  90. #!S42S22 select friedrich from (select 1 as otto) as t1;
  91. --error S42S22
  92. select friedrich from (select 1 as otto) as t1;
  93. # expectation !=response
  94. #!S00000 select friedrich from (select 1 as otto) as t1;
  95. #--error S00000
  96. #select friedrich from (select 1 as otto) as t1;
  97. --error 1
  98. --exec echo "error S00000; select friedrich from (select 1 as otto) as t1;" | $MYSQL_TEST 2>&1
  99. # ----------------------------------------------------------------------------
  100. # test cases for $mysql_errno
  101. #
  102. # $mysql_errno is a builtin variable of mysqltest and contains the return code
  103. # of the last command sent to the server.
  104. #
  105. # The following test cases often initialize $mysql_errno to 1064 by
  106. # a command with wrong syntax.
  107. # Example: --error 1064 To prevent the abort after the error.
  108. # garbage ;
  109. # ----------------------------------------------------------------------------
  110. # ----------------------------------------------------------------------------
  111. # check mysql_errno = 0 after successful statement
  112. # ----------------------------------------------------------------------------
  113. select otto from (select 1 as otto) as t1;
  114. echo $mysql_errname;
  115. eval select $mysql_errno as "after_successful_stmt_errno" ;
  116. #----------------------------------------------------------------------------
  117. # check mysql_errno = 1064 after statement with wrong syntax
  118. # ----------------------------------------------------------------------------
  119. --error ER_PARSE_ERROR
  120. garbage ;
  121. echo $mysql_errname;
  122. eval select $mysql_errno as "after_wrong_syntax_errno" ;
  123. # ----------------------------------------------------------------------------
  124. # check if let $my_var= 'abc' ; affects $mysql_errno
  125. # ----------------------------------------------------------------------------
  126. --error ER_PARSE_ERROR
  127. garbage ;
  128. let $my_var= 'abc' ;
  129. echo $mysql_errname;
  130. eval select $mysql_errno as "after_let_var_equal_value" ;
  131. # ----------------------------------------------------------------------------
  132. # check if set @my_var= 'abc' ; affects $mysql_errno
  133. # ----------------------------------------------------------------------------
  134. --error ER_PARSE_ERROR
  135. garbage ;
  136. set @my_var= 'abc' ;
  137. echo $mysql_errname;
  138. eval select $mysql_errno as "after_set_var_equal_value" ;
  139. # ----------------------------------------------------------------------------
  140. # check if the setting of --disable-warnings itself affects $mysql_errno
  141. # (May be --<whatever> modifies $mysql_errno.)
  142. # ----------------------------------------------------------------------------
  143. --error ER_PARSE_ERROR
  144. garbage ;
  145. --disable_warnings
  146. echo $mysql_errname;
  147. eval select $mysql_errno as "after_disable_warnings_command" ;
  148. # ----------------------------------------------------------------------------
  149. # check if --disable-warnings + command with warning affects the errno
  150. # stored within $mysql_errno
  151. # (May be disabled warnings affect $mysql_errno.)
  152. # ----------------------------------------------------------------------------
  153. drop table if exists t1 ;
  154. --error ER_PARSE_ERROR
  155. garbage ;
  156. drop table if exists t1 ;
  157. echo $mysql_errname;
  158. eval select $mysql_errno as "after_disable_warnings" ;
  159. --enable_warnings
  160. # ----------------------------------------------------------------------------
  161. # check if masked errors affect $mysql_errno
  162. # ----------------------------------------------------------------------------
  163. --error ER_PARSE_ERROR
  164. garbage ;
  165. --error ER_NO_SUCH_TABLE
  166. select 3 from t1 ;
  167. echo $mysql_errname;
  168. eval select $mysql_errno as "after_minus_masked" ;
  169. --error ER_PARSE_ERROR
  170. garbage ;
  171. --error ER_NO_SUCH_TABLE
  172. select 3 from t1 ;
  173. echo $mysql_errname;
  174. eval select $mysql_errno as "after_!_masked" ;
  175. # ----------------------------------------------------------------------------
  176. # Will manipulations of $mysql_errno be possible and visible ?
  177. # ----------------------------------------------------------------------------
  178. --error ER_PARSE_ERROR
  179. garbage ;
  180. let $mysql_errno= -1;
  181. eval select $mysql_errno as "after_let_errno_equal_value" ;
  182. # ----------------------------------------------------------------------------
  183. # How affect actions on prepared statements $mysql_errno ?
  184. # ----------------------------------------------------------------------------
  185. # failing prepare
  186. --error ER_PARSE_ERROR
  187. garbage ;
  188. --error ER_NO_SUCH_TABLE
  189. prepare stmt from "select 3 from t1" ;
  190. echo $mysql_errname;
  191. eval select $mysql_errno as "after_failing_prepare" ;
  192. create table t1 ( f1 char(10));
  193. # successful prepare
  194. --error ER_PARSE_ERROR
  195. garbage ;
  196. prepare stmt from "select 3 from t1" ;
  197. echo $mysql_errname;
  198. eval select $mysql_errno as "after_successful_prepare" ;
  199. # successful execute
  200. --error ER_PARSE_ERROR
  201. garbage ;
  202. execute stmt;
  203. echo $mysql_errname;
  204. eval select $mysql_errno as "after_successful_execute" ;
  205. # failing execute (table has been dropped)
  206. drop table t1;
  207. --error ER_PARSE_ERROR
  208. garbage ;
  209. --error ER_NO_SUCH_TABLE
  210. execute stmt;
  211. echo $mysql_errname;
  212. eval select $mysql_errno as "after_failing_execute" ;
  213. # failing execute (unknown statement)
  214. --error ER_PARSE_ERROR
  215. garbage ;
  216. --error ER_UNKNOWN_STMT_HANDLER
  217. execute __stmt_;
  218. echo $mysql_errname;
  219. eval select $mysql_errno as "after_failing_execute" ;
  220. # successful deallocate
  221. --error ER_PARSE_ERROR
  222. garbage ;
  223. deallocate prepare stmt;
  224. echo $mysql_errname;
  225. eval select $mysql_errno as "after_successful_deallocate" ;
  226. # failing deallocate ( statement handle does not exist )
  227. --error ER_PARSE_ERROR
  228. garbage ;
  229. --error ER_UNKNOWN_STMT_HANDLER
  230. deallocate prepare __stmt_;
  231. echo $mysql_errname;
  232. eval select $mysql_errno as "after_failing_deallocate" ;
  233. # ----------------------------------------------------------------------------
  234. # test cases for "--disable_abort_on_error"
  235. #
  236. # "--disable_abort_on_error" switches off the abort of mysqltest
  237. # after "unmasked" failing statements.
  238. #
  239. # The default is "--enable_abort_on_error".
  240. #
  241. # "Maskings" are
  242. # --error <error number> and --error <error number>
  243. # in the line before the failing statement.
  244. #
  245. # There are some additional test cases for $mysql_errno
  246. # because "--disable_abort_on_error" enables a new situation.
  247. # Example: "unmasked" statement fails + analysis of $mysql_errno
  248. # ----------------------------------------------------------------------------
  249. # ----------------------------------------------------------------------------
  250. # Switch off the abort on error and check the effect on $mysql_errno
  251. # ----------------------------------------------------------------------------
  252. --error ER_PARSE_ERROR
  253. garbage ;
  254. --disable_abort_on_error
  255. echo $mysql_errname;
  256. eval select $mysql_errno as "after_--disable_abort_on_error" ;
  257. # ----------------------------------------------------------------------------
  258. # "unmasked" failing statement should not cause an abort
  259. # ----------------------------------------------------------------------------
  260. select 3 from t1 ;
  261. # ----------------------------------------------------------------------------
  262. # masked failing statements
  263. # ----------------------------------------------------------------------------
  264. # expected error = response
  265. --error ER_NO_SUCH_TABLE
  266. select 3 from t1 ;
  267. --error ER_NO_SUCH_TABLE
  268. select 3 from t1 ;
  269. echo $mysql_errname;
  270. eval select $mysql_errno as "after_!errno_masked_error" ;
  271. # expected error <> response
  272. # --error 1000
  273. # select 3 from t1 ;
  274. # --error 1000
  275. # select 3 from t1 ;
  276. --error 1
  277. --exec echo "disable_abort_on_error; error 1000; select 3 from t1; error 1000; select 3 from t1;" | $MYSQL_TEST 2>&1
  278. # ----------------------------------------------------------------------------
  279. # Check some non-query statements that would fail
  280. # ----------------------------------------------------------------------------
  281. --exec illegal_command
  282. --cat_file does_not_exist
  283. --perl
  284. exit(2);
  285. EOF
  286. # ----------------------------------------------------------------------------
  287. # Check backtick and query_get_value, result should be empty
  288. # ----------------------------------------------------------------------------
  289. let $empty= `garbage`;
  290. echo $empty is empty;
  291. let $empty= query_get_value(nonsense, blabla, 1);
  292. echo $empty is empty;
  293. # ----------------------------------------------------------------------------
  294. # Switch the abort on error on and check the effect on $mysql_errno
  295. # ----------------------------------------------------------------------------
  296. --error ER_PARSE_ERROR
  297. garbage ;
  298. --enable_abort_on_error
  299. echo $mysql_errname;
  300. eval select $mysql_errno as "after_--enable_abort_on_error" ;
  301. # ----------------------------------------------------------------------------
  302. # masked failing statements
  303. # ----------------------------------------------------------------------------
  304. # expected error = response
  305. --error ER_NO_SUCH_TABLE
  306. select 3 from t1 ;
  307. # ----------------------------------------------------------------------------
  308. # check that the old default behaviour is not changed
  309. # Please remove the '#' to get the abort on error
  310. # ----------------------------------------------------------------------------
  311. #--error 1064
  312. #select 3 from t1 ;
  313. #
  314. #select 3 from t1 ;
  315. --error 1
  316. --exec echo "disable_abort_on_error; enable_abort_on_error; error 1064; select 3 from t1; select 3 from t1;" | $MYSQL_TEST 2>&1
  317. # ----------------------------------------------------------------------------
  318. # Test --enable and --disable with ONCE
  319. # ----------------------------------------------------------------------------
  320. --disable_abort_on_error ONCE
  321. garbage;
  322. --disable_abort_on_error ONCE
  323. --remove_file DoesNotExist
  324. --disable_result_log
  325. select 2;
  326. --enable_result_log ONCE
  327. select 3;
  328. select 5;
  329. --enable_result_log
  330. # ----------------------------------------------------------------------------
  331. # Test cumulative ONCE
  332. # ----------------------------------------------------------------------------
  333. --disable_abort_on_error ONCE
  334. --disable_query_log ONCE
  335. select 3 from t1;
  336. select 7;
  337. --error 1
  338. --exec echo "--disable_info OCNE" | $MYSQL_TEST 2>&1
  339. --enable_connect_log ONCE
  340. connect (con1,localhost,root,,);
  341. connection default;
  342. disconnect con1;
  343. # ----------------------------------------------------------------------------
  344. # Test ONCE can be combined with --error or modifiers like lowercase
  345. # ----------------------------------------------------------------------------
  346. --disable_result_log ONCE
  347. --error ER_NO_SUCH_TABLE
  348. select 5 from t1;
  349. --disable_query_log ONCE
  350. --lowercase_result
  351. select "CASE" as "LOWER";
  352. --sorted_result
  353. --disable_query_log ONCE
  354. select "xyz" as name union select "abc" as name order by name desc;
  355. # ----------------------------------------------------------------------------
  356. # Test --error with backtick operator or query_get_value
  357. # ----------------------------------------------------------------------------
  358. --error 0,ER_NO_SUCH_TABLE
  359. let $empty= `SELECT foo from bar`;
  360. echo $empty is empty;
  361. --error 0,ER_BAD_FIELD_ERROR
  362. let $empty= query_get_value(SELECT bar as foo, baz, 1);
  363. echo $empty is empty;
  364. --error 0,ER_NO_SUCH_TABLE
  365. if (!`SELECT foo from bar`) {
  366. echo "Yes it's empty";
  367. }
  368. # ----------------------------------------------------------------------------
  369. # Test comments
  370. # ----------------------------------------------------------------------------
  371. # This is a comment
  372. # This is a ; comment
  373. # This is a -- comment
  374. # -- This is also a comment
  375. # -- # This is also a comment
  376. # -- This is also a ; comment
  377. # ----------------------------------------------------------------------------
  378. # Test comments with embedded command
  379. # ----------------------------------------------------------------------------
  380. --echo hello
  381. -- echo hello
  382. -- echo ;;;;;;;;
  383. --echo # MySQL: -- The
  384. # ----------------------------------------------------------------------------
  385. # Test detect end of line "junk"
  386. # Most likely caused by a missing delimiter
  387. # ----------------------------------------------------------------------------
  388. # Too many parameters to function
  389. --error 1
  390. --exec echo "sleep 5 6;" | $MYSQL_TEST 2>&1
  391. # Too many parameters to function
  392. --error 1
  393. --exec echo "--sleep 5 6" | $MYSQL_TEST 2>&1
  394. #
  395. # Missing delimiter
  396. # The comment will be "sucked into" the sleep command since
  397. # delimiter is missing until after "show status"
  398. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  399. sleep 4
  400. # A comment
  401. show status;
  402. EOF
  403. --error 1
  404. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
  405. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  406. #
  407. # Missing delimiter until eof
  408. # The comment will be "sucked into" the sleep command since
  409. # delimiter is missing
  410. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  411. sleep 7
  412. # Another comment
  413. EOF
  414. --error 1
  415. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
  416. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  417. #
  418. # Missing delimiter until "disable_query_log"
  419. #
  420. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  421. disconnect default
  422. #
  423. # comment
  424. # comment 3
  425. disable_query_log;
  426. EOF
  427. --error 1
  428. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
  429. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  430. #
  431. # Missing delimiter until "disable_query_log"
  432. #
  433. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  434. disconnect default
  435. #
  436. # comment
  437. # comment 3
  438. disable_query_log;
  439. EOF
  440. --error 1
  441. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
  442. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  443. #
  444. # Missing delimiter until eof
  445. #
  446. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  447. disconnect default
  448. #
  449. # comment
  450. # comment2
  451. # comment 3
  452. --disable_query_log
  453. EOF
  454. --error 1
  455. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
  456. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  457. #
  458. # Missing delimiter until eof
  459. #
  460. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  461. disconnect default # comment
  462. # comment part2
  463. # comment 3
  464. --disable_query_log
  465. EOF
  466. --error 1
  467. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
  468. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  469. #
  470. # Extra delimiter
  471. #
  472. --error 1
  473. --exec echo "--sleep 4;" | $MYSQL_TEST 2>&1
  474. --error 1
  475. --exec echo "--disable_query_log;" | $MYSQL_TEST 2>&1
  476. #
  477. # Extra text after ``
  478. #
  479. # Cannot use exec echo here as ` may or may not need to be escaped
  480. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  481. let $x= `select 1` BOO ;
  482. EOF
  483. --error 1
  484. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
  485. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  486. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  487. --let $x= `select 1`;
  488. EOF
  489. --error 1
  490. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
  491. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  492. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  493. # Missing ; in next line should be detected and cause failure
  494. let $x= `select 1`
  495. let $x= 2;
  496. echo $x;
  497. EOF
  498. --error 1
  499. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
  500. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  501. # Allow trailing # comment
  502. --sleep 1 # Wait for insert delayed to be executed.
  503. --sleep 1 # Wait for insert delayed to be executed.
  504. # ----------------------------------------------------------------------------
  505. # Test error
  506. # ----------------------------------------------------------------------------
  507. # Missing argument
  508. --error 1
  509. --exec echo "error;" | $MYSQL_TEST 2>&1
  510. --error 1
  511. --exec echo "--error" | $MYSQL_TEST 2>&1
  512. # First char must be uppercase 'S' or 'E' or [0-9]
  513. --error 1
  514. --exec echo "--error s99999" | $MYSQL_TEST 2>&1
  515. --error 1
  516. --exec echo "--error e99999" | $MYSQL_TEST 2>&1
  517. --error 1
  518. --exec echo "--error 9eeeee" | $MYSQL_TEST 2>&1
  519. --error 1
  520. --exec echo "--error 1sssss" | $MYSQL_TEST 2>&1
  521. # First char 'S' but too long
  522. --error 1
  523. --exec echo "--error S999999" | $MYSQL_TEST 2>&1
  524. # First char 'S' but lowercase char found
  525. --error 1
  526. --exec echo "--error S99a99" | $MYSQL_TEST 2>&1
  527. # First char 'S' but too short
  528. --error 1
  529. --exec echo "--error S9999" | $MYSQL_TEST 2>&1
  530. # First char 'E' but not found in error array
  531. --error 1
  532. --exec echo "--error E9999" | $MYSQL_TEST 2>&1
  533. # First char [0-9] but contains chars
  534. --error 1
  535. --exec echo "--error 999e9" | $MYSQL_TEST 2>&1
  536. --error 1
  537. --exec echo "--error 9b" | $MYSQL_TEST 2>&1
  538. # Multiple errorcodes separated by ','
  539. --error 1,1,1,1
  540. #--error 9,ER_PARSE_ERROR
  541. #--error ER_PARSE_ERROR
  542. #--error 9,ER_PARSE_ERROR,9,ER_PARSE_ERROR
  543. #--error 9, ER_PARSE_ERROR, 9, ER_PARSE_ERROR
  544. #--error 9,S00000,9,ER_PARSE_ERROR
  545. #--error 9,S00000,9,ER_PARSE_ERROR,ER_PARSE_ERROR,ER_PARSE_ERROR,9,10,11,12
  546. --error 9,S00000,9
  547. --error 9,S00000,9,9,10,11,12
  548. --error 9 ,10
  549. --error 9 , 10
  550. --error 9 , 10
  551. --error 9 , 10
  552. # Too many errorcodes specified
  553. --error 1
  554. --exec echo "--error 1,2,3,4,5,6,7,8,9,10,11" | $MYSQL_TEST 2>&1
  555. # ----------------------------------------------------------------------------
  556. # Test echo command
  557. # ----------------------------------------------------------------------------
  558. echo MySQL;
  559. echo "MySQL";
  560. echo MySQL: The world''s most popular open source database;
  561. echo "MySQL: The world's most popular open source database";
  562. echo MySQL: The world''s
  563. most popular open
  564. source database;
  565. echo # MySQL: The world''s
  566. # most popular open
  567. # source database;
  568. echo - MySQL: The world''s
  569. - most popular open
  570. - source database;
  571. echo - MySQL: The world''s
  572. -- most popular
  573. -- open source database;
  574. echo # MySQL: The
  575. --world''s
  576. # most popular
  577. -- open
  578. - source database;
  579. echo "MySQL: The world's most popular; open source database";
  580. echo "MySQL: The world's most popular ; open source database";
  581. echo "MySQL: The world's most popular ;open source database";
  582. echo echo message echo message;
  583. echo ;
  584. # Illegal use of echo
  585. #--error 1
  586. #--exec echo "echo \$;" | $MYSQL_TEST 2>&1
  587. # ----------------------------------------------------------------------------
  588. # Test exec command
  589. # ----------------------------------------------------------------------------
  590. # Illegal use of exec
  591. --error 1
  592. --exec echo "--exec " | $MYSQL_TEST 2>&1
  593. # Multi-line exec
  594. exec $MYSQL
  595. test -e "select 1";
  596. exec $MYSQL test -e "select
  597. 2";
  598. let $query = select 3
  599. as X;
  600. exec $MYSQL test -e "$query";
  601. # ----------------------------------------------------------------------------
  602. # Test let command
  603. # ----------------------------------------------------------------------------
  604. let $message=MySQL;
  605. echo $message;
  606. let $message="MySQL";
  607. echo $message;
  608. let $message= MySQL: The
  609. world''s most
  610. popular open
  611. source database;
  612. echo $message;
  613. let $message= # MySQL: The
  614. # world''s most
  615. # popular open
  616. # source database;
  617. echo $message;
  618. let $message= -- MySQL: The
  619. -- world''s most
  620. -- popular
  621. -- open source database;
  622. echo $message;
  623. let $message= # MySQL: The
  624. - world''s most
  625. -- popular open
  626. # source database;
  627. echo $message;
  628. echo '$message';
  629. echo "$message";
  630. let $1=hej;
  631. echo $1;
  632. let $1 =hej ;
  633. echo $1;
  634. let $1 = hej;
  635. echo $1;
  636. let $1=1;
  637. let $2=$1;
  638. echo $2;
  639. let $5=$6;
  640. echo $5;
  641. echo $6;
  642. let $where=a long variable content;
  643. echo $where;
  644. let $where2= $where;
  645. echo $where2;
  646. let $where3=a long $where variable content;
  647. echo $where3;
  648. let $where3=a long \\\$where variable content;
  649. echo $where3;
  650. let $novar1= $novar2;
  651. echo $novar1;
  652. let $cat=na;
  653. let $cat=ba$cat$cat;
  654. echo banana = $cat;
  655. # ba\$cat\$cat should have been sufficient.
  656. # ba\\\$cat\\\$cat -> ba\$cat\$cat -> ba$cat$cat -> banana
  657. # Magnus' upcoming patch will fix the missing second interpretation.
  658. let $cat=ba\\\$cat\\\$cat;
  659. echo Not a banana: $cat;
  660. # Bug #55413 would cause this to fail
  661. let $escape= with\`some\"escaped\'quotes;
  662. echo $escape;
  663. --let $escape= with\`some\"escaped\'quotes
  664. echo $escape;
  665. # This only works with "--let" syntax
  666. --let $tick= single'tick`backtick
  667. echo $tick;
  668. # Test illegal uses of let
  669. --error 1
  670. --exec echo "let ;" | $MYSQL_TEST 2>&1
  671. --error 1
  672. --exec echo "let \$=hi;" | $MYSQL_TEST 2>&1
  673. --error 1
  674. --exec echo "let \$1 hi;" | $MYSQL_TEST 2>&1
  675. --error 1
  676. --exec echo "let \$m hi;" | $MYSQL_TEST 2>&1
  677. --error 1
  678. --exec echo "let \$hi;" | $MYSQL_TEST 2>&1
  679. --error 1
  680. --exec echo "let \$ hi;" | $MYSQL_TEST 2>&1
  681. --error 1
  682. --exec echo "let =hi;" | $MYSQL_TEST 2>&1
  683. --error 1
  684. --exec echo "let hi;" | $MYSQL_TEST 2>&1
  685. # More advanced test for Bug#17280
  686. let $success= 1;
  687. --echo # Execute: --echo # <whatever> success: \$success
  688. --echo # <whatever> success: $success
  689. --echo # Execute: echo # <whatever> success: \$success ;
  690. echo # <whatever> success: $success ;
  691. --echo # The next two variants work fine and expand the content of \$success
  692. --echo # Execute: --echo \$success
  693. --echo $success
  694. --echo # Execute: echo \$success ;
  695. echo $success ;
  696. # ----------------------------------------------------------------------------
  697. # Test to assign let from variable
  698. # let $<var_name>=$<var_name>;
  699. # ----------------------------------------------------------------------------
  700. --echo # Check if let \$B = \$A is an assignment per value.
  701. # Basic preparations:
  702. --echo let \$A = initial value of A;
  703. let $A = initial value of A;
  704. # --echo # Content of \$A is: $A
  705. --echo let \$B = initial value of B;
  706. let $B = initial value of B;
  707. # --echo # Content of \$B is: $B
  708. # Assign $B to $A:
  709. --echo let \$B = \$A
  710. let $A = $B;
  711. --echo # Content of \$A is: $A
  712. # Changes of $B must NOT affect $A and Changes of $A must NOT affect $B !
  713. --echo let \$A = changed value of A;
  714. let $A = changed value of A;
  715. --echo # Content of \$B is: $B
  716. --echo let \$B = changed value of B;
  717. let $B = changed value of B;
  718. --echo # Content of \$A is: $A
  719. # ----------------------------------------------------------------------------
  720. # Test let from query with $variable
  721. # let $<var_name>=`<query with $variable>`;
  722. # ----------------------------------------------------------------------------
  723. let $var1=content of variable 1;
  724. let $var2= `select "$var1"`;
  725. let $var3= `select concat("$var1", " ", "$var2")`;
  726. echo var2: $var2;
  727. echo var3: $var3;
  728. if (`select length("$var3") > 0`)
  729. {
  730. echo length of var3 is longer than 0;
  731. }
  732. # ----------------------------------------------------------------------------
  733. # Test to assign let from query
  734. # let $<var_name>=`<query>`;
  735. # ----------------------------------------------------------------------------
  736. echo var1;
  737. let $var1= `select "hi" as "Col", 1 as "Column1", "hi there" as Col3`;
  738. echo $var1;
  739. echo var2;
  740. let $var2= `select 2 as "Column num 2"`;
  741. echo $var2;
  742. echo var2 again;
  743. let $var2= `select 2 as "Column num 2"`;
  744. echo $var2;
  745. echo var3 two columns with same name;
  746. let $var3= `select 1 as "Col", 2 as "Col", 3 as "var3"`;
  747. echo $var3;
  748. echo var4 from query that returns NULL;
  749. let $var4= `select NULL`;
  750. echo var5 from query that returns no row;
  751. let $var5= `SHOW VARIABLES LIKE "nonexisting_variable"`;
  752. echo failing query in let;
  753. --write_file $MYSQLTEST_VARDIR/tmp/let.sql
  754. let $var2= `failing query`;
  755. echo $var2;
  756. EOF
  757. create table t1 (a varchar(100));
  758. insert into t1 values ('`select 42`');
  759. let $a= `select * from t1`;
  760. # This should output `select 42`, not evaluate it again to 42
  761. echo $a;
  762. insert into t1 values ('$dollar');
  763. # These should also output the string without evaluating it.
  764. let $a= query_get_value(select * from t1 order by a, a, 1);
  765. echo $a;
  766. let $a= query_get_value(select * from t1 order by a, a, 2);
  767. echo $a;
  768. drop table t1;
  769. --error 1
  770. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/let.sql 2>&1
  771. remove_file $MYSQLTEST_VARDIR/tmp/let.sql;
  772. # ----------------------------------------------------------------------------
  773. # Test source command
  774. # ----------------------------------------------------------------------------
  775. # Test illegal uses of source
  776. --error 1
  777. --exec echo "source ;" | $MYSQL_TEST 2>&1
  778. # Fix win paths
  779. --replace_result \\ /
  780. # Source a nonexisting file
  781. --error 1
  782. --exec echo "source non_existingFile;" | $MYSQL_TEST 2>&1
  783. # Too many source
  784. --exec echo "source $MYSQLTEST_VARDIR/tmp/recursive.sql;" > $MYSQLTEST_VARDIR/tmp/recursive.sql
  785. --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
  786. --error 1
  787. --exec echo "source $MYSQLTEST_VARDIR/tmp/recursive.sql;" | $MYSQL_TEST 2>&1
  788. remove_file $MYSQLTEST_VARDIR/tmp/recursive.sql;
  789. # Source a file with error
  790. --exec echo "garbage ;" > $MYSQLTEST_VARDIR/tmp/error.sql
  791. --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
  792. --error 1
  793. --exec echo "source $MYSQLTEST_VARDIR/tmp/error.sql;" | $MYSQL_TEST 2>&1
  794. remove_file $MYSQLTEST_VARDIR/tmp/error.sql;
  795. # Test execution of source in a while loop
  796. --write_file $MYSQLTEST_VARDIR/tmp/sourced.inc
  797. echo here is the sourced script;
  798. EOF
  799. --disable_query_log
  800. let $outer= 2; # Number of outer loops
  801. while ($outer)
  802. {
  803. eval SELECT '$outer = outer loop variable after while' AS "";
  804. --source $MYSQLTEST_VARDIR/tmp/sourced.inc
  805. eval SELECT '$outer = outer loop variable before dec' AS "";
  806. dec $outer;
  807. eval SELECT '$outer = outer loop variable after dec' AS "";
  808. }
  809. # Test source in an if in a while which is false on 1st iteration
  810. # Also test --error and --disable_abort_on_error in same context
  811. let $outer= 2; # Number of outer loops
  812. let $ifval= 0; # false 1st time
  813. while ($outer)
  814. {
  815. echo outer=$outer ifval=$ifval;
  816. if ($ifval) {
  817. --source $MYSQLTEST_VARDIR/tmp/sourced.inc
  818. --error ER_NO_SUCH_TABLE
  819. SELECT * from nowhere;
  820. --disable_abort_on_error ONCE
  821. # Statement giving a different error, to make sure we don't mask it
  822. SELECT * FROM nowhere else;
  823. }
  824. dec $outer;
  825. inc $ifval;
  826. }
  827. # Test execution of source in a while loop
  828. --disable_abort_on_error
  829. # Sourcing of a file within while loop, sourced file will
  830. # source other file
  831. let $num= 9;
  832. while ($num)
  833. {
  834. SELECT 'In loop' AS "";
  835. --source $MYSQLTEST_VARDIR/tmp/sourced.inc
  836. dec $num;
  837. }
  838. --enable_abort_on_error
  839. --enable_query_log
  840. # Test source $variable/<filename>
  841. --source $MYSQLTEST_VARDIR/tmp/sourced.inc
  842. --remove_file $MYSQLTEST_VARDIR/tmp/sourced.inc
  843. --write_file $MYSQLTEST_VARDIR/tmp/sourced.inc
  844. echo "hello";
  845. EOF
  846. let $x= sourced;
  847. source $MYSQLTEST_VARDIR/tmp/$x.inc;
  848. let $x= $MYSQLTEST_VARDIR;
  849. source $x/tmp/sourced.inc;
  850. --remove_file $MYSQLTEST_VARDIR/tmp/sourced.inc
  851. # ----------------------------------------------------------------------------
  852. # Test sleep command
  853. # ----------------------------------------------------------------------------
  854. sleep 0.5;
  855. sleep 1;
  856. real_sleep 1;
  857. # Parameter from variable, legal and illegal
  858. let $sleep_var= 0.1;
  859. sleep $sleep_var;
  860. let $sleep_var= 1;
  861. --real_sleep $sleep_var
  862. --write_file $MYSQL_TMP_DIR/sleep.inc
  863. let $sleep_var= xyz;
  864. --sleep $sleep_var
  865. EOF
  866. --error 1
  867. --exec $MYSQL_TEST < $MYSQL_TMP_DIR/sleep.inc 2>&1
  868. --remove_file $MYSQL_TMP_DIR/sleep.inc
  869. --write_file $MYSQL_TMP_DIR/sleep.inc
  870. let $sleep_var= xyz;
  871. real_sleep $sleep_var;
  872. EOF
  873. --error 1
  874. --exec $MYSQL_TEST < $MYSQL_TMP_DIR/sleep.inc 2>&1
  875. --remove_file $MYSQL_TMP_DIR/sleep.inc
  876. # Missing parameter
  877. --error 1
  878. --exec echo "sleep ;" | $MYSQL_TEST 2>&1
  879. --error 1
  880. --exec echo "real_sleep ;" | $MYSQL_TEST 2>&1
  881. # Illegal parameter
  882. --error 1
  883. --exec echo "sleep abc;" | $MYSQL_TEST 2>&1
  884. --error 1
  885. --exec echo "real_sleep abc;" | $MYSQL_TEST 2>&1
  886. # ----------------------------------------------------------------------------
  887. # Test inc
  888. # ----------------------------------------------------------------------------
  889. let $i= 0;
  890. inc $i;
  891. echo $i;
  892. let $i=100;
  893. inc $i;
  894. echo $i;
  895. let $i= -100;
  896. inc $i;
  897. echo $i;
  898. --error 1
  899. --exec echo "inc;" | $MYSQL_TEST 2>&1
  900. --error 1
  901. --exec echo "inc i;" | $MYSQL_TEST 2>&1
  902. --error 1
  903. --exec echo "inc \$i;" | $MYSQL_TEST 2>&1
  904. --error 1
  905. --exec echo "let \$i=100; inc \$i 1000; echo \$i;" | $MYSQL_TEST 2>&1
  906. --error 1
  907. --exec echo "let \$i=text; inc \$i; echo \$i;" | $MYSQL_TEST 2>&1
  908. --error 1
  909. --exec echo "let \$i=10cc; inc \$i; echo \$i;" | $MYSQL_TEST 2>&1
  910. inc $i; inc $i; inc $i; --echo $i
  911. echo $i;
  912. # ----------------------------------------------------------------------------
  913. # Test dec
  914. # ----------------------------------------------------------------------------
  915. let $d= 0;
  916. dec $d;
  917. echo $d;
  918. let $d=100;
  919. dec $d;
  920. echo $d;
  921. --error 1
  922. --exec echo "dec;" | $MYSQL_TEST 2>&1
  923. --error 1
  924. --exec echo "dec i;" | $MYSQL_TEST 2>&1
  925. --error 1
  926. --exec echo "dec \$i;" | $MYSQL_TEST 2>&1
  927. --error 1
  928. --exec echo "let \$i=100; dec \$i 1000; echo \$i;" | $MYSQL_TEST 2>&1
  929. --error 1
  930. --exec echo "let \$i=text; dec \$i; echo \$i;" | $MYSQL_TEST 2>&1
  931. --error 1
  932. --exec echo "let \$i=10cc; dec \$i; echo \$i;" | $MYSQL_TEST 2>&1
  933. # ----------------------------------------------------------------------------
  934. # Test system
  935. # ----------------------------------------------------------------------------
  936. #system ls > /dev/null;
  937. system echo "hej" > /dev/null;
  938. #--system ls > /dev/null
  939. --system echo "hej" > /dev/null;
  940. --error 1
  941. --exec echo "system;" | $MYSQL_TEST 2>&1
  942. --error 1
  943. --exec echo "system $NONEXISTSINFVAREABLI;" | $MYSQL_TEST 2>&1
  944. --disable_abort_on_error ONCE
  945. system NonExistsinfComamdn 2> /dev/null;
  946. # ----------------------------------------------------------------------------
  947. # Test delimiter
  948. # ----------------------------------------------------------------------------
  949. delimiter stop;
  950. echo teststop
  951. delimiter ;stop
  952. echo test2;
  953. --delimiter stop
  954. echo test3stop
  955. --delimiter ;
  956. echo test4;
  957. # ----------------------------------------------------------------------------
  958. # Test that delimiter within if() works in in various combinations
  959. # ----------------------------------------------------------------------------
  960. if (0)
  961. {
  962. delimiter ||;
  963. echo false-inner||
  964. if (0)
  965. {
  966. delimiter *||
  967. echo false-innerer*
  968. delimiter ||*
  969. }
  970. echo false-inner again||
  971. }
  972. echo outer;
  973. if (1)
  974. {
  975. delimiter /;
  976. echo true-inner/
  977. if (0)
  978. {
  979. delimiter %/
  980. echo true-innerer%
  981. }
  982. echo true-inner again/
  983. }
  984. echo true-outer/
  985. delimiter ;/
  986. # ----------------------------------------------------------------------------
  987. # Test if
  988. # ----------------------------------------------------------------------------
  989. let $counter=10;
  990. if ($counter)
  991. {
  992. echo Counter is greater than 0, (counter=10);
  993. }
  994. if (!$counter)
  995. {
  996. echo Counter is not 0, (counter=10);
  997. }
  998. if (! $counter)
  999. {
  1000. let $counter=5;
  1001. }
  1002. echo Counter should still be 10, is $counter;
  1003. let $counter=0;
  1004. if($counter)
  1005. {
  1006. echo Counter is greater than 0, (counter=0);
  1007. }
  1008. if (!$counter)
  1009. {
  1010. echo Counter is not 0, (counter=0);
  1011. }
  1012. if (! $counter)
  1013. {
  1014. echo Not space var works;
  1015. }
  1016. # ----------------------------------------------------------------------------
  1017. # Test if with some non-numerics
  1018. # ----------------------------------------------------------------------------
  1019. let $counter=alpha;
  1020. if ($counter)
  1021. {
  1022. echo Counter is true, (counter=alpha);
  1023. }
  1024. let $counter= ;
  1025. if ($counter)
  1026. {
  1027. echo oops, space is true;
  1028. }
  1029. let $counter=-0;
  1030. if ($counter)
  1031. {
  1032. echo oops, -0 is true;
  1033. }
  1034. # This is no longer allowed, as a precaution against mistyped conditionals
  1035. # if (beta)
  1036. # {
  1037. # echo Beta is true;
  1038. # }
  1039. let $counter=gamma;
  1040. while ($counter)
  1041. {
  1042. echo while with string, only once;
  1043. let $counter=000;
  1044. }
  1045. # ----------------------------------------------------------------------------
  1046. # Test if with compare conditions
  1047. # ----------------------------------------------------------------------------
  1048. let $ifvar= 5;
  1049. let $ifvar2= 6;
  1050. if ($ifvar < 7)
  1051. {
  1052. echo 5<7;
  1053. }
  1054. if ($ifvar< 7)
  1055. {
  1056. echo 5<7 again;
  1057. }
  1058. if ($ifvar<7)
  1059. {
  1060. echo 5<7 still;
  1061. }
  1062. if ($ifvar < $ifvar2)
  1063. {
  1064. echo 5<6;
  1065. }
  1066. if ($ifvar <= 4)
  1067. {
  1068. echo 5<=4;
  1069. }
  1070. if ($ifvar >= 5)
  1071. {
  1072. echo 5>=5;
  1073. }
  1074. if ($ifvar>=5)
  1075. {
  1076. echo 5>=5 again;
  1077. }
  1078. if ($ifvar > 3)
  1079. {
  1080. echo 5>3;
  1081. }
  1082. if ($ifvar == 4)
  1083. {
  1084. echo 5==4;
  1085. }
  1086. if ($ifvar == 5)
  1087. {
  1088. echo 5==5;
  1089. }
  1090. if ($ifvar != 8)
  1091. {
  1092. echo 5!=8;
  1093. }
  1094. # Any number should compare unequal to any string
  1095. if ($ifvar != five)
  1096. {
  1097. echo 5!=five;
  1098. }
  1099. if ($ifvar == `SELECT 3+2`)
  1100. {
  1101. echo 5==3+2;
  1102. }
  1103. if ($ifvar == 5)
  1104. {
  1105. echo 5 == 5;
  1106. }
  1107. let $ifvar= hello;
  1108. if ($ifvar == hello there)
  1109. {
  1110. echo hello == hello there;
  1111. }
  1112. if ($ifvar == hello)
  1113. {
  1114. echo hello == hello;
  1115. }
  1116. if ($ifvar == hell)
  1117. {
  1118. echo hello == hell;
  1119. }
  1120. if ($ifvar == hello)
  1121. {
  1122. echo hello == hello;
  1123. }
  1124. if ($ifvar != goodbye)
  1125. {
  1126. echo hello != goodbye;
  1127. }
  1128. let $ifvar= 'quoted';
  1129. if ($ifvar == ''quoted'')
  1130. {
  1131. echo 'quoted' == ''quoted'';
  1132. }
  1133. let $ifvar= two words;
  1134. if ($ifvar == two words)
  1135. {
  1136. echo two words;
  1137. }
  1138. if ($ifvar == 'two words')
  1139. {
  1140. echo 'two words';
  1141. }
  1142. if ($ifvar == "two words")
  1143. {
  1144. echo "two words";
  1145. }
  1146. if ($ifvar == `SELECT 'two words'`)
  1147. {
  1148. echo two words are two words;
  1149. }
  1150. if (42)
  1151. {
  1152. echo right answer;
  1153. }
  1154. if (0)
  1155. {
  1156. echo wrong answer;
  1157. }
  1158. # Non-empty string treated as 'true'
  1159. if (`SELECT 'something'`)
  1160. {
  1161. echo anything goes;
  1162. }
  1163. # Make sure 0 and string compare right
  1164. let $ifvar= 0;
  1165. if ($ifvar == string)
  1166. {
  1167. echo 0 == string;
  1168. }
  1169. if ($ifvar != string)
  1170. {
  1171. echo 0 != string;
  1172. }
  1173. --write_file $MYSQL_TMP_DIR/mysqltest.sql
  1174. let $var= 5;
  1175. if ($var >= four)
  1176. {
  1177. echo 5>=four;
  1178. }
  1179. EOF
  1180. --error 1
  1181. --exec $MYSQL_TEST < $MYSQL_TMP_DIR/mysqltest.sql 2>&1
  1182. remove_file $MYSQL_TMP_DIR/mysqltest.sql;
  1183. --write_file $MYSQL_TMP_DIR/mysqltest.sql
  1184. let $var= 5;
  1185. if ($var ~= 6)
  1186. {
  1187. echo 5~=6;
  1188. }
  1189. EOF
  1190. --error 1
  1191. --exec $MYSQL_TEST < $MYSQL_TMP_DIR/mysqltest.sql 2>&1
  1192. remove_file $MYSQL_TMP_DIR/mysqltest.sql;
  1193. --write_file $MYSQL_TMP_DIR/mysqltest.sql
  1194. let $var= text;
  1195. if (var == text)
  1196. {
  1197. echo Oops I forgot the $;
  1198. }
  1199. EOF
  1200. --error 1
  1201. --exec $MYSQL_TEST < $MYSQL_TMP_DIR/mysqltest.sql 2>&1
  1202. remove_file $MYSQL_TMP_DIR/mysqltest.sql;
  1203. --error 1
  1204. --exec echo "if (\$var ==) {" | $MYSQL_TEST 2>&1
  1205. --error 1
  1206. --exec echo "if (\$var > ) {" | $MYSQL_TEST 2>&1
  1207. # ----------------------------------------------------------------------------
  1208. # Test while with compare conditions
  1209. # ----------------------------------------------------------------------------
  1210. let $counter= 2;
  1211. while ($counter < 5)
  1212. {
  1213. echo counter is $counter;
  1214. inc $counter;
  1215. }
  1216. let $ifvar=;
  1217. while ($ifvar != stop)
  1218. {
  1219. if ($counter >= 7)
  1220. {
  1221. let $ifvar= stop;
  1222. }
  1223. echo counter is $counter;
  1224. inc $counter;
  1225. }
  1226. # ----------------------------------------------------------------------------
  1227. # Test while, { and }
  1228. # ----------------------------------------------------------------------------
  1229. let $i=1;
  1230. while ($i)
  1231. {
  1232. echo $i;
  1233. dec $i;
  1234. }
  1235. # One liner
  1236. #let $i=1;while ($i){echo $i;dec $i;}
  1237. let $i=0;
  1238. while (!$i)
  1239. {
  1240. echo Testing while with not;
  1241. inc $i;
  1242. }
  1243. # Exceed max nesting level
  1244. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest_while.inc
  1245. let $1 = 10;
  1246. while ($1)
  1247. {
  1248. while ($1)
  1249. {
  1250. while ($1)
  1251. {
  1252. while ($1)
  1253. {
  1254. while ($1)
  1255. {
  1256. while ($1)
  1257. {
  1258. while ($1)
  1259. {
  1260. while ($1)
  1261. {
  1262. while ($1)
  1263. {
  1264. while ($1)
  1265. {
  1266. while ($1)
  1267. {
  1268. while ($1)
  1269. {
  1270. while ($1)
  1271. {
  1272. while ($1)
  1273. {
  1274. while ($1)
  1275. {
  1276. while ($1)
  1277. {
  1278. while ($1)
  1279. {
  1280. while ($1)
  1281. {
  1282. while ($1)
  1283. {
  1284. while ($1)
  1285. {
  1286. while ($1)
  1287. {
  1288. while ($1)
  1289. {
  1290. while ($1)
  1291. {
  1292. while ($1)
  1293. {
  1294. while ($1)
  1295. {
  1296. while ($1)
  1297. {
  1298. while ($1)
  1299. {
  1300. while ($1)
  1301. {
  1302. while ($1)
  1303. {
  1304. while ($1)
  1305. {
  1306. while ($1)
  1307. {
  1308. while ($1)
  1309. {
  1310. while ($1)
  1311. {
  1312. while ($1)
  1313. {
  1314. while ($1)
  1315. {
  1316. while ($1)
  1317. {
  1318. while ($1)
  1319. {
  1320. while ($1)
  1321. {
  1322. while ($1)
  1323. {
  1324. while ($1)
  1325. {
  1326. while ($1)
  1327. {
  1328. while ($1)
  1329. {
  1330. while ($1)
  1331. {
  1332. while ($1)
  1333. {
  1334. while ($1)
  1335. {
  1336. while ($1)
  1337. {
  1338. while ($1)
  1339. {
  1340. while ($1)
  1341. {
  1342. while ($1)
  1343. {
  1344. echo $1;
  1345. dec $1;
  1346. }
  1347. }
  1348. }
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. }
  1355. }
  1356. }
  1357. }
  1358. }
  1359. }
  1360. }
  1361. }
  1362. }
  1363. }
  1364. }
  1365. }
  1366. }
  1367. }
  1368. }
  1369. }
  1370. }
  1371. }
  1372. }
  1373. }
  1374. }
  1375. }
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. }
  1382. EOF
  1383. # Fix win path
  1384. --replace_result \\ / $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
  1385. --error 1
  1386. --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest_while.inc;" | $MYSQL_TEST 2>&1
  1387. --remove_file $MYSQLTEST_VARDIR/tmp/mysqltest_while.inc
  1388. --error 1
  1389. --exec echo "while \$i;" | $MYSQL_TEST 2>&1
  1390. --error 1
  1391. --exec echo "while (\$i;" | $MYSQL_TEST 2>&1
  1392. --error 1
  1393. --exec echo "let \$i=1; while (\$i) dec \$i;" | $MYSQL_TEST 2>&1
  1394. --error 1
  1395. --exec echo "};" | $MYSQL_TEST 2>&1
  1396. --error 1
  1397. --exec echo "end;" | $MYSQL_TEST 2>&1
  1398. --error 1
  1399. --exec echo "{;" | $MYSQL_TEST 2>&1
  1400. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  1401. while (0)
  1402. echo hej;
  1403. EOF
  1404. --error 1
  1405. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
  1406. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  1407. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  1408. while (0)
  1409. {echo hej;
  1410. EOF
  1411. --error 1
  1412. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
  1413. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  1414. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  1415. while (0){
  1416. echo hej;
  1417. EOF
  1418. --error 1
  1419. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
  1420. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  1421. # ----------------------------------------------------------------------------
  1422. # Test error messages returned from comments starting with a command
  1423. # ----------------------------------------------------------------------------
  1424. --error 1
  1425. --exec echo "--if the other server is down" | $MYSQL_TEST 2>&1
  1426. --error 1
  1427. --exec echo "-- end when ..." | $MYSQL_TEST 2>&1
  1428. # ----------------------------------------------------------------------------
  1429. # Test replace
  1430. # ----------------------------------------------------------------------------
  1431. --replace_result a b
  1432. select "a" as col1, "c" as col2;
  1433. --replace_result a b c d
  1434. select "a" as col1, "c" as col2;
  1435. --error 1
  1436. --exec echo "--replace_result a" | $MYSQL_TEST 2>&1
  1437. --error 1
  1438. --exec echo "--replace_result a;" | $MYSQL_TEST 2>&1
  1439. --error 1
  1440. --exec echo "replace_result a;" | $MYSQL_TEST 2>&1
  1441. --error 1
  1442. --exec echo "replace_result a ;" | $MYSQL_TEST 2>&1
  1443. --exec echo "replace_result a b; echo OK; exit;" | $MYSQL_TEST 2>&1
  1444. --error 1
  1445. --exec echo "--replace_result a b c" | $MYSQL_TEST 2>&1
  1446. --error 1
  1447. --exec echo "replace_result a b c ;" | $MYSQL_TEST 2>&1
  1448. --replace_column 1 b
  1449. select "a" as col1, "c" as col2;
  1450. --replace_column 1 b 2 d
  1451. select "a" as col1, "c" as col2;
  1452. --error 1
  1453. --exec echo "--replace_column a" | $MYSQL_TEST 2>&1
  1454. --error 1
  1455. --exec echo "--replace_column 1" | $MYSQL_TEST 2>&1
  1456. --error 1
  1457. --exec echo "--replace_column a b" | $MYSQL_TEST 2>&1
  1458. --error 1
  1459. --exec echo "--replace_column a 1" | $MYSQL_TEST 2>&1
  1460. --error 1
  1461. --exec echo "--replace_column 1 b c " | $MYSQL_TEST 2>&1
  1462. let $long_rep= 1234567890123456789012345678901234567890;
  1463. let $long_rep= $long_rep,$long_rep;
  1464. let $long_rep= $long_rep,$long_rep;
  1465. let $long_rep= $long_rep,$long_rep;
  1466. let $long_rep= $long_rep,$long_rep;
  1467. let $long_rep= $long_rep,$long_rep;
  1468. # This tests from strings > 1024 (here 1311)
  1469. --replace_result $long_rep LONG_STRING
  1470. eval select "$long_rep" as x;
  1471. # Test replace within ``
  1472. --replace_result cat dog
  1473. --let $animal= `select "cat" as pet`
  1474. --echo $animal
  1475. # ----------------------------------------------------------------------------
  1476. # Test sync_with_master
  1477. # ----------------------------------------------------------------------------
  1478. --error 1
  1479. --exec echo "sync_with_master 10!;" | $MYSQL_TEST 2>&1
  1480. --error 1
  1481. --exec echo "sync_with_master a;" | $MYSQL_TEST 2>&1
  1482. # ----------------------------------------------------------------------------
  1483. # Test connect
  1484. # ----------------------------------------------------------------------------
  1485. --error 1
  1486. --exec echo "connect;" | $MYSQL_TEST 2>&1
  1487. --error 1
  1488. --exec echo "connect ();" | $MYSQL_TEST 2>&1
  1489. --error 1
  1490. --exec echo "connect (con2);" | $MYSQL_TEST 2>&1
  1491. --error 1
  1492. --exec echo "connect (con2,);" | $MYSQL_TEST 2>&1
  1493. --error 1
  1494. --exec echo "connect (con2,localhost,root,,illegal_db);" | $MYSQL_TEST 2>&1
  1495. --error 1
  1496. --exec echo "connect (con1,localhost,root,,,illegal_port,);" | $MYSQL_TEST 2>&1
  1497. --error 1
  1498. --exec echo "connect (con1,localhost,root,,,,,SMTP POP);" | $MYSQL_TEST 2>&1
  1499. # Repeat connect/disconnect
  1500. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  1501. let $i=200;
  1502. while ($i)
  1503. {
  1504. connect (test_con1,localhost,root,,);
  1505. disconnect test_con1;
  1506. dec $i;
  1507. }
  1508. echo 200 connects succeeded;
  1509. EOF
  1510. --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1
  1511. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  1512. # Select disconnected connection
  1513. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  1514. connect (test_con1,localhost,root,,);
  1515. disconnect test_con1;
  1516. connection test_con1;
  1517. EOF
  1518. --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
  1519. --error 1
  1520. --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1
  1521. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  1522. # Connection name already used
  1523. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
  1524. connect (test_con1,localhost,root,,);
  1525. connect (test_con1,localhost,root,,);
  1526. EOF
  1527. --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
  1528. --error 1
  1529. --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1
  1530. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
  1531. # connect when "disable_abort_on_error" caused "connection not found"
  1532. --disable_abort_on_error
  1533. connect (con1,localhost,root,,);
  1534. connection default;
  1535. connection con1;
  1536. disconnect con1;
  1537. --enable_abort_on_error
  1538. # Test connect without a database
  1539. connect (con2,localhost,root,,*NO-ONE*);
  1540. --error ER_NO_DB_ERROR
  1541. show tables;
  1542. disconnect con2;
  1543. connection default;
  1544. # Test enable_connect_log
  1545. --enable_connect_log
  1546. connect (con1,localhost,root,,);
  1547. connection default;
  1548. connection con1;
  1549. --disable_query_log
  1550. # These should not be logged
  1551. connect (con2,localhost,root,,*NO-ONE*);
  1552. connection con2;
  1553. disconnect con2;
  1554. connection con1;
  1555. --enable_query_log
  1556. disconnect con1;
  1557. connection default;
  1558. --disable_connect_log
  1559. # ----------------------------------------------------------------------------
  1560. # Test mysqltest arguments
  1561. # ----------------------------------------------------------------------------
  1562. # -x <file_name>, use the file specified after -x as the test file
  1563. --exec $MYSQL_TEST < $MYSQL_TEST_DIR/include/mysqltest-x.inc
  1564. --exec $MYSQL_TEST -x $MYSQL_TEST_DIR/include/mysqltest-x.inc
  1565. --exec $MYSQL_TEST --test_file=$MYSQL_TEST_DIR/include/mysqltest-x.inc
  1566. # Fix Win paths
  1567. --replace_result \\ /
  1568. --error 1
  1569. --exec $MYSQL_TEST -x non_existing_file.inc 2>&1
  1570. # ----------------------------------------------------------------------------
  1571. # TODO Test queries, especially their errormessages... so it's easy to debug
  1572. # new scripts and diagnose errors
  1573. # ----------------------------------------------------------------------------
  1574. # ----------------------------------------------------------------------------
  1575. # Test Bug#12386
  1576. # ----------------------------------------------------------------------------
  1577. let $num= 2;
  1578. while ($num)
  1579. {
  1580. --error ER_PARSE_ERROR
  1581. failing_statement;
  1582. dec $num;
  1583. }
  1584. SELECT 1 as a;
  1585. #
  1586. # Bug#10251 Identifiers containing quotes not handled correctly
  1587. #
  1588. select 1 as `a'b`, 2 as `a"b`;
  1589. # Test escaping of quotes
  1590. select 'aaa\\','aa''a',"aa""a";
  1591. #
  1592. # Check of include/show_msg.inc and include/show_msg80.inc
  1593. #
  1594. # The message contains in most cases a string with the default character set
  1595. let $message= Here comes a message;
  1596. --source include/show_msg.inc
  1597. # The message could also contain a string with character set utf8
  1598. let $message= `SELECT USER()`;
  1599. --source include/show_msg.inc
  1600. # The message contains more then 80 characters on multiple lines
  1601. # and is kept between double quotes.
  1602. let $message=
  1603. "Here comes a very very long message that
  1604. - is longer then 80 characters and
  1605. - consists of several lines";
  1606. --source include/show_msg80.inc
  1607. # The message contains more then 80 characters on multiple lines
  1608. # and uses the auxiliary character "." at the beginning of the message lines.
  1609. let $message= . Here comes a very very long message that
  1610. . - is longer then 80 characters and
  1611. . - consists of several lines;
  1612. --source include/show_msg80.inc
  1613. #
  1614. # Test --enable_parsing / disable_parsing
  1615. #
  1616. --disable_query_log
  1617. --disable_parsing
  1618. # The following will not enable query logging
  1619. --enable_query_log
  1620. select "this will not be executed";
  1621. --enable_parsing
  1622. select "this will be executed";
  1623. --enable_query_log
  1624. #
  1625. # Test zero length result file. Should not pass
  1626. #
  1627. --exec echo '' > $MYSQLTEST_VARDIR/tmp/zero_length_file.result
  1628. --exec echo "echo ok;" > $MYSQLTEST_VARDIR/tmp/query.sql
  1629. --error 1
  1630. --exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql -R $MYSQLTEST_VARDIR/tmp/zero_length_file.result > /dev/null 2>&1
  1631. remove_file $MYSQLTEST_VARDIR/tmp/zero_length_file.result;
  1632. --error 0,1
  1633. remove_file $MYSQLTEST_VARDIR/tmp/zero_length_file.reject;
  1634. --error 0,1
  1635. remove_file $MYSQLTEST_VARDIR/tmp/zero_length_file.log;
  1636. --error 0,1
  1637. remove_file $MYSQL_TEST_DIR/r/zero_length_file.reject;
  1638. #
  1639. # Test that a test file that does not generate any output fails.
  1640. #
  1641. --exec echo "let \$i= 1;" > $MYSQLTEST_VARDIR/tmp/query.sql
  1642. --error 1
  1643. --exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql 2>&1
  1644. remove_file $MYSQLTEST_VARDIR/tmp/query.sql;
  1645. #
  1646. # Test that mysqltest fails when there are no queries executed
  1647. # but a result file exists
  1648. # NOTE! This will never happen as long as it's not allowed to have
  1649. # test files that produce no output
  1650. #--exec echo "something" > $MYSQLTEST_VARDIR/tmp/result_file.result
  1651. #--exec echo "let \$i= 1;" > $MYSQLTEST_VARDIR/tmp/query.sql
  1652. #--error 1
  1653. #--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql -R $MYSQLTEST_VARDIR/tmp/result_file.result 2>&1
  1654. #
  1655. # Bug#11731 mysqltest in multi-statement queries ignores errors in
  1656. # non-1st queries
  1657. #
  1658. echo Failing multi statement query;
  1659. # PS does not support multi statement
  1660. --exec echo "--disable_ps_protocol" > $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1661. --exec echo "delimiter ||||;" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1662. --exec echo "create table t1 (a int primary key);" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1663. --exec echo "insert into t1 values (1);" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1664. --exec echo "select 'select-me';" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1665. --exec echo "insertz 'error query'||||" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1666. --exec echo "delimiter ;||||" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1667. --error 1
  1668. --exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/bug11731.sql 2>&1
  1669. drop table t1;
  1670. --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
  1671. --error 1
  1672. --exec $MYSQL_TEST --record -x $MYSQLTEST_VARDIR/tmp/bug11731.sql -R $MYSQLTEST_VARDIR/tmp/bug11731.out 2>&1
  1673. # The .out file should be non existent
  1674. --error 1
  1675. --file_exists $MYSQLTEST_VARDIR/tmp/bug11731.out
  1676. drop table t1;
  1677. echo Multi statement using expected error;
  1678. # PS does not support multi statement
  1679. --exec echo "--disable_ps_protocol" > $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1680. --exec echo "delimiter ||||;" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1681. --exec echo "--error 1064" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1682. --exec echo "create table t1 (a int primary key);" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1683. --exec echo "insert into t1 values (1);" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1684. --exec echo "select 'select-me';" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1685. --exec echo "insertz "error query"||||" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1686. --exec echo "delimiter ;||||" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1687. --exec echo "exit;" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
  1688. # These two should work since the error is expected
  1689. --exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/bug11731.sql 2>&1
  1690. drop table t1;
  1691. --exec $MYSQL_TEST --record -x $MYSQLTEST_VARDIR/tmp/bug11731.sql -R $MYSQLTEST_VARDIR/tmp/bug11731.out 2>&1
  1692. # The .out file should exist
  1693. --file_exists $MYSQLTEST_VARDIR/tmp/bug11731.out
  1694. drop table t1;
  1695. remove_file $MYSQLTEST_VARDIR/tmp/bug11731.out;
  1696. remove_file $MYSQLTEST_VARDIR/log/bug11731.log;
  1697. remove_file $MYSQLTEST_VARDIR/tmp/bug11731.sql;
  1698. #
  1699. # Bug#19890 mysqltest "query" command is broken
  1700. #
  1701. # It should be possible to use the command "query" to force mysqltest to
  1702. # send the command to the server although it's a builtin mysqltest command.
  1703. --error ER_PARSE_ERROR
  1704. query sleep;
  1705. --error ER_PARSE_ERROR
  1706. --query sleep
  1707. # Just an empty query command
  1708. --error ER_EMPTY_QUERY
  1709. query ;
  1710. # test for replace_regex
  1711. --replace_regex /at/b/
  1712. select "at" as col1, "c" as col2;
  1713. --replace_regex /at/b/i
  1714. select "at" as col1, "AT" as col2, "c" as col3;
  1715. --replace_regex /a/b/ /ct/d/
  1716. select "a" as col1, "ct" as col2;
  1717. --replace_regex /(strawberry)/raspberry and \1/ /blueberry/blackberry/ /potato/tomato/;
  1718. select "strawberry","blueberry","potato";
  1719. --error 1
  1720. --exec echo "--replace_regex a" | $MYSQL_TEST 2>&1
  1721. --error 1
  1722. --exec echo "--replace_regex a;" | $MYSQL_TEST 2>&1
  1723. --error 1
  1724. --exec echo "replace_regex a;" | $MYSQL_TEST 2>&1
  1725. --error 1
  1726. --exec echo "replace_regex a ;" | $MYSQL_TEST 2>&1
  1727. --error 1
  1728. --exec echo "replace_regex a b; echo OK;" | $MYSQL_TEST 2>&1
  1729. --error 1
  1730. --exec echo "--replace_regex /a b c" | $MYSQL_TEST 2>&1
  1731. --error 1
  1732. --exec echo "replace_regex /a /b c ;" | $MYSQL_TEST 2>&1
  1733. # REQUIREMENT
  1734. # replace_regex should replace substitutions from left to right in output
  1735. create table t1 (a int, b int);
  1736. insert into t1 values (1,3);
  1737. insert into t1 values (2,4);
  1738. --replace_regex /A/C/ /B/D/i /3/2/ /2/1/
  1739. select * from t1;
  1740. drop table t1;
  1741. # Test usage with ``
  1742. --replace_regex /x/y/
  1743. --let $result= `select "x" as col`
  1744. --echo $result
  1745. # Test usage with a variable as pattern list
  1746. --disable_query_log
  1747. --let $patt= /a /b / /less/more/
  1748. --replace_regex $patt
  1749. select "a is a and less is more" as txt;
  1750. --let $patt=
  1751. --replace_regex $patt
  1752. select "a is a and less is more" as txt;
  1753. --enable_query_log
  1754. #-------------------------------------------------------------------------
  1755. # BUG #11754855 : Passing variable to --error
  1756. #-------------------------------------------------------------------------
  1757. create table t2 ( a char(10));
  1758. let $errno1=0;
  1759. let $errno2=ER_PARSE_ERROR;
  1760. let $errno3=ER_NO_SUCH_TABLE;
  1761. --error $errno2
  1762. garbage;
  1763. --error $errno2,$errno3
  1764. garbage;
  1765. --error $errno2,ER_NO_SUCH_TABLE
  1766. garbage;
  1767. --error ER_NO_SUCH_TABLE,$errno2
  1768. insert into t1 values ("Abcd");
  1769. --error $errno1,ER_PARSE_ERROR
  1770. garbage;
  1771. drop table t2;
  1772. # ----------------------------------------------------------------------------
  1773. # Tests of send
  1774. # ----------------------------------------------------------------------------
  1775. create table t1 ( f1 char(10));
  1776. insert into t1 values ("Abcd");
  1777. # 1. Basic test
  1778. send select * from t1;
  1779. reap;
  1780. # 2. Test with error
  1781. --send select * from t2;
  1782. --error ER_NO_SUCH_TABLE
  1783. --reap
  1784. # 3. test send of next stmt
  1785. --send
  1786. select * from t1;
  1787. --reap
  1788. # 4. Non-query stmt betwen send and reap allowed
  1789. --send select * from t1;
  1790. --sleep 0.05
  1791. --echo Result coming up
  1792. --reap
  1793. # 5. Test of send_eval
  1794. --let $my_stmt= select * from t1;
  1795. --send_eval $my_stmt
  1796. --reap
  1797. # 6. Test that mysqltest does not allow query stmt between send and reap
  1798. # Untestable directly as it causes mysqltest to fail
  1799. --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.in
  1800. --send select * from t1;
  1801. select 1;
  1802. --reap
  1803. EOF
  1804. --error 1
  1805. # Must filter unpredictable extra warning from output
  1806. --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.in > $MYSQL_TMP_DIR/mysqltest.out 2>&1
  1807. --perl
  1808. my $dir= $ENV{'MYSQL_TMP_DIR'};
  1809. open (FILE, "$dir/mysqltest.out");
  1810. while (<FILE>) {
  1811. print unless /Note: net_clear/; # This shows up on rare occations
  1812. }
  1813. EOF
  1814. remove_file $MYSQL_TMP_DIR/mysqltest.out;
  1815. remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.in;
  1816. drop table t1;
  1817. # ----------------------------------------------------------------------------
  1818. # test for remove_file
  1819. # ----------------------------------------------------------------------------
  1820. --error 1
  1821. --exec echo "remove_file ;" | $MYSQL_TEST 2>&1
  1822. --error 1
  1823. remove_file non_existing_file;
  1824. # ----------------------------------------------------------------------------
  1825. # test for remove_files_wildcard
  1826. # ----------------------------------------------------------------------------
  1827. --error 1
  1828. --exec echo "remove_files_wildcard ;" | $MYSQL_TEST 2>&1
  1829. --error 1
  1830. remove_files_wildcard non_existing_dir;
  1831. --error 1
  1832. remove_files_wildcard non_existing_dir non_existing_file;
  1833. # ----------------------------------------------------------------------------
  1834. # test for write_file
  1835. # ----------------------------------------------------------------------------
  1836. --error 1
  1837. --exec echo "write_file ;" | $MYSQL_TEST 2>&1
  1838. --error 1
  1839. --exec echo "write_file filename ;" | $MYSQL_TEST 2>&1
  1840. # Comment out this test as it confuses cmd.exe with unmatched "
  1841. #--error 1
  1842. #--exec echo "write_file filename \";" | $MYSQL_TEST 2>&1
  1843. write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1844. Content for test_file1
  1845. EOF
  1846. file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1847. cat_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1848. remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1849. write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp END_DELIMITER;
  1850. Content for test_file1 contains EOF
  1851. END_DELIMITER
  1852. file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1853. # write to already exisiting file
  1854. --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
  1855. --error 1
  1856. --exec echo "write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;" | $MYSQL_TEST 2>&1
  1857. remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1858. # ----------------------------------------------------------------------------
  1859. # test for append_file
  1860. # ----------------------------------------------------------------------------
  1861. write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1862. Content for test_file1
  1863. EOF
  1864. file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1865. append_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1866. Appended text
  1867. EOF
  1868. file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1869. remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1870. append_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1871. Appended text on nonexisting file
  1872. EOF
  1873. remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1874. # Test append_file within while
  1875. let $outer= 2; # Number of outer loops
  1876. while ($outer)
  1877. {
  1878. append_file $MYSQLTEST_VARDIR/tmp/app_while.tmp;
  1879. These lines should be repeated,
  1880. if things work as expected
  1881. EOF
  1882. dec $outer;
  1883. }
  1884. cat_file $MYSQLTEST_VARDIR/tmp/app_while.tmp;
  1885. remove_file $MYSQLTEST_VARDIR/tmp/app_while.tmp;
  1886. # ----------------------------------------------------------------------------
  1887. # test for cat_file
  1888. # ----------------------------------------------------------------------------
  1889. --write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp
  1890. Some data
  1891. for cat_file command
  1892. of mysqltest
  1893. EOF
  1894. cat_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1895. remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1896. --replace_regex /my_errno=[0-9]*/(my_errno)/
  1897. --error 1
  1898. --exec echo "cat_file non_existing_file;" | $MYSQL_TEST 2>&1
  1899. # ----------------------------------------------------------------------------
  1900. # test for diff_files
  1901. # ----------------------------------------------------------------------------
  1902. --write_file $MYSQLTEST_VARDIR/tmp/diff1.tmp
  1903. Some data
  1904. for diff_file command
  1905. of mysqltest
  1906. EOF
  1907. --write_file $MYSQLTEST_VARDIR/tmp/diff2.tmp
  1908. Some data
  1909. for diff_file command
  1910. of mysqltest
  1911. EOF
  1912. --write_file $MYSQLTEST_VARDIR/tmp/diff3.tmp
  1913. Some other data
  1914. for diff_file command
  1915. of mysqltest
  1916. EOF
  1917. --write_file $MYSQLTEST_VARDIR/tmp/diff4.tmp
  1918. Some data
  1919. for diff_file command
  1920. of musqltest
  1921. EOF
  1922. # Compare equal files
  1923. --diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp
  1924. --diff_files $MYSQLTEST_VARDIR/tmp/diff2.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp
  1925. # Compare files that differ in size
  1926. --error 2
  1927. --diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff3.tmp
  1928. --error 2
  1929. --diff_files $MYSQLTEST_VARDIR/tmp/diff3.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp
  1930. # Compare files that differ only in content
  1931. --error 1
  1932. --diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff4.tmp
  1933. --error 1
  1934. --diff_files $MYSQLTEST_VARDIR/tmp/diff4.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp
  1935. # Compare equal files, again...
  1936. --diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp
  1937. --remove_file $MYSQLTEST_VARDIR/tmp/diff1.tmp
  1938. --remove_file $MYSQLTEST_VARDIR/tmp/diff2.tmp
  1939. --remove_file $MYSQLTEST_VARDIR/tmp/diff3.tmp
  1940. --remove_file $MYSQLTEST_VARDIR/tmp/diff4.tmp
  1941. # ----------------------------------------------------------------------------
  1942. # test for file_exist
  1943. # ----------------------------------------------------------------------------
  1944. --error 1
  1945. --exec echo "file_exists ;" | $MYSQL_TEST 2>&1
  1946. --error 0,1
  1947. remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1948. --error 1
  1949. file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1950. write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1951. Content for test_file1
  1952. EOF
  1953. file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1954. remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1955. --error 1
  1956. file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
  1957. # ----------------------------------------------------------------------------
  1958. # test for copy_file
  1959. # ----------------------------------------------------------------------------
  1960. --write_file $MYSQLTEST_VARDIR/tmp/file1.tmp
  1961. file1
  1962. EOF
  1963. copy_file $MYSQLTEST_VARDIR/tmp/file1.tmp $MYSQLTEST_VARDIR/tmp/file2.tmp;
  1964. file_exists $MYSQLTEST_VARDIR/tmp/file2.tmp;
  1965. remove_file $MYSQLTEST_VARDIR/tmp/file1.tmp;
  1966. remove_file $MYSQLTEST_VARDIR/tmp/file2.tmp;
  1967. --error 1
  1968. --exec echo "copy_file ;" | $MYSQL_TEST 2>&1
  1969. --error 1
  1970. --exec echo "copy_file from_file;" | $MYSQL_TEST 2>&1
  1971. # ----------------------------------------------------------------------------
  1972. # test for move_file
  1973. # ----------------------------------------------------------------------------
  1974. # - Check that if source file does not exist, nothing will be created.
  1975. --error 1
  1976. file_exists $MYSQLTEST_VARDIR/tmp/file1.tmp;
  1977. --error 1
  1978. file_exists $MYSQLTEST_VARDIR/tmp/file2.tmp;
  1979. --error 1
  1980. move_file $MYSQLTEST_VARDIR/tmp/file1.tmp $MYSQLTEST_VARDIR/tmp/file2.tmp;
  1981. --error 1
  1982. file_exists $MYSQLTEST_VARDIR/tmp/file1.tmp;
  1983. --error 1
  1984. file_exists $MYSQLTEST_VARDIR/tmp/file2.tmp;
  1985. # - Check that if source file exists, everything works properly.
  1986. --write_file $MYSQLTEST_VARDIR/tmp/file1.tmp
  1987. file1
  1988. EOF
  1989. move_file $MYSQLTEST_VARDIR/tmp/file1.tmp $MYSQLTEST_VARDIR/tmp/file2.tmp;
  1990. --error 1
  1991. file_exists $MYSQLTEST_VARDIR/tmp/file1.tmp;
  1992. file_exists $MYSQLTEST_VARDIR/tmp/file2.tmp;
  1993. # - Check that if destination file exists, everything works properly.
  1994. # (file2.tmp exists from the previous check; file1.tmp needs to be created)
  1995. --write_file $MYSQLTEST_VARDIR/tmp/file1.tmp
  1996. file1
  1997. EOF
  1998. move_file $MYSQLTEST_VARDIR/tmp/file1.tmp $MYSQLTEST_VARDIR/tmp/file2.tmp;
  1999. --error 1
  2000. file_exists $MYSQLTEST_VARDIR/tmp/file1.tmp;
  2001. file_exists $MYSQLTEST_VARDIR/tmp/file2.tmp;
  2002. remove_file $MYSQLTEST_VARDIR/tmp/file2.tmp;
  2003. # - Check usage.
  2004. --error 1
  2005. --exec echo "move_file ;" | $MYSQL_TEST 2>&1
  2006. --error 1
  2007. --exec echo "move_file from_file;" | $MYSQL_TEST 2>&1
  2008. # ----------------------------------------------------------------------------
  2009. # test for chmod
  2010. # ----------------------------------------------------------------------------
  2011. --write_file $MYSQLTEST_VARDIR/tmp/file1.tmp
  2012. file1
  2013. EOF
  2014. chmod 0000 $MYSQLTEST_VARDIR/tmp/file1.tmp;
  2015. # The below write fails, but --error is not implemented
  2016. # for write_file
  2017. #--write_file $MYSQLTEST_VARDIR/tmp/file1.tmp
  2018. #test should fail
  2019. #EOF
  2020. chmod 0777 $MYSQLTEST_VARDIR/tmp/file1.tmp;
  2021. remove_file $MYSQLTEST_VARDIR/tmp/file1.tmp;
  2022. --write_file $MYSQLTEST_VARDIR/tmp/file1.tmp
  2023. test2
  2024. EOF
  2025. remove_file $MYSQLTEST_VARDIR/tmp/file1.tmp;
  2026. --error 1
  2027. --exec echo "chmod ;" | $MYSQL_TEST 2>&1
  2028. --error 1
  2029. --exec echo "chmod 0 from_file;" | $MYSQL_TEST 2>&1
  2030. --error 1
  2031. --exec echo "chmod 08 from_file;" | $MYSQL_TEST 2>&1
  2032. --error 1
  2033. --exec echo "chmod from_file;" | $MYSQL_TEST 2>&1
  2034. --error 1
  2035. --exec echo "chmod ABZD from_file;" | $MYSQL_TEST 2>&1
  2036. --error 1
  2037. --exec echo "chmod 06789 from_file;" | $MYSQL_TEST 2>&1
  2038. # ----------------------------------------------------------------------------
  2039. # test for perl
  2040. # ----------------------------------------------------------------------------
  2041. --perl
  2042. print "hello\n";
  2043. EOF
  2044. --perl EOF
  2045. print "hello\n";
  2046. EOF
  2047. --perl DELIMITER
  2048. print "hello\n";
  2049. DELIMITER
  2050. --error 1
  2051. --exec echo "perl TOO_LONG_DELIMITER ;" | $MYSQL_TEST 2>&1
  2052. perl;
  2053. print "hello\n";
  2054. EOF
  2055. perl;
  2056. # Print "hello"
  2057. print "hello\n";
  2058. EOF
  2059. # Test perl within while, also with if being false first iteration
  2060. let $outer= 3;
  2061. let $ifval= 0;
  2062. while ($outer) {
  2063. if ($ifval) {
  2064. perl UNTIL;
  2065. my $val= 5;
  2066. print "val is $val\n";
  2067. UNTIL
  2068. }
  2069. inc $ifval;
  2070. dec $outer;
  2071. }
  2072. # ----------------------------------------------------------------------------
  2073. # test for die
  2074. # ----------------------------------------------------------------------------
  2075. --error 1
  2076. --exec echo "die test of die;" | $MYSQL_TEST 2>&1
  2077. # ----------------------------------------------------------------------------
  2078. # test for exit
  2079. # ----------------------------------------------------------------------------
  2080. --exec echo "echo Some output; exit; echo Not this;" | $MYSQL_TEST 2>&1
  2081. # ----------------------------------------------------------------------------
  2082. # test for sorted_result
  2083. # ----------------------------------------------------------------------------
  2084. create table t1( a int, b char(255), c timestamp);
  2085. insert into t1 values(1, 'Line 1', '2007-04-05'), (2, "Part 2", '2007-04-05');
  2086. insert into t1 values(1, 'Line 1', '2007-04-05'), (2, "Part 3", '2007-04-05');
  2087. select * from t1;
  2088. --sorted_result
  2089. select * from t1;
  2090. # Should not be sorted
  2091. select * from t1;
  2092. disable_result_log;
  2093. sorted_result;
  2094. select * from t1;
  2095. enable_result_log;
  2096. --sorted_result
  2097. select '';
  2098. sorted_result;
  2099. select "h";
  2100. --sorted_result
  2101. select "he";
  2102. --sorted_result
  2103. select "hep";
  2104. --sorted_result
  2105. select "hepp";
  2106. drop table t1;
  2107. # 1. Assignment of result set sorting
  2108. sorted_result;
  2109. SELECT 2 as "my_col"
  2110. UNION
  2111. SELECT 1;
  2112. #
  2113. --sorted_result
  2114. SELECT 2 as "my_col" UNION SELECT 1;
  2115. --sorted_result
  2116. SELECT 2 as "my_col"
  2117. UNION
  2118. SELECT 1;
  2119. # 2. Ensure that the table header will be not sorted into the result
  2120. --sorted_result
  2121. SELECT '2' as "3"
  2122. UNION
  2123. SELECT '1';
  2124. # 3. Ensure that an empty result set does not cause problems
  2125. CREATE TABLE t1( a CHAR);
  2126. --sorted_result
  2127. SELECT * FROM t1;
  2128. DROP TABLE t1;
  2129. # 4. Ensure that NULL values within the result set do not cause problems
  2130. SELECT NULL as "my_col1",2 AS "my_col2"
  2131. UNION
  2132. SELECT NULL,1;
  2133. --sorted_result
  2134. SELECT NULL as "my_col1",2 AS "my_col2"
  2135. UNION
  2136. SELECT NULL,1;
  2137. #
  2138. SELECT 2 as "my_col1",NULL AS "my_col2"
  2139. UNION
  2140. SELECT 1,NULL;
  2141. --sorted_result
  2142. SELECT 2 as "my_col1",NULL AS "my_col2"
  2143. UNION
  2144. SELECT 1,NULL;
  2145. # 5. "sorted_result" changes nothing when applied to a non query statement.
  2146. sorted_result;
  2147. SET @a = 17;
  2148. #
  2149. # 6. Show that "sorted_result;" before the "SET @a = 17;" above does not affect
  2150. # the now following query.
  2151. SELECT 2 as "my_col"
  2152. UNION
  2153. SELECT 1;
  2154. # 7. Ensure that "sorted_result" in combination with $variables works
  2155. let $my_stmt=SELECT 2 as "my_col"
  2156. UNION
  2157. SELECT 1;
  2158. --sorted_result
  2159. eval $my_stmt;
  2160. # 8. Ensure that "sorted_result " does not change the semantics of
  2161. # "--error ...." or the protocol output after such an expected failure
  2162. --sorted_result
  2163. --error ER_NO_SUCH_TABLE
  2164. SELECT '2' as "my_col1",2 as "my_col2"
  2165. UNION
  2166. SELECT '1',1 from t2;
  2167. # 9. Ensure that several result formatting options including "sorted_result"
  2168. # - have all an effect
  2169. # - "--sorted_result" does not need to be direct before the statement
  2170. # - Row sorting is applied after modification of the column content
  2171. --sorted_result
  2172. --replace_column 1 #
  2173. SELECT '1' as "my_col1",2 as "my_col2"
  2174. UNION
  2175. SELECT '2',1;
  2176. # 10. Ensure that at least 1024 rows within a result set do not cause problems
  2177. #
  2178. CREATE TABLE t1 (f1 INT);
  2179. INSERT INTO t1 SET f1 = 1024;
  2180. INSERT INTO t1 SELECT f1 - 1 FROM t1;
  2181. INSERT INTO t1 SELECT f1 - 2 FROM t1;
  2182. INSERT INTO t1 SELECT f1 - 4 FROM t1;
  2183. INSERT INTO t1 SELECT f1 - 8 FROM t1;
  2184. INSERT INTO t1 SELECT f1 - 16 FROM t1;
  2185. INSERT INTO t1 SELECT f1 - 32 FROM t1;
  2186. INSERT INTO t1 SELECT f1 - 64 FROM t1;
  2187. INSERT INTO t1 SELECT f1 - 128 FROM t1;
  2188. INSERT INTO t1 SELECT f1 - 256 FROM t1;
  2189. INSERT INTO t1 SELECT f1 - 512 FROM t1;
  2190. --disable_result_log ONCE
  2191. --sorted_result
  2192. SELECT * FROM t1;
  2193. DROP TABLE t1;
  2194. # ----------------------------------------------------------------------------
  2195. # test for lowercase_result
  2196. # ----------------------------------------------------------------------------
  2197. # 1. Basic test
  2198. --lowercase_result
  2199. SELECT "500g BLÅBÆRSYLTETØY" AS "WILL BE lower cased";
  2200. # 2. test that it does not apply to next statement
  2201. SELECT "UPPER" AS "WILL NOT BE lower cased";
  2202. # 3. test that it does not affect non-SQL or the following statement
  2203. --lowercase_result
  2204. --echo UP
  2205. SELECT 0 as "UP AGAIN";
  2206. # 4. test that it works with eval and variables
  2207. let $lower_stmt=SELECT "ABCdef" AS "uvwXYZ";
  2208. --lowercase_result
  2209. eval $lower_stmt;
  2210. # 5. test that it works in combination with sort
  2211. sorted_result;
  2212. lowercase_result;
  2213. SELECT "Xyz" AS Name UNION SELECT "Abc" as Name ORDER BY Name DESC;
  2214. # 6. Test combination with replace, and that lower casing is done first
  2215. --lowercase_result
  2216. --replace_result old new
  2217. SELECT 1 as "SOME OLD TEXT";
  2218. # 7. Test missing lower casing of "unknown" characters
  2219. --character_set utf8
  2220. --lowercase_result
  2221. SELECT 0 as "WILL NOT lower case ÄËÐ";
  2222. --character_set latin1
  2223. # ----------------------------------------------------------------------------
  2224. # Some coverage tests
  2225. # ----------------------------------------------------------------------------
  2226. --disable_query_log
  2227. --exec $MYSQL_TEST --help 2>&1 > /dev/null
  2228. --exec $MYSQL_TEST --version 2>&1 > /dev/null
  2229. --enable_query_log
  2230. --disable_abort_on_error ONCE
  2231. --error 1
  2232. --exec $MYSQL_TEST a b c 2>&1 > /dev/null
  2233. # ----------------------------------------------------------------------------
  2234. # test for query_get_value
  2235. # ----------------------------------------------------------------------------
  2236. CREATE TABLE t1(
  2237. a int, b varchar(255), c datetime
  2238. );
  2239. SHOW COLUMNS FROM t1;
  2240. #------------ Positive tests ------------
  2241. # 1. constant parameters
  2242. # value is simple string without spaces
  2243. let $value= query_get_value(SHOW COLUMNS FROM t1, Type, 1);
  2244. --echo statement=SHOW COLUMNS FROM t1 row_number=1, column_name="Type", Value=$value
  2245. let $value= query_get_value("SHOW COLUMNS FROM t1", Type, 1);
  2246. --echo statement="SHOW COLUMNS FROM t1" row_number=1, column_name="Type", Value=$value
  2247. #
  2248. # 2. $variables as parameters
  2249. # value IS NULL
  2250. let $my_show= SHOW COLUMNS FROM t1;
  2251. let $column_name= Default;
  2252. let $row_number= 1;
  2253. let $value= query_get_value($my_show, $column_name, $row_number);
  2254. --echo statement=$my_show row_number=$row_number, column_name=$column_name, Value=$value
  2255. #
  2256. # 3. result set of a SELECT (not recommended, because projection and
  2257. # selection could be done much better by pure SELECT functionality)
  2258. # value is string with space in the middle
  2259. let $value= query_get_value(SELECT 'A B' AS "MyColumn", MyColumn, 1);
  2260. --echo value= ->$value<-
  2261. #
  2262. # 4. column name with space
  2263. let $value= query_get_value(SELECT 1 AS "My Column", My Column, 1);
  2264. --echo value= $value
  2265. #
  2266. # 4.1 Query containing , protected by quotes, quotes also on column
  2267. let $value= query_get_value('SELECT 1 as a, 2 as b', "b", 1);
  2268. --echo value= $value
  2269. #
  2270. #------------ Negative tests ------------
  2271. # 5. Incomplete statement including missing parameters
  2272. # 5.1 incomplete statement
  2273. --error 1
  2274. --exec echo "let \$value= query_get_value(SHOW;" | $MYSQL_TEST 2>&1
  2275. # 5.2 missing query
  2276. --error 1
  2277. --exec echo "let \$value= query_get_value;" | $MYSQL_TEST 2>&1
  2278. # 5.3 missing column name
  2279. --error 1
  2280. --exec echo "let \$value= query_get_value(SHOW COLUMNS FROM t1);" | $MYSQL_TEST 2>&1
  2281. # 5.4 missing row number
  2282. --error 1
  2283. --exec echo "let \$value= query_get_value(SHOW COLUMNS FROM t1, Field);" | $MYSQL_TEST 2>&1
  2284. #
  2285. # 6. Somehow "wrong" value of parameters
  2286. # 6.1 row parameter
  2287. # 6.1.1 non sense number 0
  2288. let $value= initialized;
  2289. let $value= query_get_value(SHOW COLUMNS FROM t1, Field, 0);
  2290. --echo value= $value
  2291. # 6.1.2 after the last row
  2292. let $value= initialized;
  2293. let $value= query_get_value(SHOW COLUMNS FROM t1, Field, 10);
  2294. --echo value= $value
  2295. # 6.1.3 invalid row number
  2296. --error 1
  2297. --exec echo "let \$value= query_get_value(SHOW COLUMNS FROM t1, Field, notnumber);" | $MYSQL_TEST 2>&1
  2298. # 6.2 column name parameter, name of not existing column
  2299. --error 1
  2300. --exec echo "let \$value= query_get_value(SHOW COLUMNS FROM t1, column_not_exists, 1);" | $MYSQL_TEST 2>&1
  2301. # 6.3. statement which never gives a result set
  2302. --error 1
  2303. --exec echo "let \$value= query_get_value(SET @A = 1, Field, 1);" | $MYSQL_TEST 2>&1
  2304. # 6.4. statement contains a ","
  2305. # Note: There is no need to improve this, because we need query_get_value
  2306. # for SHOW commands only.
  2307. --error 1
  2308. --exec echo "let \$value= query_get_value(SELECT 1 AS "A", 1 AS "B", 1);" | $MYSQL_TEST 2>&1
  2309. #
  2310. # 7. empty result set
  2311. let $value= initialized;
  2312. let $value= query_get_value(SELECT a FROM t1, a, 1);
  2313. --echo value= $value
  2314. #
  2315. # 9. failing statement
  2316. --error 1
  2317. --exec echo "let \$value= query_get_value(SHOW COLNS FROM t1, Field, 1);" | $MYSQL_TEST 2>&1
  2318. #
  2319. # 10. Artificial example how to process a complete SHOW result set:
  2320. let $show_statement= SHOW COLUMNS FROM t1;
  2321. let $rowno= 1;
  2322. let $run=1;
  2323. let $count= 0;
  2324. --echo
  2325. --echo Field Type Null Key Default Extra
  2326. while ($run)
  2327. {
  2328. let $Field= query_get_value($show_statement, Field, $rowno);
  2329. if ($Field == No such row)
  2330. {
  2331. let $run= 0;
  2332. }
  2333. if ($Field != No such row)
  2334. {
  2335. let $Type= query_get_value($show_statement, Type, $rowno);
  2336. let $Null= query_get_value($show_statement, Null, $rowno);
  2337. if ($Null == YES)
  2338. {
  2339. inc $count;
  2340. }
  2341. let $Key= query_get_value($show_statement, Key, $rowno);
  2342. let $Default= query_get_value($show_statement, Default, $rowno);
  2343. let $Extra= query_get_value($show_statement, Extra, $rowno);
  2344. --echo $Field $Type $Null ->$Key<- $Default $Extra
  2345. inc $rowno;
  2346. }
  2347. }
  2348. --echo
  2349. --echo Number of columns with Default NULL: $count
  2350. --echo
  2351. eval $show_statement;
  2352. drop table t1;
  2353. # ----------------------------------------------------------------------------
  2354. # Test change_user command
  2355. # ----------------------------------------------------------------------------
  2356. --error 1
  2357. --exec echo "--change_user root,,inexistent" | $MYSQL_TEST 2>&1
  2358. --error 1
  2359. --exec echo "--change_user inexistent,,test" | $MYSQL_TEST 2>&1
  2360. --error 1
  2361. --exec echo "--change_user root,inexistent,test" | $MYSQL_TEST 2>&1
  2362. --change_user
  2363. --change_user root
  2364. --change_user root,,
  2365. --change_user root,,test
  2366. # ----------------------------------------------------------------------------
  2367. # Test mkdir and rmdir command
  2368. # ----------------------------------------------------------------------------
  2369. mkdir $MYSQLTEST_VARDIR/tmp/testdir;
  2370. rmdir $MYSQLTEST_VARDIR/tmp/testdir;
  2371. # Directory already exist
  2372. mkdir $MYSQLTEST_VARDIR/tmp/testdir;
  2373. --error 1
  2374. mkdir $MYSQLTEST_VARDIR/tmp/testdir;
  2375. # Remove dir with file inside
  2376. write_file $MYSQLTEST_VARDIR/tmp/testdir/file1.txt;
  2377. hello
  2378. EOF
  2379. # Verify that --replace_result also work on list_files
  2380. --replace_result file REPLACED_FILE
  2381. list_files $MYSQLTEST_VARDIR/tmp/testdir;
  2382. # list_files gets the directory list before creating the new file
  2383. list_files_write_file $MYSQLTEST_VARDIR/tmp/testdir/file2.txt $MYSQLTEST_VARDIR/tmp/testdir *;
  2384. list_files_append_file $MYSQLTEST_VARDIR/tmp/testdir/file2.txt $MYSQLTEST_VARDIR/tmp/testdir *2*;
  2385. list_files_write_file $MYSQLTEST_VARDIR/tmp/testdir/file2.txt $MYSQLTEST_VARDIR/tmp/testdir file?.txt;
  2386. list_files_append_file $MYSQLTEST_VARDIR/tmp/testdir/file3.txt $MYSQLTEST_VARDIR/tmp/testdir file*.txt;
  2387. diff_files $MYSQLTEST_VARDIR/tmp/testdir/file2.txt $MYSQLTEST_VARDIR/tmp/testdir/file3.txt;
  2388. --error 1
  2389. rmdir $MYSQLTEST_VARDIR/tmp/testdir;
  2390. cat_file $MYSQLTEST_VARDIR/tmp/testdir/file3.txt;
  2391. list_files_write_file $MYSQLTEST_VARDIR/tmp/testdir/file11.txt $MYSQLTEST_VARDIR/tmp/testdir file?.txt;
  2392. remove_files_wildcard $MYSQLTEST_VARDIR/tmp/testdir file?.txt;
  2393. list_files_write_file $MYSQLTEST_VARDIR/tmp/testdir/dir-list.txt $MYSQLTEST_VARDIR/tmp/testdir file*.txt;
  2394. cat_file $MYSQLTEST_VARDIR/tmp/testdir/dir-list.txt;
  2395. remove_files_wildcard $MYSQLTEST_VARDIR/tmp/testdir file*.txt;
  2396. list_files $MYSQLTEST_VARDIR/tmp/testdir;
  2397. remove_files_wildcard $MYSQLTEST_VARDIR/tmp/testdir;
  2398. list_files $MYSQLTEST_VARDIR/tmp/testdir;
  2399. rmdir $MYSQLTEST_VARDIR/tmp/testdir;
  2400. #
  2401. # Bug#36041 mysql-test-run doesn't seem to string match 100% effectively
  2402. # on Windows
  2403. #
  2404. --replace_result c:\\a.txt z
  2405. SELECT 'c:\\a.txt' AS col;
  2406. # ----------------------------------------------------------------------------
  2407. # Test that -- is not allowed as comment, only as mysqltest builtin command
  2408. # ----------------------------------------------------------------------------
  2409. # valid
  2410. select 1;
  2411. --query select 1
  2412. --query -- a comment for the server
  2413. # Not valid, "select" is not a mysqltest command
  2414. --error 1
  2415. --exec echo "--select 1;" | $MYSQL_TEST 2>&1
  2416. # ----------------------------------------------------------------------------
  2417. # BUG#35701 please allow test language variables in connection and sync_slave_with_master
  2418. # Test that "connection $variable" works and that $CURRENT_CONNECTION has the right value.
  2419. # ----------------------------------------------------------------------------
  2420. connect (con1,localhost,root,,);
  2421. --echo $CURRENT_CONNECTION
  2422. connect (con2,localhost,root,,);
  2423. --echo $CURRENT_CONNECTION
  2424. connection default;
  2425. --echo $CURRENT_CONNECTION
  2426. connection con1;
  2427. --echo $CURRENT_CONNECTION
  2428. connection con2;
  2429. --echo $CURRENT_CONNECTION
  2430. let $x= con1;
  2431. let $y= con2;
  2432. connection $x;
  2433. --echo $CURRENT_CONNECTION
  2434. connection $y;
  2435. --echo $CURRENT_CONNECTION
  2436. # Disconnect the not selected connection
  2437. disconnect $x;
  2438. --echo $CURRENT_CONNECTION
  2439. # Disconnect the selected connection
  2440. disconnect $y;
  2441. --echo $CURRENT_CONNECTION
  2442. --echo End of tests
  2443. connection default;
  2444. # Wait till we reached the initial number of concurrent sessions
  2445. --source include/wait_until_count_sessions.inc