| 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.Operation2; |
| 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 Function2 extends Operation2 implements NamedExpression { |
| 19 |
|
| 20 |
protected Function2(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 = right.getValue(session); |
| 31 |
if (v2 == ValueNull.INSTANCE) { |
| 32 |
return ValueNull.INSTANCE; |
| 33 |
} |
| 34 |
return getValue(session, v1, v2); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Returns the value of this function. |
| 39 |
* |
| 40 |
* @param session |
| 41 |
* the session |
| 42 |
* @param v1 |
| 43 |
* the value of first argument |
| 44 |
* @param v2 |
| 45 |
* the value of second argument |
| 46 |
* @return the resulting value |
| 47 |
*/ |
| 48 |
protected Value getValue(SessionLocal session, Value v1, Value v2) { |
| 49 |
throw DbException.getInternalError(); |
| 50 |
} |
| 51 |
|
| 52 |
@Override |
| 53 |
public StringBuilder getUnenclosedSQL(StringBuilder builder, int sqlFlags) { |
| 54 |
left.getUnenclosedSQL(builder.append(getName()).append('('), sqlFlags).append(", "); |
| 55 |
return right.getUnenclosedSQL(builder, sqlFlags).append(')'); |
| 56 |
} |
| 57 |
|
| 58 |
} |