Parse error unidac

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
albourgz
Posts: 160
Joined: Wed 06 May 2009 12:17
Location: belgium

Parse error unidac

Post by albourgz » Thu 20 Oct 2016 13:21

c++ builder XE10 pro, unidac 6.4.14, TUniQuery.
This sql is correctly parsed:

Code: Select all

SELECT {fn TRUNCATE(DESTROY_DATE,'')} as closedate, sealbag, sb_type
FROM vsectransdetok 
WHERE DEPT=:1 AND SB_TYPE=:2
AND {fn TRUNCATE(DESTROY_DATE,'')}={fn TRUNCATE({CURRENTDATE},'')}
GROUP BY {fn TRUNCATE(DESTROY_DATE,'')}, sealbag, sb_type
ORDER BY {fn TRUNCATE(DESTROY_DATE,'')}, sealbag, sb_type
This one is not (I get "Empty Macro or function name" at design-time when saving the query, even not when opening it)

Code: Select all

SELECT o.SEALBAG,  si.name as gache, pr.name as product, o.tsCreate, o.ObjectKey, o.infoText, o.infoDate, {fn truncate(sm1.ondt,'')} as dtgache, {fn truncate(sm2.ondt,'')} as dtdestroy, o.cnt, o.job
FROM objectsToClass o join sites si on o.info1=si.id join products pr on o.product=pr.id 
left outer join stockmoves sm1 on o.stockId1=sm1.ID left outer join stockmoves sm2 on o.stockId2=sm2.ID
WHERE  o.ObjectType=:1


AND o.TSCREATE BETWEEN :2 and :3
GROUP by o.sealbag, si.name, pr.name, o.tsCreate, o.ObjectKey, o.infoText, o.infoDate, {fn truncate(sm1.ondt,'')}, {fn truncate(sm2.ondt,'')}, o.cnt, o.job
order by o.sealbag, si.name, pr.name, o.tsCreate, o.ObjectKey, o.infoText, o.infoDate, {fn truncate(sm1.ondt,'')}, {fn truncate(sm2.ondt,'')}, o.cnt, o.job
Why wy why? Only one macro is used, truncate, and the syntax used is the same in both statements.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Parse error unidac

Post by MaximG » Fri 04 Nov 2016 12:02

Please specify what kind of database do you use? For further issue investigation, please send us the script to create database objects, used in your queries.

albourgz
Posts: 160
Joined: Wed 06 May 2009 12:17
Location: belgium

Re: Parse error unidac

Post by albourgz » Fri 04 Nov 2016 12:21

it is oracle 12c but the TUniSession was disconnected.
To reproduce the problem, put a TUniQuery with as select:

Code: Select all

SELECT count(o.SEALBAG),  {fn truncate(sm1.ondt,'')} as dtgache
FROM objectsToClass o 
left outer join stockmoves sm1 on o.stockId1=sm1.ID left 
GROUP BY { fn truncate(sm1.ondt,'')}
order by { fn truncate(sm1.ondt,'')}
Notice the space between { and fn that is in order by and Group By and NOT in select.
Once this happens, The only way to fix it is to put another TUniQuery with {fn expressions exactly the same (case and spaces) in select and in order by/group by.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Parse error unidac

Post by MaximG » Mon 07 Nov 2016 13:56

We still can't reproduce the error according to your description. The following construction is syntactically correct:

Code: Select all

{fn truncate(sm1.ondt,")}
, no additional spaces in front of the fn operator. In this case, this query returns correct data in our test database. Maybe, we will be able to reproduce the error using your test data. So, please send us the script for creating the DB table and the query for this table using UniSQL, executing which you get the error.

albourgz
Posts: 160
Joined: Wed 06 May 2009 12:17
Location: belgium

Re: Parse error unidac

Post by albourgz » Mon 07 Nov 2016 14:19

Do you mean that a space between { and fn is something that is syntaxically incorrect?
To reproduce, new vcl project, drop TUniConnection on the form. Specify Oracle as provider, don't even connect it.
Drop TUniQuery on the form, paste as sql:

Code: Select all

SELECT o.SEALBAG,  si.name as gache, pr.name as product, o.tsCreate, o.ObjectKey, o.infoText, o.infoDate, {fn truncate(sm1.ondt,'')} as dtgache, {fn truncate(sm2.ondt,'')} as dtdestroy, o.cnt, o.job
FROM objectsToClass o join sites si on o.info1=si.id join products pr on o.product=pr.id 
left outer join stockmoves sm1 on o.stockId1=sm1.ID left outer join stockmoves sm2 on o.stockId2=sm2.ID
WHERE  o.ObjectType=:1


AND o.TSCREATE BETWEEN :2 and :3
GROUP by o.sealbag, si.name, pr.name, o.tsCreate, o.ObjectKey, o.infoText, o.infoDate, { fn truncate(sm1.ondt,'')}, {fn truncate(sm2.ondt,'')}, o.cnt, o.job
order by o.sealbag, si.name, pr.name, o.tsCreate, o.ObjectKey, o.infoText, o.infoDate, {fn truncate(sm1.ondt,'')}, {fn truncate(sm2.ondt,'')}, o.cnt, o.job
And press OK button.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Parse error unidac

Post by MaximG » Tue 08 Nov 2016 08:34

We will fix the behavior of UniDAC, while using spaces in expressions UniSQL. As a temporary solution do not use spaces in front of the construction fn :

Code: Select all

 ...GROUP by o.sealbag, si.name, pr.name o.tsCreate, o.ObjectKey, o.infoText, o.infoDate, {fn truncate(sm1.ondt,")}, … 

Post Reply