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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:17:15+00:00 2026-06-11T20:17:15+00:00

Im transfering txt files into a sqlite3 database using sqlite-ruby, each txt file is

  • 0

Im transfering txt files into a sqlite3 database using sqlite-ruby, each txt file is about 3,5 MB which ruby reads really fast, but populating the database takes more than 10 minutes per file. I don´t know if this is normal, i guess not. Can somebody tell me a faster way to do this or if im doing something crazy? code and txt scheme below, thanks.

EDIT: more than 30 min per file…

require 'sqlite3'

db = SQLite3::Database.new( "firstTest.db" )

filename="file1.txt" # this file is 3.5 MB

streetArray=[]
mothertablename="tmother"
coordstablename="tcoords"

db.execute("create table '#{mothertablename}' (id INTEGER,stName TEXT,stBC TEXT,stPrice INTEGER,stUrl TEXT);")
db.execute("create table '#{coordstablename}' (id INTEGER,num INTEGER,xcoord DOUBLE,ycoord DOUBLE);")

f=[]
File.open("_history/" + "#{filename}").each{|line| f.push(line)}

counter=0

for i in 1...f.length
    f[i].gsub!("'","") #get rid of comma character
    ptsArray=f[i].split(';')

    if ptsArray[0]==ptsArray[1]
        streetArray.push(f[i])
    end

    if ptsArray[0]=="next\n"
        counter +=1
        namestreetArray=f[i-1].split(';')
        stname=nil
        stprice=nil
        stbc=nil
        sturl=nil
        if namestreetArray[0]=="name"
            stname=namestreetArray[1]
            if namestreetArray.length>2
                stprice=namestreetArray.last
            else
                stprice=nil
            end
        end

        db.execute(  "insert into '#{mothertablename}' (id, stName, stBC, stPrice, stUrl) 
        values ('#{counter}','#{stname}','#{stbc}','#{stprice}','#{sturl}');")

        localcounter=0

        streetArray.each do |coord|
            localcounter +=1
            xcoord=coord.split(";")[3].to_f
            ycoord=coord.split(";")[2].to_f
            db.execute(  "insert into '#{coordstablename}' (id, num, xcoord, ycoord) 
            values ('#{counter}','#{localcounter}','#{xcoord}','#{ycoord}');")
        end
        streetArray.clear
    end
end

here´s the txt scheme

206358589;206358589;37.3907322;-5.9885633
195966401;195966401;37.3909862;-5.988974
195969491;195969491;37.3910908;-5.9891081
195969493;195969493;37.3911863;-5.9893141
195969494;195969494;37.3912954;-5.9895115
813726831;813726831;37.3914352;-5.98973
name;Calle Descalzos;3085
next
440230342;440230342;37.3918677;-5.9905477
813726823;813726823;37.3916168;-5.9905285
192037929;192037929;37.3916184;-5.9905125
195970140;195970140;37.391872;-5.990398
440230342;440230342;37.3918677;-5.9905477
next
192009475;192009475;37.3875271;-5.9937949
710633000;710633000;37.3875013;-5.9941761
name;Calle Felipe Perez;
next
195982576;195982576;37.387349;-5.9937755
308836571;308836571;37.3873649;-5.9936472
next
...   
  • 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-11T20:17:16+00:00Added an answer on June 11, 2026 at 8:17 pm

    See the faq of sqlite “INSERT is really slow – I can only do few dozen INSERTs per second”

    In short, you can speed up the sqlite by two ways:

    • Group multiple INSERT statements with BEGIN…COMMIT to make the inserts into one transaction. In ruby, you should do something like:

      database.transaction do |db| db.execute( "insert into table values ( 'a', 'b', 'c' )" ) ... end 
      
    • Or simply run PRAGMA synchronous=OFF.

    And remember to prepare the statement before executing it.

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

Sidebar

Related Questions

I am remotely transfering the files into linux box from windows via batch script
im doing an application in which im transfering file through FTP.i succesfully done all
I'm following Using your own SQLite database in your Android applications , and in
I am processing a big .gz file using PHP (transfering data from gz to
So I'm starting to look into using the EF with POCO and transfering DTO
I want to rename a bunch of files using bash, transforming this file pattern:
I'm using WCF services in the client application for transfering data from client to
I have to put tons of integers and floats into a mysql database from
Is transfering a file from the desktop to an iPhone quicker than downloading the
I am transfering data from an old database to a new one, and I

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.