From bf5aa4b06e2ef46cd9c19d14d9b7ee5366cf2475 Mon Sep 17 00:00:00 2001 From: Nikolaos Konstantinou Date: Mon, 2 Dec 2013 22:56:23 +0200 Subject: [PATCH] fixed wrong sql query generation in refObjectMap Check sql query for "order by" keyword before inserting "where" condition in refObjectMap definitions with a joinCondition --- src/main/java/gr/seab/r2rml/beans/Generator.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/gr/seab/r2rml/beans/Generator.java b/src/main/java/gr/seab/r2rml/beans/Generator.java index 251db5c..fbfa966 100644 --- a/src/main/java/gr/seab/r2rml/beans/Generator.java +++ b/src/main/java/gr/seab/r2rml/beans/Generator.java @@ -455,7 +455,13 @@ public void createTriples(MappingDocument mappingDocument) { String parentFieldName = predicateObjectMap.getRefObjectMap().getParent(); if (!databaseType.equals("postgresql")) parentFieldName = parentFieldName.replaceAll("\"", ""); //in mysql, table names must not be enclosed in quotes String addition = " WHERE " + parentFieldName + " = " + childValue; - parentQuery += addition; + int order = parentQuery.toUpperCase().indexOf("ORDER BY"); + if (order != -1) { + String orderCondition = parentQuery.substring(order); + parentQuery = parentQuery.substring(0, order) + addition + " " + orderCondition; + } else { + parentQuery += addition; + } } else { log.error("In the logical table mapping <" + logicalTableMapping.getUri() + ">, the SQL query that generates the parent triples in the parent logical table mapping <" + l.getUri() + "> contains results from more than one tables. " + " Consider using rr:tableName instead of rr:sqlQuery in the parent logical table mapping. Terminating.");