use of org.eclipse.scout.rt.server.jdbc.parsers.token.ValueInputToken in project scout.rt by eclipse.
the class StatementProcessorTest method exec.
private String[] exec(final boolean checkForDuplicateBinds, final String statement, final Object... binds) {
final Collection<String> duplicates = new ArrayList<>();
final AbstractSqlService sqlService = new AbstractSqlService() {
};
new StatementProcessor(sqlService, statement, binds) {
@Override
protected boolean isBindDuplicateCheckEnabled() {
return checkForDuplicateBinds;
}
@Override
protected void onDuplicateBind(IToken token) {
if (token instanceof ValueInputToken) {
duplicates.add(((ValueInputToken) token).getName());
} else if (token instanceof ValueOutputToken) {
duplicates.add(((ValueOutputToken) token).getName());
} else {
throw new ProcessingException("Unexpected token: {}", token);
}
}
}.simulate();
return duplicates.toArray(new String[duplicates.size()]);
}
use of org.eclipse.scout.rt.server.jdbc.parsers.token.ValueInputToken in project scout.rt by eclipse.
the class SqlFunctionReplaceTest method testFunctionReplacement.
/**
* sql functions in sql style
*/
@Test
public void testFunctionReplacement() {
String sql = "SELECT $$sysdate FROM DUAL";
BindModel bindModel = new BindParser(sql).parse();
IToken[] tokens = bindModel.getAllTokens();
int dbSpecTokenFound = 0;
for (IToken token : tokens) {
if (token instanceof DatabaseSpecificToken) {
assertEquals("sysdate", ((DatabaseSpecificToken) token).getName());
dbSpecTokenFound++;
}
}
assertTrue("no DatabaseSpecificToken found", dbSpecTokenFound > 0);
sql = "SELECT $$sysdate FROM TABLE1 WHERE COLUMN1 != $$nvl(:val1,0)";
bindModel = new BindParser(sql).parse();
tokens = bindModel.getAllTokens();
dbSpecTokenFound = 0;
int dbSpecTokenCount = 0;
for (IToken token : tokens) {
if (token instanceof DatabaseSpecificToken) {
if (dbSpecTokenCount == 0) {
assertEquals("sysdate", ((DatabaseSpecificToken) token).getName());
}
if (dbSpecTokenCount == 1) {
assertEquals("nvl", ((DatabaseSpecificToken) token).getName());
}
dbSpecTokenCount++;
dbSpecTokenFound++;
}
}
assertTrue("no DatabaseSpecificToken found", dbSpecTokenFound > 0);
sql = "SELECT A, B, C " + "FROM TABLE1 " + "WHERE COLUMN1 != $$nvl(:val1,0) " + "INTO :{a}, :{b}, {c} ";
bindModel = new BindParser(sql).parse();
tokens = bindModel.getAllTokens();
dbSpecTokenFound = 0;
int valueInputCount = 0;
for (IToken token : tokens) {
if (token instanceof DatabaseSpecificToken) {
assertEquals("nvl", ((DatabaseSpecificToken) token).getName());
dbSpecTokenFound++;
}
if (token instanceof ValueInputToken) {
if (valueInputCount == 0) {
assertEquals("val1", ((ValueInputToken) token).getName());
}
if (valueInputCount == 1) {
assertEquals("a", ((ValueInputToken) token).getName());
}
if (valueInputCount == 2) {
assertEquals("b", ((ValueInputToken) token).getName());
}
if (valueInputCount == 3) {
assertEquals("c", ((ValueInputToken) token).getName());
}
valueInputCount++;
}
}
assertTrue("no DatabaseSpecificToken found", dbSpecTokenFound > 0);
sql = "INSERT INTO TABLE1 (A, B, C) " + "VALUES (:{a}, :{b}, :{c}) ";
bindModel = new BindParser(sql).parse();
tokens = bindModel.getAllTokens();
valueInputCount = 0;
for (IToken token : tokens) {
if (token instanceof ValueInputToken) {
if (valueInputCount == 0) {
assertEquals("a", ((ValueInputToken) token).getName());
}
if (valueInputCount == 1) {
assertEquals("b", ((ValueInputToken) token).getName());
}
if (valueInputCount == 2) {
assertEquals("c", ((ValueInputToken) token).getName());
}
valueInputCount++;
}
}
}
Aggregations