Reputation: 77
I have a SQL file that contains several queries. Since it is a SQL file, it has queries delimited with semicolon (;). I want to read the SQL file and have the queries as an Array[String]
in Scala.
For example, I have queries.sql
file that contains queries like:
select * from table1;
select col1,col2,col3 from table1 where col1 = ''
col2 = '';
select count(*) from table;
I want the output to look like this:
Array("select * from table1","select col1,col2,col3 from table1 where col1 = '' col2 =' '","select count(*) from table")
Upvotes: 0
Views: 676
Reputation: 1515
You might want to try this:
import scala.io.Source
val theArrayYouWant = Source.fromFile(<filename>).getLines.mkString.split(";")
Upvotes: 4