Commits

Anonymous committed ac28470

dbi: Af/getters refactoring

Comments (0)

Files changed (1)

src/dbi/dbi_pg.ml

 *)
 
 
+module G
+ =
+  struct
+
+    value string x = x
+    ;
+
+    value number pres ~col =
+      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 *)
+      fun str -> Decimal.of_string_scale str scale
+    ;
+
+    value int64 str =
+      try
+        Int64.of_string str
+      with
+      [ Failure "int_of_string" -> raise (Etype "int64" str)
+      ]
+    ;
+
+    value bool str =
+      match str with
+      [ "t" -> True
+      | "f" -> False
+      | _ -> failwith "Dbi_pg: expected bool (t/f), found %S" str
+      ]
+    ;
+
+  end
+;
+
+
 module C
  :
   sig
     ;
 
     value get_as_string pres ~row ~col =
-      pres#getvalue row col
+      G.string (pres#getvalue row col)
     ;
 
     value string = common
     value number = common
       ~want_ftype:"number (numeric, decimal)"
       (fun pres ~row ~col ->
-         let str = pres#getvalue row col 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
+         G.number pres ~col (pres#getvalue row col)
       )
     ;
 
     value int64 = common
       ~want_ftype:"int64 (bigint, bigserial)"
       (fun pres ~row ~col ->
-         let str = pres#getvalue row col in
-         try
-           Int64.of_string str
-         with
-         [ Failure "int_of_string" -> raise (Etype "int64" str)
-         ]
+         G.int64 (pres#getvalue row col)
       )
     ;
 
     value bool = common
       ~want_ftype:"boolean"
       (fun pres ~row ~col ->
-         let str = pres#getvalue row col in
-         match str with
-         [ "t" -> True
-         | "f" -> False
-         | _ -> failwith "Dbi_pg: expected bool (t/f), found %S" str
-         ]
+         G.bool (pres#getvalue row col)
       )
     ;