JPA Criteria API causing missing right parenthesis error - jpa

I have the following Expression to concatenate two columns
Expression<String> stringConcat =
criteriaBuilder.concat(criteriaBuilder.concat(rootPr.get(ProductList_.prodDesc), " # "),
rootEmp.get(ProductEmp_.empNo));
and it used in CriteriQuery in the followng manner,
criteriaQuery.multiselect(root.get(ProductCatalogue_.userId),
root.get(ProductCatalogue_.productList),criteriaBuilder.selectCase()
.when(criteriaBuilder.equal(root.get(ProductCatalogue_.prodId),"ZCX"), stringConcat)
.otherwise(rootPr.get(ProductList_.prodDesc)));
However when SQL is generated, it is throwing error
missing right parenthesis
because in if else part of SQL has a question mark as it is expecting a parameter
THEN (t0.prodDesc = ?)
How to resolve this problem?

This is an EclipseLink bug, that was fixed in version 2.4.2.
Upgrade to a newer version, and it will work (tested on EclipseLink 2.5.2).

Related

Using Knex/Postgresql What Does This Mean? "error: column "*" does not exist"

I had a project that I shelved for awhile, but recently I dusted it off and updated all the NPM packages. Now when I try to do anything database related (using Knex/Postgresql) I get the error:
error: column "*" does not exist
This will happen with a seemingly harmless query like:
select "*" from "some_table" where "id" = $1
If I run that query directly against the DB:
select * from "some_table" where "id" = 1;
it works fine. But no matter what I try with knex, whether it's running a regular query or trying to reset my whole database, I keep getting that seemingly nonsensical error.
Can anyone explain what it means?
The double quotes around the * cause it not to be interpreted as “all columns”, but as a column with that very name.

Syntax error on DB2 XMLELEMENT

I get this error when trying out this command in the BIRT Classic Models sample database in Data Studio
select xmlelement(name "custno", customers.customernumber) from customers
Syntax error: Encountered "\"custno\"" at line 1, column 24.
I do not know how to correct it.
Thanks.
I'm not familiar with db2, but according to this your statement looks quite alrigth (although I'd place an alias to name this field...)
But this
Syntax error: Encountered "\"custno\"" at line 1, column 24.
seems to be a quite clear hint, that your error is connected to the NAME of the element.
I'm pretty sure, that this statement was created on string level.
Did you try to escape the "-characters with \"?
The SQL reaching the engine might look like
select xmlelement(name \"custno\", customers.customernumber) from customers
or
select xmlelement(name "\"custno"\", customers.customernumber) from customers
... which is wrong of course...
But to be honest: just guessing...

Slick 2.1.x Invalid query because of `

I am working on legacy code which was written in slick 2.1 (can't upgrade right now).
val query = foo.filter(x => x.d >= input._1).filter(x => x.d < input._2)
println(query.selectStatement)
query.list
I can see that this generate the query
select x2.`a`, x2.`b`, x2.`c`, x2.`d` from `foo` x2 where (x2.`d` >= {ts '2016-07-30 00:00:00.0'}) and (x2.`d` < {ts '2016-07-30 23:23:59.0'})
when this executes, it gives an error java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
When I copy paste this printed query into Oracle query editor it gives the same error there. However if I remove all the ```s then it works. Why is slick 2.1.x generate bad query? is there anyway to tell it to stop generating "`"s
I found the answer. I had imported the wrong driver. I had imported MySQLDriver and was trying to execute the code against Oracle.
Importing the right OracleDriver (via slick-extensions) generated the right query.

PyCharm PostgreSQL dialect detection

Having a problem with PostgreSQL dialect in PyCharm. I have the below SELECT query:
"SELECT * FROM table WHERE ST_DWithin(table.geog_column,
ST_GeographyFromText(\'SRID=4326;POINT(%s %s)\'), %s)"
The query performs as expected in a query editor but Pycharm complains <expression> expected, got '%'. I have set the dialect detection to PostgreSQL.
I believe there is an issue with the parameter binding but not able to figure out what the issue is. Any help would be appreciated.
EDIT: I somehow missed the clear warnings on psycopg2 documentation about using python string interpolation and concatenation.
The right way of doing it is to use SQLAlchemy to construct raw SQL queries:
from sqlalchemy import text
sql = text("SELECT * FROM table WHERE ST_DWithin(table.geog_column,
ST_GeographyFromText(\'SRID=4326;POINT(:long :lat)\'), :distance)")
data = {'long': longitude, 'lat': latitude, 'distance': distance}
result = conn.execute(sql, data)
The below approach is WRONG and is susceptible to SQL injections. I have left it here for reference only.
I just found the mistake and for anyone else who is caffeine starved, you need to add the %s within single quotes. Elementary but can easily be missed.
"SELECT * FROM table WHERE ST_DWithin(table.geog_column,
ST_GeographyFromText(\'SRID=4326;POINT('%s' '%s')\'), *'%s'*)"
The quotes fixed the issue for me but I am not entirely sure if this is the right approach and hence leaving it here to get some input.

Running a query using date from a form MS Access

How do I run a query using a value from a textbox from a form I have? I know that there is another post here at Stackoverflow dealing with this issue but I found it to be insufficient for my needs.
I formated my textbox into Medium Date format with its default value being =Date(). However, when I pick up a date and open my report I get this error:
Runtime error 3071: Expression Too Complex
My where clause is this
WHERE
(
(AllInfo.DateOpened >= CDate([Forms]![Main Form]![WindowPrintOptions]![CustomizedReport]!txtDateOpenedFrom.Value))
)
and I am sure it is this code piece that is throwing the problem since when I take it out of the query the error message simply disappears.
Any ideas?
Try with:
(AllInfo.DateOpened >= DateValue([Forms]![Main Form]![WindowPrintOptions].[Form]!txtDateOpenedFrom))
)
Folks,
I got the problem. It was the "AllInfo" alias. It wasn't applicable at that escope inside the query. By changing the proper things, it was enough to write:
[Forms]![Main Form]![WindowPrintOptions]![CustomizedReport]!txtDateOpenedFrom.Value
Issue solved. Thank you all!