I have a C# app that writes some data into a SQLite database, the problem comes when I try to store a C# double into a SQLite REAL field.
It saves it into the database with a comma as decimal separator (as usual in my country, not sure it counts for anything).
The table has the following structure:
CREATE TABLE `valoresStock` (
`Fecha` TEXT,
`IdArticulo` TEXT,
`IdColor` INTEGER,
`KgPorUnidad` REAL,
`Stock` REAL,
`CostePorKg` REAL,
`CostePorUnidad` REAL,
PRIMARY KEY(Fecha,IdArticulo,IdColor)
);
And the query I use in my app is the following:
cmd.CommandText = "INSERT INTO valoresStock (Fecha, IdArticulo, IdColor, KgPorUnidad, Stock, CostePorKg, costePorUnidad) VALUES ('" + DateTime.Today + "','" + referencia.idArticulo + "', '" + referencia.idColor + "', '" + referencia.kilos + "', '" + referencia.stockActual + "', '" + referencia.valorPorKg + "', '" + referencia.valorPorUnidad + "') ";
As I said, the four last fields are of type double. No error is given.
Then the data is stored as follows:
That is, using a dot when it doesn't have decimal part, and a comma when it does.
The problem with this is for example when I use a SELECT statement to calculate, such as this:
SELECT VS.Fecha, VS.IdArticulo, VS.IdColor, (VS.Stock * (VS.CostePorUnidad + VS.CostePorKg * Vs.KgPorUnidad)) AS Valor FROM valoresStock VS
This gives the following result, which is wrong (only took the number with the dot).
So If I manually change the commas for dots in my table, it works properly.
But how to make my app do this, some kind of culture change?
Or can I make SQLite understand or automatically transform the commas?
Why does SQLite accept that number as valid if it doesn't understand it later?