Class SqlParserUtils
java.lang.Object
org.evomaster.client.java.sql.internal.SqlParserUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanParseSqlStatement(String sqlCommand) static net.sf.jsqlparser.statement.select.FromItemgetFrom(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.TablegetTable(net.sf.jsqlparser.statement.select.FromItem fromItem) static StringgetTableName(net.sf.jsqlparser.statement.select.FromItem fromItem) Retrieves the fully qualified name of a table from the providedFromItem.static net.sf.jsqlparser.expression.ExpressiongetWhere(net.sf.jsqlparser.statement.Statement parsedStatement) static booleanstatic booleanstatic booleanWe 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 booleanisSelectOne(String sqlCommand) check if the sql is `Select 1` detected by proxyprint as ERROR - FAILED TO COMPUTE HEURISTICS FOR SQL: SELECT 1static booleanisTable(net.sf.jsqlparser.statement.select.FromItem fromItem) Checks if the given FromItem is a Table.static booleanisUnion(net.sf.jsqlparser.statement.Statement statement) Checks if the givenStatementis a UNION statement.static booleanstatic net.sf.jsqlparser.statement.StatementparseSqlCommand(String sqlCommand) This method assumes that the SQL command can be successfully parsed.
-
Constructor Details
-
SqlParserUtils
public SqlParserUtils()
-
-
Method Details
-
isSelect
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
-
isUpdate
-
isInsert
-
isSelectOne
check if the sql is `Select 1` detected by proxyprint as ERROR - FAILED TO COMPUTE HEURISTICS FOR SQL: SELECT 1https://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 aStatementobject. This is typically obtained using JSQLParser's `CCJSqlParserUtil.parse`.- Returns:
- The
FromItemrepresenting the "FROM" clause or the main table for the statement. - For a SELECT statement, returns the mainFromItemin 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
This method assumes that the SQL command can be successfully parsed.- Parameters:
sqlCommand- to be parsed- Returns:
- the AST root node
-
canParseSqlStatement
-
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
Retrieves the fully qualified name of a table from the providedFromItem.This method checks if the given
fromItemis an instance ofTable. If it is, the method extracts and returns the fully qualified name of the table. Otherwise, it throws anIllegalArgumentException.- Parameters:
fromItem- theFromIteminstance to extract the table name from.- Returns:
- the fully qualified name of the table as a
String. - Throws:
IllegalArgumentException- if the providedfromItemis not an instance ofTable.- 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 givenStatementis 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
-