File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -130,6 +130,18 @@ public String generateInsertScriptFor(String... sqlQueries) {
130130 return generateInsertScriptFor (queries );
131131 }
132132
133+ /**
134+ * Generates an SQL insertion script from a DatasetRow object. This script contains INSERT
135+ * statements taking into account the database integrity constraints.
136+ *
137+ * @param datasetRow A dataset row
138+ * @return An SQL script allowing to create in database the dataset row given in parameter
139+ */
140+ public String generateInsertScriptFor (DatasetRow datasetRow ) {
141+ SqlQuery sqlQuery = SqlQuery .buildFromRow (datasetRow , dbType );
142+ return generateInsertScriptFor (sqlQuery .toString ());
143+ }
144+
133145 /**
134146 * Generates a list of INSERT statements allowing to create in database the dataset row given in
135147 * parameter. These INSERT statements take into account the database integrity constraints.
Original file line number Diff line number Diff line change 2222
2323public class DatasetRowApiTest extends H2Config {
2424
25+ @ Test
26+ public void should_generate_an_insert_script_from_a_dataset_row () {
27+
28+ // GIVEN
29+ TestTable playerTable =
30+ buildUniqueTable (
31+ DATA_SOURCE ,
32+ "Player" ,
33+ " id bigint" + ", firstName varchar(255)" + ", lastName varchar(255)" )
34+ .create ()
35+ .insertValues ("1, 'Paul', 'Pogba'" );
36+
37+ DatasetRow datasetRow =
38+ DatasetRow .ofTable (playerTable .getTableName ())
39+ .addColumnValue ("id" , 1 )
40+ .addColumnValue ("firstName" , "Paul" )
41+ .addColumnValue ("lastName" , "Pogba" );
42+
43+ QuickSqlTestData quickSqlTestData = QuickSqlTestData .buildFrom (DATA_SOURCE );
44+
45+ // WHEN
46+ String insertScript = quickSqlTestData .generateInsertScriptFor (datasetRow );
47+
48+ // THEN
49+ playerTable .recreate ();
50+ SQL_EXECUTOR .execute (insertScript );
51+ assertThat (playerTable )
52+ .withScript (insertScript )
53+ .hasNumberOfRows (1 )
54+ .row (0 )
55+ .hasValues (1 , "Paul" , "Pogba" );
56+ }
57+
2558 @ Test
2659 public void should_generate_working_insert_from_a_dataset_row () {
2760
You can’t perform that action at this time.
0 commit comments