Hello,
I tried to have a resulset filtered by a computed field generated from a DbFunctionCall, but I can't find a way to do this
I have this dynamicList:
ResultsetFields fields = new ResultsetFields(16);
fields.DefineField(ServizioAttivoFields.IdservizioAttivo, 0);
fields.DefineField(ServizioAttivoFields.Idservizio, 1);
fields.DefineField(ServizioAttivoFields.DataScadenza, 2);
[.... some other fileds....]
EntityField ggToExpire = new EntityField("DayToExpire",
new DbFunctionCall("DATEDIFF", new object[] { "CURDATE()", "servizioattivo.DataScadenza" }));
fields.DefineField(ggToExpire, 15);
the custom field ggToExpire, is calculated by a DbFunctionCall: it works properly and returns on the resultes an integer, like this:
IdservizioAttivo - Idservizio - DayToExpire
36 1 30
42 1 56
47 1 -15
I need to build a Predicate Expression, base on the calculated field DayToExpire, to obtain the records where DayToExpire < [x days]
I tried in some ways, in according to the documentation and other forums threads that i found, but it doesn't seems works: my resultset is always 0 records.
DbFunctionCall call = new DbFunctionCall("DATEDIFF", new object[] { "CURDATE()" , "servizioattivo.DataScadenza" });
EntityField tmpField = new EntityField("tmpFld", call);
PredicateExpression exp = new PredicateExpression();
exp.Add(tmpField < giorniToScadenza);
I tried also this, that generates the same output on the query:
PredicateExpression exp = new PredicateExpression();
exp.Add(ggToExpire < giorniToScadenza);
The generated query is:
SELECT DISTINCT `servizioattivo`.`IDServizioAttivo` AS `IdservizioAttivo`, `servizioattivo`.`IDServizio` AS `Idservizio`, `servizioattivo`.`IDCliente` AS `Idcliente`, `servizioattivo`.`IDStatoServizioAttivo` AS `IdstatoServizioAttivo`, `servizioattivo`.`IDServer` AS `Idserver`, `servizioattivo`.`IP` AS `Ip`, `servizioattivo`.`Descrizione`, `servizioattivo`.`IDDominio` AS `Iddominio`, `servizioattivo`.`DataScadenza`, `servizioattivo`.`TipoBilling`, `servizioattivo`.`NoteAdmin`, `servizioattivo`.`NoteCliente`, `servizioattivo`.`ServerFtpUsername`, `servizioattivo`.`ServerPassword`, `servizioattivo`.`Prezzo`, DATEDIFF(@LO412fa4e61, @LO6e3643fc2) AS `DaysToExpire` FROM `servizioattivo` WHERE ( ( DATEDIFF(@LO412fa4e64, @LO6e3643fc5) < @tmpFld3)) ORDER BY `servizioattivo`.`DataScadenza` ASC
Parameter: @LO412fa4e61 : AnsiString. Length: 9. Precision: 0. Scale: 0. Direction: Input. Value: "CURDATE()".
Parameter: @LO6e3643fc2 : AnsiString. Length: 27. Precision: 0. Scale: 0. Direction: Input. Value: "servizioattivo.DataScadenza".
Parameter: @LO412fa4e64 : AnsiString. Length: 9. Precision: 0. Scale: 0. Direction: Input. Value: "CURDATE()".
Parameter: @LO6e3643fc5 : AnsiString. Length: 27. Precision: 0. Scale: 0. Direction: Input. Value: "servizioattivo.DataScadenza".
Parameter: @tmpFld3 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 20.
they returns 0 records.
I tested the same query on MySQL shell:
SELECT DISTINCT `servizioattivo`.`IDServizioAttivo` AS `IdservizioAttivo`, `servizioattivo`.`IDServizio` AS `Idservizio`, `servizioattivo`.`IDCliente` AS `Idcliente`, `servizioattivo`.`IDStatoServizioAttivo` AS `IdstatoServizioAttivo`, `servizioattivo`.`IDServer` AS `Idserver`, `servizioattivo`.`IP` AS `Ip`, `servizioattivo`.`Descrizione`, `servizioattivo`.`IDDominio` AS `Iddominio`, `servizioattivo`.`DataScadenza`, `servizioattivo`.`TipoBilling`, `servizioattivo`.`NoteAdmin`, `servizioattivo`.`NoteCliente`, `servizioattivo`.`ServerFtpUsername`, `servizioattivo`.`ServerPassword`, `servizioattivo`.`Prezzo`, DATEDIFF(CURDATE(), servizioattivo.DataScadenza) AS `DaysToExpire` FROM `servizioattivo` WHERE ( ( DATEDIFF(CURDATE(), servizioattivo.DataScadenza) < 20 )) ORDER BY `servizioattivo`.`DataScadenza` ASC
the SAME query there works
I think the issue depends on how the DQE generates the field on the WHERE clause: using parameters
Do you think that this is a bug OR of is there a way to genereate the where clause properly?
LLBLGen Pro 2.6 final (May 15th, 2009)
Selfservicing - MySQL 5 - CoreLab driver