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

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

Source:SqlHandler.java Github

copy

Full Screen

...226 following does not handle the case of sub-selects involving other227 tables... but likely that is not something we need to support right now228 */229 Map<String, Set<String>> data = new HashMap<>();230 // move getWhere before SqlNameContext, otherwise null where would cause exception in new SqlNameContext231 Expression where = ParserUtils.getWhere(statement);232 if (where == null) {233 return data;234 }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)...

Full Screen

Full Screen

Source:DataRow.java Github

copy

Full Screen

1package org.evomaster.client.java.controller.db;2import org.evomaster.client.java.controller.api.dto.database.operations.DataRowDto;3import org.evomaster.client.java.controller.internal.db.SqlNameContext;4import org.evomaster.client.java.utils.SimpleLogger;5import java.sql.Clob;6import java.util.*;7import java.util.stream.Collectors;8/**9 * A row of data in the table results of a Select query.10 * Must include information on its columns.11 */12public class DataRow {13 /**14 * Descriptors for the columns15 */16 private final List<VariableDescriptor> variableDescriptors;17 /**18 * The actual data values. This list must be aligned with variableDescriptors19 */20 private final List<Object> values;21 private final static String NULL_VALUE = "NULL";22 public DataRow(String columnName, Object value, String tableName) {23 this(Arrays.asList(new VariableDescriptor(columnName, null, tableName)), Arrays.asList(value));24 }25 public DataRow(List<VariableDescriptor> descriptors, List<Object> values) {26 Objects.requireNonNull(descriptors);27 Objects.requireNonNull(values);28 if (descriptors.size() != values.size()) {29 throw new IllegalArgumentException("Size mismatch");30 }31 List<VariableDescriptor> list = new ArrayList<>();32 list.addAll(descriptors);33 this.variableDescriptors = Collections.unmodifiableList(list);34 List<Object> valList = new ArrayList<>();35 valList.addAll(values);36 this.values = Collections.unmodifiableList(valList);37 }38 public List<VariableDescriptor> getVariableDescriptors() {39 return variableDescriptors;40 }41 public Object getValue(int index) {42 Object value = values.get(index);43 if(value instanceof Clob){44 Clob clob = (Clob) value;45 try {46 return clob.getSubString(1, (int) clob.length());47 } catch (Exception e){48 SimpleLogger.error("Failed to retrieve CLOB data");49 return null;50 }51 }52 return value;53 }54 public Object getValueByName(String name) {55 return getValueByName(name, null);56 }57 public Object getValueByName(String name, String table) {58 Objects.requireNonNull(name);59 String n = name.trim();60 String t = (table == null ? null : table.trim());61 //true/false are reserved keywords62 if(n.equalsIgnoreCase("true")){63 return true;64 }65 if(n.equalsIgnoreCase("false")){66 return false;67 }68 //first check aliases, but only if no specify table69 if (t == null || t.isEmpty()) {70 for (int i = 0; i < variableDescriptors.size(); i++) {71 VariableDescriptor desc = variableDescriptors.get(i);72 if (n.equalsIgnoreCase(desc.getAlias())) {73 return getValue(i);74 }75 }76 }77 //if none, then check column names78 for (int i = 0; i < variableDescriptors.size(); i++) {79 VariableDescriptor desc = variableDescriptors.get(i);80 if (n.equalsIgnoreCase(desc.getColumnName()) &&81 (t == null || t.isEmpty()82 || t.equalsIgnoreCase(desc.getTableName())83 /*84 TODO: this does not cover all possible cases, as in theory85 there can be many unnamed tables (eg results of sub-selects)86 with same column names. At this moment, we would not87 be able to distinguish them88 */89 || t.equalsIgnoreCase(SqlNameContext.UNNAMED_TABLE)90 )91 ) {92 return getValue(i);93 }94 }95 throw new IllegalArgumentException("No variable called '" + name + "' for table '" + table + "'");96 }97 public String getAsLine() {98 return values.stream().map(obj -> (obj != null) ? obj.toString(): NULL_VALUE).collect(Collectors.joining(","));99 }100 public DataRowDto toDto(){101 DataRowDto dto = new DataRowDto();102 dto.columnData = values.stream().map(obj -> (obj != null) ? obj.toString(): NULL_VALUE).collect(Collectors.toList());103 return dto;...

Full Screen

Full Screen

SqlNameContext

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.internal.db.SqlColumn;2import org.evomaster.client.java.controller.internal.db.SqlTable;3import org.evomaster.client.java.controller.internal.db.SqlInsertBuilder;4import org.evomaster.client.java.controller.internal.db.SqlNameContext;5public class Main {6 public static void main(String[] args) {7 SqlNameContext context = new SqlNameContext("schemaName", "tableName");8 SqlTable table = new SqlTable(context, "col1", "col2", "col3");9 SqlColumn col1 = table.getColumn("col1");10 SqlColumn col2 = table.getColumn("col2");11 SqlColumn col3 = table.getColumn("col3");12 SqlInsertBuilder insert = new SqlInsertBuilder(context, table);13 insert.add(col1, "a");14 insert.add(col2, "b");15 insert.add(col3, "c");16 String sql = insert.build();17 System.out.println(sql);18 }19}20INSERT INTO schemaName.tableName(col1, col2, col3) VALUES ('a', 'b', 'c')21import org.evomaster.client.java.controller.internal.db.SqlColumn;22import org.evomaster.client.java.controller.internal.db.SqlTable;23import org.evomaster.client.java.controller.internal.db.SqlInsertBuilder;24public class Main {25 public static void main(String[] args) {26 SqlTable table = new SqlTable("tableName", "col1", "col2", "col3");27 SqlColumn col1 = table.getColumn("col1");28 SqlColumn col2 = table.getColumn("col2");29 SqlColumn col3 = table.getColumn("col3");30 SqlInsertBuilder insert = new SqlInsertBuilder(table);31 insert.add(col1, "a");32 insert.add(col2, "b");33 insert.add(col3, "c");34 String sql = insert.build();35 System.out.println(sql);36 }37}38INSERT INTO tableName(col1, col2, col3) VALUES ('a', 'b', 'c')

Full Screen

Full Screen

SqlNameContext

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto;2import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;3import org.evomaster.client.java.controller.api.dto.database.schema.DbSchemaDto;4import org.evomaster.client.java.controller.internal.db.SqlInsertBuilder;5import org.evomaster.client.java.controller.internal.db.SqlScriptExecutor;6import org.evomaster.client.java.controller.internal.db.SqlScriptRunner;7import org.evomaster.client.java.controller.internal.db.SqlNameContext;8import org.evomaster.client.java.controller.internal.db.h2.H2ConnectionFactory;9import org.evomaster.client.java.controller.internal.db.h2.H2Driver;10import org.evomaster.client.java.controller.internal.db.h2.H2TableCreator;11import org.evomaster.client.java.controller.internal.db.h2.H2TableSchemaExtractor;12import javax.sql.DataSource;13import java.sql.Connection;14import java.sql.SQLException;15import java.util.ArrayList;16import java.util.List;17public class SqlInsertBuilderExample {18 public static void main(String[] args) throws SQLException {19 DataSource ds = H2ConnectionFactory.createDataSource("mem:myDb;DB_CLOSE_DELAY=-1");20 H2TableCreator tableCreator = new H2TableCreator(ds);21 tableCreator.createTable("CREATE TABLE my_table(id INT, name VARCHAR(50))");22 SqlScriptRunner scriptRunner = new SqlScriptRunner(ds);23 SqlNameContext nameContext = new SqlNameContext("my_table");24 SqlInsertBuilder insertBuilder = new SqlInsertBuilder(nameContext);25 SqlScriptExecutor scriptExecutor = new SqlScriptExecutor(ds);26 SqlScriptDto scriptDto = insertBuilder.insertRow("id", 1).insertRow("name", "John").build();27 System.out.println(scriptDto.getSql());28 scriptRunner.runScript(scriptDto);29 scriptDto = insertBuilder.insertRow("id", 2).insertRow("name", "Mary").build();30 System.out.println(scriptDto.getSql());31 scriptRunner.runScript(scriptDto);

Full Screen

Full Screen

SqlNameContext

Using AI Code Generation

copy

Full Screen

1public class 3 {2 public static void main(String[] args) {3 SqlNameContext context = new SqlNameContext();4 context.setSchemaName("schema");5 context.setTableName("table");6 context.setColumnName("column");7 context.setIndexName("index");8 context.setConstraintName("constraint");9 context.setSequenceName("sequence");10 context.setTriggerName("trigger");11 context.setForeignKeyName("foreign_key");12 context.setPrimaryKeyName("primary_key");13 context.setUniqueKeyName("unique_key");14 context.setUserName("user");15 context.setCatalogName("catalog");16 context.setAliasName("alias");17 context.setSchemaName("schema");18 context.setDatabaseName("database");19 context.setProcedureName("procedure");20 context.setPackageName("package");21 context.setPackageName("package");

Full Screen

Full Screen

SqlNameContext

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.examples;2import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto;3import org.evomaster.client.java.controller.api.dto.database.operations.InsertionDto;4import org.evomaster.client.java.controller.api.dto.database.operations.SelectionDto;5import org.evomaster.client.java.controller.api.dto.database.schema.DbSchemaDto;6import org.evomaster.client.java.controller.api.dto.database.schema.TableDto;7import org.evomaster.client.java.controller.api.dto.database.schema.TableIndexDto;8import org.evomaster.client.java.controller.api.dto.database.schema.TableIndexType;9import org.evomaster.client.java.controller.api.dto.database.schema.TableSchemaDto;10import org.evomaster.client.java.controller.api.dto.database.schema.TableType;11import org.evomaster.client.java.controller.api.dto.database.schema.ViewSchemaDto;12import org.evomaster.client.java.controller.api.dto.database.schema.ViewType;13import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseExecutionDto;14import org.evomaster.client.java.controller.api.dto.database.operations.DeletionDto;15import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;16import org.evomaster.client.java.controller.api.dto.database.schema.ColumnDto;17import org.evomaster.client.java.controller.api.dto.database.schema.DataType;18import org.evomaster.client.java.controller.api.dto.database.schema.ForeignKeyDto;19import org.evomaster.client.java.controller.api.dto.database.schema.IndexDto;20import org.evomaster.client.java.controller.api.dto.database.schema.IndexType;21import org.evomaster.client.java.controller.api.dto.database.schema.PrimaryKeyDto;22import org.evomaster.client.java.controller.api.dto.database.schema.SchemaDto;23import org.evomaster.client.java.controller.api.dto.database.schema.TableColumnDto;24import org.evomaster.client.java.controller.api.dto.database.schema.ViewColumnDto;25import org.evomaster.client.java.controller.internal.db.SqlScriptExecutor;26import org.evomaster.client.java.controller.internal.db.SqlNameContext;27import java.sql.SQLException;28import java.util.ArrayList;29import java.util

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.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful