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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:27:32+00:00 2026-05-24T12:27:32+00:00

I have an SQLite database with 4 tables in it that I want to

  • 0

I have an SQLite database with 4 tables in it that I want to load into my Core Data database so I can implement core data. Can anyone help me with this?

I have the core data app ready, and I have the SQLite database ready. I need to copy the data from SQLite tables their 4 respective entities in core data in App delegate.

I’m currently using this code, how can I edit it so that instead of adding to array, it creates a new object in MOC?

-(NSMutableArray *) getCPTCodes
{
    sqlite3 *database = CodesDatabase();

    NSMutableArray *cptCodes = [[[NSMutableArray alloc] init] autorelease];

    NSString *nsquery = [[NSString alloc] initWithFormat:@"SELECT code, short_description, medium_description FROM cpt_codes"];
    const char *query = [nsquery UTF8String];
    [nsquery release];

    sqlite3_stmt *statement;
    int prepareCode = (sqlite3_prepare_v2( database, query, -1, &statement, NULL));
    if(prepareCode == SQLITE_OK) {
        while (sqlite3_step(statement) == SQLITE_ROW)
        {
            CPTCodes *code = [[CPTCodes alloc] init];
            code.code = [NSString stringWithCString:(char *)sqlite3_column_text(statement, 0) encoding:NSUTF8StringEncoding];
            code.name = [NSString stringWithCString:(char *)sqlite3_column_text(statement, 1) encoding:NSUTF8StringEncoding];
            code.description = [NSString stringWithCString:(char *)sqlite3_column_text(statement, 2) encoding:NSUTF8StringEncoding];
            [cptCodes addObject:code];
            //            NSLog(@"Code: %@ Short Description: %@ Long Description: %@", hcpcsCode.code, hcpcsCode.name, hcpcsCode.description);
            [code release];
        }
        sqlite3_finalize(statement);
    }
    return cptCodes;
}

Instead of loading that into an array, I need to add it as an object in core data, using this?

insertNewObjectForEntityForName:inManagedObjectContext:

  • 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-24T12:27:34+00:00Added an answer on May 24, 2026 at 12:27 pm

    It looks like you can create an entity and NSManagedObject subclass to take the place of the Code class in your existing code.

    Your entity would look like:

    CPTCode{
      code:string
      name:string
      desc:string // "description" is a method of NSObject so you can't use it as a property name
    }
    

    … and then you could have Xcode generate a custom subclass, lets call it CPTCodeMO just for clarity.

    Then you adapt your existing code:

    CPTCodeMO *code;
    while (sqlite3_step(statement) == SQLITE_ROW){
      code=[NSEntityDescription insertNewObjectForEntityForName:@"CPTCode" inManagedObjectContext:self.managedObjectContext];
      code.code = [NSString stringWithCString:(char *)sqlite3_column_text(statement, 0) encoding:NSUTF8StringEncoding];
      code.name = [NSString stringWithCString:(char *)sqlite3_column_text(statement, 1) encoding:NSUTF8StringEncoding];
      code.description = [NSString stringWithCString:(char *)sqlite3_column_text(statement, 2) encoding:NSUTF8StringEncoding];
    }
    

    Each pass through the loop would create a new CPTCodeMO instances and insert it in the managed object context. When you have created all the new instances you would just save the context:

    [self.managedObjectContext save:&saveError];
    

    … and your done.

    There are nuances of course but this is the basic idea.

    Do that once and you will have a Core Data SQLite store file with the existing data. You can then include that in the app bundle to ship with the app or do something else with it.

    I usually create a small utility app project in Xcode just to do this kind of import.

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

Sidebar

Related Questions

I have a database file that is generated on a PC using Sqlite. This
I have a SQLite database, and several tables within that datbase. I am developing
I have an old SQL Server 2000 database that I want to get into
I have created a Python module that creates and populates several SQLite tables. Now,
I have a file of about 30000 lines of data that I want to
C# (.NET 3.5) I have an SQLite database with two tables - employees (the
I have a text field in SQLite database, which I want the user to
I'm creating a application that will fetch data from an SQLite database and display
I'm using SQLite.cs wrapper for helping me with the database and I have this
Background I have an Android project that has a database with two tables: tbl_question

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.