From d89fd37a66ab73ea7eba5e2574c4e679c4026f0b Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Tue, 3 Dec 2013 16:54:04 -0500 Subject: Increase precision for rendering floats to SQL --- src/c/urweb.c | 4 ++-- src/mysql.sml | 2 +- src/postgres.sml | 2 +- src/sqlite.sml | 2 +- tests/sqlprecision.ur | 12 ++++++++++++ tests/sqlprecision.urp | 5 +++++ tests/sqlprecision.urs | 1 + 7 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 tests/sqlprecision.ur create mode 100644 tests/sqlprecision.urp create mode 100644 tests/sqlprecision.urs diff --git a/src/c/urweb.c b/src/c/urweb.c index 4ff7a218..8bd5ada9 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -1622,7 +1622,7 @@ char *uw_Basis_attrifyFloat(uw_context ctx, uw_Basis_float n) { 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 @@ char *uw_Basis_sqlifyIntN(uw_context ctx, uw_Basis_int *n) { 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 --git a/src/mysql.sml b/src/mysql.sml index f708da04..c70a1cdd 100644 --- a/src/mysql.sml +++ b/src/mysql.sml @@ -385,7 +385,7 @@ fun init {dbstring, prepared = ss, tables, views, sequences} = 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 --git a/src/postgres.sml b/src/postgres.sml index 44101527..41529173 100644 --- a/src/postgres.sml +++ b/src/postgres.sml @@ -376,7 +376,7 @@ fun init {dbstring, prepared = ss, tables, views, sequences} = 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 --git a/src/sqlite.sml b/src/sqlite.sml index 4ec64788..09c4c683 100644 --- a/src/sqlite.sml +++ b/src/sqlite.sml @@ -160,7 +160,7 @@ fun init {dbstring, prepared = ss, tables, views, sequences} = 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 --git a/tests/sqlprecision.ur b/tests/sqlprecision.ur new file mode 100644 index 00000000..0391ea04 --- /dev/null +++ b/tests/sqlprecision.ur @@ -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 --git a/tests/sqlprecision.urp b/tests/sqlprecision.urp new file mode 100644 index 00000000..7a396b50 --- /dev/null +++ b/tests/sqlprecision.urp @@ -0,0 +1,5 @@ +database dbname=test +rewrite url Sqlprecision/* +sql sqlprecision.sql + +sqlprecision diff --git a/tests/sqlprecision.urs b/tests/sqlprecision.urs new file mode 100644 index 00000000..6ac44e0b --- /dev/null +++ b/tests/sqlprecision.urs @@ -0,0 +1 @@ +val main : unit -> transaction page -- cgit v1.2.3