Deterministic mysqldump-shaped SQL: two tables and a view, then `stmts` * extended INSERTs of `rows` tuples. `mysql_esc` writes a quote inside a string * as \' (MySQL) instead of '' (standard). `mixed` puts one tuple holding a * subquery and one holding a function call in the middle of every INSERT. The * first two INSERTs separate their tuples with a newline and with a comment, the * way pre
| 1069 | * first two INSERTs separate their tuples with a newline and with a comment, the |
| 1070 | * way pretty-printed dumps do. */ |
| 1071 | static char *sql_dump(int stmts, int rows, bool mysql_esc, bool mixed) { |
| 1072 | cov_buf_t b = {NULL, 0, 0}; |
| 1073 | cov_put(&b, "-- MySQL dump 10.13\n" |
| 1074 | "/*!40101 SET NAMES utf8mb4 */;\n" |
| 1075 | "CREATE TABLE `city` (\n" |
| 1076 | " `ID` int NOT NULL,\n" |
| 1077 | " `Name` char(35) NOT NULL DEFAULT '',\n" |
| 1078 | " `CountryCode` char(3),\n" |
| 1079 | " `Note` text,\n" |
| 1080 | " `Population` int\n" |
| 1081 | ");\n" |
| 1082 | "CREATE TABLE country (Code char(3), Name char(52));\n" |
| 1083 | "CREATE VIEW big_cities AS SELECT Name FROM city WHERE Population > 1000000;\n" |
| 1084 | "LOCK TABLES `city` WRITE;\n"); |
| 1085 | uint32_t seed = 1735; |
| 1086 | int id = 1; |
| 1087 | for (int s = 0; s < stmts; s++) { |
| 1088 | cov_put(&b, "INSERT INTO `city` VALUES "); |
| 1089 | const char *sep = s == 0 ? ",\n" : (s == 1 ? ", /* split */ " : ","); |
| 1090 | for (int r = 0; r < rows; r++) { |
| 1091 | if (r > 0) { |
| 1092 | cov_put(&b, "%s", sep); |
| 1093 | } |
| 1094 | if (mixed && r == rows / 2) { |
| 1095 | cov_put(&b, "((SELECT MAX(Code) FROM country),'x','AAA',NULL,1)"); |
| 1096 | continue; |
| 1097 | } |
| 1098 | if (mixed && r == rows / 2 + 1) { |
| 1099 | cov_put(&b, "(%d,UPPER('y'),'BBB',NULL,2)", id++); |
| 1100 | continue; |
| 1101 | } |
| 1102 | seed = seed * 1103515245u + 12345u; |
| 1103 | const char *w = DUMP_WORDS[(seed >> 8) % DUMP_WORD_COUNT]; |
| 1104 | cov_put(&b, "(%d,'", id++); |
| 1105 | for (const char *p = w; *p; p++) { |
| 1106 | cov_put(&b, *p == '\'' ? (mysql_esc ? "\\'" : "''") : "%c", *p); |
| 1107 | } |
| 1108 | cov_put(&b, "','%c%c%c',%s,%u)", 'A' + (int)(seed % 26), 'A' + (int)((seed >> 5) % 26), |
| 1109 | 'A' + (int)((seed >> 10) % 26), DUMP_ODD[(seed >> 12) % DUMP_ODD_COUNT], |
| 1110 | (seed >> 3) % 9000000u); |
| 1111 | } |
| 1112 | cov_put(&b, ";\n"); |
| 1113 | } |
| 1114 | cov_put(&b, "UNLOCK TABLES;\n"); |
| 1115 | return b.s; |
| 1116 | } |
| 1117 | |
| 1118 | static void fp_s(cov_buf_t *b, const char *s) { |
| 1119 | cov_put(b, "%s|", s ? s : "~"); |
no test coverage detected