|
16 | 16 | import net.sf.jsqlparser.statement.select.Limit; |
17 | 17 | import net.sf.jsqlparser.statement.select.OrderByElement; |
18 | 18 |
|
| 19 | +import java.util.ArrayList; |
19 | 20 | import java.util.Arrays; |
20 | 21 | import java.util.Collections; |
21 | 22 | import java.util.List; |
@@ -192,6 +193,58 @@ public void setParameters(ExpressionList<?> list) { |
192 | 193 | parameters = list; |
193 | 194 | } |
194 | 195 |
|
| 196 | + /** |
| 197 | + * Returns the parameter expression at the given index without any attached clause wrapper. |
| 198 | + * Returns {@code null} if there are no parameters. |
| 199 | + */ |
| 200 | + public Expression getParameterExpression(int parameterIndex) { |
| 201 | + if (parameters == null) { |
| 202 | + return null; |
| 203 | + } |
| 204 | + |
| 205 | + Expression parameter = parameters.get(parameterIndex); |
| 206 | + if (parameter instanceof FunctionParameterClauseExpression) { |
| 207 | + return ((FunctionParameterClauseExpression) parameter).getExpression(); |
| 208 | + } |
| 209 | + return parameter; |
| 210 | + } |
| 211 | + |
| 212 | + /** |
| 213 | + * Returns the trailing clause attached to a parameter, e.g. {@code ERROR ON ERROR}, or |
| 214 | + * {@code null} when no clause is attached. |
| 215 | + */ |
| 216 | + public String getParameterTrailingClause(int parameterIndex) { |
| 217 | + if (parameters == null) { |
| 218 | + return null; |
| 219 | + } |
| 220 | + |
| 221 | + Object parameter = parameters.get(parameterIndex); |
| 222 | + if (parameter instanceof FunctionParameterClauseExpression) { |
| 223 | + return ((FunctionParameterClauseExpression) parameter).getClause(); |
| 224 | + } |
| 225 | + return null; |
| 226 | + } |
| 227 | + |
| 228 | + /** |
| 229 | + * Returns one entry per parameter with the attached trailing clause at that index, or |
| 230 | + * {@code null} when no clause is attached to that parameter. |
| 231 | + */ |
| 232 | + public List<String> getParameterTrailingClauses() { |
| 233 | + if (parameters == null) { |
| 234 | + return Collections.emptyList(); |
| 235 | + } |
| 236 | + |
| 237 | + List<String> clauses = new ArrayList<>(parameters.size()); |
| 238 | + for (Object parameter : parameters) { |
| 239 | + if (parameter instanceof FunctionParameterClauseExpression) { |
| 240 | + clauses.add(((FunctionParameterClauseExpression) parameter).getClause()); |
| 241 | + } else { |
| 242 | + clauses.add(null); |
| 243 | + } |
| 244 | + } |
| 245 | + return clauses; |
| 246 | + } |
| 247 | + |
195 | 248 | /** |
196 | 249 | * the parameters might be named parameters, e.g. substring('foobar' from 2 for 3) |
197 | 250 | * |
|
0 commit comments