def execute sql, bind_vars = [], *args, &block
hack = Object.const_defined?(:ActiveRecord) && sql =~ /^PRAGMA index_list/
if bind_vars.nil? || !args.empty?
if args.empty?
bind_vars = []
else
bind_vars = [nil] + args
end
warn("\#{caller[0]} is calling SQLite3::Database#execute with nil or multiple bind params\nwithout using an array. Please switch to passing bind parameters as an array.\n") if $VERBOSE
end
prepare( sql ) do |stmt|
stmt.bind_params(bind_vars)
if type_translation
stmt = ResultSet.new(self, stmt).to_a
end
if block_given?
stmt.each do |row|
if @results_as_hash
h = Hash[*stmt.columns.zip(row).flatten]
row.each_with_index { |r, i| h[i] = r }
yield h
else
yield row
end
end
else
if @results_as_hash
stmt.map { |row|
h = Hash[*stmt.columns.zip(row).flatten]
row.each_with_index { |r, i| h[i] = r }
h['unique'] = h['unique'].to_s if hack
h
}
else
stmt.to_a
end
end
end
end