How to use visit method of org.evomaster.client.java.controller.internal.db.SqlNameContext class

Best EvoMaster code snippet using org.evomaster.client.java.controller.internal.db.SqlNameContext.visit

Source:SqlHandler.java Github

copy

Full Screen

...235 SqlNameContext context = new SqlNameContext(statement);236 if(schema != null) {237 context.setSchema(schema);238 }239 ExpressionVisitor visitor = new ExpressionVisitorAdapter() {240 @Override241 public void visit(Column column) {242 String tn = context.getTableName(column);243 if(tn.equalsIgnoreCase(SqlNameContext.UNNAMED_TABLE)){244 // TODO handle it properly when ll have support for sub-selects245 return;246 }247 String cn = column.getColumnName().toLowerCase();248 if(! context.hasColumn(tn, cn)) {249 /*250 This is an issue with the JsqlParser library. Until we upgrade it, or fix it if not fixed yet,251 we use this workaround.252 The problem is that some SQL databases do not have support for boolean types, so parser can253 interpret constants like TRUE as column names.254 And all databases have differences on how booleans are treated, eg.255 - H2: TRUE, FALSE, and UNKNOWN (NULL).256 http://www.h2database.com/html/datatypes.html#boolean_type257 - Postgres: true, yes, on, 1, false, no, off, 0 (as well as abbreviations like t and f)258 https://www.postgresql.org/docs/9.5/datatype-boolean.html259 */260 if (booleanConstantNames.contains(cn)) {261 //case in which a boolean constant is wrongly treated as a column name.262 //TODO not sure what we can really do here without modifying the parser263 } else {264 SimpleLogger.warn("Cannot find column '" + cn +"' in table '" + tn +"'");265 }266 return;267 }268 data.putIfAbsent(tn, new HashSet<>());269 Set<String> set = data.get(tn);270 set.add(cn);271 }272 };273 where.accept(visitor);274 return data;275 }276 private static void mergeNewData(277 Map<String, Set<String>> current,278 Map<String, Set<String>> toAdd279 ) {280 for (Map.Entry<String, Set<String>> e : toAdd.entrySet()) {281 String key = e.getKey();282 Set<String> values = e.getValue();283 Set<String> existing = current.get(key);284 if (existing != null && existing.contains("*")) {285 //nothing to do286 continue;287 }...

Full Screen

Full Screen

Source:SqlNameContext.java Github

copy

Full Screen

...86 }87 private List<String> getTableNamesInFrom() {88 FromItem fromItem = getFromItem();89 List<String> names = new ArrayList<>();90 FromItemVisitorAdapter visitor = new FromItemVisitorAdapter(){91 @Override92 public void visit(Table table) {93 names.add(table.getName());94 }95 };96 fromItem.accept(visitor);97 return names;98 }99 private FromItem getFromItem() {100 FromItem fromItem = null;101 if(statement instanceof Select) {102 SelectBody selectBody = ((Select) statement).getSelectBody();103 if (selectBody instanceof PlainSelect) {104 PlainSelect plainSelect = (PlainSelect) selectBody;105 fromItem = plainSelect.getFromItem();106 } else {107 throw new IllegalArgumentException("Currently only handling Plain SELECTs");108 }109 }110 if(fromItem == null)111 throw new IllegalArgumentException("Cannot handle FromItem for: " + statement);112 return fromItem;113 }114 private void computeAliases() {115 if (statement instanceof Select) {116 FromItem fromItem = getFromItem();117 fromItem.accept(new AliasVisitor(tableAliases));118 SelectBody selectBody = ((Select) statement).getSelectBody();119 PlainSelect plainSelect = (PlainSelect) selectBody;120 List<Join> joins = plainSelect.getJoins();121 if (joins != null) {122 joins.forEach(j -> j.getRightItem().accept(new AliasVisitor(tableAliases)));123 }124 } else if(statement instanceof Delete){125 //no alias required?126 return;127 } else if(statement instanceof Update){128 /*129 TODO can update have aliases?130 https://www.h2database.com/html/commands.html#update131 */132 return;133 }134 }135 private static class AliasVisitor extends FromItemVisitorAdapter {136 private final Map<String, String> aliases;137 private AliasVisitor(Map<String, String> aliases) {138 this.aliases = aliases;139 }140 @Override141 public void visit(Table table) {142 handleAlias(aliases, table);143 }144 @Override145 public void visit(SubSelect subSelect) {146 handleAlias(aliases, subSelect);147 }148 }149 private static void handleAlias(Map<String, String> aliases, SubSelect subSelect) {150 Alias alias = subSelect.getAlias();151 if (alias != null) {152 String aliasName = alias.getName();153 if (aliasName != null) {154 /*155 FIXME: need to generalize,156 ie for when there can be several un-named sub-selects referring157 to columns with same names158 */159 String tableName = UNNAMED_TABLE;...

Full Screen

Full Screen

visit

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.internal.db.SqlNameContext;2import org.evomaster.client.java.controller.internal.db.SqlScriptRunner;3import org.evomaster.client.java.controller.internal.db.SqlScriptRunnerImpl;4import org.evomaster.client.java.controller.internal.db.SqlScriptWriter;5import org.evomaster.client.java.controller.internal.db.SqlScriptWriterImpl;6import org.evomaster.client.java.controller.internal.db.SqlTable;7import org.evomaster.client.java.controller.internal.db.SqlTableVisitor;8import org.evomaster.client.java.controller.internal.db.SqlTableVisitorImpl;9import org.evomaster.client.java.controller.internal.db.h2.H2SqlScriptRunner;10import org.evomaster.client.java.controller.internal.db.h2.H2SqlScriptWriter;11import org.evomaster.client.java.controller.internal.db.h2.H2TableVisitor;12import org.evomaster.client.java.controller.internal.db.h2.H2TableVisitorImpl;13import org.evomaster.client.java.controller.internal.db.h2.H2UrlBuilder;14import org.evomaster.client.java.controller.internal.db.schema.SqlSchema;15import org.evomaster.client.java.controller.internal.db.schema.SqlSchemaExtractor;16import org.evomaster.client.java.controller.internal.db.schema.SqlSchemaExtractorImpl;17import org.evomaster.client.java.controller.internal.db.schema.SqlSchemaInfo;18import org.evomaster.client.java.controller.internal.db.sql.SqlInsertionBuilder;19import org.evomaster.client.java.controller.internal.db.sql.SqlInsertionBuilderImpl;20import org.evomaster.client.java.controller.internal.db.sql.SqlInsertionDto;21import org.evomaster.client.java.controller.internal.db.sql.SqlInsertionDtoVisitor;22import org.evomaster.client.java.controller.internal.db.sql.SqlInsertionDtoVisitorImpl;23import org.evomaster.client.java.controller.internal.db.sql.SqlInsertionWriter;24import org.evomaster.client.java.controller.internal.db.sql.SqlInsertionWriterImpl;25import org.evomaster.client.java.controller.internal.db.sql.SqlTableBuilder;26import org.evomaster.client.java.controller.internal.db.sql.SqlTableBuilderImpl;27import org.evomaster.client.java.controller.internal.db.sql.SqlTableDto;28import org.evomaster.client.java.controller.internal.db.sql.SqlTableDtoVisitor;29import org.evomaster.client.java.controller.internal.db.sql.SqlTableDtoVisitorImpl;30import org.evomaster.client.java.controller.internal.db.sql.SqlTableWriter;31import org.evomaster.client.java.controller.internal.db.sql.SqlTableWriterImpl;32import org.evomaster.client.java.controller.internal

Full Screen

Full Screen

visit

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.internal.db.SqlNameContext;2public class 3 {3 public static void main(String[] args) {4 SqlNameContext sqlNameContext = new SqlNameContext();5 sqlNameContext.visit("test");6 }7}8import org.evomaster.client.java.controller.internal.db.SqlNameContext;9public class 4 {10 public static void main(String[] args) {11 SqlNameContext sqlNameContext = new SqlNameContext();12 sqlNameContext.visit("test");13 }14}15import org.evomaster.client.java.controller.internal.db.SqlNameContext;16public class 5 {17 public static void main(String[] args) {18 SqlNameContext sqlNameContext = new SqlNameContext();19 sqlNameContext.visit("test");20 }21}22import org.evomaster.client.java.controller.internal.db.SqlNameContext;23public class 6 {24 public static void main(String[] args) {25 SqlNameContext sqlNameContext = new SqlNameContext();26 sqlNameContext.visit("test");27 }28}29import org.evomaster.client.java.controller.internal.db.SqlNameContext;30public class 7 {31 public static void main(String[] args) {32 SqlNameContext sqlNameContext = new SqlNameContext();33 sqlNameContext.visit("test");34 }35}36import org.evomaster.client.java.controller.internal.db.SqlNameContext;37public class 8 {38 public static void main(String[] args) {39 SqlNameContext sqlNameContext = new SqlNameContext();40 sqlNameContext.visit("test");41 }42}43import org.evomaster.client.java.controller.internal.db.SqlName

Full Screen

Full Screen

visit

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.internal.db;2import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;3import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptEntryDto;4import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;5import org.evomaster.client.java.controller.api.dto.database.schema.TableDto;6import org.evomaster.client.java.controller.api.dto.database.schema.TableIndexDto;7import org.evomaster.client.java.controller.api.dto.database.schema.TableIndexType;8import org.evomaster.client.java.controller.api.dto.database.schema.TableType;9import org.evomaster.client.java.controller.api.dto.database.schema.ViewDto;10import org.evomaster.client.java.controller.internal.db.constraint.Constraint;11import org.evomaster.client.java.controller.internal.db.constraint.ForeignKeyConstraint;12import org.evomaster.client.java.controller.internal.db.constraint.PrimaryKeyConstraint;13import org.evomaster.client.java.controller.internal.db.schema.Column;14import org.evomaster.client.java.controller.internal.db.schema.ForeignKey;15import org.evomaster.client.java.controller.internal.db.schema.Index;16import org.evomaster.client.java.controller.internal.db.schema.Table;17import org.evomaster.client.java.controller.internal.db.schema.View;18import org.evomaster.client.java.controller.internal.db.table.TableRow;19import org.evomaster.client.java.controller.internal.db.table.TableRowColumn;20import org.evomaster.client.java.controller.internal.db.table.TableRowIndex;21import java.util.ArrayList;22import java.util.List;23import java.util.Map;24import java.util.Set;25import java.util.stream.Collectors;26public class SqlScriptDtoGenerator {27 public static SqlScriptDto generateSqlScriptDto(String databaseName, String schemaName, DatabaseType databaseType,28 Set<TableRow> tableRows) {29 SqlScriptDto dto = new SqlScriptDto();30 dto.databaseName = databaseName;31 dto.schemaName = schemaName;32 dto.databaseType = databaseType;33 dto.tables = tables.stream().map(SqlScriptDtoGenerator::generateTableDto).collect(Collectors.toList());34 dto.constraints = constraints.stream().map(SqlScriptDtoGenerator::generateConstraintDto).collect(Collectors.toList());35 dto.foreignKeys = foreignKeys.stream().map(SqlScriptDtoGenerator::generateForeignKeyDto).collect(Collectors.toList());36 dto.indexes = indexes.stream().map(SqlScriptDtoGenerator::

Full Screen

Full Screen

visit

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.internal.db.SqlNameContext;2import org.evomaster.client.java.controller.internal.db.Table;3public class Main {4 public static void main(String[] args) {5 SqlNameContext context = new SqlNameContext();6 Table table = new Table();7 table.setName("table1");8 context.visit(table);9 }10}11import org.evomaster.client.java.controller.internal.db.SqlNameContext;12import org.evomaster.client.java.controller.internal.db.TableColumn;13public class Main {14 public static void main(String[] args) {15 SqlNameContext context = new SqlNameContext();16 TableColumn column = new TableColumn();17 column.setName("column1");18 context.visit(column);19 }20}21import org.evomaster.client.java.controller.internal.db.SqlNameContext;22import org.evomaster.client.java.controller.internal.db.Table;23public class Main {24 public static void main(String[] args) {25 SqlNameContext context = new SqlNameContext();26 Table table = new Table();27 table.setName("table1");28 context.visit(table);29 }30}31import org.evomaster.client.java.controller.internal.db.SqlNameContext;32import org.evomaster.client.java.controller.internal.db.TableColumn;33public class Main {34 public static void main(String[] args) {35 SqlNameContext context = new SqlNameContext();36 TableColumn column = new TableColumn();37 column.setName("column1");38 context.visit(column);39 }40}41import org.evomaster.client.java.controller.internal.db.SqlNameContext;42import org.evomaster.client.java.controller.internal.db.Table;43public class Main {44 public static void main(String[] args) {45 SqlNameContext context = new SqlNameContext();46 Table table = new Table();47 table.setName("table1");48 context.visit(table);49 }50}

Full Screen

Full Screen

visit

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.internal.db;2import java.sql.ResultSet;3import java.sql.SQLException;4import java.sql.Statement;5import java.util.ArrayList;6import java.util.List;7import java.util.function.BiConsumer;8import java.util.function.Consumer;9import java.util.function.Function;10import java.util.stream.Stream;11public class SqlNameContext {12 private final Statement statement;13 private final String sql;14 private final List<SqlNameContext> children = new ArrayList<>();15 private final List<SqlNameContext> parents = new ArrayList<>();16 public SqlNameContext(Statement statement, String sql) {17 this.statement = statement;18 this.sql = sql;19 }20 public void addChild(SqlNameContext child) {21 children.add(child);22 }23 public void addParent(SqlNameContext parent) {24 parents.add(parent);25 }26 public void visit(Consumer<SqlNameContext> consumer) {27 consumer.accept(this);28 children.forEach(c -> c.visit(consumer));29 }30 public void visit(BiConsumer<SqlNameContext, Integer> consumer) {31 visit(consumer, 0);32 }33 private void visit(BiConsumer<SqlNameContext, Integer> consumer, int level) {34 consumer.accept(this, level);35 children.forEach(c -> c.visit(consumer, level + 1));36 }37 public Stream<SqlNameContext> stream() {38 return stream(this);39 }40 private Stream<SqlNameContext> stream(SqlNameContext context) {41 return Stream.concat(42 Stream.of(context),43 context.children.stream().flatMap(this::stream)44 );45 }46 public boolean isUpdate() {47 return sql.toLowerCase().startsWith("update");48 }49 public boolean isInsert() {50 return sql.toLowerCase().startsWith("insert");51 }52 public boolean isDelete() {53 return sql.toLowerCase().startsWith("delete");54 }55 public boolean isSelect() {56 return sql.toLowerCase().startsWith("select");57 }58 public boolean isCreate() {59 return sql.toLowerCase().startsWith("create");60 }61 public boolean isAlter() {62 return sql.toLowerCase().startsWith("alter");63 }64 public boolean isDrop() {65 return sql.toLowerCase().startsWith("drop");66 }67 public boolean isTruncate() {68 return sql.toLowerCase().startsWith("truncate");69 }70 public boolean isCall() {71 return sql.toLowerCase().startsWith("call");72 }

Full Screen

Full Screen

visit

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.internal.db;2import java.util.List;3public class SqlNameContext {4 private List<String> currentTable;5 private List<String> currentColumn;6 private List<String> currentJoinTable;7 private List<String> currentJoinColumn;8 private List<String> currentJoinTable2;9 private List<String> currentJoinColumn2;10 private List<String> currentJoinTable3;11 private List<String> currentJoinColumn3;12 private List<String> currentJoinTable4;13 private List<String> currentJoinColumn4;14 private List<String> currentJoinTable5;15 private List<String> currentJoinColumn5;16 private List<String> currentJoinTable6;17 private List<String> currentJoinColumn6;18 private List<String> currentJoinTable7;19 private List<String> currentJoinColumn7;20 private List<String> currentJoinTable8;21 private List<String> currentJoinColumn8;22 private List<String> currentJoinTable9;23 private List<String> currentJoinColumn9;24 private List<String> currentJoinTable10;25 private List<String> currentJoinColumn10;26 private List<String> currentJoinTable11;27 private List<String> currentJoinColumn11;28 private List<String> currentJoinTable12;29 private List<String> currentJoinColumn12;30 private List<String> currentJoinTable13;31 private List<String> currentJoinColumn13;32 private List<String> currentJoinTable14;33 private List<String> currentJoinColumn14;34 private List<String> currentJoinTable15;35 private List<String> currentJoinColumn15;36 private List<String> currentJoinTable16;37 private List<String> currentJoinColumn16;38 private List<String> currentJoinTable17;39 private List<String> currentJoinColumn17;40 private List<String> currentJoinTable18;41 private List<String> currentJoinColumn18;42 private List<String> currentJoinTable19;43 private List<String> currentJoinColumn19;44 private List<String> currentJoinTable20;45 private List<String> currentJoinColumn20;46 private List<String> currentJoinTable21;47 private List<String> currentJoinColumn21;48 private List<String> currentJoinTable22;49 private List<String> currentJoinColumn22;50 private List<String> currentJoinTable23;51 private List<String> currentJoinColumn23;

Full Screen

Full Screen

visit

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.internal.db.SqlNameContext;2import java.util.List;3public class 3 {4 public static void main(String[] args) {5 List<String> names = SqlNameContext.visit("SELECT * FROM table1");6 System.out.println(names);7 }8}

Full Screen

Full Screen

visit

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.internal.db;2import java.sql.Connection;3import java.sql.DatabaseMetaData;4import java.sql.ResultSet;5import java.sql.SQLException;6import java.util.ArrayList;7import java.util.List;8public class SqlNameContext {9 private final List<String> tables = new ArrayList<>();10 public SqlNameContext(Connection con) throws SQLException {11 DatabaseMetaData meta = con.getMetaData();12 ResultSet rs = meta.getTables(null, null, null, new String[]{"TABLE"});13 while (rs.next()) {14 String tableName = rs.getString("TABLE_NAME");15 tables.add(tableName);16 }17 }18 public String getSqlName(String name) {19 if (tables.contains(name)) {20 return name;21 }22 return null;23 }24}25package org.evomaster.client.java.controller.internal.db;26import org.evomaster.client.java.controller.db.SqlScriptRunner;27import org.evomaster.client.java.controller.db.SqlTable;28import org.evomaster.client.java.controller.db.TableRow;29import org.evomaster.client.java.controller.internal.db.h2.H2TableCreator;30import org.evomaster.client.java.controller.internal.db.h2.H2TableDataWriter;31import org.evomaster.client.java.controller.internal.db.h2.H2TableNameVisitor;32import org.evomaster.client.java.controller.internal.db.h2.H2TriggerCreator;33import org.evomaster.client.java.controller.internal.db.schema.SqlSchema;34import org.evomaster.client.java.controller.internal.db.schema.SqlTableSchema;35import org.evomaster.client.java.controller.internal.db.schema.SqlTriggerSchema;36import org.evomaster.client.java.controller.internal.db.schema.TableIndex;37import org.evomaster.client.java.controller.internal.db.schema.TableIndexColumn;38import java.sql.Connection;39import java.sql.SQLException;40import java.util.ArrayList;41import java.util.List;42import java.util.Map;43import java.util.stream.Collectors;44public class DbCleaner {45 private final SqlScriptRunner runner;46 public DbCleaner(SqlScriptRunner runner) {47 this.runner = runner;48 }49 public void cleanDatabase() throws SQLException {

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