Search in sources :

Example 1 with IToken

use of org.eclipse.scout.rt.server.jdbc.parsers.token.IToken in project scout.rt by eclipse.

the class BindParser method parseBind.

private IToken parseBind() {
    if (LOG.isTraceEnabled()) {
        trace("parseBind");
    }
    IToken token = null;
    int index = m_pos.getIndex();
    if ((token = parsePlainValueBind()) != null || (token = parseFunctionBind()) != null || (token = parseDatabaseSpecificToken()) != null || (token = parseStdBind()) != null) {
        return token;
    } else {
        m_pos.setIndex(index);
        return null;
    }
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.token.IToken)

Example 2 with IToken

use of org.eclipse.scout.rt.server.jdbc.parsers.token.IToken in project scout.rt by eclipse.

the class BindParser method parseExtendedBind.

private IToken parseExtendedBind() {
    if (LOG.isTraceEnabled()) {
        trace("parseExtendedBind");
    }
    int index = m_pos.getIndex();
    String attribute = null;
    String op = null;
    IToken token = null;
    if ((attribute = parseAttribute()) == null || !parseWhitespace(0) || (op = parseOp()) == null || !parseWhitespace(0)) {
        m_pos.setIndex(index);
        attribute = null;
        op = null;
        if ((op = parseOp()) == null || !parseWhitespace(0)) {
            m_pos.setIndex(index);
        }
    }
    int indexAfterOp = m_pos.getIndex();
    if ((token = parseBind()) != null) {
        if (token instanceof ValueInputToken) {
            addTextTokenUntil(index);
            ((ValueInputToken) token).setParsedAttribute(attribute);
            ((ValueInputToken) token).setParsedOp(op);
        } else {
            addTextTokenUntil(indexAfterOp);
        }
        addToken(token, m_pos.getIndex());
        return token;
    } else {
        m_pos.setIndex(index);
        return null;
    }
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.token.IToken) ValueInputToken(org.eclipse.scout.rt.server.jdbc.parsers.token.ValueInputToken)

Example 3 with IToken

use of org.eclipse.scout.rt.server.jdbc.parsers.token.IToken in project scout.rt by eclipse.

the class BindParserTest method testInListAttribute.

/**
 * Column starts with "IN"
 */
@Test
public void testInListAttribute() {
    String sql = "SELECT INT_COLUMN_ID FROM TABLE1 WHERE INT_COLUMN_ID != :refId";
    BindModel bindModel = new BindParser(sql).parse();
    IToken[] tokens = bindModel.getIOTokens();
    ValueInputToken tok = (ValueInputToken) tokens[0];
    assertEquals("INT_COLUMN_ID", tok.getParsedAttribute());
    assertEquals("!=", tok.getParsedOp());
    assertEquals(":refId", tok.getParsedToken());
    assertEquals("refId", tok.getName());
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.token.IToken) ValueInputToken(org.eclipse.scout.rt.server.jdbc.parsers.token.ValueInputToken) Test(org.junit.Test)

Example 4 with IToken

use of org.eclipse.scout.rt.server.jdbc.parsers.token.IToken in project scout.rt by eclipse.

the class StatementProcessor method createPlainText.

/*
   * (non-Javadoc)
   * @seeorg.eclipse.scout.rt.server.services.common.sql.internal.exec.
   * IStatementProcessor#createPlainText()
   */
@Override
public String createPlainText() {
    for (IToken t : m_ioTokens) {
        if (t instanceof ValueInputToken) {
            ValueInputToken vt = (ValueInputToken) t;
            if (vt.isPlainSql()) {
            // ok
            } else if (vt.isPlainValue()) {
            // ok
            } else {
                vt.setPlainValue(true);
            }
        } else if (t instanceof FunctionInputToken) {
            FunctionInputToken ft = (FunctionInputToken) t;
            ft.setPlainValue(true);
        }
    }
    if (hasNextInputBatch()) {
        nextInputBatch();
        prepareInputStatementAndBinds();
        resetInputBatch();
    }
    return m_currentInputStm;
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.token.IToken) FunctionInputToken(org.eclipse.scout.rt.server.jdbc.parsers.token.FunctionInputToken) ValueInputToken(org.eclipse.scout.rt.server.jdbc.parsers.token.ValueInputToken)

Example 5 with IToken

use of org.eclipse.scout.rt.server.jdbc.parsers.token.IToken in project scout.rt by eclipse.

the class BindParser method parse.

public BindModel parse() {
    m_pos = new ParsePosition(0);
    parseStatement();
    addTextTokenUntil(m_str.length());
    if (m_pos.getIndex() < m_str.length()) {
        LOG.warn("statement not fully parsed (index {}): {}", m_pos.getIndex(), m_str);
    }
    return new BindModel(m_tokenList.toArray(new IToken[m_tokenList.size()]));
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.token.IToken) ParsePosition(java.text.ParsePosition)

Aggregations

IToken (org.eclipse.scout.rt.server.jdbc.parsers.token.IToken)7 ValueInputToken (org.eclipse.scout.rt.server.jdbc.parsers.token.ValueInputToken)5 Test (org.junit.Test)2 ParsePosition (java.text.ParsePosition)1 ArrayList (java.util.ArrayList)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 AbstractSqlService (org.eclipse.scout.rt.server.jdbc.AbstractSqlService)1 DatabaseSpecificToken (org.eclipse.scout.rt.server.jdbc.parsers.token.DatabaseSpecificToken)1 FunctionInputToken (org.eclipse.scout.rt.server.jdbc.parsers.token.FunctionInputToken)1 ValueOutputToken (org.eclipse.scout.rt.server.jdbc.parsers.token.ValueOutputToken)1