oscarotero / simple-crud

PHP library to provide magic CRUD in MySQL/Sqlite databases with zero configuration
MIT License
242 stars 58 forks source link

wrong datatype (int/float) for aggregation functions #24

Closed andrenam closed 6 years ago

andrenam commented 6 years ago

commit 9349d297bda91c7c0e78db46d09450ae10532ba2 breaks datatypes for MAX()/MIN()/etc.. queries.

MAX(), MIN() should return the same datatype as the field. Think of datetime, varchar, etc. All datatypes with a order relation can be used with a MIN()/MAX().

CREATE TABLE test (
field DATE DEFAULT NULL
);
INSERT INTO test (field) VALUES ('2012-04-01'), ('2013-05-12');
SELECT MIN(field), MAX(field) FROM test;

Even with SUM() and numeric fields, the behavior is a little bit unexpected:

CREATE TABLE test2 (
field DOUBLE DEFAULT NULL
);
INSERT INTO test2 (field) VALUES (0.5), (0.25), (0.20), (0.05);
SELECT SUM(field) FROM test2;

I would expect the value 1.0 as float and not 1 as integer.

oscarotero commented 6 years ago

Fair enough. Commit reverted.