Commits

Anonymous committed c650c64

dbi: result: + '#iter_t : array sql_t -> unit'

Comments (0)

Files changed (1)

src/dbi/dbi_pg.ml

       ]
     ;
 
+    value int32 str =
+      try
+        Int32.of_string str
+      with
+      [ Failure "int_of_string" -> raise (Etype "int32" str)
+      ]
+    ;
+
+    value int ty str =
+      try
+        int_of_string str
+      with
+      [ Failure "int_of_string" -> raise (Etype ty str)
+      ]
+    ;
+
     value bool str =
       match str with
       [ "t" -> True
 
 
 
-
 (*
 value (sql_t : record -> ~col:int -> sql_t) record ~col =
   let pres = record.rres in
     ;
 
 
+    method iter_t : (array sql_t -> unit) -> unit = fun f ->
+      let ntup = presult#ntuples in
+      if ntup = 0
+      then
+        ()
+      else
+        let nfields = presult#nfields in
+        let mappers = Array.init nfields
+          (fun i ->
+             match presult#ftype i with
+             [ P.BYTEA -> fun x -> `Binary x
+             | P.CHAR
+             | P.TEXT
+             | P.NAME
+             | P.VARCHAR
+                 -> fun x -> `String x
+             | P.INT8 -> fun x -> `Int64 (G.int64 x)
+             | P.INT2 -> fun x -> `Int (G.int "int2" x)
+             | P.INT4 -> fun x -> `Int32 (G.int32 x)
+             | P.NUMERIC ->
+                 let f = G.number presult ~col:i
+                 in fun x -> `Num (f x)
+             | P.DATE -> fun x -> `Date x
+             | P.TIME -> fun x -> `Time x
+             | P.TIMESTAMP -> fun x -> `Timestamp x
+             | P.TIMESTAMPTZ -> fun x -> `TimestampTZ x
+             | P.TIMETZ -> fun x -> `TimeTZ x
+             | P.BOOL -> fun x -> `Bool (G.bool x)
+
+             | P.FLOAT8
+             | P.INT2VECTOR
+             | P.REGPROC
+             | P.OID
+             | P.TID
+             | P.XID
+             | P.CID
+             | P.OIDVECTOR
+             | P.POINT
+             | P.LSEG
+             | P.PATH
+             | P.BOX
+             | P.POLYGON
+             | P.LINE
+             | P.FLOAT4
+             | P.ABSTIME
+             | P.RELTIME
+             | P.TINTERVAL
+             | P.UNKNOWN
+             | P.CIRCLE
+             | P.CASH
+             | P.MACADDR
+             | P.INET
+             | P.CIDR
+             | P.ACLITEM
+             | P.BPCHAR
+             | P.INTERVAL
+             | P.BIT
+             | P.VARBIT
+             | P.ANYELEMENT
+             | P.OPAQUE
+             | P.INTERNAL
+             | P.LANGUAGE_HANDLER
+             | P.TRIGGER
+             | P.VOID
+             | P.ANYARRAY
+             | P.ANY
+             | P.CSTRING
+             | P.RECORD
+             | P.REGTYPE
+             | P.REGCLASS
+             | P.REGOPERATOR
+             | P.REGOPER
+             | P.REGPROCEDURE
+             | P.REFCURSOR
+                 as ftype
+                 -> raise & error_type_not_sup & P.string_of_ftype ftype
+             ]
+          )
+        in
+        let getvalue = presult#getvalue
+        and getisnull = presult#getisnull
+        in
+        let rec inner i =
+          if i = ntup
+          then ()
+          else
+            let record = Array.mapi
+              (fun j mapper ->
+                 if getisnull i j
+                 then `Null
+                 else mapper (getvalue i j)
+              )
+              mappers
+            in
+            let () = f record in
+            inner (i + 1)
+        in
+          inner 0
+    ;
+
+
 (*
     method fetchall_array () : array (array sql_t) = [| [|  |] |];
     method fetchall_list () : list (array sql_t) = [ [| |] ];
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.