Debian Codegraph @

src/main/org/h2/mode/OnDuplicateKeyValues.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.mode;
7
8 import org.h2.command.dml.Update;
9 import org.h2.engine.SessionLocal;
10 import org.h2.expression.ExpressionVisitor;
11 import org.h2.expression.Operation0;
12 import org.h2.message.DbException;
13 import org.h2.table.Column;
14 import org.h2.value.TypeInfo;
15 import org.h2.value.Value;
16
17 /**
18 * VALUES(column) function for ON DUPLICATE KEY UPDATE clause.
19 */
20 public final class OnDuplicateKeyValues extends Operation0 {
21
22 private final Column column;
23
24 private final Update update;
25
26 public OnDuplicateKeyValues(Column column, Update update) {
27 this.column = column;
28 this.update = update;
29 }
30
31 @Override
32 public Value getValue(SessionLocal session) {
33 Value v = update.getOnDuplicateKeyInsert().getOnDuplicateKeyValue(column.getColumnId());
34 if (v == null) {
35 throw DbException.getUnsupportedException(getTraceSQL());
36 }
37 return v;
38 }
39
40 @Override
41 public StringBuilder getUnenclosedSQL(StringBuilder builder, int sqlFlags) {
42 return column.getSQL(builder.append("VALUES("), sqlFlags).append(')');
43 }
44
45 @Override
46 public boolean isEverything(ExpressionVisitor visitor) {
47 switch (visitor.getType()) {
48 case ExpressionVisitor.DETERMINISTIC:
49 return false;
50 }
51 return true;
52 }
53
54 @Override
55 public TypeInfo getType() {
56 return column.getType();
57 }
58
59 @Override
60 public int getCost() {
61 return 1;
62 }
63
64 }