I have the following array of strings:
array = [id, message, date, length]
Example:
array = ["1", "test's message", "2016-01-01", "15"]
I want to merge it into one string. I will use that string to insert data in DB using:
ActiveRecord::Base.connection.execute
I did:
result = "(#{array[0}', '#{array[1]}', '#{array[2]}', '#{array[3]}')"
message
contains special characters '
(ASCII code 039). This results in SQL exception. How can I construct a result
string that includes the '
character?
EDIT:
To put data in BD I use:
conn = ActiveRecord::Base.connection
sql = "INSERT INTO table_name (`id`, `message`, `date`, `length`) VALUES #{result}"
conn.execute sql
EDIT:
I fixed this using AR method:
ActiveRecord::Base.connection.quote(message)