Skip to content

Commit 7882a01

Browse files
authored
remove duplicate execute_ddl, @impl true, table prefixes (#103)
1 parent 6dcc0b2 commit 7882a01

File tree

3 files changed

+62
-199
lines changed

3 files changed

+62
-199
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This is a breaking change in the sense that rebuilding the schema from scratch w
1919

2020
We kept `TEXT_DATETIME` to satisfy the old Ecto2 implementation to keep backwards compatibility.
2121

22+
- **breaking**: raise when table prefixes are used. [#103](https://github.com/elixir-sqlite/ecto_sqlite3/pull/103)
2223

2324
## v0.9.1 - 2022-12-21
2425
- changed: Use `Connection.connect` instead of `Sqlite3.open`. [#96](https://github.com/elixir-sqlite/ecto_sqlite3/pull/96)

lib/ecto/adapters/sqlite3/connection.ex

Lines changed: 6 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ defmodule Ecto.Adapters.SQLite3.Connection do
5454
DBConnection.execute(conn, cached, params, options)
5555
end
5656

57-
@impl true
5857
def execute(
5958
conn,
6059
%Exqlite.Query{statement: statement, ref: nil},
@@ -64,7 +63,6 @@ defmodule Ecto.Adapters.SQLite3.Connection do
6463
execute(conn, statement, params, options)
6564
end
6665

67-
@impl true
6866
def execute(conn, sql, params, options) when is_binary(sql) or is_list(sql) do
6967
query = Exqlite.Query.build(name: "", statement: IO.iodata_to_binary(sql))
7068

@@ -75,7 +73,6 @@ defmodule Ecto.Adapters.SQLite3.Connection do
7573
end
7674
end
7775

78-
@impl true
7976
def execute(conn, query, params, options) do
8077
case DBConnection.execute(conn, query, params, options) do
8178
{:ok, _} = ok -> ok
@@ -163,7 +160,6 @@ defmodule Ecto.Adapters.SQLite3.Connection do
163160
raise ArgumentError, "locks are not supported by SQLite3"
164161
end
165162

166-
@impl true
167163
def all(query, as_prefix \\ []) do
168164
sources = create_names(query, as_prefix)
169165

@@ -233,7 +229,6 @@ defmodule Ecto.Adapters.SQLite3.Connection do
233229
raise ArgumentError, "JOINS are not supported on DELETE statements by SQLite"
234230
end
235231

236-
@impl true
237232
def delete_all(query) do
238233
sources = create_names(query, [])
239234
cte = cte(query, sources)
@@ -261,7 +256,6 @@ defmodule Ecto.Adapters.SQLite3.Connection do
261256
]
262257
end
263258

264-
@impl true
265259
def insert(prefix, table, header, rows, on_conflict, returning, _placeholders) do
266260
fields = quote_names(header)
267261

@@ -375,7 +369,6 @@ defmodule Ecto.Adapters.SQLite3.Connection do
375369
raise ArgumentError, "SQLite3 adapter does not support keyword lists in :options"
376370
end
377371

378-
@impl true
379372
def execute_ddl({:create, %Table{} = table, columns}) do
380373
{table, composite_pk_def} = composite_pk_definition(table, columns)
381374
composite_fk_defs = composite_fk_definitions(table, columns)
@@ -395,7 +388,6 @@ defmodule Ecto.Adapters.SQLite3.Connection do
395388
]
396389
end
397390

398-
@impl true
399391
def execute_ddl({:create_if_not_exists, %Table{} = table, columns}) do
400392
{table, composite_pk_def} = composite_pk_definition(table, columns)
401393
composite_fk_defs = composite_fk_definitions(table, columns)
@@ -415,7 +407,6 @@ defmodule Ecto.Adapters.SQLite3.Connection do
415407
]
416408
end
417409

418-
@impl true
419410
def execute_ddl({:drop, %Table{} = table}) do
420411
[
421412
[
@@ -425,12 +416,10 @@ defmodule Ecto.Adapters.SQLite3.Connection do
425416
]
426417
end
427418

428-
@impl true
429419
def execute_ddl({:drop, %Table{} = table, _mode}) do
430420
execute_ddl({:drop, table})
431421
end
432422

433-
@impl true
434423
def execute_ddl({:drop_if_exists, %Table{} = table}) do
435424
[
436425
[
@@ -440,12 +429,10 @@ defmodule Ecto.Adapters.SQLite3.Connection do
440429
]
441430
end
442431

443-
@impl true
444432
def execute_ddl({:drop_if_exists, %Table{} = table, _mode}) do
445433
execute_ddl({:drop_if_exists, table})
446434
end
447435

448-
@impl true
449436
def execute_ddl({:alter, %Table{} = table, changes}) do
450437
Enum.map(changes, fn change ->
451438
[
@@ -457,111 +444,6 @@ defmodule Ecto.Adapters.SQLite3.Connection do
457444
end)
458445
end
459446

460-
@impl true
461-
def execute_ddl({:create, %Index{} = index}) do
462-
fields = intersperse_map(index.columns, ", ", &index_expr/1)
463-
464-
[
465-
[
466-
"CREATE ",
467-
if_do(index.unique, "UNIQUE "),
468-
"INDEX ",
469-
quote_name(index.name),
470-
" ON ",
471-
quote_table(index.prefix, index.table),
472-
" (",
473-
fields,
474-
?),
475-
if_do(index.where, [" WHERE ", to_string(index.where)])
476-
]
477-
]
478-
end
479-
480-
@impl true
481-
def execute_ddl({:create_if_not_exists, %Index{} = index}) do
482-
fields = intersperse_map(index.columns, ", ", &index_expr/1)
483-
484-
[
485-
[
486-
"CREATE ",
487-
if_do(index.unique, "UNIQUE "),
488-
"INDEX IF NOT EXISTS ",
489-
quote_name(index.name),
490-
" ON ",
491-
quote_table(index.prefix, index.table),
492-
" (",
493-
fields,
494-
?),
495-
if_do(index.where, [" WHERE ", to_string(index.where)])
496-
]
497-
]
498-
end
499-
500-
@impl true
501-
def execute_ddl({:drop, %Index{} = index}) do
502-
[
503-
[
504-
"DROP INDEX ",
505-
quote_table(index.prefix, index.name)
506-
]
507-
]
508-
end
509-
510-
@impl true
511-
def execute_ddl({:drop, %Index{} = index, _mode}) do
512-
execute_ddl({:drop, index})
513-
end
514-
515-
@impl true
516-
def execute_ddl({:drop_if_exists, %Index{} = index}) do
517-
[
518-
[
519-
"DROP INDEX IF EXISTS ",
520-
quote_table(index.prefix, index.name)
521-
]
522-
]
523-
end
524-
525-
@impl true
526-
def execute_ddl({:drop_if_exists, %Index{} = index, _mode}) do
527-
execute_ddl({:drop_if_exists, index})
528-
end
529-
530-
@impl true
531-
def execute_ddl({:rename, %Table{} = current_table, %Table{} = new_table}) do
532-
[
533-
[
534-
"ALTER TABLE ",
535-
quote_table(current_table.prefix, current_table.name),
536-
" RENAME TO ",
537-
quote_table(nil, new_table.name)
538-
]
539-
]
540-
end
541-
542-
@impl true
543-
def execute_ddl({:rename, %Table{} = current_table, old_col, new_col}) do
544-
[
545-
[
546-
"ALTER TABLE ",
547-
quote_table(current_table.prefix, current_table.name),
548-
" RENAME COLUMN ",
549-
quote_name(old_col),
550-
" TO ",
551-
quote_name(new_col)
552-
]
553-
]
554-
end
555-
556-
@impl true
557-
def execute_ddl(string) when is_binary(string), do: [string]
558-
559-
@impl true
560-
def execute_ddl(keyword) when is_list(keyword) do
561-
raise ArgumentError, "SQLite3 adapter does not support keyword lists in execute"
562-
end
563-
564-
@impl true
565447
def execute_ddl({:create, %Index{} = index}) do
566448
fields = intersperse_map(index.columns, ", ", &index_expr/1)
567449

@@ -574,16 +456,14 @@ defmodule Ecto.Adapters.SQLite3.Connection do
574456
quote_name(index.name),
575457
" ON ",
576458
quote_table(index.prefix, index.table),
577-
?\s,
578-
?(,
459+
" (",
579460
fields,
580461
?),
581462
if_do(index.where, [" WHERE ", to_string(index.where)])
582463
]
583464
]
584465
end
585466

