c# - Why does sqlite converts . To , -


i confused sqlite right now. use system.data.sqlite version c#

i have 2 tables:

table 1: in have created 2 columns (more important in case , statement way long post it). first 1 called recstat , second 1 doxinm. both decimal , created this: ...

[rectstat] decimal, [doxinm] decimal, 

...

the create table statement looks this:

create table if not exists "table1" (..columns..); 

when insert value in table decimal works fine , when read out works on xaml gui.

after created second table has decimal column. created table same way (this short one, can give whole statement)

create table if not exists "table2" (  [id] integer not null primary key,  [material] varchar(10],  [thickness] decimal); 

c# code creation (note work const string sql commands):

mysqlitecommand.commandtext = @"" + databasepara.create_sql + " " + databasepara.table_sql + " " + databasepara.if_sql + " " + databasepara.not_sql + " " + databasepara.exists_sql + " " + dbtablefilter.filter + "      mysqlitecommand.commandtext += @"([" + dbtablefilter.id + "] " + databasepara.integer_sql + " " + databasepara.not_sql + " " + databasepara.null_sql + " " + databasepara.primarykey_sql + ", "; mysqlitecommand.commandtext += @"[" + dbtablefilter.material + "] " + databasepara.varchar_sql + "(360), "; mysqlitecommand.commandtext += @"[" + dbtablefilter.thickness + "] " + databasepara.decimal_sql + ");"; mysqlitecommand.executenonquery(); 

in both case same insert decimal column:

insert table1 ('rectstat') values ('10.5'); insert table1 ('doxinm') values ('1.3');   insert table2 ('thickness') values ('0.25'); 

for table2 insert:

for (int filterindex = 0; filterindex < database.filtertable.filterlist.count; filterindex++)          {            mysqlitecommand.commandtext = @"" + databasepara.insertinto_sql + " " + dbtablefilter.filter + "(" + dbtablefilter.material + ", " + dbtablefilter.thickness + ") ";            mysqlitecommand.commandtext += @"" + databasepara.values_sql + " ('" + database.filtertable.getfilterat(filterindex).material_property + "', " + database.filtertable.getfilterat(filterindex).thickness_property + ");";            mysqlitecommand.executenonquery();           } 

now database inserts first 2 statements 10.5/1.3 , last 1 0,25 when read out value first 2 works fine last 1 shown without numbers after decimal "point".

so question is. why happens? (btw have more 20 decimals columns in table , "thickness" 1 problem)

i hope can me.

thanks in advance richard

what have tried:

tried different values (had hope because of 0.25) tried without ''. statement thought had 3 values 2 columns...

first of all, should use parameterized queries. rid of conversion problems , prevent sql injection. issues created fact, type of query creation calls decimal.tostring() implicitly. locales, replaces . , leads syntax error.

 var query = "insert yourtable columns(col1, col2, col3) values(@p1, @p2, @p3)";  var cmd = new sqlitecommand(query, connection);  cmd.parameters.addwithvalue("@p1", 1);  cmd.parameters.addwithvalue("@p2", 2.2);  cmd.parameters.addwithvalue("@p3", "three");  cmd.executenonquery(); 

this will, among other things, send decimals server in correct format, , take care of possible ' quotes in string literals , prevent sql injection, making code more secure.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -