public class SqlParserUtils extends Object
| Constructor and Description |
|---|
SqlParserUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
canParseSqlStatement(String sqlCommand) |
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.
|
public static boolean isSelect(String sqlCommand)
sqlCommand - public static boolean isDelete(String sqlCommand)
public static boolean isUpdate(String sqlCommand)
public static boolean isInsert(String sqlCommand)
public static boolean isSelectOne(String sqlCommand)
https://stackoverflow.com/questions/3668506/efficient-sql-test-query-or-validation-query-that-will-work-across-all-or-most
public static net.sf.jsqlparser.expression.Expression getWhere(net.sf.jsqlparser.statement.Statement parsedStatement)
public static net.sf.jsqlparser.statement.select.FromItem getFrom(net.sf.jsqlparser.statement.Statement parsedStatement)
parsedStatement - The parsed SQL statement as a Statement object.
This is typically obtained using JSQLParser's `CCJSqlParserUtil.parse`.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.IllegalArgumentException - If the provided statement type is not SELECT, DELETE, or UPDATE.public static List<net.sf.jsqlparser.statement.select.Join> getJoins(net.sf.jsqlparser.statement.Statement parsedStatement)
public static net.sf.jsqlparser.statement.Statement parseSqlCommand(String sqlCommand)
sqlCommand - to be parsedpublic static boolean canParseSqlStatement(String sqlCommand)
public static boolean isTable(net.sf.jsqlparser.statement.select.FromItem fromItem)
fromItem - the FromItem to checkpublic static String getTableName(net.sf.jsqlparser.statement.select.FromItem fromItem)
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.
fromItem - the FromItem instance to extract the table name from.String.IllegalArgumentException - if the provided fromItem is not an instance of Table.Table.getFullyQualifiedName()public static net.sf.jsqlparser.schema.Table getTable(net.sf.jsqlparser.statement.select.FromItem fromItem)
public static boolean isUnion(net.sf.jsqlparser.statement.Statement statement)
Statement is a UNION statement.statement - public static List<net.sf.jsqlparser.statement.select.FromItem> getFromAndJoinItems(net.sf.jsqlparser.statement.select.Select select)
select - the SQL SELECT statementCopyright © 2016–2025. All rights reserved.