Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Thanks a lot! I now remember I have had such problems with |
|
Oh, interesting. Do you remember what wasn't working with If there is an issue with it, I added simple read/write tests, which run through. Are there more complex tests we can/should add? |
|
It's been very long since I have dealt with the matter. I have tried to pinpoint this down through digging in both my memory and my git history. Additionally Google and the Propel/Perpl code. It is a story of multiple things gone wrong - but I think I have both learned something again and also have an improvement suggestion for Perpl. It begins with me thinking until yesterday that In my history, I could only retrieve the point ca. 4.5 years ago when I have changed my column definition from Instead, I would have needed to define my column type as follows:
Because until now, Propel/Perpl always int-casts the size attribute. But then again, someone tried it with scale and failed so as well in here: propelorm/PropelBundle#320. Marc's answer here doesn't satisfy me as well, as yes the default for size in MySQL is 10 but there is no default for scale. Regardless if the scale attribute works or not - first of all I would have never expected that this is needed at all and secondly I find it ill-conceived to put the scale into a separate attribute as a normal SQL column definition would just be DECIMAL(10,2). So why don't we allow size attributes just to include the scale value? P.S.: |
|
Ah, I see, thank you for researching! I get confused with The space ahead of "Scale" in In regards to the The linked post, is that true, does Propel/Perpl omit precision and scale if they are the default values? That would mean that someone deliberately added the default values to the code, implemented a comparison and an adjustment to the output when the values match. A lot of work to make the output less verbose. |
Fully agree
I would not call it an inner format - at least for us. Because semantically, "our" size attribute is also uniformly used across data types in SQL, be it CHAR(4) and VARCHAR(4), INT(4), DECIMAL(4), DECIMAL(4,2), FLOAT(4,2) or TIME(4). Although they can mean different things, MySQL just calls all of this attribute the data type description. To my understanding from this, the scale part intrinsically belongs to the precision part. It is just not specified/needed everywhere. "Our" size attribute already means a lot of different things, depending on the byte hunger of the actual data type. So if this is an inner format - it would actually be on the SQL side and we would just be mirroring it. So I would argue in favor of a "magical" size attribute and just see it as an elongated arm of the data type description from SQL and hence also let it be just as magical as it is in SQL.
Actually I could not verify this so far. And it does not make sense with the linked post and Marc's answer. Because although 10 Precision is default on SQL side, it should not be default on Propel/Perpl side and why should Propel/Perpl even care about that? A default would only matter if size would be omitted but then it would not be on Propel/Perpl to figure out but on the RDBMS side. And with regards to the scale attribute it makes even less sense as there is not even a default on SQL side (for obvious reason, as scale is optional and only really matters on DOUBLE/FLOAT, DECIMAL/NUMERAL). The only default size in Propel/Perpl I have found so far is 255 for VARCHAR without size value. |
Issue
The column type
NUMERIC, Propel's fixed precision number type (DECIMAL) correctly uses string in PHP, but binds parameter to PDO statments as int, which cuts off the fractional part.Changes
PDO type is changed to string, matching
DECIMALtype.Implementation Details
All vendors use
NUMERICas alias forDECIMAL(or the corresponding type on that platform), so using a different PDO type betweenNUMERICandDECIMALhas to be a bug.Test strategy
Added simple read and write test for
NUMERICandDECIMAL.Also added a DECIMAL column to the bookstore schema, to have at least one of them linted and analyzed.