changeset 1920:2f33d9a51765

Increase precision for rendering floats to SQL
author Adam Chlipala <adam@chlipala.net>
date Tue, 03 Dec 2013 16:54:04 -0500
parents f5d1037effc9
children 312b62cdaa48 b44138e6a3bf 1e360ea06a09
files src/c/urweb.c src/mysql.sml src/postgres.sml src/sqlite.sml tests/sqlprecision.ur tests/sqlprecision.urp tests/sqlprecision.urs
diffstat 7 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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,
--- 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,
--- 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,
--- /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 <xml/>
+
+fun main () = return <xml><body>
+  <form>
+    <textbox{#N}/>
+    <submit action={insert}/>
+  </form>
+</body></xml>
--- /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
--- /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