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

  • SEARCH
  • Home
  • 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 7075275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:09:28+00:00 2026-05-28T06:09:28+00:00

Newbie question. I am trying to use ActiveRecord::Base.connection.execute(..) in a ruby 3.1 app and

  • 0

Newbie question.

I am trying to use ActiveRecord::Base.connection.execute(..) in a ruby 3.1 app and docs I have read seem to be straight forward but for the life in me I can seem to understand why I cant get the code below to work. The error message I am getting suggests that the execute function is looking for a column with the name of one of the values I am trying to save but I dont understand why.

Firstly, my db table structure is as follows:

  create_table "countries", :force => true do |t|
    t.string   "iso3"
    t.string   "iso2"
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

And the code Im playing with is as follows:

code = 'ZA'
name = 'South Africa'

ActiveRecord::Base.connection.execute("INSERT INTO countries ('iso3', 'iso2', 'name')
  VALUES ('Null', #{code}, #{name})")

The error message I am getting is as follows:

SQLite3::SQLException: no such column: ZA: INSERT INTO countries ('iso3', 'iso2', 'name')
                                                VALUES ('Null', ZA, SouthAfrica)
  • 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-05-28T06:09:29+00:00Added an answer on May 28, 2026 at 6:09 am

    Where did you get the basis for this? Code of this variety is a sterling example of what not to do.

    If you have ActiveRecord, then you have ActiveRecord::Model, and with that you’re on the right track and pretty much done. You don’t need to write raw SQL for routine things of this variety. It’s not necessary, and more, it’s extremely dangerous for the reasons you’ve just discovered. You can’t just shove random things in to your query or you will end up with nothing but trouble.

    What you should be doing is declaring a model and then using it:

    # Typically app/models/country.rb
    class Country < ActiveRecord::Base
    end
    

    To insert once you have a model is made seriously easy:

    Country.create(
      :code => 'ZA',
      :name => 'South Africa'
    )
    

    A good ActiveRecord reference is invaluable as this facility will make your life significantly easier if you make use of it.

    Within Rails you usually go about generating these automatically so that you have something rough to start with:

    rails generate model country
    

    This will take care of creating the migration file, the model file, and some unit test stubs you can fill in later.

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

Sidebar

Related Questions

Newbie question here. I am trying to use the django-extjs library in my django
A newbie question, I am trying to use Freebase Suggest as a tagging resource
Sorry for the newbie question, I'm trying to use the Spring MVC framework to
I seem to have similar problem as this guy: Django newbie deployment question -
Newbie question since I'm not up to speed using maven at all. I'm trying
Total newbie question but this is driving me mad! I'm trying this: myInt =
This is a total newbie question, so thanks in advance. I'm trying to get
Hey all. Newbie question time. I'm trying to setup JMXQuery to connect to my
Just getting started with Linq to SQL so forgive the newbie question. I'm trying
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier

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.