Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
BUG: SQL COUNT() and literal null
Message
De
12/02/2005 11:59:44
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Problèmes
Titre:
BUG: SQL COUNT() and literal null
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
00986294
Message ID:
00986294
Vues:
68
Expected : SQL COUNT(expression) aggregate function count 1 when expression is not null,
and 0 when the expression is null.
The datatype of the expression does not influence on the COUNT() result.

Observed: the VFP Engine fire a error if the expression
evaluated during the phase of analysis it is a literal NULL ( a X datatype ).

repro:
CREATE CURSOR aaa ( ax i NULL)
INSERT INTO aaa values(NULL)
INSERT INTO aaa values(1)
INSERT INTO aaa values(2)
INSERT INTO aaa values(3)
INSERT INTO aaa values(4)

 && this have variant NULLs, and correctly don't fire a error
SELECT COUNT(IIF(ax%1=0,CAST(NULL AS I),CAST(NULL AS C))) FROM aaa

* bug: this fire a error because the first phase of the SELECT search a datatype
* VFP engine solution: COUNT() uses a Logical nullable always
SELECT COUNT(NULL) FROM aaa

* Where this create a problem ? On conditional Count
* The standard code for conditional count is :
* NVL(SUM(IIF(condition,1,0)),0)
* but this solution IS not the best solution
* today i have found the correct solution :
* COUNT(EVL(condition,NULL))
* but the null bug force to a useless casting
* SELECT COUNT(CAST(EVL(condition,NULL) AS L)) FROM aaa

SELECT COUNT(EVL(ax%1,NULL)) FROM aaa  && the first record return a logical null

CREATE CURSOR aaa ( ax i NULL)
INSERT INTO aaa values(1)
INSERT INTO aaa values(2)
INSERT INTO aaa values(3)
INSERT INTO aaa values(4)

&& the first record return a logical .f., then the literal null fire the error
SELECT COUNT(EVL(ax%1,NULL)) FROM aaa 

SELECT COUNT(CAST(EVL(ax%1,NULL) AS L)) FROM aaa
Fabio
Répondre
Fil
Voir

Click here to load this message in the networking platform