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

[ADQL] Support the special escaping syntax for string literals in Postgres...

[ADQL] Support the special escaping syntax for string literals in Postgres (strings to escape must be prefixed by a E before the starting ').
parent 24883674
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ package adql.translator; ...@@ -21,6 +21,7 @@ package adql.translator;
*/ */
import adql.query.IdentifierField; import adql.query.IdentifierField;
import adql.query.operand.StringConstant;
import adql.query.operand.function.MathFunction; import adql.query.operand.function.MathFunction;
import adql.query.operand.function.geometry.AreaFunction; import adql.query.operand.function.geometry.AreaFunction;
import adql.query.operand.function.geometry.BoxFunction; import adql.query.operand.function.geometry.BoxFunction;
...@@ -45,7 +46,7 @@ import adql.query.operand.function.geometry.RegionFunction; ...@@ -45,7 +46,7 @@ import adql.query.operand.function.geometry.RegionFunction;
* </i></p> * </i></p>
* *
* @author Gr&eacute;gory Mantelet (CDS;ARI) * @author Gr&eacute;gory Mantelet (CDS;ARI)
* @version 1.3 (08/2014) * @version 1.3 (10/2014)
* *
* @see PgSphereTranslator * @see PgSphereTranslator
*/ */
...@@ -98,6 +99,19 @@ public class PostgreSQLTranslator extends JDBCTranslator { ...@@ -98,6 +99,19 @@ public class PostgreSQLTranslator extends JDBCTranslator {
return field == null ? false : field.isCaseSensitive(caseSensitivity); return field == null ? false : field.isCaseSensitive(caseSensitivity);
} }
@Override
public String translate(StringConstant strConst) throws TranslationException{
// Deal with the special escaping syntax of Postgres:
/* A string containing characters to escape must be prefixed by an E.
* Without this prefix, Potsgres does not escape the concerned characters and
* consider backslashes as normal characters.
* For instance: E'foo\tfoo2'. */
if (strConst.getValue() != null && strConst.getValue().contains("\\"))
return "E'" + strConst.getValue() + "'";
else
return super.translate(strConst);
}
@Override @Override
public String translate(MathFunction fct) throws TranslationException{ public String translate(MathFunction fct) throws TranslationException{
switch(fct.getType()){ switch(fct.getType()){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment