From 23ee4a612fc1bf45d1dae8744aa3087df68622e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Sat, 14 May 2022 14:42:37 -0400 Subject: [PATCH 1/2] fix: Fix bad error when creating a table with option --- lib/ecto/adapters/sqlite3/connection.ex | 4 ++-- test/ecto/adapters/sqlite3/connection_test.exs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ecto/adapters/sqlite3/connection.ex b/lib/ecto/adapters/sqlite3/connection.ex index 2b84480..f0949fb 100644 --- a/lib/ecto/adapters/sqlite3/connection.ex +++ b/lib/ecto/adapters/sqlite3/connection.ex @@ -333,7 +333,7 @@ defmodule Ecto.Adapters.SQLite3.Connection do ## @impl true - def execute_ddl({_command, %Table{options: keyword}, _}) when keyword != nil do + def execute_ddl({_command, %Table{options: options}, _}) when is_list(options) do raise ArgumentError, "SQLite3 adapter does not support keyword lists in :options" end @@ -1624,7 +1624,7 @@ defmodule Ecto.Adapters.SQLite3.Connection do defp options_expr(nil), do: [] - defp options_expr(keyword) when is_list(keyword) do + defp options_expr(options) when is_list(options) do raise ArgumentError, "SQLite3 adapter does not support keyword lists in :options" end diff --git a/test/ecto/adapters/sqlite3/connection_test.exs b/test/ecto/adapters/sqlite3/connection_test.exs index 8f2409f..5c218b5 100644 --- a/test/ecto/adapters/sqlite3/connection_test.exs +++ b/test/ecto/adapters/sqlite3/connection_test.exs @@ -2232,12 +2232,12 @@ defmodule Ecto.Adapters.SQLite3.ConnectionTest do ] end - test "create table with options" do + test "create table with list as options" do assert_raise( ArgumentError, "SQLite3 adapter does not support keyword lists in :options", fn -> - {:create, table(:posts, options: "WITH FOO=BAR"), + {:create, table(:posts, options: ["WITH FOO=BAR"]), [{:add, :id, :serial, [primary_key: true]}, {:add, :created_at, :datetime, []}]} |> execute_ddl() end From f785f40e2b6f42ffe7ad7e2f7727bad1e6256cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20L=C3=A9vesque?= Date: Sat, 14 May 2022 14:48:27 -0400 Subject: [PATCH 2/2] test: Add test for succesful options usage --- test/ecto/adapters/sqlite3/connection_test.exs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/ecto/adapters/sqlite3/connection_test.exs b/test/ecto/adapters/sqlite3/connection_test.exs index 5c218b5..32af2c3 100644 --- a/test/ecto/adapters/sqlite3/connection_test.exs +++ b/test/ecto/adapters/sqlite3/connection_test.exs @@ -2232,6 +2232,23 @@ defmodule Ecto.Adapters.SQLite3.ConnectionTest do ] end + test "create table with options" do + create = + {:create, table(:posts, options: "WITH FOO=BAR"), + [ + {:add, :id, :serial, [primary_key: true]} + ]} + + assert execute_ddl(create) == [ + """ + CREATE TABLE "posts" (\ + "id" INTEGER PRIMARY KEY AUTOINCREMENT\ + ) \ + WITH FOO=BAR\ + """ + ] + end + test "create table with list as options" do assert_raise( ArgumentError,