This is an automated email from the ASF dual-hosted git repository.

lresende pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-toree.git


The following commit(s) were added to refs/heads/master by this push:
     new 9184002  Fix SQL statement variable injection in Scala 2.12
9184002 is described below

commit 9184002adf668713f207f01701f7b865901e1341
Author: Luciano Resende <[email protected]>
AuthorDate: Sat May 8 12:05:17 2021 -0700

    Fix SQL statement variable injection in Scala 2.12
---
 .../src/main/scala/org/apache/toree/magic/builtin/Sql.scala       | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git 
a/sql-interpreter/src/main/scala/org/apache/toree/magic/builtin/Sql.scala 
b/sql-interpreter/src/main/scala/org/apache/toree/magic/builtin/Sql.scala
index e56dffa..ee60357 100644
--- a/sql-interpreter/src/main/scala/org/apache/toree/magic/builtin/Sql.scala
+++ b/sql-interpreter/src/main/scala/org/apache/toree/magic/builtin/Sql.scala
@@ -24,6 +24,7 @@ import org.apache.toree.magic.dependencies.IncludeKernel
 import org.apache.toree.plugins.annotations.Event
 
 import scala.tools.nsc.interpreter
+import scala.tools.nsc.interpreter.Results
 
 /**
  * Represents the magic interface to use the SQL interpreter.
@@ -40,7 +41,12 @@ class Sql extends CellMagic with IncludeKernel {
     val scala = kernel.interpreter("Scala")
     val evaluated = if (scala.nonEmpty && scala.get != null) {
       val scalaInterpreter = scala.get.asInstanceOf[ScalaInterpreter]
-      scalaInterpreter.iMain.valueOfTerm("s\"" + code.replace("\n", " ") + 
"\"").asInstanceOf[String]
+
+      scalaInterpreter.iMain.interpret("s\"" + code.replace("\n", " ") + "\"") 
match {
+        case Results.Success =>
+          
scalaInterpreter.iMain.valueOfTerm(scalaInterpreter.iMain.mostRecentVar).get.asInstanceOf[String]
+        case _ => code
+      }
     } else {
       code
     }

Reply via email to