<commit_before>package com.tesora.dve.sql;

/*
 * #%L
 * Tesora Inc.
 * Database Virtualization Engine
 * %%
 * Copyright (C) 2011 - 2014 Tesora Inc.
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import com.tesora.dve.common.DBHelper;
import com.tesora.dve.common.PEStringUtils;
import com.tesora.dve.errmap.MySQLErrors;
import com.tesora.dve.exceptions.PECodingException;
import com.tesora.dve.exceptions.PEException;
import com.tesora.dve.exceptions.PESQLStateException;
import com.tesora.dve.resultset.ColumnSet;
import com.tesora.dve.resultset.ResultColumn;
import com.tesora.dve.resultset.ResultRow;
import com.tesora.dve.server.bootstrap.BootstrapHost;
import com.tesora.dve.server.global.HostService;
import com.tesora.dve.singleton.Singletons;
import com.tesora.dve.sql.parser.TimestampVariableUtils;
import com.tesora.dve.sql.schema.VariableScopeKind;
import com.tesora.dve.sql.util.ComparisonOptions;
import com.tesora.dve.sql.util.Functional;
import com.tesora.dve.sql.util.PEDDL;
import com.tesora.dve.sql.util.ProjectDDL;
import com.tesora.dve.sql.util.ProxyConnectionResource;
import com.tesora.dve.sql.util.ProxyConnectionResourceResponse;
import com.tesora.dve.sql.util.ResourceResponse;
import com.tesora.dve.sql.util.StorageGroupDDL;
import com.tesora.dve.standalone.PETest;
import com.tesora.dve.variables.VariableHandler;
import com.tesora.dve.variables.VariableManager;

public class SQLVariableTest extends SchemaTest {

	private static final ProjectDDL sysDDL =
		new PEDDL("sysdb",
				new StorageGroupDDL("sys",2,"sysg"),
				"schema");
	
	private static final String nonRootUser = "ben";
	private static final String nonRootAccess = "localhost";
	
	@BeforeClass
	public static void setup() throws Throwable {
		PETest.projectSetup(sysDDL);
		PETest.bootHost = BootstrapHost.startServices(PETest.class);
		ProxyConnectionResource pcr = new ProxyConnectionResource();
		sysDDL.create(pcr);
		removeUser(pcr,nonRootUser,nonRootAccess);
		pcr.execute(String.format("create user '%s'@'%s' identified by '%s'",nonRootUser,nonRootAccess,nonRootUser));
		pcr.disconnect();
	}

	ProxyConnectionResource conn = null;
	
	@Before
	public void before() throws Throwable {
		conn = new ProxyConnectionResource();
	}
	
	@After
	public void after() throws Throwable {
		conn.disconnect();
	}

	
	@Test
	public void testA() throws Throwable {
		conn.execute("set names latin1");
		conn.assertResults("show session variables like 'character%'",
				br(nr,"character_set_client", "latin1",
				   nr,"character_set_connection", "latin1",
				   nr,"character_set_results","latin1",
				   nr,"character_set_server","utf8",
				   nr,"character_set_system","utf8"));
		conn.assertResults("show variables like 'character%'",
				br(nr,"character_set_client", "latin1",
				   nr,"character_set_connection", "latin1",
				   nr,"character_set_results","latin1",
				   nr,"character_set_server","utf8",
				   nr,"character_set_system","utf8"));
		conn.execute("set @prevcharset = @@character_set_connection");
		conn.execute("set names utf8");
		conn.assertResults("show session variables like 'character%'",
				br(nr,"character_set_client", "utf8",
				   nr,"character_set_connection", "utf8",
				   nr,"character_set_results","utf8",
				   nr,"character_set_server","utf8",
				   nr,"character_set_system","utf8"));
		conn.assertResults("select @@character_set_client,@@session.character_set_connection,@@character_set_results",br(nr,"utf8","utf8","utf8"));
		conn.execute("set @@character_set_connection = @prevcharset");
		conn.assertResults("select @@character_set_connection",br(nr,"latin1"));
        conn.assertResults("show dve variables like 'version'",br(nr,"version", Singletons.require(HostService.class).getDveServerVersion()));
		try {
			// this should fail
			conn.execute("set version = '1.0'");
			fail("SET VERSION command should have thrown an exception");
		} catch (PEException re) {
			assertException(re,PEException.class,"Variable 'version' not settable as session variable");
		}		
	}
	
	@Test
	public void testB() throws Throwable {
		conn.execute("use " + sysDDL.getDatabaseName());
		conn.execute("create table `vtest` (`id` int, `pl` varchar(32))");
		conn.execute("set @default_payload = 'this is some text'");
		conn.execute("set @default_id = 15");
		conn.assertResults("show variables like 'tx_isolation'",br(nr,"tx_isolation","READ-COMMITTED"));
		conn.assertResults("select @@tx_isolation",br(nr,"READ-COMMITTED"));
		conn.execute("set transaction isolation level serializable");
		conn.assertResults("show variables like 'tx_isolation'", br(nr,"tx_isolation","SERIALIZABLE"));
		conn.assertResults("select @@tx_isolation",br(nr,"SERIALIZABLE"));
		conn.execute("insert into `vtest` (`id`, `pl`) values (1,'one'),(2,@default_payload),(@default_id, 'three')");
		conn.assertResults("select * from vtest where id = 15",br(nr,new Integer(15),"three"));
		conn.assertResults("select id from vtest where pl = @default_payload",br(nr,new Integer(2)));
	}

	@Test
	public void testShowVariables() throws Throwable {
		ResourceResponse rr = conn.fetch("show variables");
		List<ResultRow> results = rr.getResults();
		for(ResultRow row : results) {
			assertFalse(row.getResultColumn(1).getColumnValue() + " should have a value",row.getResultColumn(2).isNull());
		}
		
		// PE-668 needs this for reports to work
		rr = conn.fetch("show /*!50000 global */ variables");
		results = rr.getResults();
		for(ResultRow row : results) {
			//skip the aws ones
			if (!StringUtils.containsIgnoreCase((String)row.getResultColumn(1).getColumnValue(), "aws")) {
				assertFalse(row.getResultColumn(1).getColumnValue() + " should have a value",row.getResultColumn(2).isNull());
			}
		}
	}
	
	// when we actually support the where clause - that's the point at which we enable this again
	@Ignore
	@Test
	public void testShowVariablesFilter() throws Throwable {
		ResourceResponse unfiltered = conn.fetch("show variables");
		ResourceResponse filtered = conn.fetch("show variables where Variable_name = 'version_comment'");
		unfiltered.assertEqualResults("testShowVariablesFilter", filtered, ComparisonOptions.DEFAULT.withIgnoreOrder());
	}
	
	@Test
	public void setNamesWithVariousQuotes() throws Throwable {

		// PE-144 support double quotes for set names
		// so support no quotes, single and double quotes
		String charSet = "latin1";
		conn.execute("set names " + charSet);
		conn.assertResults("show session variables like 'character%'",
				br(nr,"character_set_client", charSet,
				   nr,"character_set_connection", charSet,
				   nr,"character_set_results",charSet,
				   nr,"character_set_server","utf8",
				   nr,"character_set_system","utf8"
				   ));
		
		charSet = "utf8";
		conn.execute("set names " + "'" + charSet + "'");
		conn.assertResults("show session variables like 'character%'",
				br(nr,"character_set_client", charSet,
				   nr,"character_set_connection", charSet,
				   nr,"character_set_results",charSet,
				   nr,"character_set_server","utf8",
				   nr,"character_set_system","utf8"
				   ));
		
		charSet = "ascii";
		conn.execute("set names " + "\"" + charSet + "\"");
		conn.assertResults("show session variables like 'character%'",
				br(nr,"character_set_client", charSet,
				   nr,"character_set_connection", charSet,
				   nr,"character_set_results",charSet,
				   nr,"character_set_server","utf8",
				   nr,"character_set_system","utf8"
				   ));
	}

	@Test
	public void testPE293() throws Throwable {

		// PE-293 support CHARSET, CHARACTER SET and CHAR SET
		String charSet = "utf8";
		String command = "CHARSET";
		conn.execute("set " + command + " " + charSet);
		conn.assertResults("show variables like 'charset'",
				br(nr,"charset", charSet));
		
		charSet = "latin1";
		command = "CHAR SET";
		conn.execute("set " + command + " " + charSet);
		conn.assertResults("show variables like 'charset'",
				br(nr,"charset", charSet));
		
		charSet = "ascii";
		command = "CHARACTER SET";
		conn.execute("set " + command + " " + charSet);
		conn.assertResults("show variables like 'charset'",
				br(nr,"charset", charSet));
	}

	@Test
	public void testShowPlugins() throws Throwable {

		ProxyConnectionResourceResponse rr = (ProxyConnectionResourceResponse) conn.fetch("show plugins");
		
		// can't check the data returned cause it may vary on different machines
		// will check the header and number of columns
		String[] colHeaders = new String[] {"Name", "Status", "Type", "Library", "License"};
		List<String> returnedColHeaders = new ArrayList<String>();
		ColumnSet cs = rr.getColumns();
		for (int i = 1; i <= cs.size(); i++) {
			returnedColHeaders.add(cs.getColumn(i).getAliasName().trim());
		}
		for (int i = 0; i < colHeaders.length; i++) {
			returnedColHeaders.contains(colHeaders[i]);
			assertTrue("Column " + colHeaders[i] + " must be one of the column headers for show plugins", 
					returnedColHeaders.contains(colHeaders[i]));
		}

		assertTrue("Must have at least one row from a show plugin", rr.getResults().size() > 0);
	}
	
	@Test
	public void testExtensionComments() throws Throwable {
		
		conn.execute("/*!40103 set @OLD_TIME_ZONE=@@TIME_ZONE */");
		conn.execute("/*!40103 set TIME_ZONE='+00:30' */");
		conn.assertResults("select @@TIME_ZONE", br(nr,"+00:30"));
		conn.execute("/*!40103 set TIME_ZONE=@OLD_TIME_ZONE */");
		conn.assertResults("select /* comment */ @@TIME_ZONE /* another comment */", br(nr,"+00:00"));
		
	}
	
	@Test
	public void testDisabledVariables() throws Throwable {

		// should not be able to set sql_auto_is_null to 1
		new ExpectedSqlErrorTester() {
			@Override
			public void test() throws Throwable {
				conn.execute("set sql_auto_is_null = 1");
			}
		}.assertError(SchemaException.class, MySQLErrors.internalFormatter,
					"Internal error: No support for sql_auto_is_null = 1 (planned)");
		conn.execute("set sql_auto_is_null = 0");
	}
	
	@Test
	public void testPE378() throws Throwable {
		conn.execute("set sql_safe_updates = 1");
		conn.execute("set sql_safe_updates = 0");
		conn.execute("set sql_safe_updates = 'can be anything cause we ignore this variable'");
	}

	@Test
	public void testSetTxIsolationLevel() throws Throwable {
		final String variableName = "tx_isolation";

		assertVariableValue(variableName, "READ-COMMITTED");
		conn.execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
		assertVariableValue(variableName, "SERIALIZABLE");
		conn.execute("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED");
		assertVariableValue(variableName, "READ-COMMITTED");
	}

	@Test
	public void testSqlModeDefault() throws Throwable {
		final String variableName = "sql_mode";

		// Reset the GLOBAL value first to test for PE-1608.
		assertVariableValue(variableName, "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION");
		conn.execute("SET GLOBAL sql_mode=default;");
		assertVariableValue(variableName, "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION");

		conn.execute("SET sql_mode=ALLOW_INVALID_DATES;");
		assertVariableValue(variableName, "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ALLOW_INVALID_DATES");
		conn.execute("SET sql_mode=default;");
		assertVariableValue(variableName, "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION");
		conn.execute("SET sql_mode=\" NO_AUTO_CREATE_USER , no_engine_substitution , ALLOW_INVALID_DATES \";");
		assertVariableValue(variableName, "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ALLOW_INVALID_DATES");
		conn.execute("SET sql_mode=\"\";");
		assertVariableValue(variableName, "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION");
	}

	@Test
	public void testPE1586() throws Throwable {
		assertVariableValue("lower_case_file_system", "OFF");
	}

	@Test
	public void testPE1587() throws Throwable {
		assertVariableValue("have_query_cache", "YES");
	}

	@Test
	public void testPE1589() throws Throwable {
		assertVariableValue("have_ssl", "NO");
		assertVariableValue("have_openssl", "NO");
	}
