@@ -252,7 +252,7 @@ defmodule Sqlite.Ecto.Test do
252
252
test "distinct" do
253
253
assert_raise ArgumentError , "DISTINCT with multiple columns is not supported by SQLite" , fn ->
254
254
query = Model |> distinct ( [ r ] , r . x ) |> select ( [ r ] , { r . x , r . y } ) |> normalize
255
- assert SQL . all ( query )
255
+ SQL . all ( query )
256
256
end
257
257
258
258
query = Model |> distinct ( [ r ] , true ) |> select ( [ r ] , { r . x , r . y } ) |> normalize
@@ -298,7 +298,7 @@ defmodule Sqlite.Ecto.Test do
298
298
test "lock" do
299
299
assert_raise ArgumentError , "locks are not supported by SQLite" , fn ->
300
300
query = Model |> lock ( "FOR SHARE NOWAIT" ) |> select ( [ ] , 0 ) |> normalize
301
- assert SQL . all ( query )
301
+ SQL . all ( query )
302
302
end
303
303
end
304
304
@@ -370,15 +370,15 @@ defmodule Sqlite.Ecto.Test do
370
370
test "tagged type" do
371
371
assert_raise ArgumentError , "UUID is not supported by SQLite" , fn ->
372
372
query = Model |> select ( [ ] , type ( ^ << 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 >> , :uuid ) ) |> normalize
373
- assert SQL . all ( query )
373
+ SQL . all ( query )
374
374
end
375
375
376
376
query = Model |> select ( [ ] , type ( ^ 1 , :float ) ) |> normalize
377
377
assert SQL . all ( query ) == ~s{ SELECT CAST ( ? AS NUMERIC ) FROM "model" AS m0}
378
378
379
379
assert_raise ArgumentError , "Array type is not supported by SQLite" , fn ->
380
380
query = Model |> select ( [ ] , type ( ^ [ 1 , 2 , 3 ] , { :array , :integer } ) ) |> normalize
381
- assert SQL . all ( query )
381
+ SQL . all ( query )
382
382
end
383
383
end
384
384
@@ -510,7 +510,7 @@ defmodule Sqlite.Ecto.Test do
510
510
assert SQL . update_all ( query , [ x: 0 ] ) == ~s{ UPDATE "model" SET "x" = 0}
511
511
512
512
query = from ( e in Model , where: e . x == 123 ) |> normalize
513
- assert SQL . update_all ( query , [ x: 0 ] ) == ~s{ UPDATE "model" SET "x" = 0 WHERE ( "x" = 123 )}
513
+ assert SQL . update_all ( query , [ x: 0 ] ) == ~s{ UPDATE "model" SET "x" = 0 WHERE ( "model"." x" = 123 )}
514
514
515
515
query = Model |> Queryable . to_query |> normalize
516
516
assert SQL . update_all ( query , [ x: 0 , y: "123" ] ) == ~s{ UPDATE "model" SET "x" = 0, "y" = '123'}
@@ -520,24 +520,33 @@ defmodule Sqlite.Ecto.Test do
520
520
521
521
assert_raise ArgumentError , "JOINS are not supported on UPDATE statements by SQLite" , fn ->
522
522
query = Model |> join ( :inner , [ p ] , q in Model2 , p . x == q . z ) |> normalize
523
- assert SQL . update_all ( query , [ x: 0 ] )
523
+ SQL . update_all ( query , [ x: 0 ] )
524
524
end
525
525
end
526
526
527
- # test "delete all" do
528
- # query = Model |> Queryable.to_query |> normalize
529
- # assert SQL.delete_all(query) == ~s{DELETE FROM "model" AS m0}
530
- #
531
- # query = from(e in Model, where: e.x == 123) |> normalize
532
- # assert SQL.delete_all(query) ==
533
- # ~s{DELETE FROM "model" AS m0 WHERE (m0."x" = 123)}
534
- #
527
+ test "delete all" do
528
+ query = Model |> Queryable . to_query |> normalize
529
+ assert SQL . delete_all ( query ) == ~s{ DELETE FROM "model"}
530
+
531
+ query = from ( e in Model , where: e . x == 123 ) |> normalize
532
+ assert SQL . delete_all ( query ) == ~s{ DELETE FROM "model" WHERE ( "model"."x" = 123 )}
533
+
534
+ assert_raise ArgumentError , "JOINS are not supported on DELETE statements by SQLite" , fn ->
535
+ query = Model |> join ( :inner , [ p ] , q in Model2 , p . x == q . z ) |> normalize
536
+ SQL . delete_all ( query )
537
+ end
538
+
539
+ # The assertions commented out below represent how joins *could* be
540
+ # handled in SQLite to produce the same effect. Evenually, joins should
541
+ # be converted to the below output. Until then, joins should raise
542
+ # exceptions.
543
+
535
544
# query = Model |> join(:inner, [p], q in Model2, p.x == q.z) |> normalize
536
- # assert SQL.delete_all(query) ==
537
- # ~s{DELETE FROM "model" AS m0 USING "model2" AS m1 WHERE m0 ."x" = m1."z"}
545
+ # # assert SQL.delete_all(query) == ~s{DELETE FROM "model" AS m0 USING "model2" AS m1 WHERE m0."x" = m1."z"}
546
+ # assert SQL.delete_all(query) == ~s{DELETE FROM "model" WHERE "model" ."x" IN ( SELECT m1."z" FROM "model2" AS m1 ) }
538
547
#
539
548
# query = from(e in Model, where: e.x == 123, join: q in Model2, on: e.x == q.z) |> normalize
540
- # assert SQL.delete_all(query) ==
541
- # ~s{DELETE FROM "model" AS m0 USING "model2" AS m1 WHERE m0 ."x" = m1."z" AND (m0 ."x" = 123)}
542
- # end
549
+ # # assert SQL.delete_all(query) == ~s{DELETE FROM "model" AS m0 USING "model2" AS m1 WHERE m0."x" = m1."z" AND (m0."x" = 123)}
550
+ # assert SQL.delete_all(query) == ~s{DELETE FROM "model" WHERE "model" ."x" IN ( SELECT m1."z" FROM "model2" AS m1 ) AND ( "model" ."x" = 123 )}
551
+ end
543
552
end
0 commit comments