Class SqlParserUtils

java.lang.Object
org.evomaster.client.java.sql.internal.SqlParserUtils

public class SqlParserUtils extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
     
    static net.sf.jsqlparser.statement.select.FromItem
    getFrom(net.sf.jsqlparser.statement.Statement parsedStatement)
    Extracts the "FROM" clause or the primary table involved in a SQL statement.
    static List<net.sf.jsqlparser.statement.select.FromItem>
    getFromAndJoinItems(net.sf.jsqlparser.statement.select.Select select)
    Retrieves the "FROM" and "JOIN" items from a given SQL SELECT statement.
    static List<net.sf.jsqlparser.statement.select.Join>
    getJoins(net.sf.jsqlparser.statement.Statement parsedStatement)
     
    static net.sf.jsqlparser.schema.Table
    getTable(net.sf.jsqlparser.statement.select.FromItem fromItem)
     
    static String
    getTableName(net.sf.jsqlparser.statement.select.FromItem fromItem)
    Retrieves the fully qualified name of a table from the provided FromItem.
    static net.sf.jsqlparser.expression.Expression
    getWhere(net.sf.jsqlparser.statement.Statement parsedStatement)
     
    static boolean
    isDelete(String sqlCommand)
     
    static boolean
    isInsert(String sqlCommand)
     
    static boolean
    isSelect(String sqlCommand)
    We only use the selects that refer to objects in the database that are meaningful for testing purposes, when code access to a sequence for example when getting the next id for a new object in the table, then we don't want to use that select as a target.
    static boolean
    isSelectOne(String sqlCommand)
    check if the sql is `Select 1` detected by proxyprint as ERROR - FAILED TO COMPUTE HEURISTICS FOR SQL: SELECT 1
    static boolean
    isTable(net.sf.jsqlparser.statement.select.FromItem fromItem)
    Checks if the given FromItem is a Table.
    static boolean
    isUnion(net.sf.jsqlparser.statement.Statement statement)
    Checks if the given Statement is a UNION statement.
    static boolean
    isUpdate(String sqlCommand)
     
    static net.sf.jsqlparser.statement.Statement
    parseSqlCommand(String sqlCommand)
    This method assumes that the SQL command can be successfully parsed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SqlParserUtils

      public SqlParserUtils()
  • Method Details

    • isSelect

      public static boolean isSelect(String sqlCommand)
      We only use the selects that refer to objects in the database that are meaningful for testing purposes, when code access to a sequence for example when getting the next id for a new object in the table, then we don't want to use that select as a target.
      Parameters:
      sqlCommand -
      Returns:
    • isDelete

      public static boolean isDelete(String sqlCommand)
    • isUpdate

      public static boolean isUpdate(String sqlCommand)
    • isInsert

      public static boolean isInsert(String sqlCommand)
    • isSelectOne

      public static boolean isSelectOne(String sqlCommand)
      check if the sql is `Select 1` detected by proxyprint as ERROR - FAILED TO COMPUTE HEURISTICS FOR SQL: SELECT 1

      https://stackoverflow.com/questions/3668506/efficient-sql-test-query-or-validation-query-that-will-work-across-all-or-most

    • getWhere

      public static net.sf.jsqlparser.expression.Expression getWhere(net.sf.jsqlparser.statement.Statement parsedStatement)
    • getFrom

      public static net.sf.jsqlparser.statement.select.FromItem getFrom(net.sf.jsqlparser.statement.Statement parsedStatement)
      Extracts the "FROM" clause or the primary table involved in a SQL statement. This method supports SELECT, DELETE, and UPDATE SQL statements.
      Parameters:
      parsedStatement - The parsed SQL statement as a Statement object. This is typically obtained using JSQLParser's `CCJSqlParserUtil.parse`.
      Returns:
      The FromItem representing the "FROM" clause or the main table for the statement. - For a SELECT statement, returns the main FromItem in the "FROM" clause. - For a DELETE statement, returns the table being deleted from. - For an UPDATE statement, returns the table being updated.
      Throws:
      IllegalArgumentException - If the provided statement type is not SELECT, DELETE, or UPDATE.
    • getJoins

      public static List<net.sf.jsqlparser.statement.select.Join> getJoins(net.sf.jsqlparser.statement.Statement parsedStatement)
    • parseSqlCommand

      public static net.sf.jsqlparser.statement.Statement parseSqlCommand(String sqlCommand)
      This method assumes that the SQL command can be successfully parsed.
      Parameters:
      sqlCommand - to be parsed
      Returns:
      the AST root node
    • canParseSqlStatement

      public static boolean canParseSqlStatement(String sqlCommand)
    • isTable

      public static boolean isTable(net.sf.jsqlparser.statement.select.FromItem fromItem)
      Checks if the given FromItem is a Table.
      Parameters:
      fromItem - the FromItem to check
      Returns:
      true if the FromItem is a Table, false otherwise
    • getTableName

      public static String getTableName(net.sf.jsqlparser.statement.select.FromItem fromItem)
      Retrieves the fully qualified name of a table from the provided FromItem.

      This method checks if the given fromItem is an instance of Table. If it is, the method extracts and returns the fully qualified name of the table. Otherwise, it throws an IllegalArgumentException.

      Parameters:
      fromItem - the FromItem instance to extract the table name from.
      Returns:
      the fully qualified name of the table as a String.
      Throws:
      IllegalArgumentException - if the provided fromItem is not an instance of Table.
      See Also:
      • Table.getFullyQualifiedName()
    • getTable

      public static net.sf.jsqlparser.schema.Table getTable(net.sf.jsqlparser.statement.select.FromItem fromItem)
    • isUnion

      public static boolean isUnion(net.sf.jsqlparser.statement.Statement statement)
      Checks if the given Statement is a UNION statement.
      Parameters:
      statement -
      Returns:
    • getFromAndJoinItems

      public static List<net.sf.jsqlparser.statement.select.FromItem> getFromAndJoinItems(net.sf.jsqlparser.statement.select.Select select)
      Retrieves the "FROM" and "JOIN" items from a given SQL SELECT statement.
      Parameters:
      select - the SQL SELECT statement
      Returns:
      a list of FromItem objects representing the "FROM" and "JOIN" items