preloader
軟體工程

Tricky number operation between SQLite and MySQL

Important: The result of 10/110 in SQLite is 0 and different with 0.09090909 when manipulating in MySQL.  

When testing Laravel Eloquent ORM both at local machine with SQLite and at remote machine with MySQL, you will find some execution results don’t same as expected at local machine. That’s is because SQLite won’t  transform integer to real number automatically.

Workaround: Add multiply 1.0 to ORM SQL statement and it becomes portable between SQLite and MySQL.

Solution: Change the table column definition from integer to decimal(real number in SQLite).