<commit_msg>PE-1629 - Fixed unit test.<commit_after>package com.tesora.dve.sql;

/*
 * #%L
 * Tesora Inc.
 * Database Virtualization Engine
 * %%
 * Copyright (C) 2011 - 2014 Tesora Inc.
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import com.tesora.dve.common.DBHelper;
import com.tesora.dve.common.PEStringUtils;
import com.tesora.dve.errmap.MySQLErrors;
import com.tesora.dve.exceptions.PECodingException;
import com.tesora.dve.exceptions.PEException;
import com.tesora.dve.exceptions.PESQLStateException;
import com.tesora.dve.resultset.ColumnSet;
import com.tesora.dve.resultset.ResultColumn;
import com.tesora.dve.resultset.ResultRow;
import com.tesora.dve.server.bootstrap.BootstrapHost;
import com.tesora.dve.server.global.HostService;
import com.tesora.dve.singleton.Singletons;
import com.tesora.dve.sql.parser.TimestampVariableUtils;
import com.tesora.dve.sql.schema.VariableScopeKind;
import com.tesora.dve.sql.util.ComparisonOptions;
import com.tesora.dve.sql.util.Functional;
import com.tesora.dve.sql.util.PEDDL;
import com.tesora.dve.sql.util.ProjectDDL;
import com.tesora.dve.sql.util.ProxyConnectionResource;
import com.tesora.dve.sql.util.ProxyConnectionResourceResponse;
import com.tesora.dve.sql.util.ResourceResponse;
import com.tesora.dve.sql.util.StorageGroupDDL;
import com.tesora.dve.standalone.PETest;
import com.tesora.dve.variables.VariableHandler;
import com.tesora.dve.variables.VariableManager;

public class SQLVariableTest extends SchemaTest {

	private static final ProjectDDL sysDDL =
		new PEDDL("sysdb",
				new StorageGroupDDL("sys",2,"sysg"),
				"schema");
	
	private static final String nonRootUser = "ben";
	private static final String nonRootAccess = "localhost";
	
	@BeforeClass
	public static void setup() throws Throwable {
		PETest.projectSetup(sysDDL);
		PETest.bootHost = BootstrapHost.startServices(PETest.class);
		ProxyConnectionResource pcr = new ProxyConnectionResource();
		sysDDL.create(pcr);
		removeUser(pcr,nonRootUser,nonRootAccess);
		pcr.execute(String.format("create user '%s'@'%s' identified by '%s'",nonRootUser,nonRootAccess,nonRootUser));
		pcr.disconnect();
	}

	ProxyConnectionResource conn = null;
	
	@Before
	public void before() throws Throwable {
		conn = new ProxyConnectionResource();
	}
	
	@After
	public void after() throws Throwable {
		conn.disconnect();
	}

	
	@Test
	public void testA() throws Throwable {
		conn.execute("set names latin1");
		conn.assertResults("show session variables like 'character%'",
				br(nr,"character_set_client", "latin1",
				   nr,"character_set_connection", "latin1",
				   nr,"character_set_results","latin1",
				   nr,"character_set_server","utf8",
				   nr,"character_set_system","utf8"));
		conn.assertResults("show variables like 'character%'",
				br(nr,"character_set_client", "latin1",
				   nr,"character_set_connection", "latin1",
				   nr,"character_set_results","latin1",
				   nr,"character_set_server","utf8",
				   nr,"character_set_system","utf8"));
		conn.execute("set @prevcharset = @@character_set_connection");
		conn.execute("set names utf8");
		conn.assertResults("show session variables like 'character%'",
				br(nr,"character_set_client", "utf8",
				   nr,"character_set_connection", "utf8",
				   nr,"character_set_results","utf8",
				   nr,"character_set_server","utf8",
				   nr,"character_set_system","utf8"));
		conn.assertResults("select @@character_set_client,@@session.character_set_connection,@@character_set_results",br(nr,"utf8","utf8","utf8"));
		conn.execute("set @@character_set_connection = @prevcharset");
		conn.assertResults("select @@character_set_connection",br(nr,"latin1"));
        conn.assertResults("show dve variables like 'version'",br(nr,"version", Singletons.require(HostService.class).getDveServerVersion()));
		try {
			// this should fail
			conn.execute("set version = '1.0'");
			fail("SET VERSION command should have thrown an exception");
		} catch (PEException re) {
			assertException(re,PEException.class,"Variable 'version' not settable as session variable");
		}		
	}
	
	@Test
	public void testB() throws Throwable {
		conn.execute("use " + sysDDL.getDatabaseName());
		conn.execute("create table `vtest` (`id` int, `pl` varchar(32))");
		conn.execute("set @default_payload = 'this is some text'");
		conn.execute("set @default_id = 15");
		conn.assertResults("show variables like 'tx_isolation'",br(nr,"tx_isolation","READ-COMMITTED"));
		conn.assertResults("select @@tx_isolation",br(nr,"READ-COMMITTED"));
		conn.execute("set transaction isolation level serializable");
		conn.assertResults("show variables like 'tx_isolation'", br(nr,"tx_isolation","SERIALIZABLE"));
		conn.assertResults("select @@tx_isolation",br(nr,"SERIALIZABLE"));
		conn.execute("insert into `vtest` (`id`, `pl`) values (1,'one'),(2,@default_payload),(@default_id, 'three')");
		conn.assertResults("select * from vtest where id = 15",br(nr,new Integer(15),"three"));
		conn.assertResults("select id from vtest where pl = @default_payload",br(nr,new Integer(2)));
	}

	@Test
	public void testShowVariables() throws Throwable {
		ResourceResponse rr = conn.fetch("show variables");
		List<ResultRow> results = rr.getResults();
		for(ResultRow row : results) {
			assertFalse(row.getResultColumn(1).getColumnValue() + " should have a value",row.getResultColumn(2).isNull());
		}
		
		// PE-668 needs this for reports to work
		rr = conn.fetch("show /*!50000 global */ variables");
		results = rr.getResults();
		for(ResultRow row : results) {
			//skip the aws ones
			if (!StringUtils.containsIgnoreCase((String)row.getResultColumn(1).getColumnValue(), "aws")) {
				assertFalse(row.getResultColumn(1).getColumnValue() + " should have a value",row.getResultColumn(2).isNull());
			}
		}
	}
	
	// when we actually support the where clause - that's the point at which we enable this again
	@Ignore
	@Test
	public void testShowVariablesFilter() throws Throwable {
		ResourceResponse unfiltered = conn.fetch("show variables");
		ResourceResponse filtered = conn.fetch("show variables where Variable_name = 'version_comment'");
		unfiltered.assertEqualResults("testShowVariablesFilter", filtered, ComparisonOptions.DEFAULT.withIgnoreOrder());
	}
	
	@Test
	public void setNamesWithVariousQuotes() throws Throwable {

		// PE-144 support double quotes for set names
		// so support no quotes, single and double quotes
		String charSet = "latin1";
		conn.execute("set names " + charSet);
		conn.assertResults("show session variables like 'character%'",
				br(nr,"character_set_client", charSet,
				   nr,"character_set_connection", charSet,
				   nr,"character_set_results",charSet,
				   nr,"character_set_server","utf8",
				   nr,"character_set_system","utf8"
				   ));
		
		charSet = "utf8";
		conn.execute("set names " + "'" + charSet + "'");
		conn.assertResults("show session variables like 'character%'",
				br(nr,"character_set_client", charSet,
				   nr,"character_set_connection", charSet,
				   nr,"character_set_results",charSet,
				   nr,"character_set_server","utf8",
				   nr,"character_set_system","utf8"
				   ));
		
		charSet = "ascii";
		conn.execute("set names " + "\"" + charSet + "\"");
		conn.assertResults("show session variables like 'character%'",
				br(nr,"character_set_client", charSet,
				   nr,"character_set_connection", charSet,
				   nr,"character_set_results",charSet,
				   nr,"character_set_server","utf8",
				   nr,"character_set_system","utf8"
				   ));
	}

	@Test
	public void testPE293() throws Throwable {

		// PE-293 support CHARSET, CHARACTER SET and CHAR SET
		String charSet = "utf8";
		String command = "CHARSET";
		conn.execute("set " + command + " " + charSet);
		conn.assertResults("show variables like 'charset'",
				br(nr,"charset", charSet));
		
		charSet = "latin1";
		command = "CHAR SET";
		conn.execute("set " + command + " " + charSet);
		conn.assertResults("show variables like 'charset'",
				br(nr,"charset", charSet));
		
		charSet = "ascii";
		command = "CHARACTER SET";
		conn.execute("set " + command + " " + charSet);
		conn.assertResults("show variables like 'charset'",
				br(nr,"charset", charSet));
	}

	@Test
	public void testShowPlugins() throws Throwable {

		ProxyConnectionResourceResponse rr = (ProxyConnectionResourceResponse) conn.fetch("show plugins");
		
		// can't check the data returned cause it may vary on different machines
		// will check the header and number of columns
		String[] colHeaders = new String[] {"Name", "Status", "Type", "Library", "License"};
		List<String> returnedColHeaders = new ArrayList<String>();
		ColumnSet cs = rr.getColumns();
		for (int i = 1; i <= cs.size(); i++) {
			returnedColHeaders.add(cs.getColumn(i).getAliasName().trim());
		}
		for (int i = 0; i < colHeaders.length; i++) {
			returnedColHeaders.contains(colHeaders[i]);
			assertTrue("Column " + colHeaders[i] + " must be one of the column headers for show plugins", 
					returnedColHeaders.contains(colHeaders[i]));
		}

		assertTrue("Must have at least one row from a show plugin", rr.getResults().size() > 0);
	}
	
	@Test
	public void testExtensionComments() throws Throwable {
		
		conn.execute("/*!40103 set @OLD_TIME_ZONE=@@TIME_ZONE */");
		conn.execute("/*!40103 set TIME_ZONE='+00:30' */");
		conn.assertResults("select @@TIME_ZONE", br(nr,"+00:30"));
		conn.execute("/*!40103 set TIME_ZONE=@OLD_TIME_ZONE */");
		conn.assertResults("select /* comment */ @@TIME_ZONE /* another comment */", br(nr,"+00:00"));
		
	}
	
	@Test
	public void testDisabledVariables() throws Throwable {

		// should not be able to set sql_auto_is_null to 1
		new ExpectedSqlErrorTester() {
			@Override
			public void test() throws Throwable {
				conn.execute("set sql_auto_is_null = 1");
			}
		}.assertError(SchemaException.class, MySQLErrors.internalFormatter,
					"Internal error: No support for sql_auto_is_null = 1 (planned)");
		conn.execute("set sql_auto_is_null = 0");
	}
	
	@Test
	public void testPE378() throws Throwable {
		conn.execute("set sql_safe_updates = 1");
		conn.execute("set sql_safe_updates = 0");
		conn.execute("set sql_safe_updates = 'can be anything cause we ignore this variable'");
	}

	@Test
	public void testSetTxIsolationLevel() throws Throwable {
		final String variableName = "tx_isolation";

		assertVariableValue(variableName, "READ-COMMITTED");
		conn.execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
		assertVariableValue(variableName, "SERIALIZABLE");
		conn.execute("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED");
		assertVariableValue(variableName, "READ-COMMITTED");
	}

	@Test
	public void testSqlModeDefault() throws Throwable {
		final String variableName = "sql_mode";

		// Reset the GLOBAL value first to test for PE-1608.
		assertVariableValue(variableName, "NO_ENGINE_SUBSTITUTION");
		conn.execute("SET GLOBAL sql_mode=default;");
		assertVariableValue(variableName, "NO_ENGINE_SUBSTITUTION");

		conn.execute("SET sql_mode=ALLOW_INVALID_DATES;");
		assertVariableValue(variableName, "NO_ENGINE_SUBSTITUTION,ALLOW_INVALID_DATES");
		conn.execute("SET sql_mode=default;");
		assertVariableValue(variableName, "NO_ENGINE_SUBSTITUTION");
		conn.execute("SET sql_mode=\" NO_AUTO_CREATE_USER , no_engine_substitution , ALLOW_INVALID_DATES \";");
		assertVariableValue(variableName, "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ALLOW_INVALID_DATES");
		conn.execute("SET sql_mode=\"\";");
		assertVariableValue(variableName, "NO_ENGINE_SUBSTITUTION");
	}

	@Test
	public void testPE1586() throws Throwable {
		assertVariableValue("lower_case_file_system", "OFF");
	}

	@Test
	public void testPE1587() throws Throwable {
		assertVariableValue("have_query_cache", "YES");
	}

	@Test
	public void testPE1589() throws Throwable {
		assertVariableValue("have_ssl", "NO");
		assertVariableValue("have_openssl", "NO");
	}

{'fraction_non_alphanumeric': 0.13406823739471335, 'fraction_numerical': 0.01032488452431782, 'mean_word_length': 5.119714964370546, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5564446', 'n_tokens_mistral': 8943, 'n_tokens_neox': 7994, 'n_words': 1801}