Package com.impossibl.postgres.jdbc.SQLTextTree

Examples of com.impossibl.postgres.jdbc.SQLTextTree.Node


  private static Node processEscape(EscapeNode escape, Context context) throws SQLException {

    PieceNode type = getNodeNotOf(escape, 0, WhitespacePiece.class, PieceNode.class);

    Node result = null;

    switch(type.toString().toLowerCase()) {
      case "fn":
        result = processFunctionEscape(escape);
        break;
View Full Code Here


    escape.removeAll(WhitespacePiece.class, false);

    checkSize(escape, 2, 4);

    Node rows = getNode(escape, 1, Node.class);

    Node offset = null;
    if (escape.getNodeCount() == 4) {
      checkLiteralNode(escape, 2, "OFFSET");
      offset = getNode(escape, 3, Node.class);
    }

    Node limit = sequence("LIMIT", rows);

    if (offset != null) {
      limit = concat(limit, sequence(space(), "OFFSET", offset));
    }
View Full Code Here

  }

  private static <T extends Node> T getNode(CompositeNode comp, int idx, Class<T> nodeType) throws SQLException {

    Node node = comp.get(idx);
    if (!nodeType.isInstance(node))
      throw new SQLException("invalid escape (" + comp.getStartPos() + ")", "Syntax Error");

    return nodeType.cast(node);
  }
View Full Code Here

    return nodeType.cast(node);
  }

  private static <T extends Node, U extends Node> U getNodeNotOf(CompositeNode comp, int idx, Class<T> notNodeType, Class<U> nodeType) throws SQLException {

    Node node = null;

    while (idx < comp.getNodeCount()) {
      node = comp.get(idx);
      if (!notNodeType.isInstance(node))
        break;
View Full Code Here

    List<Node> comps = new ArrayList<>();

    Iterator<Node> nodeIter = nodes.iterator();
    while (nodeIter.hasNext()) {

      Node node = nodeIter.next();

      if (node instanceof PieceNode && matchList.contains(((PieceNode) node).getText().toUpperCase())) {

        current.trim();

        if (current.getNodeCount() > 0) {

          comps.add(current);
          current = new CompositeNode(node.getEndPos());

        }

        if (includeMatches) {
          comps.add(node);
View Full Code Here

    if (args.size() == 2) {
      return sequence("position",
          groupedSequence(args.get(0), "in", args.get(1)));
    }
    else if (args.size() == 3) {
      Node tmp = sequence("position",
          groupedSequence(args.get(0), "in", "substring", groupedSequence(args.get(1), "from", args.get(2))));
      return groupedSequence(args.get(2), grammar("*"), ident("sign"), groupedSequence(tmp), grammar("+"), tmp);
    }
    else {
      throw new SQLException(GT.tr("{0} function takes two or three arguments.", "locate"), PSQLState.SYNTAX_ERROR);
View Full Code Here

  /** time stamp add */
  public static Node sqltimestampadd(String name, List<Node> args) throws SQLException {
    if (args.size() != 3) {
      throw new SQLException(GT.tr("{0} function takes three and only three arguments.", "timestampadd"), PSQLState.SYNTAX_ERROR);
    }
    Node interval = constantToInterval(args.get(0).toString(), args.get(1));
    return groupedSequence(interval, grammar("+"), args.get(2));
  }
View Full Code Here

  /** time stamp diff */
  public static Node sqltimestampdiff(String name, List<Node> args) throws SQLException {
    if (args.size() != 3) {
      throw new SQLException(GT.tr("{0} function takes three and only three arguments.", "timestampdiff"), PSQLState.SYNTAX_ERROR);
    }
    Node datePart = constantToDatePart(args.get(0).toString());
    return sequence("extract", groupedSequence(datePart, "from", groupedSequence(args.get(2), grammar("-"), args.get(1))));
  }
View Full Code Here

    ListIterator<Object> argsIter = args.listIterator();
    while (argsIter.hasNext()) {

      Object obj = argsIter.next();

      Node lastNode = seqNode.getLastNode();
      if (!(lastNode instanceof WhitespacePiece) && !(obj instanceof WhitespacePiece) &&
          !(obj instanceof ParenGroupNode) &&
          (lastNode instanceof IdentifierPiece || obj instanceof IdentifierPiece || obj instanceof String)) {
        seqNode.add(new WhitespacePiece(" ", -1));
      }
View Full Code Here

TOP

Related Classes of com.impossibl.postgres.jdbc.SQLTextTree.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.