/** * Get the name of the character set for the current database, via the "character_set_database" system property. * * @return the name of the character set for the current database, or null if not known ... */ public String currentDatabaseCharset() { String charsetName = systemVariables.getVariable(MySqlSystemVariables.CHARSET_NAME_DATABASE); if (charsetName == null || "DEFAULT".equalsIgnoreCase(charsetName)) { charsetName = systemVariables.getVariable(MySqlSystemVariables.CHARSET_NAME_SERVER); } return charsetName; }
/** * Get the name of the character set for the current database, via the "character_set_database" system property. * * @return the name of the character set for the current database, or null if not known ... */ protected String currentDatabaseCharset() { String charsetName = systemVariables.getVariable("character_set_database"); if (charsetName == null || "DEFAULT".equalsIgnoreCase(charsetName)) { charsetName = systemVariables.getVariable(SERVER_CHARSET_NAME); } return charsetName; }
@Override public void enterCreateDatabaseOption(MySqlParser.CreateDatabaseOptionContext ctx) { if (ctx.charsetName() != null) { String charsetName = parser.withoutQuotes(ctx.charsetName()); if ("DEFAULT".equalsIgnoreCase(charsetName)) { charsetName = parser.systemVariables().getVariable(MySqlSystemVariables.CHARSET_NAME_SERVER); } parser.charsetNameForDatabase().put(databaseName, charsetName); } super.enterCreateDatabaseOption(ctx); } }
protected void parseDatabaseOptions(Marker start, String dbName) { // Handle the default character set and collation ... tokens.canConsume("DEFAULT"); if (tokens.canConsume("CHARACTER", "SET") || tokens.canConsume("CHARSET")) { tokens.canConsume("="); String charsetName = tokens.consume(); if ("DEFAULT".equalsIgnoreCase(charsetName)) { charsetName = systemVariables.getVariable(SERVER_CHARSET_NAME); } charsetNameForDatabase.put(dbName, charsetName); } if (tokens.canConsume("COLLATE")) { tokens.canConsume("="); tokens.consume(); // collation name } }
/** * Load the database schema information using the previously-recorded history, and stop reading the history when the * the history reaches the supplied starting point. * * @param startingPoint the source information with the current {@link SourceInfo#partition()} and {@link SourceInfo#offset() * offset} at which the database schemas are to reflect; may not be null */ public void loadHistory(SourceInfo startingPoint) { // Read the system variables from the MySQL instance and load them into the DDL parser as defaults ... Map<String, String> variables = connectionContext.readMySqlCharsetSystemVariables(); dbSchema.setSystemVariables(variables); // And then load the history ... dbSchema.loadHistory(startingPoint); // The server's default character set may have changed since we last recorded it in the history, // so we need to see if the history's state does not match ... String systemCharsetName = variables.get(MySqlSystemVariables.CHARSET_NAME_SERVER); String systemCharsetNameFromHistory = dbSchema.systemVariables().getVariable(MySqlSystemVariables.CHARSET_NAME_SERVER); if (!Strings.equalsIgnoreCase(systemCharsetName, systemCharsetNameFromHistory)) { // The history's server character set is NOT the same as the server's current default, // so record the change in the history ... String ddlStatement = connectionContext.setStatementFor(variables); dbSchema.applyDdl(source, "", ddlStatement, null); } recordProcessor.regenerate(); }
systemVariables.setVariable(scope.get(), "character_set_results", charsetName); systemVariables.setVariable(MySqlScope.SESSION, MySqlSystemVariables.CHARSET_NAME_CONNECTION, systemVariables.getVariable(MySqlSystemVariables.CHARSET_NAME_DATABASE));
protected void assertVariable(SystemVariables.Scope scope, String name, String expectedValue) { String actualValue = parser.systemVariables().getVariable(name, scope); if (expectedValue == null) { assertThat(actualValue).isNull(); } else { assertThat(actualValue).isEqualToIgnoringCase(expectedValue); } }
protected void assertVariable(String name, String expectedValue) { String actualValue = parser.systemVariables().getVariable(name); if (expectedValue == null) { assertThat(actualValue).isNull(); } else { assertThat(actualValue).isEqualToIgnoringCase(expectedValue); } }
@Override public void enterSetCharset(MySqlParser.SetCharsetContext ctx) { String charsetName = ctx.charsetName() != null ? parser.withoutQuotes(ctx.charsetName()) : parser.currentDatabaseCharset(); // Sets variables according to documentation at // https://dev.mysql.com/doc/refman/5.7/en/set-character-set.html // Using default scope for these variables, because this type of set statement you cannot specify // the scope manually parser.systemVariables().setVariable(MySqlSystemVariables.MySqlScope.SESSION, MySqlSystemVariables.CHARSET_NAME_CLIENT, charsetName); parser.systemVariables().setVariable(MySqlSystemVariables.MySqlScope.SESSION, MySqlSystemVariables.CHARSET_NAME_RESULT, charsetName); parser.systemVariables().setVariable(MySqlSystemVariables.MySqlScope.SESSION, MySqlSystemVariables.CHARSET_NAME_CONNECTION, parser.systemVariables().getVariable(MySqlSystemVariables.CHARSET_NAME_DATABASE)); super.enterSetCharset(ctx); }
protected void assertVariable(SystemVariables.Scope scope, String name, String expectedValue) { String actualValue = parser.systemVariables().getVariable(name, scope); if (expectedValue == null) { assertThat(actualValue).isNull(); } else { assertThat(actualValue).isEqualToIgnoringCase(expectedValue); } }
protected void assertVariable(String name, String expectedValue) { String actualValue = parser.systemVariables().getVariable(name); if (expectedValue == null) { assertThat(actualValue).isNull(); } else { assertThat(actualValue).isEqualToIgnoringCase(expectedValue); } }