Commits

Anonymous committed 864c99e

.

Comments (0)

Files changed (3)

src/dbi/dbi_pg.ml

   ~want_ftype:"number (numeric, decimal)"
   (fun pres ~row ~col ->
      let str = pres#getvalue row col in
-     let scale = pres#fmod row in
-     let () = failwith "WC.number: str=%S, scale=%i" str scale in
+     let fmod = pres#fmod col in
+     if fmod = -1 then failwith "number: fmod = -1  =>  heeeelp!" else
+     let _total_digits = (fmod lsr 16) land 0xFFFF
+     and after_point_digits_4 = fmod land 0xFFFF in
+     let scale = after_point_digits_4 - 4 in
+     (* let () = failwith "WC.number: str=%S, scale=%i" str scale in *)
      Decimal.of_string_scale str scale
   )
 ;
 value string_opt : ident -> uncomp_getter (option string)
 ;
 
+value number : ident -> uncomp_getter Decimal.t
+;
+
+value number_opt : ident -> uncomp_getter (option Decimal.t)
+;
+
+
       end
      =
       struct

src/dbi/decimal.ml

 ;
 
 
+module N
+ :
+  sig
+    value num_of_string_fix : string -> Num.num;
+  end
+ =
+  struct
+    module I = Iteratees.Make(Pure_IO);
+
+    module It_add
+     =
+      struct
+        open I
+        ;
+        open I.Ops
+        ;
+        module IO = It_IO
+        ;
+
+        value enum_string ?(chunk_size=4096) str =
+          let str_len = String.length str in
+          let arr_sz = min str_len chunk_size in
+          let arr = Array.make arr_sz '\x00' in
+          let fill_array ofs : int =
+            let ilen = min arr_sz (str_len - ofs) in
+            let imax = ilen - 1 in
+            ( for i = 0 to imax do
+                ( arr.(i) := str.[ofs + i]
+                )
+              done
+            ; ilen
+            )
+          in
+          inner 0
+          where rec inner ofs it =
+            match it with
+            [ IE_done _ | IE_cont (Some _) _ -> IO.return it
+            | IE_cont None k ->
+                let len = fill_array ofs in
+                if len = 0
+                then
+                  IO.return it
+                else
+                  k (Chunk (S.of_array_sub arr 0 len)) >>% fun (it, _s) ->
+                  inner (ofs + len) it
+            ]
+        ;
+
+        value test_enum_string : unit =
+         ignore (IO.runIO (
+          (enum_string ~chunk_size:3 "abcdef" (break_chars (fun _ -> False)))
+          >>% fun it ->
+          (I.run it)
+          >>% fun res -> (failwith "res=%s" res ; IO.return ())
+         ))
+        ;
+
+      end
+    ;
+
+    open It_add
+    ;
+
+(*
+    value read_num ;
+*)
+
+    value num_of_string_fix _ = raise Exit
+    ;
+
+  end
+;
+
+
 value of_string_scale str scale =
   let num =
     try
 ;
 
 
+value to_string n =
+  approx_num_fix n.scale n.num
+;
+
+
 value add = maxscale add_num
   and sub = maxscale sub_num
 ;

tests/test_http_service.ml

 
 module I = Iteratees.Make(IO);
 
+(*
+module II : sig exception EIO of (exn * It_Types.place); end = I;
+*)
+
 module S = Amall_http_service.Service(IO)(I);