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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:32:07+00:00 2026-05-30T21:32:07+00:00

I have a ruby script which will read data from some CSV file and

  • 0

I have a ruby script which will read data from some CSV file and import them into sqlite database.
I can do this task easily from console using following command:

sqlite> .import <filename> <tablename>
sqlite> .import test.csv PROJECT_REPORT

How can I achieve the same form Ruby script ?

I am doing something similar like following(just a work arround):

 CSV.foreach("timelog.csv") do |row|
     database.execute("INSERT INTO PROJECT_REPORT(
     Date,User,Activity,Comment)
     values
    (#{row[0]}, '#{row[1]}', '#{row[2]}', '#{row[3]}') ")
 end 
  • 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-30T21:32:08+00:00Added an answer on May 30, 2026 at 9:32 pm

    If it’s a one time job and you have a simple script that works why not stick with what you already have? If you need to grow the ruby script and want to expand it look at DataMapper (or on of the other ORMs) as an interface to your SQLite database. Create a simple class to contain your Date, User, Activiy and Comment fields and let DataMapper do the heavy lifting to the database.

    Updated with datamapper example
    Here’s a simple pseudo-example the datamapper implementation. This is not tested!

    #datamapper configuration here
    #.
    #.
    class UserActivity
     include DataMapper::Resource
    
      property :id,         Serial    
      property :log_date,       DateTime  
      property :user,       Text        
      property :activity    Text
      property :comment     Text
      property :created_at, DateTime
    end
    

    So to use it in your example above…

    CSV.foreach("timelog.csv") do |row|
      userActivity = UserActivity.new( :log_date => row[0], :user => row[1], :activity => row[2], :comment => row[3])
      userActivity.save!
    end
    

    Obviously this isn’t a complete solution, but it will get you started.

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

Sidebar

Related Questions

I have a Ruby script that generates a UTF8 CSV file remotely in a
I need to write some ruby script which will help me with big image
I have written a ruby script which opens up dlink admin page in firefox
I have a small ruby script in which I'd like to use ActiveRecord to
I have a cron job to run a Ruby script, which runs fine on
so i have ruby script that simply writes to a test.txt file with hello
I am trying to write a ruby script which will look in a directory
I have some regular expressions in my database which are then instantiated in Ruby
I'm looking to write a Ruby script which I can load into the Rails
I have a ruby cgi script which writes it output like this: cgi.out(Cache-Control =>

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.