Debian Codegraph @

src/main/org/h2/command/dml/ExecuteImmediate.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.command.dml;
7
8 import org.h2.api.ErrorCode;
9 import org.h2.command.CommandInterface;
10 import org.h2.command.Prepared;
11 import org.h2.engine.SessionLocal;
12 import org.h2.expression.Expression;
13 import org.h2.message.DbException;
14 import org.h2.result.ResultInterface;
15
16 /**
17 * This class represents the statement
18 * EXECUTE IMMEDIATE.
19 */
20 public class ExecuteImmediate extends Prepared {
21
22 private Expression statement;
23
24 public ExecuteImmediate(SessionLocal session, Expression statement) {
25 super(session);
26 this.statement = statement.optimize(session);
27 }
28
29 @Override
30 public long update() {
31 String sql = statement.getValue(session).getString();
32 if (sql == null) {
33 throw DbException.getInvalidValueException("SQL command", null);
34 }
35 Prepared command = session.prepare(sql);
36 if (command.isQuery()) {
37 throw DbException.get(ErrorCode.SYNTAX_ERROR_2, sql, "<not a query>");
38 }
39 return command.update();
40 }
41
42 @Override
43 public boolean isTransactional() {
44 return true;
45 }
46
47 @Override
48 public int getType() {
49 return CommandInterface.EXECUTE_IMMEDIATELY;
50 }
51
52 @Override
53 public ResultInterface queryMeta() {
54 return null;
55 }
56
57 }