Datetime paramtere and Union all problem
Posted: 31.03.2021, 13:10
Hi there!
I am Zoltan and I am using ZeosDBO in Lazarus 2.0.4 windows version.
At my workplace previously I was using Delphi 6.0 for developing programs, but since Delphi 6 has problems with newer Windows versions,
also Lazarus has much more features and plug-ins - like Zeos - I started to use Lazarus for developing softwares. We are using Oracle as main database for our logistic system and my programs have to use that database.
My old programs, written in Delphi, work perfectly with Oracle. My Lazarus programs have some special problems.
I have observed two main problems:
- the UNION ALL statement causes problems to Zeos, basically we cannot use it, but this would be the smaller problem
- the HUGE problem is when the SQL statement uses datetime parameters
- in most cases datetime parameters in the WHERE clause works fine
- but in some cases, and that is connected to certain dates, then it crashes
a concret example: see the attached SQL :
---------------------------------------------------------------------------------------------------------------
select SubStr(b.bemerkung,1,50) as bemerkung,
t.tnre, SubStr(t.bez,1,25) as Megnevezes,
To_Char(b.mge) as darab, (b.mge * b.ekmittel) as DEPWert,
TK.UPE AS UPE,
(b.mge*tk.upe) as upewert,
t.gew as suly,
b.lagerort, To_Char(b.na_dat) as Idopont,
to_char((select sum(bst) from tup u where u.tnr=t.tnr))
as Keszlet,
G.GITPH AS GITPH, G.BEZ AS GITPHBEZ,
to_char(T.LINR) AS LIEFKOD,
GPT.NAME AS LIEFNEV
from bstkorr b, tst t, GITPH G, GPT, tstkalk tk
where SubStr(b.na_dat,1,10) >= :KezdDat
and SubStr(b.na_dat,1,10) <= :VegDat
and b.bstkorrcd = :KorrKod
and t.tnr = b.tnr
AND T.GITPH=G.GITPH
AND T.LINR=GPT.GPTNR
AND B.TNR=TK.TNR
AND trunc(B.na_dat) > trunc(TK.ABDAT)
AND trunc(B.na_dat)<=trunc(TK.BISDAT)
order by lagerort;
---------------------------------------------------------------------------------------------------------------
it can be seen that this SQL statement has 3 parameters to pass :
- KezdDat - date format YYYY-MM-DD
- VegDat - date format YYYY-MM-DD
- KorrKod - integer
if KezdDat = '2021-03-05' and VegDat = '2021-03-30' then it works perfectly, it has a result of 102 rows
BUT
if KezdDat = '2021-03-01' and VegDat = '2021-03-30' then it crashes, the result has only 1 row!!!
in the Delphi version
KezdDat = '2021-03-01' and VegDat = '2021-03-30' gives 132 rows and that is the good result.
I set a trace for the Oracle Instant Client and the result is the following:
- BDE file - created with my old Delphi program - at position 540506 starts the SQL block given to the Oracle client
this was the original SQL statement, this had to be truncated because of the previous UNION ALL problem
this statement has 6 parameters, but basically doesnt matter
at the end of the block - position 544118 - all the parameters can be seen in plain
- LAZ file - created with my Lazarus program - the SQL statement without UNION ALL statement,
starts at position 698225 and ends at position 699203
the 3 parameters are missing !!!!
I have tried to change the type of the paramaters from datetime to string, but doesn't change, BUT if I insert
the desired dates instead of the parameters, then it works perfectly!!!
Thank You for Your help in advance!
Zoltan
I am Zoltan and I am using ZeosDBO in Lazarus 2.0.4 windows version.
At my workplace previously I was using Delphi 6.0 for developing programs, but since Delphi 6 has problems with newer Windows versions,
also Lazarus has much more features and plug-ins - like Zeos - I started to use Lazarus for developing softwares. We are using Oracle as main database for our logistic system and my programs have to use that database.
My old programs, written in Delphi, work perfectly with Oracle. My Lazarus programs have some special problems.
I have observed two main problems:
- the UNION ALL statement causes problems to Zeos, basically we cannot use it, but this would be the smaller problem
- the HUGE problem is when the SQL statement uses datetime parameters
- in most cases datetime parameters in the WHERE clause works fine
- but in some cases, and that is connected to certain dates, then it crashes
a concret example: see the attached SQL :
---------------------------------------------------------------------------------------------------------------
select SubStr(b.bemerkung,1,50) as bemerkung,
t.tnre, SubStr(t.bez,1,25) as Megnevezes,
To_Char(b.mge) as darab, (b.mge * b.ekmittel) as DEPWert,
TK.UPE AS UPE,
(b.mge*tk.upe) as upewert,
t.gew as suly,
b.lagerort, To_Char(b.na_dat) as Idopont,
to_char((select sum(bst) from tup u where u.tnr=t.tnr))
as Keszlet,
G.GITPH AS GITPH, G.BEZ AS GITPHBEZ,
to_char(T.LINR) AS LIEFKOD,
GPT.NAME AS LIEFNEV
from bstkorr b, tst t, GITPH G, GPT, tstkalk tk
where SubStr(b.na_dat,1,10) >= :KezdDat
and SubStr(b.na_dat,1,10) <= :VegDat
and b.bstkorrcd = :KorrKod
and t.tnr = b.tnr
AND T.GITPH=G.GITPH
AND T.LINR=GPT.GPTNR
AND B.TNR=TK.TNR
AND trunc(B.na_dat) > trunc(TK.ABDAT)
AND trunc(B.na_dat)<=trunc(TK.BISDAT)
order by lagerort;
---------------------------------------------------------------------------------------------------------------
it can be seen that this SQL statement has 3 parameters to pass :
- KezdDat - date format YYYY-MM-DD
- VegDat - date format YYYY-MM-DD
- KorrKod - integer
if KezdDat = '2021-03-05' and VegDat = '2021-03-30' then it works perfectly, it has a result of 102 rows
BUT
if KezdDat = '2021-03-01' and VegDat = '2021-03-30' then it crashes, the result has only 1 row!!!
in the Delphi version
KezdDat = '2021-03-01' and VegDat = '2021-03-30' gives 132 rows and that is the good result.
I set a trace for the Oracle Instant Client and the result is the following:
- BDE file - created with my old Delphi program - at position 540506 starts the SQL block given to the Oracle client
this was the original SQL statement, this had to be truncated because of the previous UNION ALL problem
this statement has 6 parameters, but basically doesnt matter
at the end of the block - position 544118 - all the parameters can be seen in plain
- LAZ file - created with my Lazarus program - the SQL statement without UNION ALL statement,
starts at position 698225 and ends at position 699203
the 3 parameters are missing !!!!
I have tried to change the type of the paramaters from datetime to string, but doesn't change, BUT if I insert
the desired dates instead of the parameters, then it works perfectly!!!
Thank You for Your help in advance!
Zoltan