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 9135591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:50:41+00:00 2026-06-17T08:50:41+00:00

I have this small ruby script that collects data and then save them in

  • 0

I have this small ruby script that collects data and then save them in a hash and then stores them in a sqlite db.

The hash looks like this:

@track = {:name => "Chris Brown", :song => "Sweet Love", :time => "3:20", :album => "Fortune" }

And I have a method that save this hash into a sqlite database:

def add_db
 db  = SQLite3::Database.new("playlist.sqlite")
 sql = "INSERT INTO tracks (name, song, time, album)" +
           "VALUES(#{@track[:name]}, #{@track[:song]},#{@track[:time]}, #{@track[:album]})"
 db.execute(sql)
 db.close
end

But I get this error: initialize': near "Playlist": syntax error (SQLite3::SQLException)

Is this the rigth way to save hash values into a sqlite3?

  • 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-17T08:50:42+00:00Added an answer on June 17, 2026 at 8:50 am

    Your problem is that you’re not quoting anything that you’re inserting so SQLite ends up seeing things like this:

    insert into tracks (name, song, time, album) values (Playlist, ...)
    

    and that’s not valid SQL. You should use placeholders:

    db.execute(
        'insert into tracks (name, song, time, album) values (?, ?, ?, ?)',
        @track[:name], @track[:song], @track[:time], @track[:album]
    )
    

    You can also use ActiveRecord but somethings that’s too heavy for a simple data importing script.

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

Sidebar

Related Questions

I have this small PHP script that takes a POST variable and writes it
I have this small class called City that simply holds some information about a
I have this small piece of code that basically takes a list and runs
I have a small Ruby script where an array is initialized to hold a
I have this small snipped of code. I don't know ruby and I think
I have a small ruby application that I made on my local machine. It
I have built a small ruby webservice, in this I have implemented cancan authorization.
I have a small ruby application I wrote that's an anagram searcher. It's for
I've made a very small ruby script today that makes use of regexes to
I have this small class looking like this: private static int field1 = -

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.