/** * Set the system variables on the DDL parser. * * @param variables the system variables; may not be null but may be empty */ public void setSystemVariables(Map<String, String> variables) { variables.forEach((varName, value) -> { ddlParser.systemVariables().setVariable(MySqlScope.SESSION, varName, value); }); }
protected void parseUse(Marker marker) { tokens.consume("USE"); String dbName = tokens.consume(); setCurrentSchema(dbName); // Every time MySQL switches to a different database, it sets the "character_set_database" and "collation_database" // system variables. We replicate that behavior here (or the variable we care about) so that these variables are always // right for the current database. String charsetForDb = charsetNameForDatabase.get(dbName); systemVariables.setVariable(MySqlScope.GLOBAL, "character_set_database", charsetForDb); }
@Override public void enterSetNames(MySqlParser.SetNamesContext 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-names.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, charsetName); super.enterSetNames(ctx); } }
@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); }
@Override public void enterUseStatement(MySqlParser.UseStatementContext ctx) { String dbName = parser.parseName(ctx.uid()); parser.setCurrentSchema(dbName); // Every time MySQL switches to a different database, it sets the "character_set_database" and "collation_database" // system variables. We replicate that behavior here (or the variable we care about) so that these variables are always // right for the current database. String charsetForDb = parser.charsetNameForDatabase().get(dbName); parser.systemVariables().setVariable(MySqlSystemVariables.MySqlScope.SESSION, MySqlSystemVariables.CHARSET_NAME_DATABASE, charsetForDb); super.enterUseStatement(ctx); } }
charsetName = currentDatabaseCharset(); systemVariables.setVariable(scope.get(), "character_set_client", charsetName); systemVariables.setVariable(scope.get(), "character_set_results", charsetName); systemVariables.setVariable(MySqlScope.SESSION, MySqlSystemVariables.CHARSET_NAME_CONNECTION, systemVariables.getVariable(MySqlSystemVariables.CHARSET_NAME_DATABASE)); charsetName = currentDatabaseCharset(); systemVariables.setVariable(scope.get(), "character_set_client", charsetName); systemVariables.setVariable(scope.get(), "character_set_results", charsetName); systemVariables.setVariable(scope.get(), "character_set_connection", charsetName); systemVariables.setVariable(scope.get(), variableName, value);
parser.systemVariables().setVariable(scope, variableName, value);