How to use asStatement method of org.evomaster.client.java.controller.internal.db.ParserUtils class

Best EvoMaster code snippet using org.evomaster.client.java.controller.internal.db.ParserUtils.asStatement

Source:ColumnTableAnalyzer.java Github

copy

Full Screen

...17 if(! ParserUtils.isDelete(delete)){18 throw new IllegalArgumentException("Input string is not a valid SQL DELETE: " + delete);19 }20 Set<String> set = new HashSet<>();21 Delete stmt = (Delete) ParserUtils.asStatement(delete);22 Table table = stmt.getTable();23 if(table != null){24 set.add(table.getName());25 } else {26 //TODO need to handle special cases of multi-tables with JOINs27 throw new IllegalArgumentException("Cannot handle delete: " + delete);28 }29 return set;30 }31 public static Map<String, Set<String>> getInsertedDataFields(String insert){32 if(! ParserUtils.isInsert(insert)){33 throw new IllegalArgumentException("Input string is not a valid SQL INSERT: " + insert);34 }35 Map<String, Set<String>> map = new HashMap<>();36 Insert stmt = (Insert) ParserUtils.asStatement(insert);37 Table table = stmt.getTable();38 if(table != null){39 handleTable(map, table);40 } else {41 //TODO all other cases42 throw new IllegalArgumentException("Cannot handle insert: " + insert);43 }44 return map;45 }46 public static Map<String, Set<String>> getUpdatedDataFields(String update){47 if(! ParserUtils.isUpdate(update)){48 throw new IllegalArgumentException("Input string is not a valid SQL INSERT: " + update);49 }50 Map<String, Set<String>> map = new HashMap<>();51 Update stmt = (Update) ParserUtils.asStatement(update);52 List<Table> tables = stmt.getTables();53 if(tables!=null && !tables.isEmpty()){54 for(Table t: tables){55 handleTable(map, t);56 }57 } else {58 //TODO all other cases59 throw new IllegalArgumentException("Cannot handle update: " + update);60 }61 return map;62 }63 /**64 * Given a SELECT, check what it returns is based on (columns and tables).65 * Something like "select x from Foo" would give info on "Foo-&gt;{x}".66 * However, at times, what is returned is not directly the content of a column, but67 * rather some computations on it.68 * For example, in "select avg(x) from Foo", we would still be just interested in69 * the info that the data in "Foo-&gt;{x}" was used to compute the result.70 *71 * @param select SQL select command72 * @return a map from table_names to column_names73 */74 public static Map<String, Set<String>> getSelectReadDataFields(String select){75 if(! ParserUtils.isSelect(select)){76 throw new IllegalArgumentException("Input string is not a valid SQL SELECT: " + select);77 }78 Map<String, Set<String>> map = new HashMap<>();79 /*80 TODO: for now, we just use * for all read Tables.81 But, we should look at actual read columns.82 */83 Select stmt = (Select) ParserUtils.asStatement(select);84 SelectBody selectBody = stmt.getSelectBody();85 if (selectBody instanceof PlainSelect) {86 PlainSelect plainSelect = (PlainSelect) selectBody;87 FromItem fromItem = plainSelect.getFromItem();88 if(fromItem == null){89 //is this even possible? ie, a SELECT without FROM90 return map;91 }92 extractUsedColumnsAndTables(map, fromItem);93 List<Join> joins = plainSelect.getJoins();94 if(joins != null) {95 for (Join join : joins) {96 FromItem rightItem = join.getRightItem();97 extractUsedColumnsAndTables(map, rightItem);...

Full Screen

Full Screen

asStatement

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto2import org.evomaster.client.java.controller.api.dto.database.operations.InsertionDto3import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto4import org.evomaster.client.java.controller.api.dto.database.operations.UpdateDto5import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType6import org.evomaster.client.java.controller.api.dto.database.schema.TableDto7import org.evomaster.client.java.controller.internal.db.SqlInsertBuilder8import org.evomaster.client.java.controller.internal.db.SqlScriptRunner9import org.evomaster.client.java.controller.internal.db.SqlUpdateBuilder10import org.evomaster.client.java.controller.internal.db.TableRow11import org.evomaster.client.java.controller.internal.db.parser.ParserUtils12import org.evomaster.client.java.controller.internal.db.parser.SqlParser13import org.evomaster.client.java.controller.internal.db.parser.TableParser14import org.evomaster.client.java.controller.internal.db.parser.TableRowParser15import org.slf4j.Logger16import org.slf4j.LoggerFactory17class SqlScriptExecutor {18 companion object {19 private val log: Logger = LoggerFactory.getLogger(SqlScriptExecutor::class.java)20 }21 fun executeSqlScript(script: SqlScriptDto, dbType: DatabaseType, dbName: String): Boolean {22 if (sql == null && table == null) {23 throw IllegalArgumentException("SQL script or table info must be supplied")24 }25 if (sql != null) {26 return executeSql(sql, dbType, dbName)27 }28 return executeTable(table!!, dbType, dbName)29 }30 private fun executeSql(sql: String, dbType: DatabaseType, dbName: String): Boolean {31 val statements = ParserUtils.asStatements(sql)32 return SqlScriptRunner().run(statements, dbType, dbName)33 }34 private fun executeTable(table: TableDto, dbType: DatabaseType, dbName: String): Boolean {35 val rows = TableParser().parse(table)36 val insert = SqlInsertBuilder()37 .setTable(tableName)38 .setRows(rows)39 .build()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run EvoMaster automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful