Skip to content
Snippets Groups Projects
Commit 9e8f8e72 authored by gmantele's avatar gmantele
Browse files

[ADQL] Fix ADQL to SQL translation of strings: the character ' was not escaped.

Now, all occurences of ' are replaced by '' in the SQL translation.
parent 0e609698
No related branches found
No related tags found
No related merge requests found
......@@ -167,8 +167,8 @@ import adql.query.operand.function.geometry.RegionFunction;
* </p>
*
* @author Gr&eacute;gory Mantelet (ARI)
* @version 1.3 (05/2015)
* @since 1.3
* @version 1.4 (09/2015)
* @since 1.4
*
* @see PostgreSQLTranslator
* @see PgSphereTranslator
......@@ -677,7 +677,7 @@ public abstract class JDBCTranslator implements ADQLTranslator {
@Override
public String translate(StringConstant strConst) throws TranslationException{
return "'" + strConst.getValue() + "'";
return "'" + strConst.getValue().replaceAll("'", "''") + "'";
}
@Override
......
package adql.translator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
import adql.db.DBType;
import adql.db.STCS.Region;
import adql.parser.ParseException;
import adql.query.IdentifierField;
import adql.query.operand.StringConstant;
import adql.query.operand.function.geometry.AreaFunction;
import adql.query.operand.function.geometry.BoxFunction;
import adql.query.operand.function.geometry.CentroidFunction;
import adql.query.operand.function.geometry.CircleFunction;
import adql.query.operand.function.geometry.ContainsFunction;
import adql.query.operand.function.geometry.DistanceFunction;
import adql.query.operand.function.geometry.ExtractCoord;
import adql.query.operand.function.geometry.ExtractCoordSys;
import adql.query.operand.function.geometry.IntersectsFunction;
import adql.query.operand.function.geometry.PointFunction;
import adql.query.operand.function.geometry.PolygonFunction;
import adql.query.operand.function.geometry.RegionFunction;
public class TestJDBCTranslator {
@Before
public void setUp() throws Exception{}
@Test
public void testTranslateStringConstant(){
JDBCTranslator tr = new AJDBCTranslator();
/* Ensure the translation from ADQL to SQL of strings is correct ;
* particularly, ' should be escaped otherwise it would mean the end of a string in SQL
*(the way to escape a such character is by doubling the character '): */
try{
assertEquals("'SQL''s translation'", tr.translate(new StringConstant("SQL's translation")));
}catch(TranslationException e){
e.printStackTrace(System.err);
fail("There should have been no problem to translate a StringConstant object into SQL.");
}
}
public final static class AJDBCTranslator extends JDBCTranslator {
@Override
public String translate(ExtractCoord extractCoord) throws TranslationException{
return null;
}
@Override
public String translate(ExtractCoordSys extractCoordSys) throws TranslationException{
return null;
}
@Override
public String translate(AreaFunction areaFunction) throws TranslationException{
return null;
}
@Override
public String translate(CentroidFunction centroidFunction) throws TranslationException{
return null;
}
@Override
public String translate(DistanceFunction fct) throws TranslationException{
return null;
}
@Override
public String translate(ContainsFunction fct) throws TranslationException{
return null;
}
@Override
public String translate(IntersectsFunction fct) throws TranslationException{
return null;
}
@Override
public String translate(PointFunction point) throws TranslationException{
return null;
}
@Override
public String translate(CircleFunction circle) throws TranslationException{
return null;
}
@Override
public String translate(BoxFunction box) throws TranslationException{
return null;
}
@Override
public String translate(PolygonFunction polygon) throws TranslationException{
return null;
}
@Override
public String translate(RegionFunction region) throws TranslationException{
return null;
}
@Override
public boolean isCaseSensitive(IdentifierField field){
return false;
}
@Override
public DBType convertTypeFromDB(int dbmsType, String rawDbmsTypeName, String dbmsTypeName, String[] typeParams){
return null;
}
@Override
public String convertTypeToDB(DBType type){
return null;
}
@Override
public Region translateGeometryFromDB(Object jdbcColValue) throws ParseException{
return null;
}
@Override
public Object translateGeometryToDB(Region region) throws ParseException{
return null;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment