Skip to content

Commit 1a0fb2b

Browse files
committed
WL#5291 MySQL Install / Upgrade script format
1 parent db1201c commit 1a0fb2b

13 files changed

Lines changed: 547 additions & 262 deletions

client/mysql_upgrade.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2000 MySQL AB
1+
/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -757,17 +757,35 @@ static void print_line(char* line)
757757
static int run_sql_fix_privilege_tables(void)
758758
{
759759
int found_real_errors= 0;
760+
const char **query_ptr;
761+
DYNAMIC_STRING ds_script;
760762
DYNAMIC_STRING ds_result;
761763
DBUG_ENTER("run_sql_fix_privilege_tables");
762764

765+
if (init_dynamic_string(&ds_script, "", 65536, 1024))
766+
die("Out of memory");
767+
763768
if (init_dynamic_string(&ds_result, "", 512, 512))
764769
die("Out of memory");
765770

766771
verbose("Running 'mysql_fix_privilege_tables'...");
767-
run_query(mysql_fix_privilege_tables,
772+
773+
/*
774+
Individual queries can not be executed independently by invoking
775+
a forked mysql client, because the script uses session variables
776+
and prepared statements.
777+
*/
778+
for ( query_ptr= &mysql_fix_privilege_tables[0];
779+
*query_ptr != NULL;
780+
query_ptr++
781+
)
782+
{
783+
dynstr_append(&ds_script, *query_ptr);
784+
}
785+
786+
run_query(ds_script.str,
768787
&ds_result, /* Collect result */
769788
TRUE);
770-
771789
{
772790
/*
773791
Scan each line of the result for real errors
@@ -792,6 +810,7 @@ static int run_sql_fix_privilege_tables(void)
792810
}
793811

794812
dynstr_free(&ds_result);
813+
dynstr_free(&ds_script);
795814
return found_real_errors;
796815
}
797816

libmysqld/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2006 MySQL AB
1+
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -84,7 +84,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
8484
../sql/rpl_utility.cc
8585
../sql/sys_vars.cc
8686
${CMAKE_BINARY_DIR}/sql/sql_builtin.cc
87-
../sql/mdl.cc ../sql/transaction.cc
87+
../sql/mdl.cc ../sql/transaction.cc ../sql/sql_bootstrap.cc
8888
${GEN_SOURCES}
8989
${MYSYS_LIBWRAP_SOURCE}
9090
)

libmysqld/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2001-2006 MySQL AB
1+
# Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This library is free software; you can redistribute it and/or
44
# modify it under the terms of the GNU Library General Public
@@ -78,7 +78,7 @@ sqlsources = derror.cc field.cc field_conv.cc strfunc.cc filesort.cc \
7878
debug_sync.cc sql_tablespace.cc transaction.cc \
7979
rpl_injector.cc my_user.c partition_info.cc \
8080
sql_servers.cc event_parse_data.cc sql_signal.cc \
81-
rpl_handler.cc mdl.cc keycaches.cc sql_audit.cc
81+
rpl_handler.cc mdl.cc keycaches.cc sql_audit.cc sql_bootstrap.cc
8282

8383
libmysqld_int_a_SOURCES= $(libmysqld_sources)
8484
nodist_libmysqld_int_a_SOURCES= $(libmysqlsources) $(sqlsources)

mysql-test/mysql-test-run.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/perl
22
# -*- cperl -*-
33

4-
# Copyright (C) 2009 Sun Microsystems, Inc
4+
# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -2868,7 +2868,7 @@ sub mysql_install_db {
28682868
{
28692869
my $sql_dir= dirname($path_sql);
28702870
# Use the mysql database for system tables
2871-
mtr_tofile($bootstrap_sql_file, "use mysql\n");
2871+
mtr_tofile($bootstrap_sql_file, "use mysql;\n");
28722872

28732873
# Add the offical mysql system tables
28742874
# for a production system

scripts/Makefile.am

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2000-2006 MySQL AB
1+
# Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -111,14 +111,15 @@ mysql_fix_privilege_tables.sql: mysql_system_tables.sql \
111111
@echo "Building $@";
112112
@cat mysql_system_tables.sql mysql_system_tables_fix.sql > $@
113113

114+
comp_sql_SOURCES= comp_sql.c
115+
114116
#
115117
# Build mysql_fix_privilege_tables_sql.c from
116118
# mysql_fix_privileges_tables.sql using comp_sql
117119
# The "sleep" ensures the generated file has a younger timestamp than its source
118120
# (which may have been generated in this very same "make" run).
119121
#
120-
mysql_fix_privilege_tables_sql.c: comp_sql.c mysql_fix_privilege_tables.sql
121-
$(MAKE) $(AM_MAKEFLAGS) comp_sql$(EXEEXT)
122+
mysql_fix_privilege_tables_sql.c: comp_sql$(EXEEXT) mysql_fix_privilege_tables.sql
122123
sleep 2
123124
$(top_builddir)/scripts/comp_sql$(EXEEXT) \
124125
mysql_fix_privilege_tables \

scripts/comp_sql.c

Lines changed: 80 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2004 MySQL AB
1+
/* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -13,10 +13,6 @@
1313
along with this program; if not, write to the Free Software
1414
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
1515

16-
/*
17-
Written by Magnus Svensson
18-
*/
19-
2016
/*
2117
Converts a SQL file into a C file that can be compiled and linked
2218
into other programs
@@ -26,7 +22,20 @@
2622
#include <stdlib.h>
2723
#include <stdio.h>
2824

29-
FILE *in, *out;
25+
#include "../sql/sql_bootstrap.h"
26+
27+
/*
28+
This is an internal tool used during the build process only,
29+
- do not make a library just for this,
30+
which would make the Makefiles and the server link
31+
more complex than necessary,
32+
- do not duplicate the code either.
33+
so just add the sql_bootstrap.cc code as is.
34+
*/
35+
#include "../sql/sql_bootstrap.cc"
36+
37+
FILE *in;
38+
FILE *out;
3039

3140
static void die(const char *fmt, ...)
3241
{
@@ -54,13 +63,60 @@ static void die(const char *fmt, ...)
5463
exit(1);
5564
}
5665

66+
char *fgets_fn(char *buffer, size_t size, fgets_input_t input)
67+
{
68+
return fgets(buffer, size, (FILE*) input);
69+
}
70+
71+
static void print_query(FILE *out, const char *query)
72+
{
73+
const char *ptr= query;
74+
int column= 0;
75+
76+
fprintf(out, "\"");
77+
while (*ptr)
78+
{
79+
if (column >= 120)
80+
{
81+
/* Wrap to the next line, tabulated. */
82+
fprintf(out, "\"\n \"");
83+
column= 2;
84+
}
85+
switch(*ptr)
86+
{
87+
case '\n':
88+
/*
89+
Preserve the \n character in the query text,
90+
and wrap to the next line, tabulated.
91+
*/
92+
fprintf(out, "\\n\"\n \"");
93+
column= 2;
94+
break;
95+
case '\r':
96+
/* Skipped */
97+
break;
98+
case '\"':
99+
fprintf(out, "\\\"");
100+
column++;
101+
break;
102+
default:
103+
putc(*ptr, out);
104+
column++;
105+
break;
106+
}
107+
ptr++;
108+
}
109+
fprintf(out, "\\n\",\n");
110+
}
57111

58112
int main(int argc, char *argv[])
59113
{
60-
char buff[512];
114+
char query[MAX_BOOTSTRAP_QUERY_SIZE];
61115
char* struct_name= argv[1];
62116
char* infile_name= argv[2];
63117
char* outfile_name= argv[3];
118+
int rc;
119+
int query_length;
64120

65121
if (argc != 4)
66122
die("Usage: comp_sql <struct_name> <sql_filename> <c_filename>");
@@ -71,55 +127,31 @@ int main(int argc, char *argv[])
71127
if (!(out= fopen(outfile_name, "w")))
72128
die("Failed to open output file '%s'", outfile_name);
73129

74-
fprintf(out, "const char* %s={\n\"", struct_name);
130+
fprintf(out, "/*\n");
131+
fprintf(out, " Do not edit this file, it is automatically generated from:\n");
132+
fprintf(out, " <%s>\n", infile_name);
133+
fprintf(out, "*/\n");
134+
fprintf(out, "const char* %s[]={\n", struct_name);
75135

76-
while (fgets(buff, sizeof(buff), in))
136+
for ( ; ; )
77137
{
78-
char *curr= buff;
79-
while (*curr)
80-
{
81-
if (*curr == '\n')
82-
{
83-
/*
84-
Reached end of line, add escaped newline, escaped
85-
backslash and a newline to outfile
86-
*/
87-
fprintf(out, "\\n \"\n\"");
88-
curr++;
89-
}
90-
else if (*curr == '\r')
91-
{
92-
curr++; /* Skip */
93-
}
94-
else
95-
{
96-
if (*curr == '"')
97-
{
98-
/* Needs escape */
99-
fputc('\\', out);
100-
}
101-
102-
fputc(*curr, out);
103-
curr++;
104-
}
105-
}
106-
if (*(curr-1) != '\n')
107-
{
108-
/*
109-
Some compilers have a max string length,
110-
insert a newline at every 512th char in long
111-
strings
112-
*/
113-
fprintf(out, "\"\n\"");
114-
}
138+
rc= read_bootstrap_query(query, &query_length,
139+
(fgets_input_t) in, fgets_fn);
140+
141+
if (rc == READ_BOOTSTRAP_ERROR)
142+
die("Failed to read the bootstrap input file.\n");
143+
144+
if (rc == READ_BOOTSTRAP_EOF)
145+
break;
146+
147+
print_query(out, query);
115148
}
116149

117-
fprintf(out, "\\\n\"};\n");
150+
fprintf(out, "NULL\n};\n");
118151

119152
fclose(in);
120153
fclose(out);
121154

122155
exit(0);
123-
124156
}
125157

0 commit comments

Comments
 (0)