fix issue #1802 -- escape single quote in SQL export
This commit is contained in:
parent
c7cc84a282
commit
02871e1b6f
@ -121,7 +121,7 @@ public class SqlInsertBuilder {
|
|||||||
handleNullField(allowNullChkBox, defaultValue, nullValueNull, val.getColumnName(), rowValue, true);
|
handleNullField(allowNullChkBox, defaultValue, nullValueNull, val.getColumnName(), rowValue, true);
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
rowValue.append("'" + val.getText() + "'");
|
rowValue.append("'" + val.getText().replace("'","''") + "'");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,6 +360,32 @@ public class SqlExporterTests extends RefineTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExportSqlWithSingleQuote(){
|
||||||
|
int noOfCols = 4;
|
||||||
|
int noOfRows = 1;
|
||||||
|
createGridWithSingleQuote(noOfRows, noOfCols);
|
||||||
|
String tableName = "sql_table_test";
|
||||||
|
JSONObject optionsJson = createOptionsFromProject(tableName, null, null, null, false);
|
||||||
|
optionsJson.put("includeStructure", true);
|
||||||
|
optionsJson.put("includeDropStatement", true);
|
||||||
|
optionsJson.put("convertNulltoEmptyString", true);
|
||||||
|
|
||||||
|
when(options.getProperty("options")).thenReturn(optionsJson.toString());
|
||||||
|
try {
|
||||||
|
SUT.export(project, options, engine, writer);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
String result = writer.toString();
|
||||||
|
logger.info("\nresult:={} ", result);
|
||||||
|
|
||||||
|
Assert.assertTrue(result.contains("INSERT INTO sql_table_test (column0,column1,column2,column3) VALUES \n" +
|
||||||
|
"( 'It''s row0cell0','It''s row0cell1','It''s row0cell2','It''s row0cell3' )"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//helper methods
|
//helper methods
|
||||||
|
|
||||||
public int countWordInString(String input, String word){
|
public int countWordInString(String input, String word){
|
||||||
@ -399,6 +425,18 @@ public class SqlExporterTests extends RefineTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createGridWithSingleQuote(int noOfRows, int noOfColumns){
|
||||||
|
createColumns(noOfColumns);
|
||||||
|
|
||||||
|
for(int i = 0; i < noOfRows; i++){
|
||||||
|
Row row = new Row(noOfColumns);
|
||||||
|
for(int j = 0; j < noOfColumns; j++){
|
||||||
|
row.cells.add(new Cell("It's row" + i + "cell" + j, null));
|
||||||
|
}
|
||||||
|
project.rows.add(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void createGridWithNullFields(int noOfRows, int noOfColumns, int noOfNullFields){
|
protected void createGridWithNullFields(int noOfRows, int noOfColumns, int noOfNullFields){
|
||||||
createColumns(noOfColumns);
|
createColumns(noOfColumns);
|
||||||
if(noOfNullFields > (noOfColumns * noOfRows)) {
|
if(noOfNullFields > (noOfColumns * noOfRows)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user