Skip to content

Commit

Permalink
more line comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Nov 7, 2024
1 parent ee54548 commit b1c3ba4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/ecto/adapters/clickhouse/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,9 @@ defmodule Ecto.Adapters.ClickHouse.Connection do
end

extract_statements_quotes = %{
# https://clickhouse.com/docs/en/sql-reference/syntax#string
"single_quote" => ?',
# https://clickhouse.com/docs/en/sql-reference/syntax#keywords
"double_quote" => ?",
"backtick" => ?`
}
Expand Down Expand Up @@ -1233,23 +1235,24 @@ defmodule Ecto.Adapters.ClickHouse.Connection do
end
end

# https://clickhouse.com/docs/en/sql-reference/syntax#comments
extract_statements_line_comments = [
{_starts_with = "--", _ends_with = ?\n}
"--",
?#
]

# ... and we ignore semicolons in line comments ...
for {started, ended} <- extract_statements_line_comments do
start_length = IO.iodata_length([started])
end_length = IO.iodata_length([ended])
for pattern <- extract_statements_line_comments do
pattern_len = IO.iodata_length([pattern])

# line comment begins
defp extract_statements(<<unquote(started), rest::bytes>>, from, len, og, acc) do
extract_statements_exit_line_comment(rest, from, len + unquote(start_length), og, acc)
defp extract_statements(<<unquote(pattern), rest::bytes>>, from, len, og, acc) do
extract_statements_exit_line_comment(rest, from, len + unquote(pattern_len), og, acc)
end

# line comment is over
defp extract_statements_exit_line_comment(<<unquote(ended), rest::bytes>>, from, len, og, acc) do
extract_statements(rest, from, len + unquote(end_length), og, acc)
defp extract_statements_exit_line_comment(<<?\n, rest::bytes>>, from, len, og, acc) do
extract_statements(rest, from, len + 1, og, acc)
end

# line comment continues
Expand All @@ -1264,6 +1267,7 @@ defmodule Ecto.Adapters.ClickHouse.Connection do
end
end

# https://clickhouse.com/docs/en/sql-reference/syntax#comments
extract_statements_block_comments = [
{_starts_with = "/*", _ends_with = "*/"}
]
Expand Down

0 comments on commit b1c3ba4

Please sign in to comment.