Can somebody tell me how to add a single backslash in the SQL statement in Elixir
iex(1)> sql = "select * from user limit 1 \G;"
"select * from user limit 1 G;"
iex(2)> sql = "select * from user limit 1 \\G;"
"select * from user limit 1 \\G;"
I just need '\G' in my sql statement
$ elixir -v
Elixir 1.1.0-dev
In fact, I want to use the mariaex library, but I still cannot make it work
defmodule Customer do
def main(args) do
sql = "SELECT name FROM user limit 3 \\G;"
{:ok, p} = Mariaex.Connection.start_link(username: "root", password: "password", database: "user")
res = Mariaex.Connection.query(p, sql )
IO.inspect res
end
end
When I execute the code it tell me that I have a syntax error around '\G'
$ escript billutil
{:error,
%Mariaex.Error{mariadb: %{code: 1064,
message: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\\G' at line 1"},
message: nil}}
How should I format the string please?
Your second attempt is correct. You see two backslashes in the output, since it's an inspected output (printed as Elixir term). If you try printing that sql to console, you'll see one backslash:
iex(1)> IO.puts("select * from user limit 1 \\G;")
select * from user limit 1 \G;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With