Forum: Ruby on Rails "ActiveRecord::Base.connection.execute" nubee problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Abe (Guest)
on 2006-05-09 17:08
Is there any way of executing a full sql script, and not just one
statement?

You can do this:

ActiveRecord::Base.connection.execute("insert into batches (name) values
'name'")

but not this:

ActiveRecord::Base.connection.execute("insert into batches (name) values
'name'; "insert into batches (name) values 'name2';"")
Nick S. (Guest)
on 2006-05-09 17:40
(Received via mailing list)
How about....
statements.split(";").each do |statement|
  ActiveRecord::Base.connection.execute(statement)
end
Abe (Guest)
on 2006-05-09 18:23
No, i WANT to send in all my statements at once for quicker execution.
Is this possible?
Lionel B. (Guest)
on 2006-05-10 02:38
(Received via mailing list)
Abe wrote the following on 09.05.2006 16:23 :
> No, i WANT to send in all my statements at once for quicker execution.
> Is this possible?
>
>
I may be wrong but it seems to me that the difference should be
unnoticeable as you are using the same connection (the only additional
delay should be the network or system latencies between your client and
the server).
I'm wondering if the command-line SQL clients actually send a single
string to execute or instead split them before execution (the servers
might not support a single semicolon delimited string).

Lionel.
This topic is locked and can not be replied to.