# HG changeset patch # User Adam Chlipala # Date 1386107644 18000 # Node ID 2f33d9a5176544c9bd9c5a8be802f024537d7bf5 # Parent f5d1037effc979a782f95abad0a6ccca20363bf6 Increase precision for rendering floats to SQL diff -r f5d1037effc9 -r 2f33d9a51765 src/c/urweb.c --- a/src/c/urweb.c Sun Dec 01 16:28:02 2013 -0500 +++ b/src/c/urweb.c Tue Dec 03 16:54:04 2013 -0500 @@ -1622,7 +1622,7 @@ int len; uw_check_heap(ctx, FLOATS_MAX); result = ctx->heap.front; - sprintf(result, "%g%n", n, &len); + sprintf(result, "%.16g%n", n, &len); ctx->heap.front += len+1; return result; } @@ -2406,7 +2406,7 @@ return uw_Basis_sqlifyInt(ctx, *n); } -char *uw_sqlfmtFloat = "%g::float8%n"; +char *uw_sqlfmtFloat = "%.16g::float8%n"; char *uw_Basis_sqlifyFloat(uw_context ctx, uw_Basis_float n) { int len; diff -r f5d1037effc9 -r 2f33d9a51765 src/mysql.sml --- a/src/mysql.sml Sun Dec 01 16:28:02 2013 -0500 +++ b/src/mysql.sml Tue Dec 03 16:54:04 2013 -0500 @@ -385,7 +385,7 @@ newline, box [string "uw_sqlfmtInt = \"%lld%n\";", newline, - string "uw_sqlfmtFloat = \"%g%n\";", + string "uw_sqlfmtFloat = \"%.16g%n\";", newline, string "uw_Estrings = 0;", newline, diff -r f5d1037effc9 -r 2f33d9a51765 src/postgres.sml --- a/src/postgres.sml Sun Dec 01 16:28:02 2013 -0500 +++ b/src/postgres.sml Tue Dec 03 16:54:04 2013 -0500 @@ -376,7 +376,7 @@ newline, box [string "uw_sqlfmtInt = \"%lld::int8%n\";", newline, - string "uw_sqlfmtFloat = \"%g::float8%n\";", + string "uw_sqlfmtFloat = \"%.16g::float8%n\";", newline, string "uw_Estrings = 1;", newline, diff -r f5d1037effc9 -r 2f33d9a51765 src/sqlite.sml --- a/src/sqlite.sml Sun Dec 01 16:28:02 2013 -0500 +++ b/src/sqlite.sml Tue Dec 03 16:54:04 2013 -0500 @@ -160,7 +160,7 @@ newline, box [string "uw_sqlfmtInt = \"%lld%n\";", newline, - string "uw_sqlfmtFloat = \"%g%n\";", + string "uw_sqlfmtFloat = \"%.16g%n\";", newline, string "uw_Estrings = 0;", newline, diff -r f5d1037effc9 -r 2f33d9a51765 tests/sqlprecision.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/sqlprecision.ur Tue Dec 03 16:54:04 2013 -0500 @@ -0,0 +1,12 @@ +table t : { N : float } + +fun insert r = + dml (INSERT INTO t (N) VALUES ({[readError r.N]})); + return + +fun main () = return +
+ + + +
diff -r f5d1037effc9 -r 2f33d9a51765 tests/sqlprecision.urp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/sqlprecision.urp Tue Dec 03 16:54:04 2013 -0500 @@ -0,0 +1,5 @@ +database dbname=test +rewrite url Sqlprecision/* +sql sqlprecision.sql + +sqlprecision diff -r f5d1037effc9 -r 2f33d9a51765 tests/sqlprecision.urs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/sqlprecision.urs Tue Dec 03 16:54:04 2013 -0500 @@ -0,0 +1,1 @@ +val main : unit -> transaction page