|
12 | 12 | import static java.util.Collections.singletonMap;
|
13 | 13 | import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
14 | 14 | import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
| 15 | +import static net.bytebuddy.implementation.bytecode.assign.Assigner.Typing.DYNAMIC; |
15 | 16 |
|
16 | 17 | import com.google.auto.service.AutoService;
|
17 | 18 | import datadog.appsec.api.blocking.BlockingException;
|
@@ -75,6 +76,7 @@ public static class StatementAdvice {
|
75 | 76 | @Advice.OnMethodEnter(suppress = Throwable.class)
|
76 | 77 | public static AgentScope onEnter(
|
77 | 78 | @Advice.Argument(value = 0, readOnly = false) String sql,
|
| 79 | + @Advice.AllArguments(typing = DYNAMIC) Object[] args, |
78 | 80 | @Advice.This final Statement statement) {
|
79 | 81 | // TODO consider matching known non-wrapper implementations to avoid this check
|
80 | 82 | final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(Statement.class);
|
@@ -127,6 +129,18 @@ public static AgentScope onEnter(
|
127 | 129 | // context_info and v$session.action respectively.
|
128 | 130 | // we should not also inject it into SQL comments to avoid duplication
|
129 | 131 | final boolean injectTraceInComment = injectTraceContext && !isSqlServer && !isOracle;
|
| 132 | + |
| 133 | + boolean appendComment = StatementInstrumentation.appendComment; |
| 134 | + |
| 135 | + // There is a bug in the SQL Server JDBC driver that prevents |
| 136 | + // the generated keys from being returned when the |
| 137 | + // SQL comment is prepended to the SQL query. |
| 138 | + // We only append in this case to avoid the comment from being truncated. |
| 139 | + // @see https://github.com/microsoft/mssql-jdbc/issues/2729 |
| 140 | + if (isSqlServer && args.length == 2 && args[1] instanceof Integer && (Integer) args[1] == Statement.RETURN_GENERATED_KEYS) { |
| 141 | + appendComment = true; |
| 142 | + } |
| 143 | + |
130 | 144 | sql =
|
131 | 145 | SQLCommenter.inject(
|
132 | 146 | sql,
|
|
0 commit comments