-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow MyXQL to specify
:prepare
per operation. (#650)
- Loading branch information
1 parent
6345716
commit 802914d
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
defmodule Ecto.Integration.PrepareTest do | ||
use Ecto.Integration.Case, async: false | ||
|
||
import Ecto.Query, only: [from: 2] | ||
|
||
alias Ecto.Integration.TestRepo | ||
alias Ecto.Integration.Post | ||
|
||
test "prepare option" do | ||
TestRepo.insert!(%Post{title: "one"}) | ||
|
||
query = from p in Post, select: fragment("'mxql test prepare option'") | ||
stmt_count_query = "SHOW GLOBAL STATUS LIKE '%prepared_stmt_count%'" | ||
|
||
%{rows: [[_, orig_count]]} = TestRepo.query!(stmt_count_query, []) | ||
orig_count = String.to_integer(orig_count) | ||
|
||
# Uncached | ||
assert TestRepo.all(query, prepare: :unnamed) == ["mxql test prepare option"] | ||
%{rows: [[_, new_count]]} = TestRepo.query!(stmt_count_query, []) | ||
assert String.to_integer(new_count) == orig_count | ||
|
||
assert TestRepo.all(query, prepare: :named) == ["mxql test prepare option"] | ||
assert %{rows: [[_, new_count]]} = TestRepo.query!(stmt_count_query, []) | ||
assert String.to_integer(new_count) == orig_count + 1 | ||
|
||
# Cached | ||
assert TestRepo.all(query, prepare: :unnamed) == ["mxql test prepare option"] | ||
assert %{rows: [[_, new_count]]} = TestRepo.query!(stmt_count_query, []) | ||
assert String.to_integer(new_count) == orig_count + 1 | ||
|
||
assert TestRepo.all(query, prepare: :named) == ["mxql test prepare option"] | ||
assert %{rows: [[_, new_count]]} = TestRepo.query!(stmt_count_query, []) | ||
assert String.to_integer(new_count) == orig_count + 1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters