Debian Codegraph @

src/main/org/h2/expression/function/Function1_2.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.expression.function;
7
8 import org.h2.engine.SessionLocal;
9 import org.h2.expression.Expression;
10 import org.h2.expression.Operation1_2;
11 import org.h2.message.DbException;
12 import org.h2.value.Value;
13 import org.h2.value.ValueNull;
14
15 /**
16 * Function with two arguments.
17 */
18 public abstract class Function1_2 extends Operation1_2 implements NamedExpression {
19
20 protected Function1_2(Expression left, Expression right) {
21 super(left, right);
22 }
23
24 @Override
25 public Value getValue(SessionLocal session) {
26 Value v1 = left.getValue(session);
27 if (v1 == ValueNull.INSTANCE) {
28 return ValueNull.INSTANCE;
29 }
30 Value v2;
31 if (right != null) {
32 v2 = right.getValue(session);
33 if (v2 == ValueNull.INSTANCE) {
34 return ValueNull.INSTANCE;
35 }
36 } else {
37 v2 = null;
38 }
39 return getValue(session, v1, v2);
40 }
41
42 /**
43 * Returns the value of this function.
44 *
45 * @param session
46 * the session
47 * @param v1
48 * the value of first argument
49 * @param v2
50 * the value of second argument, or {@code null}
51 * @return the resulting value
52 */
53 protected Value getValue(SessionLocal session, Value v1, Value v2) {
54 throw DbException.getInternalError();
55 }
56
57 @Override
58 public StringBuilder getUnenclosedSQL(StringBuilder builder, int sqlFlags) {
59 left.getUnenclosedSQL(builder.append(getName()).append('('), sqlFlags);
60 if (right != null) {
61 right.getUnenclosedSQL(builder.append(", "), sqlFlags);
62 }
63 return builder.append(')');
64 }
65
66 }