--- a/src/main/scala/SparqlToSql.scala Fri Jun 11 21:45:18 2010 -0400
+++ b/src/main/scala/SparqlToSql.scala Fri Jun 11 21:46:40 2010 -0400
@@ -993,7 +993,7 @@
* @param concat if true, keys will produce SQL functions to generate a URI, e.g. SELECT CONCAT(stemURI, table, "/", pk, ".", R_who.pk) AS who
* @return an SQL query corresponding to sparquery
*/
- def apply (db:sql.DatabaseDesc, sparquery:sparql.Select, stem:StemURI, enforceForeignKeys:Boolean, concat:Boolean) : sql.Select = {
+ def translate (db:sql.DatabaseDesc, sparquery:sparql.Select, stem:StemURI, enforceForeignKeys:Boolean, concat:Boolean) : (sql.Select, Map[sparql.Assignable, SQL2RDFValueMapper]) = {
val sparql.Select(attrs, triples) = sparquery
/** Create an object to hold our compilation state. */
@@ -1037,9 +1037,13 @@
case _ => Some(sql.ExprConjunction(r2rState.exprs))
}
)
+ (select, r2rState.varmap)
+ }
+
+ def apply (db:sql.DatabaseDesc, sparquery:sparql.Select, stem:StemURI, enforceForeignKeys:Boolean, concat:Boolean) : sql.Select = {
// println("r2rState.varmap: " + r2rState.varmap)
// println("select.expression: " + select.expression)
- select.makePretty() // eliminate foo.bar=foo.bar and stuff like that.
+ translate(db, sparquery, stem, enforceForeignKeys, concat)._1.makePretty() // eliminate foo.bar=foo.bar and stuff like that.
}
}
--- a/src/test/scala/SparqlToSqlTest.scala Fri Jun 11 21:45:18 2010 -0400
+++ b/src/test/scala/SparqlToSqlTest.scala Fri Jun 11 21:46:40 2010 -0400
@@ -35,6 +35,26 @@
| 3 | thingy | 18 |
| 4 | toy | 253 |
+--------+--------+------+
+
+ INSERT INTO Employee (empid, lastName, birthday, manager) VALUES ( 18, "Johnson" , 1969-11-08, NULL);
+ INSERT INTO Employee (empid, lastName, birthday, manager) VALUES (253, "Smith" , 1979-01-18, 18);
+ INSERT INTO Employee (empid, lastName, birthday, manager) VALUES (255, "Jones" , 1981-03-24, 253);
+ INSERT INTO Employee (empid, lastName, birthday, manager) VALUES ( 19, "Xu" , 1966-11-08, NULL);
+ INSERT INTO Employee (empid, lastName, birthday, manager) VALUES (254, "Ishita" , 1971-10-31, 253);
+
+ INSERT INTO Tasks (taskid, name, lead) VALUES (1, "widget", 18);
+ INSERT INTO Tasks (taskid, name, lead) VALUES (2, "dingus", 253);
+ INSERT INTO Tasks (taskid, name, lead) VALUES (3, "thingy", 18);
+ INSERT INTO Tasks (taskid, name, lead) VALUES (4, "toy" , 253);
+
+ INSERT INTO TaskAssignments (id, task, employee) VALUES (1, 1, 18);
+ INSERT INTO TaskAssignments (id, task, employee) VALUES (2, 2, 253);
+ INSERT INTO TaskAssignments (id, task, employee) VALUES (3, 3, 19);
+ INSERT INTO TaskAssignments (id, task, employee) VALUES (4, 4, 253);
+ INSERT INTO TaskAssignments (id, task, employee) VALUES (5, 1, 253);
+ INSERT INTO TaskAssignments (id, task, employee) VALUES (6, 2, 255);
+ INSERT INTO TaskAssignments (id, task, employee) VALUES (7, 3, 255);
+ INSERT INTO TaskAssignments (id, task, employee) VALUES (8, 4, 254);
*/
val DDLParser = Sql()