# "ActiveRecord::Base.connection.execute" nubee problem

**URL:** <https://www.ruby-forum.com/t/activerecord-base-connection-execute-nubee-problem/60020>\
**Category:** Rails\
**Created:** [May 9, 2006, 3:08pm UTC](https://www.ruby-forum.com/t/activerecord-base-connection-execute-nubee-problem/60020 "2006-05-09T15:08:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Abe](https://www.ruby-forum.com/u/Abe)\
**Post date:** [May 9, 2006, 3:08pm UTC](https://www.ruby-forum.com/t/activerecord-base-connection-execute-nubee-problem/60020/1 "2006-05-09T15:08:25Z")

</div>

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’;””)

---

<div class="post-metadata">

**Author:** ![Abe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Abe](https://www.ruby-forum.com/u/Abe)\
**Post date:** [May 9, 2006, 3:40pm UTC](https://www.ruby-forum.com/t/activerecord-base-connection-execute-nubee-problem/60020/2 "2006-05-09T15:40:03Z")

</div>

How about…  
statements.split(";").each do |statement|  
ActiveRecord::Base.connection.execute(statement)  
end

---

<div class="post-metadata">

**Author:** ![Abe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Abe](https://www.ruby-forum.com/u/Abe)\
**Post date:** [May 9, 2006, 4:23pm UTC](https://www.ruby-forum.com/t/activerecord-base-connection-execute-nubee-problem/60020/3 "2006-05-09T16:23:41Z")

</div>

No, i WANT to send in all my statements at once for quicker execution.  
Is this possible?

---

<div class="post-metadata">

**Author:** ![Abe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Abe](https://www.ruby-forum.com/u/Abe)\
**Post date:** [May 10, 2006, 12:38am UTC](https://www.ruby-forum.com/t/activerecord-base-connection-execute-nubee-problem/60020/4 "2006-05-10T00:38:59Z")

</div>

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.
