summaryrefslogtreecommitdiff
path: root/sql/sql_bootstrap.cc
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2021-03-03 10:24:16 +0100
committerVladislav Vaintroub <wlad@mariadb.com>2021-03-18 08:02:48 +0100
commit9186ff88dad674ba4c335a47e9657e5b54efbf69 (patch)
treea68edc5fd765a782cfb13d40f3e1be58b1ae217a /sql/sql_bootstrap.cc
parent601c577142639d7bde947d071ca944c16920340c (diff)
downloadmariadb-git-9186ff88dad674ba4c335a47e9657e5b54efbf69.tar.gz
MDEV-9077 - sys schema preparation
- increase MAX_BOOTSTRAP_QUERY_SIZE (sys.schema has SP over 50K large) don't allocate bootstrap query on heap anymore. - support DELIMITER in bootstrap
Diffstat (limited to 'sql/sql_bootstrap.cc')
-rw-r--r--sql/sql_bootstrap.cc53
1 files changed, 46 insertions, 7 deletions
diff --git a/sql/sql_bootstrap.cc b/sql/sql_bootstrap.cc
index dbeb971cd5a..b39d7a57bc0 100644
--- a/sql/sql_bootstrap.cc
+++ b/sql/sql_bootstrap.cc
@@ -18,9 +18,20 @@
#include <ctype.h>
#include <string.h>
#include "sql_bootstrap.h"
+#include <string>
-int read_bootstrap_query(char *query, int *query_length,
- fgets_input_t input, fgets_fn_t fgets_fn, int *error)
+static bool is_end_of_query(const char *line, size_t len,
+ const std::string& delimiter)
+{
+ if (delimiter.length() > len)
+ return false;
+ return !strcmp(line + len-delimiter.length(),delimiter.c_str());
+}
+
+static std::string delimiter= ";";
+extern "C" int read_bootstrap_query(char *query, int *query_length,
+ fgets_input_t input, fgets_fn_t fgets_fn,
+ int preserve_delimiter, int *error)
{
char line_buffer[MAX_BOOTSTRAP_LINE_SIZE];
const char *line;
@@ -73,9 +84,32 @@ int read_bootstrap_query(char *query, int *query_length,
if ((line[0] == '-') && (line[1] == '-'))
continue;
- /* Skip delimiter, ignored. */
- if (strncmp(line, "delimiter", 9) == 0)
+ size_t i=0;
+ while (line[i] == ' ')
+ i++;
+
+ /* Skip -- comments */
+ if (line[i] == '-' && line[i+1] == '-')
+ continue;
+
+ if (strncmp(line, "DELIMITER", 9) == 0)
+ {
+ const char *p= strrchr(line,' ');
+ if (!p || !p[1])
+ {
+ /* Invalid DELIMITER specifier */
+ return READ_BOOTSTRAP_ERROR;
+ }
+ delimiter.assign(p+1);
+ if (preserve_delimiter)
+ {
+ memcpy(query,line,len);
+ query[len]=0;
+ *query_length = (int)len;
+ return READ_BOOTSTRAP_SUCCESS;
+ }
continue;
+ }
/* Append the current line to a multi line query. If the new line will make
the query too long, preserve the partial line to provide context for the
@@ -105,13 +139,18 @@ int read_bootstrap_query(char *query, int *query_length,
memcpy(query + query_len, line, len);
query_len+= len;
- if (line[len - 1] == ';')
+ if (is_end_of_query(line, len, delimiter))
{
/*
- The last line is terminated by ';'.
+ The last line is terminated by delimiter
Return the query found.
*/
- query[query_len]= '\0';
+ if (!preserve_delimiter)
+ {
+ query_len-= delimiter.length();
+ query[query_len++]= ';';
+ }
+ query[query_len]= 0;
*query_length= (int)query_len;
return READ_BOOTSTRAP_SUCCESS;
}