Skip to content

Commit 924e596

Browse files
committed
fix optional param in update stmt
1 parent 8320824 commit 924e596

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

lib/sql.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ module Source_type = struct
548548
end
549549

550550
type 't param = { id : param_id; typ : 't; } [@@deriving show, make]
551-
type option_actions_kind = BoolChoices | SetDefault [@@deriving show]
551+
type option_actions_kind = BoolChoices | SetDefault | SetSelf of string [@@deriving show]
552552
type params = Type.t param list [@@deriving show]
553553
type in_or_not_in = [`In | `NotIn] [@@deriving show]
554554
type ctor =

lib/syntax.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ let resolve_column_assignments ~env l =
257257
let l_with_meta = List.map (fun (n,e) -> n, Option.map (set_param_meta ~env col) e) l in
258258
Choices (n, List.map (fun (n,e) -> n, Option.map (equality typ) e) l_with_meta)
259259
| RegularExpr (OptionActions ch) ->
260-
OptionActions { ch with choice = (equality typ) ch.choice } (* FIXME hack, should propagate properly *)
260+
OptionActions { ch with choice = (equality typ) ch.choice; kind = SetSelf col.cname }
261261
| RegularExpr expr -> equality typ (set_param_meta ~env col expr)
262262
| WithDefaultParam (e, pos) -> with_default @@ OptionActions { choice = equality typ (set_param_meta ~env col e); pos; kind = SetDefault }
263263
| AssignDefault -> with_default @@ (Value typ)

src/gen.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ let substitute_vars s vars subst_param =
156156
let args = Some(vars) in
157157
{ctor; args; sql; is_poly=false} in
158158
let n =
159-
let sql = Static (match kind with | BoolChoices -> " TRUE " | SetDefault -> " DEFAULT ") in
159+
let sql = Static (match kind with | BoolChoices -> " TRUE " | SetDefault -> " DEFAULT " | SetSelf col -> " " ^ col ^ " ") in
160160
let ctor = Sql.{ value=Some("None"); pos=(0, 0); } in
161161
let args = None in
162162
{ctor; args; sql=[sql]; is_poly=false} in

test/cram/test.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3468,6 +3468,6 @@ optional parameter in UPDATE:
34683468
T.set_param_Int p id;
34693469
T.finish_params p
34703470
in
3471-
T.execute db ("UPDATE products SET stock = " ^ (match stock with Some _ -> " ( " ^ " " ^ "?" ^ " " ^ " ) " | None -> " TRUE ") ^ " WHERE id = ?") set_params
3471+
T.execute db ("UPDATE products SET stock = " ^ (match stock with Some _ -> " ( " ^ " " ^ "?" ^ " " ^ " ) " | None -> " stock ") ^ " WHERE id = ?") set_params
34723472
34733473
end (* module Sqlgg *)

0 commit comments

Comments
 (0)