31,026
edits
m (→SQL rules) |
m (→SQL rules) |
||
| Line 65: | Line 65: | ||
</source> | </source> | ||
* Into SQL requests, you must quote fields except fields that contains amounts that must be stored as double or real type. Quotes on numbers may results in saving a different value. For example 412.62 in an insert will be saved with value 412.61999512 into database fi target field has type double(24,8). Only PHP see value 412.61999512. Other tools will see 412.62 giving sensation that there is no problem. But it's PHP that hase the good vision. There is really a wrong value into database. By removing quotes on numbers, no problem occurs. | |||
* | |||
Example: | Example: | ||
| Line 75: | Line 73: | ||
</source> | </source> | ||
Note, problem of float numbers is same problem on all langauges and not only when inserting data into database. It occurs also with any language when you work on "real" numbers, so numbers must be, as soon as they are affected, cleaned with function price2num with second parameter defined to : | |||
'MU', 'MT' | 'MU', 'MT' or 'MS' depending on usage of number. (see function documentation) | ||
Well, to be compatible with any accurency required by any country on amounts, we will use the following type into database: | |||
- double(24,8) | - double(24,8) for any amount | ||
- double(6,3) | - double(6,3) for any vat rate | ||
- real | - real for a quantity | ||
* Dolibarr | * Dolibarr must works even if Mysql option '''strict''' is active. | ||
To activate it (recommanded when developping on Dolibarr), add the following line into the config file of your Mysql server (my.cnf) | |||
<source lang="ini"> | <source lang="ini"> | ||
sql-mode="STRICT_ALL_TABLES" | sql-mode="STRICT_ALL_TABLES" | ||
</source> | </source> | ||
* | * Functions NOW or SYSDATE are forbidden inside SQL requests. If you must use the current date into a field, value must come from the PHP and not from the database engine. This is to avoid a better portability of code and a correct management of TimeZone. | ||
= Normes HTML = | = Normes HTML = | ||