Class SqlScriptRunner
- java.lang.Object
-
- org.evomaster.client.java.controller.db.SqlScriptRunner
-
public class SqlScriptRunner extends Object
Class used to execute SQL commands from a script file
-
-
Constructor Summary
Constructors Constructor Description SqlScriptRunner()Default constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static QueryResultexecCommand(Connection conn, String command)static LongexecInsert(Connection conn, String command)static Map<Long,Long>execInsert(Connection conn, List<InsertionDto> insertions)Execute the different SQL insertions.List<String>readCommands(Reader reader)static voidrunCommands(Connection connection, List<String> commands)static voidrunScript(Connection connection, Reader reader)Runs an SQL script (read in using the Reader parameter)static voidrunScriptFromResourceFile(Connection connection, String resourcePath)voidsetDelimiter(String delimiter, boolean fullLineDelimiter)
-
-
-
Field Detail
-
delimP
public static final Pattern delimP
regex to detect delimiter. ignores spaces, allows delimiter in comment, allows an equals-sign
-
-
Method Detail
-
setDelimiter
public void setDelimiter(String delimiter, boolean fullLineDelimiter)
-
runScript
public static void runScript(Connection connection, Reader reader)
Runs an SQL script (read in using the Reader parameter)- Parameters:
reader- - the source of the script
-
runScriptFromResourceFile
public static void runScriptFromResourceFile(Connection connection, String resourcePath)
-
runCommands
public static void runCommands(Connection connection, List<String> commands)
-
execInsert
public static Map<Long,Long> execInsert(Connection conn, List<InsertionDto> insertions) throws SQLException
Execute the different SQL insertions. Those can refer to each other via foreign keys, even in the case of auto-generated ids- Parameters:
conn- a JDBC connection to the databaseinsertions- the SQL insertions to execute- Returns:
- a map from InsertionDto id to id of auto-generated primary keys in the database (if any was generated). If an InsertionDto has no id, we will not keep track of any auto-generated value for it.
- Throws:
SQLException
-
execInsert
public static Long execInsert(Connection conn, String command) throws SQLException
- Parameters:
conn- a JDBC connection to the databasecommand- the SQL insertion to execute- Returns:
- a single id for the new row, if any was automatically generated,
nullotherwise. In other words, return the value of auto-generated primary key, if any was created. - Throws:
SQLException
-
execCommand
public static QueryResult execCommand(Connection conn, String command) throws SQLException
- Throws:
SQLException
-
-