@Override public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection) throws SQLException { if (sql == null && interceptedStatement instanceof com.mysql.jdbc.PreparedStatement) { sql = ((com.mysql.jdbc.PreparedStatement) interceptedStatement).asSql(); } int p; if (sql != null && (p = sql.indexOf("testEnableEscapeProcessing:")) != -1) { int tst = Integer.parseInt(sql.substring(sql.indexOf('(', p) + 1, sql.indexOf(')', p))); boolean enableEscapeProcessing = (tst & 0x1) != 0; boolean processEscapeCodesForPrepStmts = (tst & 0x2) != 0; boolean useServerPrepStmts = (tst & 0x4) != 0; boolean isPreparedStatement = interceptedStatement instanceof PreparedStatement; String testCase = String.format("Case: %d [ %s | %s | %s ]/%s", tst, enableEscapeProcessing ? "enEscProc" : "-", processEscapeCodesForPrepStmts ? "procEscProcPS" : "-", useServerPrepStmts ? "useSSPS" : "-", isPreparedStatement ? "PreparedStatement" : "Statement"); boolean escapeProcessingDone = sql.indexOf('{') == -1; assertTrue(testCase, isPreparedStatement && processEscapeCodesForPrepStmts == escapeProcessingDone || !isPreparedStatement && enableEscapeProcessing == escapeProcessingDone); } return super.preProcess(sql, interceptedStatement, connection); }
@Override public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection) throws SQLException { if (interceptedStatement instanceof com.mysql.jdbc.PreparedStatement) { String asSql = interceptedStatement.toString(); int firstColon = asSql.indexOf(":"); asSql = asSql.substring(firstColon + 2); if (asSql.equals(this.prevSql)) { throw new RuntimeException("Previous statement matched current: " + sql); } this.prevSql = asSql; ParameterBindings b = ((com.mysql.jdbc.PreparedStatement) interceptedStatement).getParameterBindings(); vals.add(new Integer(b.getInt(1))); } return null; }
@Override public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection) throws SQLException { if (!(interceptedStatement instanceof ServerPreparedStatement)) { String query = sql; if (query == null && interceptedStatement instanceof com.mysql.jdbc.PreparedStatement) { query = interceptedStatement.toString(); query = query.substring(query.indexOf(':') + 2); } if (query != null && ((query.startsWith("INSERT") || query.startsWith("UPDATE") || query.startsWith("CALL")) && !query.contains("no_ts_trunk"))) { if (this.sendFracSecs ^ query.contains(".999")) { fail("Wrong TIMESTAMP trunctation in query [" + query + "]"); } } } return super.preProcess(sql, interceptedStatement, connection); }
@Override public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection) throws SQLException { String query = sql; if (query == null && interceptedStatement instanceof com.mysql.jdbc.PreparedStatement) { query = interceptedStatement.toString(); query = query.substring(query.indexOf(':') + 2); } if (query != null && query.indexOf("testBug77681") != -1) { System.out.println(this.execCounter + " --> " + query); if (this.execCounter > this.expected.length) { fail("Failed to rewrite statements"); } assertEquals("Wrong statement at execution number " + this.execCounter, this.expected[this.execCounter++], query.charAt(0)); } return super.preProcess(sql, interceptedStatement, connection); }
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException { String key = getSessionKey(); if (key != null && !key.equals(this.currentSessionKey)) { PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?"); try { pstmt.setString(1, key); pstmt.execute(); } finally { pstmt.close(); } this.currentSessionKey = key; } return null; }
@Override public ResultSetInternalMethods postProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, ResultSetInternalMethods originalResultSet, com.mysql.jdbc.Connection connection, int warningCount, boolean noIndexUsed, boolean noGoodIndexUsed, SQLException statementException) throws SQLException { if (sql.contains("lc_messages=ru_RU") && statementException == null) { connection.createStatement().executeQuery("SELECT * FROM `" + connection.getCatalog() + "`.`\u307b\u3052\u307b\u3052`"); } return super.postProcess(sql, interceptedStatement, originalResultSet, connection, warningCount, noIndexUsed, noGoodIndexUsed, statementException); }
@Override public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection) throws SQLException { if (sql.contains("SHOW COLLATION")) { this.cnt++; } return null; }
@Override public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection) throws SQLException { if (sql.contains("SET NAMES") || sql.contains("character_set_results") && !(sql.contains("SHOW VARIABLES") || sql.contains("SELECT @@"))) { throw new SQLException("Wrongt statement issued: " + sql); } return null; }
@Override public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection) throws SQLException { if (sql == null) { sql = ""; } if (sql.length() == 0 && interceptedStatement instanceof com.mysql.jdbc.PreparedStatement) { sql = ((com.mysql.jdbc.PreparedStatement) interceptedStatement).asSql(); } if (sql.indexOf("nonexistent_table") >= 0) { assertTrue("Different connection expected.", !connection.equals(previousConnection)); previousConnection = connection; } return null; }
@Override public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection) throws SQLException { if (sql.contains("SHOW VARIABLES WHERE")) { throw new SQLException("'SHOW VARIABLES WHERE' statement issued: " + sql); } return null; }
@Override public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection) throws SQLException { if (sql.contains("<HOST_NAME>")) { return (ResultSetInternalMethods) interceptedStatement.executeQuery(sql.replace("<HOST_NAME>", connection.getHost())); } return super.preProcess(sql, interceptedStatement, connection); }
public ResultSetInternalMethods postProcess(String sql, Statement interceptedStatement, ResultSetInternalMethods originalResultSet, Connection connection) throws SQLException { // requirement of anonymous class final ResultSetInternalMethods finalResultSet = originalResultSet; return (ResultSetInternalMethods) Proxy.newProxyInstance(originalResultSet.getClass().getClassLoader(), new Class[] { ResultSetInternalMethods.class }, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("equals".equals(method.getName())) { // Let args[0] "unwrap" to its InvocationHandler if it is a proxy. return args[0].equals(this); } Object invocationResult = method.invoke(finalResultSet, args); String methodName = method.getName(); if (invocationResult != null && invocationResult instanceof String || "getString".equals(methodName) || "getObject".equals(methodName) || "getObjectStoredProc".equals(methodName)) { Matcher matcher = ResultSetScannerInterceptor.this.regexP.matcher(invocationResult.toString()); if (matcher.matches()) { throw new SQLException("value disallowed by filter"); } } return invocationResult; } }); }
@Override public ResultSetInternalMethods postProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, ResultSetInternalMethods originalResultSet, com.mysql.jdbc.Connection connection, int warningCount, boolean noIndexUsed, boolean noGoodIndexUsed, SQLException statementException) throws SQLException { if (noIndexUsed) { hasSeenScan = true; } if (noGoodIndexUsed) { hasSeenBadIndex = true; } return null; }
@Override public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection) throws SQLException { if (isActive) { String query = sql; if (query == null && interceptedStatement instanceof com.mysql.jdbc.PreparedStatement) { query = interceptedStatement.toString(); query = query.substring(query.indexOf(':') + 2); } fail(testCase + ": Unexpected query executed - " + query); } return super.preProcess(sql, interceptedStatement, connection); }
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException { if (connection.versionMeetsMinimum(5, 0, 2)) { populateMapWithSessionStatusValues(connection, this.preExecuteValues); } return null; // we don't actually modify a result set }
@Override public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection) throws SQLException { if (sql.contains("SET NAMES utf8") && !sql.contains("utf8mb4")) { throw new SQLException("Character set statement issued: " + sql); } return null; }
@Override public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection conn) throws SQLException { if (sql.equals("SELECT 1")) { java.sql.Statement test = conn.createStatement(); return (ResultSetInternalMethods) test.executeQuery("/* execute this, not the original */ SELECT 1"); } return null; }