Yes they both exist. I have created the query using the query builder and
they work fine.

CSV:

val dataContext = DataContextFactory.createCsvDataContext(csvFile)
val dataSet =
dataContext.query().from(fileName).selectAll().where("name").eq("rojo").execute()

JSON:

val dataContext = DataContextFactory.createJsonDataContext(jsonFile)
val dataSet =
dataContext.query().from(fileName).selectAll().where("id").eq(1).execute()

I am really interested in using the executeQuery method with a string query
because I am developing a web application and I am getting the query
directly from the user. It would be awesome if I could call the
executeQuery method passing the string query.

Best regards,

Alberto


2014-09-02 17:19 GMT+02:00 Kasper Sørensen <[email protected]>:

> Can you verify (using getDefaultSchema, getTable(0), getColumnByName) that
> these columns actually exist. If not a string query would not be parsed
> properly. You could also be using the typed query builder to make it safer.
> Den 02/09/2014 17.13 skrev "Alberto Rodriguez" <[email protected]>:
>
> > Hi Hans,
> >
> > You are right my code snippet was not complete, here it is:
> >
> > val dataContext = DataContextFactory.createCsvDataContext(csvFile)
> > val dataSet = dataContext.executeQuery("""SELECT * FROM testdata.csv
> WHERE
> > name='rojo'""")
> >
> > I have just tested the same with a JsonDataContext and getting the same
> > exception:
> >
> > val fileName = "testdata.json"
> > val jsonFile = new File(s"test/resources/$fileName")
> > val dataContext = DataContextFactory.createJsonDataContext(jsonFile)
> > val dataSet = dataContext.executeQuery("""SELECT * FROM testdata.json
> WHERE
> > id='1'""")
> >
> > I am afraid that you can only include 'WHERE' clauses within a
> executeQuery
> > method (with a string format query) using the JdbcDataContext.
> >
> > Kind regards,
> >
> > Alberto
> >
> >
> > 2014-09-02 16:59 GMT+02:00 Hans Drexler <[email protected]
> >:
> >
> > > Hi Alberto,
> > >
> > > I am not the biggest expert, but I think queries should work against
> all
> > > types of data contexts. That is one leading principle of MetaModel.
> From
> > > your code example, it seems the second code snippet (with the csv data
> > > context) is not complete. There is not a complete query in it. Can you
> > > double check your code and post? Maybe then we can help better.
> > >
> > > Kind regards,
> > >
> > > Hans Drexler
> > >
> > > -----Original Message-----
> > > From: Alberto Rodriguez [mailto:[email protected]]
> > > Sent: Tuesday, September 02, 2014 4:54 PM
> > > To: [email protected]
> > > Subject: Problem executing string-format queries
> > >
> > > Hi all,
> > >
> > > I have just come across your awesome library and am integrating it in
> my
> > > project.
> > >
> > > I have just written a couple of tests and noticed that I can execute a
> > > string-format query against a JdbcDataContext whereas I am getting an
> > > IllegarArgumentException ( Expression-based filters cannot be manually
> > > evaluated) when I execute the same query using a CsvDataContext.
> > >
> > > This is working fine:
> > >
> > > val dataContext = DataContextFactory.createJdbcDataContext(connection)
> > >         val dataSet = dataContext.executeQuery("""SELECT * FROM
> > > public.data_sources WHERE TYPE='rest'""")
> > >
> > > This is returning the exception:
> > >
> > >  val dataContext = DataContextFactory.createCsvDataContext(csvFile)
> > > WHERE name='rojo'""")
> > >
> > > Is there any way of executing string queries against all the
> datacontext
> > > types?
> > >
> > > Thank you!
> > >
> >
>

Reply via email to