How to display single backslash in Elixir string

Can someone tell me how to add a single backslash to SQL statements 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

Actually, I want to use the mariaex library, but I still can't get it to 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 run the code, it tells 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?

+3


source to share


1 answer


Your second try is correct. You see two backslashes in the output, as this is a verified result (printed as an Elixir term). If you try to print this sql to console you will see one backslash:



iex(1)> IO.puts("select * from user limit 1 \\G;")
select * from user limit 1 \G;

      

+7


source







All Articles