On Oct 9, 2009, at 10:51 AM, Guyren G Howe wrote:
>
> On Oct 9, 2009, at 10:26 , Nic Benders wrote:
>
>> I don't believe that you can pass multiple statements using the
>> connection.execute method. Try breaking it up into 4 different
>> execute statements, wrapped within a transaction if needed.
>
> Well, I can't see any way that makes sense.
The reason is that the SQL APIs aren't just text connections, so they
aren't always equivalent to typing something into a mysql command line
client. So in this case I think you are trying to execute a single
large statement that contains semi-colon characters (which are
reserved), instead of trying to execute four statements in a row.
There are also AR helpers for the different basic SQL commands that
will give you slightly more useful return values than the basic
"execute" does (if you want that information).
For example (with Martin's suggestion of using delete_all):
MicroProvenance.transaction do
MicroProvenance.delete_all(selector_n)
MicroProvenance.delete_all(selector_b)
MicroProvenance.delete_all(selector_g)
MicroProvenance.connection.insert(multi_insert_sql)
end
delete_all also works with named scopes. So you can DRY up the
selection quite a bit if you have scopes already setup with something
like this:
class MicroProvenance < ActiveRecord::Base
named_scope :wifi_n_device, :conditions => { :provenable_type =>
'Device', :field_name => 'wifi_n_ie' }
named_scope :wifi_b_device, :conditions => { :provenable_type =>
'Device', :field_name => 'wifi_b_ie' }
named_scope :wifi_g_device, :conditions => { :provenable_type =>
'Device', :field_name => 'wifi_g_ie' }
end
and then:
MicroProvenance.wifi_n_device.delete_all(smaller_selector_n)
--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---