From fc017a0133012e801714a99ed6098d7e3b6b7e3a Mon Sep 17 00:00:00 2001 From: ygrek Date: Thu, 3 Sep 2009 16:45:52 +0300 Subject: [PATCH] sqlgg_mysql - functor over Number --- demo/demo_caml_mysql.ml | 2 +- impl/sqlgg_mysql.ml | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/demo/demo_caml_mysql.ml b/demo/demo_caml_mysql.ml index 9d2c575..ca6e93f 100644 --- a/demo/demo_caml_mysql.ml +++ b/demo/demo_caml_mysql.ml @@ -2,7 +2,7 @@ open Printf module M = Mysql -module G = Demo_caml_gen_mysql.Sqlgg(Sqlgg_mysql) +module G = Demo_caml_gen_mysql.Sqlgg(Sqlgg_mysql.Make(Int64)) let main () = let db = M.quick_connect ~database:"test" ~user:"root" () in diff --git a/impl/sqlgg_mysql.ml b/impl/sqlgg_mysql.ml index 370fe32..e184153 100644 --- a/impl/sqlgg_mysql.ml +++ b/impl/sqlgg_mysql.ml @@ -5,13 +5,15 @@ open Printf module M = Mysql module P = Mysql.P +module Make(Number : sig type t val of_string : string -> t val to_string : t -> string end) = struct + type statement = P.stmt type connection = M.dbd type params = statement * string array type row = string option array type result = P.result -type num = int64 +type num = Number.t type text = string type any = string @@ -21,7 +23,7 @@ let opt = function Some x -> x | None -> failwith "opt" let get_column_Int row index = try - Int64.of_string (opt (row.(index))) + Number.of_string (opt (row.(index))) with e -> oops "get_column_Int %i (%s)" index (Printexc.to_string e) @@ -44,7 +46,7 @@ let finish_params (stmt,params) = P.execute stmt params let set_param_Text stmt index v = bind_param (Some v) stmt index let set_param_null stmt index = bind_param None stmt index let set_param_Any = set_param_Text -let set_param_Int stmt index v = bind_param (Some (Int64.to_string v)) stmt index +let set_param_Int stmt index v = bind_param (Some (Number.to_string v)) stmt index let no_params stmt = P.execute stmt [||] @@ -79,3 +81,5 @@ let select1 db sql set_params callback = | Some row -> Some (callback row) | None -> None) +end + -- 2.11.4.GIT