586-
@impl true
587467
def execute_ddl({:create_if_not_exists, %Index{} = index}) do
588468
fields = intersperse_map(index.columns, ", ", &index_expr/1)
589469

@@ -596,21 +476,18 @@ defmodule Ecto.Adapters.SQLite3.Connection do
596476
quote_name(index.name),
597477
" ON ",
598478
quote_table(index.prefix, index.table),
599-
?\s,
600-
?(,
479+
" (",
601480
fields,
602481
?),
603482
if_do(index.where, [" WHERE ", to_string(index.where)])
604483
]
605484
]
606485
end
607486

608-
@impl true
609487
def execute_ddl({:create, %Constraint{}}) do
610488
raise ArgumentError, "SQLite3 does not support ALTER TABLE ADD CONSTRAINT."
611489
end
612490

613-
@impl true
614491
def execute_ddl({:drop, %Index{} = index}) do
615492
[
616493
[
@@ -620,12 +497,10 @@ defmodule Ecto.Adapters.SQLite3.Connection do
620497
]
621498
end
622499

623-
@impl true
624500
def execute_ddl({:drop, %Index{} = index, _mode}) do
625501
execute_ddl({:drop, index})
626502
end
627503

628-
@impl true
629504
def execute_ddl({:drop_if_exists, %Index{} = index}) do
630505
[
631506
[
@@ -635,22 +510,18 @@ defmodule Ecto.Adapters.SQLite3.Connection do
635510
]
636511
end
637512

638-
@impl true
639513
def execute_ddl({:drop_if_exists, %Index{} = index, _mode}) do
640514
execute_ddl({:drop_if_exists, index})
641515
end
642516

643-
@impl true
644517
def execute_ddl({:drop, %Constraint{}, _mode}) do
645518
raise ArgumentError, "SQLite3 does not support ALTER TABLE DROP CONSTRAINT."
646519
end
647520

648-
@impl true
649521
def execute_ddl({:drop_if_exists, %Constraint{}, _mode}) do
650522
raise ArgumentError, "SQLite3 does not support ALTER TABLE DROP CONSTRAINT."
651523
end
652524

653-
@impl true
654525
def execute_ddl({:rename, %Table{} = current_table, %Table{} = new_table}) do
655526
[
656527
[
@@ -662,7 +533,6 @@ defmodule Ecto.Adapters.SQLite3.Connection do
662533
]
663534
end
664535

665-
@impl true
666536
def execute_ddl({:rename, %Table{} = table, current_column, new_column}) do
667537
[
668538
[
@@ -676,10 +546,8 @@ defmodule Ecto.Adapters.SQLite3.Connection do
676546
]
677547
end
678548

679-
@impl true
680549
def execute_ddl(string) when is_binary(string), do: [string]
681550

682-
@impl true
683551
def execute_ddl(keyword) when is_list(keyword) do
684552
raise ArgumentError, "SQLite3 adapter does not support keyword lists in execute"
685553
end
@@ -1799,7 +1667,10 @@ defmodule Ecto.Adapters.SQLite3.Connection do
17991667
def quote_table(table), do: quote_entity(table)
18001668

18011669
defp quote_table(nil, name), do: quote_entity(name)
1802-
defp quote_table(prefix, name), do: [quote_entity(prefix), ?., quote_entity(name)]
1670+
1671+
defp quote_table(_prefix, _name) do
1672+
raise ArgumentError, "SQLite3 does not support table prefixes"
1673+
end
18031674

18041675
defp quote_entity(val) when is_atom(val) do
18051676
quote_entity(Atom.to_string(val))

0 commit comments

Comments
 (0)