Return to Snippet

Revision: 1547
at October 20, 2006 02:09 by rduv


Initial Code
def self.insert_multiple_rows(columns, values)
  values_statement = ""
  values.each { |row| values_statement << "(#{columns.length.times}

  connection.execute(<<-EOF)
  INSERT INTO #{table_name} (#{columns.join(",")})
  VALUES
    #{values_statement}
  EOF
end

Now you'll be able to call, for example:

columns = ["username","real_name", "password"]
values  = [
  ["divoxx", "Rodrigo", "foo"],
  ["johng", "John Gary", "yay"]
]
User.insert_multiple_rows(columns, values)

Initial URL

                                

Initial Description

                                

Initial Title
insert multiple rows

Initial Tags

                                

Initial Language
Ruby