Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7721949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:03:41+00:00 2026-06-01T04:03:41+00:00

1) require ‘sqlite3’ db = SQLite3::Database.new(‘development.sqlite3’) db.results_as_hash = true; rows = db.execute( SELECT *

  • 0

1)

require 'sqlite3'

db = SQLite3::Database.new('development.sqlite3')
db.results_as_hash = true;


rows = db.execute(" SELECT * FROM listings WHERE name = '' OR telephone = '' OR latitude = '' OR longitude = '' ")

rows do |row|

  id_num = row['id']
  puts "Id = #{id_num}"

  dupe_name = row['name']
  puts "name = #{dupe_name}"

  dupe_tel = row['telephone']
  puts "tel = #{dupe_tel}"

  dupe_lat = row['latitude']
  puts "lat = #{dupe_lat}" 

  dupe_long = row['longitude']
  puts "lat = #{dupe_long}" 
  puts '===end===='



end

2)

    require 'sqlite3'

db = SQLite3::Database.new('development.sqlite3')
db.results_as_hash = true;


db.execute(" SELECT * FROM listings WHERE name = '' OR telephone = '' OR latitude = '' OR longitude = '' ") do |row|

  id_num = row['id']
  puts "Id = #{id_num}"

  dupe_name = row['name']
  puts "name = #{dupe_name}"

  dupe_tel = row['telephone']
  puts "tel = #{dupe_tel}"

  dupe_lat = row['latitude']
  puts "lat = #{dupe_lat}" 

  dupe_long = row['longitude']
  puts "lat = #{dupe_long}" 
  puts '===end===='



end

The 2nd one works and the 1st one does not.

Why is that so? Doesn’t the db.execute function return a result set. If so why cant you loop through it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:03:42+00:00Added an answer on June 1, 2026 at 4:03 am

    Have you tried changing rows do |row| to rows.each do |row| for the first function?.

    With the first one you get a collection and assign it to rows. You need to create a iterator for rows after that to loop trough the collection.

    The second function, .execute already returns a iterator.

    More on Iterators

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I require to allow the user to select a file from the network drive
require 'test_helper' class MyTest < ActionController::IntegrationTest test view posts from login page do visit(/logins/new)
require(includes/connect.php); $result = mysql_query(SELECT * FROM entries, $link); while ($row = mysql_fetch_array($result)) { htmlentities($row['quotes']);
require 'rubygems' require 'active_record' ActiveRecord::Base.establish_connection( :adapter => 'mysql2', :database => 'vft', :user => 'vft',
require 'sketchup' entities = Sketchup.active_model.entities summa = Hash.new for face in entities next unless
i require a generic accounting system database schema is there any sites which provide
require 'openssl' if ARGV.length == 2 pkcs12 = OpenSSL::PKCS12.new(File.read(ARGV[0]), ARGV[1]) p pkcs12.certificate else puts
require 'rubygems' require 'mechanize' rational = Mechanize.new { |agent| agent.user_agent_alias = 'Windows Mozilla' }
require 'ruby2ruby' require 'parsetree' code = puts(var) sexp = SexpProcessor.new.process(ParseTree.translate(code)) # => s(:fcall, :puts,
require 'rubygems' require 'mechanize' agent = Mechanize.new page = agent.get(http://google.com/) This simple script works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.