return BuiltinOperators.ZERO_VAL;
}
long lv = param1.getAsLong();
- return BuiltinOperators.toValue(Long.toHexString(lv));
+ return BuiltinOperators.toValue(Long.toHexString(lv).toUpperCase());
}
});
}
});
- public static final Function LTRIM = registerFunc(new Func1NullIsNull("LTrim") {
+ public static final Function LTRIM = registerStringFunc(new Func1NullIsNull("LTrim") {
@Override
protected Value eval1(EvalContext ctx, Value param1) {
String str = param1.getAsString();
}
});
- public static final Function RTRIM = registerFunc(new Func1NullIsNull("RTrim") {
+ public static final Function RTRIM = registerStringFunc(new Func1NullIsNull("RTrim") {
@Override
protected Value eval1(EvalContext ctx, Value param1) {
String str = param1.getAsString();
}
});
- public static final Function TRIM = registerFunc(new Func1NullIsNull("Trim") {
+ public static final Function TRIM = registerStringFunc(new Func1NullIsNull("Trim") {
@Override
protected Value eval1(EvalContext ctx, Value param1) {
String str = param1.getAsString();
}
});
- public static final Function STRREVERSE = registerStringFunc(new Func1("StrReverse") {
+ public static final Function STRREVERSE = registerFunc(new Func1("StrReverse") {
@Override
protected Value eval1(EvalContext ctx, Value param1) {
String str = param1.getAsString();
case IS_COMP_FLAG:
- switch(exprType) {
- case DEFAULT_VALUE:
-
- // special case
- if((c == EQUALS_CHAR) && (buf.prevPos() == 0)) {
- // a leading equals sign indicates how a default value should be
- // evaluated
- tokens.add(new Token(TokenType.OP, String.valueOf(c)));
- continue;
- }
- // def values can't have cond at top level
- throw new IllegalArgumentException(
- exprType + " cannot have top-level conditional " + buf);
-
- case FIELD_VALIDATOR:
- case RECORD_VALIDATOR:
-
- tokens.add(new Token(TokenType.OP, parseCompOp(c, buf)));
- break;
+ // special case for default values
+ if((exprType == Type.DEFAULT_VALUE) && (c == EQUALS_CHAR) &&
+ (buf.prevPos() == 0)) {
+ // a leading equals sign indicates how a default value should be
+ // evaluated
+ tokens.add(new Token(TokenType.OP, String.valueOf(c)));
+ continue;
}
-
+
+ tokens.add(new Token(TokenType.OP, parseCompOp(c, buf)));
break;
case IS_DELIM_FLAG:
--- /dev/null
+/*
+Copyright (c) 2016 James Ahlborn
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package com.healthmarketscience.jackcess.impl.expr;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import com.healthmarketscience.jackcess.DatabaseBuilder;
+import com.healthmarketscience.jackcess.TestUtil;
+import com.healthmarketscience.jackcess.expr.EvalContext;
+import com.healthmarketscience.jackcess.expr.Expression;
+import com.healthmarketscience.jackcess.expr.Function;
+import com.healthmarketscience.jackcess.expr.TemporalConfig;
+import com.healthmarketscience.jackcess.expr.Value;
+import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.impl.expr.ExpressionatorTest.eval;
+
+/**
+ *
+ * @author James Ahlborn
+ */
+public class DefaultFunctionsTest extends TestCase
+{
+
+ public DefaultFunctionsTest(String name) {
+ super(name);
+ }
+
+ public void testFuncs() throws Exception
+ {
+ assertEquals("foo", eval("=IIf(10 > 1, \"foo\", \"bar\")"));
+ assertEquals("bar", eval("=IIf(10 < 1, \"foo\", \"bar\")"));
+ assertEquals(102L, eval("=Asc(\"foo\")"));
+ assertEquals(9786L, eval("=AscW(\"\u263A\")"));
+ assertEquals("f", eval("=Chr(102)"));
+ assertEquals("\u263A", eval("=ChrW(9786)"));
+ assertEquals("263A", eval("=Hex(9786)"));
+ }
+
+}
assertEquals(cleanStr, expr.toString());
}
- private static Object eval(String exprStr) {
+ static Object eval(String exprStr) {
Expression expr = Expressionator.parse(
Expressionator.Type.DEFAULT_VALUE, exprStr, new TestParseContext());
return expr.eval(new TestEvalContext(null));
}
public Function getExpressionFunction(String name) {
- return null;
+ return DefaultFunctions.getFunction(name);
}
}