Skip to content

Commit 00ceb86

Browse files
allow subquery values in insert_all (#137)
1 parent 4378ca8 commit 00ceb86

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/ecto/adapters/sqlite3/connection.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,9 @@ defmodule Ecto.Adapters.SQLite3.Connection do
799799
raise ArgumentError,
800800
"Cell-wise default values are not supported on INSERT statements by SQLite3"
801801

802+
{%Ecto.Query{} = query, params_counter}, counter ->
803+
{[?(, all(query), ?)], counter + params_counter}
804+
802805
_, counter ->
803806
# TODO: Should we have cell wise value support?
804807
# Essentially ``?1 ?2 ?3`` instead of ``? ? ?``

test/ecto/integration/crud_test.exs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,20 @@ defmodule Ecto.Integration.CrudTest do
5252
end
5353

5454
test "insert_all" do
55+
TestRepo.insert!(%User{name: "John"}, [])
5556
timestamp = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
57+
# doing this a weird way to test multiple query parameters
58+
name_query =
59+
from(u in User, where: u.name == ^"John" and ^true, select: u.name)
5660

5761
account = %{
58-
name: "John",
62+
name: name_query,
5963
inserted_at: timestamp,
6064
updated_at: timestamp
6165
}
6266

6367
{1, nil} = TestRepo.insert_all(Account, [account], [])
68+
%{name: "John"} = TestRepo.one(Account)
6469
end
6570
end
6671

0 commit comments

Comments
 (0)