I am dynamically creating an insert statement for a database that I want
DBI to execute.
In the first part of my example below I am passing each value I want
escaped to the database handlers “do” method as a separate argument.
That works fine. What I’d need is a way to pass the values I want
inserted as an array as the number of inserts are going to change each
time the script is run. Is there a way to do that?
I could escape the characters myself and insert them directly into the
sql statement, but I thought I would check with you guys first if you
know of another and better way to do this.
DB_PASSWORD) do |dbh|
value1 = “Something”
value2 = “Something”
value3 = “Something”
array_in = [value1, value2, value3]
sql_insert = “INSERT INTO users (email) VALUES (?), (?), (?)”
dbh.do(sql_insert, value1, value2, value3)
#This is what I need to work