Skip to content

Commit e7a78c5

Browse files
committed
Support 64-bit unsigned fields.
1 parent 61c1da2 commit e7a78c5

15 files changed

+259
-10
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ function.
203203
type value =
204204
[ `Int of int
205205
| `Int64 of Int64.t
206+
| `UInt64 of Unsigned.UInt64.t
206207
| `Float of float
207208
| `String of string
208209
| `Bytes of bytes
@@ -220,6 +221,7 @@ provided to extract the OCaml types directly from a field:
220221
```ocaml
221222
val int : Field.t -> int
222223
val int64 : Field.t -> Int64.t
224+
val uint64 : Field.t -> Unsigned.Int64.t
223225
val float : Field.t -> float
224226
val string : Field.t -> string
225227
val bytes : Field.t -> bytes
@@ -234,6 +236,7 @@ For nullable fields, the following analogous functions are also provided:
234236
```ocaml
235237
val int_opt : Field.t -> int option
236238
val int64_opt : Field.t -> Int64.t option
239+
val uint64_opt : Field.t -> Unsigned.UInt64.t option
237240
val float_opt : Field.t -> float option
238241
val string_opt : Field.t -> string option
239242
val bytes_opt : Field.t -> bytes option

_oasis

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,13 @@ Executable "blocking_stress_test"
172172
NativeOpt: -warn-error +1..45
173173
CompiledObject: best
174174
BuildDepends: mariadb
175+
176+
Executable "nonblocking_stress_test"
177+
Build$: flag(lwt)
178+
Install: false
179+
Path: examples/nonblocking
180+
MainIs: nonblocking_stress_test.ml
181+
ByteOpt: -warn-error +1..45
182+
NativeOpt: -warn-error +1..45
183+
CompiledObject: best
184+
BuildDepends: mariadb

_tags

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OASIS_START
2-
# DO NOT EDIT (digest: fc4f1def45cd9de0092739442e8a8081)
2+
# DO NOT EDIT (digest: a8014746fe4d0fecde6592853a3e34bc)
33
# Ignore VCS directories, you can use the same kind of rule outside
44
# OASIS_START/STOP if you want to exclude directories that contains
55
# useless stuff for the build process
@@ -159,4 +159,17 @@ true: annot, bin_annot
159159
<examples/blocking/*.ml{,i,y}>: package(unix)
160160
<examples/blocking/*.ml{,i,y}>: use_mariadb
161161
<examples/blocking/*.ml{,i,y}>: use_mariadb_bindings
162+
# Executable nonblocking_stress_test
163+
<examples/nonblocking/nonblocking_stress_test.{native,byte}>: oasis_executable_nonblocking_stress_test_byte
164+
<examples/nonblocking/*.ml{,i,y}>: oasis_executable_nonblocking_stress_test_byte
165+
<examples/nonblocking/nonblocking_stress_test.{native,byte}>: oasis_executable_nonblocking_stress_test_native
166+
<examples/nonblocking/*.ml{,i,y}>: oasis_executable_nonblocking_stress_test_native
167+
<examples/nonblocking/nonblocking_stress_test.{native,byte}>: package(ctypes.stubs)
168+
<examples/nonblocking/nonblocking_stress_test.{native,byte}>: package(unix)
169+
<examples/nonblocking/nonblocking_stress_test.{native,byte}>: use_mariadb
170+
<examples/nonblocking/nonblocking_stress_test.{native,byte}>: use_mariadb_bindings
171+
<examples/nonblocking/*.ml{,i,y}>: package(ctypes.stubs)
172+
<examples/nonblocking/*.ml{,i,y}>: package(unix)
173+
<examples/nonblocking/*.ml{,i,y}>: use_mariadb
174+
<examples/nonblocking/*.ml{,i,y}>: use_mariadb_bindings
162175
# OASIS_STOP

examples/async/nonblocking_async_example.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ let print_row row =
6767
match M.Field.value field with
6868
| `Int i -> printf "%d\n%!" i
6969
| `Int64 i -> printf "%Ld\n%!" i
70+
| `UInt64 i -> printf "%s\n%!" (Unsigned.UInt64.to_string i)
7071
| `Float x -> printf "%f\n%!" x
7172
| `String s -> printf "%s\n%!" s
7273
| `Bytes b -> printf "%s\n%!" (Caml_bytes.to_string b)

examples/blocking/blocking_example.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ let print_row row =
1818
match M.Field.value field with
1919
| `Int i -> printf "%d\n%!" i
2020
| `Int64 i -> printf "%Ld\n%!" i
21+
| `UInt64 i -> printf "%s\n%!" (Unsigned.UInt64.to_string i)
2122
| `Float x -> printf "%f\n%!" x
2223
| `String s -> printf "%s\n%!" s
2324
| `Bytes b -> printf "%s\n%!" (Bytes.to_string b)

examples/lwt/nonblocking_lwt_example.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ let print_row row =
5353
match M.Field.value field with
5454
| `Int i -> Lwt_io.printf "%d\n%!" i
5555
| `Int64 i -> Lwt_io.printf "%Ld\n%!" i
56+
| `UInt64 i -> Lwt_io.printf "%s\n%!" (Unsigned.UInt64.to_string i)
5657
| `Float x -> Lwt_io.printf "%f\n%!" x
5758
| `String s -> Lwt_io.printf "%s\n%!" s
5859
| `Bytes b -> Lwt_io.printf "%s\n%!" (Bytes.to_string b)

examples/nonblocking/nonblocking_stress_test.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module Make (W : Mariadb.Nonblocking.Wait) = struct
7070
| `Null -> "NULL"
7171
| `Int i -> sprintf "(%d : int)" i
7272
| `Int64 i -> sprintf "(%Ld : int64)" i
73+
| `UInt64 i -> sprintf "(x : uint64)"
7374
| `Float x -> sprintf "(%.8g : float)" x
7475
| `String s -> sprintf "(%S : string)" s
7576
| `Bytes s -> sprintf "(%S : bytes)" (Bytes.to_string s)
@@ -92,8 +93,12 @@ module Make (W : Mariadb.Nonblocking.Wait) = struct
9293
| `Int i, `Float x | `Float x, `Int i -> float_of_int i = x
9394
| `Int64 i, `Int x | `Int x, `Int64 i -> Int64.(equal i (of_int x))
9495
| `Int64 i, `Float x | `Float x, `Int64 i -> Int64.to_float i = x
96+
| `UInt64 i, `Int x | `Int x, `UInt64 i -> Unsigned.UInt64.(equal i (of_int x))
97+
| `UInt64 i, `Float x | `Float x, `UInt64 i -> Int64.to_float (Unsigned.UInt64.to_int64 i) = x
98+
| `UInt64 i, `Int64 x | `Int64 x, `UInt64 i -> Int64.equal (Unsigned.UInt64.to_int64 i) x
9599
| `Int _, _ | _, `Int _ -> false
96100
| `Int64 _, _ | _, `Int64 _ -> false
101+
| `UInt64 _, _ | _, `UInt64 _ -> false
97102
| `Float x, `Float x' -> equal_float x x'
98103
| `Float _, _ | _, `Float _ -> false
99104
| `String s, `String s' -> s = s'

examples/select/nonblocking_select_example.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ let print_row row =
5656
match M.Field.value field with
5757
| `Int i -> printf "%d\n%!" i
5858
| `Int64 i -> printf "%Ld\n%!" i
59+
| `UInt64 i -> printf "%s\n%!" (Unsigned.UInt64.to_string i)
5960
| `Float x -> printf "%f\n%!" x
6061
| `String s -> printf "%s\n%!" s
6162
| `Bytes b -> printf "%s\n%!" (Bytes.to_string b)

lib/common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ module Stmt = struct
340340
| `Null -> Bind.null b ~at
341341
| `Int i -> Bind.int b i ~at
342342
| `Int64 i -> Bind.int64 b i ~at
343-
| `UInt64 i -> Bind.int64 ~unsigned:true b i ~at
343+
| `UInt64 i -> Bind.int64 ~unsigned:true b (Unsigned.UInt64.to_int64 i) ~at
344344
| `Float x -> Bind.float b x ~at
345345
| `String s -> Bind.string b s ~at
346346
| `Bytes s -> Bind.blob b s ~at

lib/field.ml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type value =
66
[ `Null
77
| `Int of int
88
| `Int64 of Int64.t
9+
| `UInt64 of Unsigned.UInt64.t
910
| `Float of float
1011
| `String of string
1112
| `Bytes of bytes
@@ -82,7 +83,7 @@ let convert field typ unsigned =
8283
| `Short, false -> `Int (UInt.to_int (cast_to uint field))
8384
| (`Int24 | `Long), true -> `Int (UInt32.to_int (cast_to uint32_t field))
8485
| (`Int24 | `Long), false -> `Int (Int32.to_int (cast_to int32_t field))
85-
| `Long_long, true -> `Int64 (UInt64.to_int64 (cast_to uint64_t field))
86+
| `Long_long, true -> `UInt64 (cast_to uint64_t field)
8687
| `Long_long, false -> `Int64 (cast_to int64_t field)
8788
| `Float, _ -> `Float (cast_to float field)
8889
| `Double, _ -> `Float (cast_to double field)
@@ -108,7 +109,12 @@ let int field =
108109
let int64 field =
109110
match value field with
110111
| `Int64 i -> i
111-
| _ -> err field ~info:"an 64-bit integer"
112+
| _ -> err field ~info:"a 64-bit integer"
113+
114+
let uint64 field =
115+
match value field with
116+
| `UInt64 i -> i
117+
| _ -> err field ~info:"a 64-bit unsigned integer"
112118

113119
let float field =
114120
match value field with
@@ -142,6 +148,12 @@ let int64_opt field =
142148
| `Null -> None
143149
| _ -> err field ~info:"a nullable 64-bit integer"
144150

151+
let uint64_opt field =
152+
match value field with
153+
| `UInt64 i -> Some i
154+
| `Null -> None
155+
| _ -> err field ~info:"a nullable 64-bit unsigned integer"
156+
145157
let float_opt field =
146158
match value field with
147159
| `Float x -> Some x

0 commit comments

Comments
 (0)