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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:38:40+00:00 2026-05-12T07:38:40+00:00

I have a 2 MB file, not too large, that I’d like to put

  • 0

I have a 2 MB file, not too large, that I’d like to put into an sqlite database so that I can search it. There are about 30K entries that are in CSV format, with six fields per line. My understanding is that sqlite on the iPhone can handle a database of this size.

I have taken a few approaches but they have all been slow > 30 s. I’ve tried:

1) Using C code to read the file and parse the fields into arrays.

2) Using the following Objective-C code to parse the file and put it into directly into the sqlite database:

NSString *file_text = [NSString stringWithContentsOfFile: filePath usedEncoding: NULL error: NULL];

NSArray  *lineArray = [file_text componentsSeparatedByString:@"\n"];

for(int k = 0; k < [lineArray count]; k++){
    NSArray *parts = [[lineArray objectAtIndex:k] componentsSeparatedByString: @","];

    NSString *field0       = [parts objectAtIndex:0];
    NSString *field2       = [parts objectAtIndex:2];
    NSString *field3       = [parts objectAtIndex:3];

NSString *loadSQLi = [[NSString alloc] initWithFormat: @"INSERT INTO TABLE (TABLE, FIELD0, FIELD2, FIELD3) VALUES ('%@', '%@', '%@');",field0, field2, field3];


    if (sqlite3_exec (db_table, [loadSQLi  UTF8String], NULL, NULL, &errorMsg) != SQLITE_OK) {
        sqlite3_close(db_table);
        NSAssert1(0, @"Error loading table: %s", errorMsg);
    }

Am I missing something? Does anyone know of a fast way to get the file into a database?

Or is it possible to translate the file into a sqlite format that can be read directly into sqlite?

Or should I turn the file into a plist and load it into a Dictionary? Unfortunately I need to search on two of the fields, and I think a Dictionary can only have one key?


Louis, thanks for your response.

I should have mentioned that I only want to write the data into the database once at the beginning of the app, and then later I only need to do reads of the database, no writes.

Can you tell me how to generate the sqlite3 database directly from the CSV file as part of the build process?

  • 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-12T07:38:40+00:00Added an answer on May 12, 2026 at 7:38 am

    OK, I think I’ve got it. Starting from the Unix command prompt, the following reads in the CSV file and writes out a SQL file:

     % sqlite3
     sqlite3> .mode csv
     sqlite3>  create table NEWTABLE (ITEM_ID INTEGER PRIMARY KEY, FIELD0 TEXT, FIELD1 TEXT, FIELD2 TEXT, FIELD3 TEXT, FIELD4 TEXT, FIELD5 TEXT);
     sqlite3> .import csvfile.csv NEWTABLE
     sqlite3> .output csvfile.sql
     sqlite3> .dump NEWTABLE
    

    The part I still haven’t figured out is if there is a quick way to read the sql file into sqlite3. The approach I currently have is to read each line of the sql file and execute on the iPhone. Is there a one line approach to reading the sql file into sqlite3?

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

Sidebar

Related Questions

I have a large file in my repository that is not text-mergeable and that
I have a db2 database file, but do not have a db2 server. I
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I have a txt file that I’m trying to import as flat file into
I have a million points and a large shape file—8GB—which is too big for
In the filesystem I have /file.aspx /directory/default.aspx I want to configure IIS so that
I have a file that I want to include in Python but the included
I have a file which is an XML representation of some data that is
I have a file temp.txt, that I want to sort with the sort command
I have a bin file that I need to convert to a byte array.

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.