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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:21:09+00:00 2026-06-01T09:21:09+00:00

I have a problem with SQLite3 on Xcode. the problem is that I have

  • 0

I have a problem with SQLite3 on Xcode.
the problem is that I have this database:

-------------------------|
| ID | Company  |  Model |
|------------------------|
| 1  | Audi     |  A4    |
| 2  | Audi     |  A4    |
| 3  | Audi     |  A3    |
| 4  | Audi     |  A4    |
| 5  | BMW      |  330Ci |
| 6  | BMW      |  330Ci |
| 7  | BMW      |  750i  |
| 8  | Mercedes |  CL65  |
| 9  | Mercedes |  CL65  |
--------------------------

I want the sqlite3 to show me like this:

-------------------------|
| ID | Company  |  Model |
|------------------------|
| 1  | Audi     |  A4    |
| 2  | Audi     |  A3    |
| 3  | BMW      |  330Ci |
| 4  | BMW      |  750i  |
| 5  | Mercedes |  CL65  |
--------------------------

I have this function:

-(NSString *)loadModel
{
    thecars = [[NSString alloc]initWithFormat:@"The data has been loaded to the pickers."];
    sqlite3_stmt * sqlStatement;
    @try {
        NSString *dbPath = [self path];
        if(sqlite3_open([[self path]UTF8String], &db) == SQLITE_OK)
        {
            NSLog(@"**** Database found at path.");
        }
        if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
        {
            NSLog(@"**** An error has occured: %@", sqlite3_errmsg(db));
        }
        NSString * hello = [NSString stringWithFormat:@"SELECT DISTINCT Model FROM Comp WHERE Company=%@",theChoosenCompany];
        const char * sql = [hello UTF8String];
        if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
        {
            NSLog(@"**** Problem with prepare statement: %@", sqlite3_errmsg(db));
        }
        else
        {
            while (sqlite3_step(sqlStatement) == SQLITE_ROW) {
                NSString * model = [NSString stringWithUTF8String:(char *)sqlite3_column_text(sqlStatement, 2)]; // Car models
                [modelsArray addObject:model];
            }
        }
    }
    @catch (NSException *exception) {
        NSLog(@"**** Problem with prepare statement:  %@", sqlite3_errmsg(db));
    }
    @finally {
        sqlite3_finalize(sqlStatement);
        sqlite3_close(db);
        return thecars;
    }
}

the problem is that I always gets an error and the program crush with error “Thread 1: Program received signal: “EXC_BAD_ACCESS””.

I believe that the stament is wrong.

Please if someone can help, i’m new to objective-c so please be patient.

Thanks alot!

  • 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-01T09:21:11+00:00Added an answer on June 1, 2026 at 9:21 am

    Personally, I’d start stepping through the code line-by-line in a debugger and see precisely what line is causing the problem.

    As an aside, I don’t see where you’re setting theChoosenCompany. Is that properly quoted and stuff like that?

    Also, if you want unique combinations of Model & Company, isn’t it just

    SELECT Model, Company FROM Comp GROUP BY Model, Company
    

    Obviously I don’t know your logic, as you said above you wanted just the unique Model/Company combinations, but your code seems to try to retrieve unique models for a given company.

    Finally, there are Objective C wrappers for SQLite3, such as FMDB (at https://github.com/ccgus/fmdb), that get you out of the weeds of sqlite3 calls for stuff like this.

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

Sidebar

Related Questions

I have some problem with reading from sqlite3 database. -(void) readMessengesFromDatabase { sqlite3 *database;
i have a problem that i can't solve ! (sqlite3, but i think it
i have a huge problem with my sqlite3 database on the iphone sdk 4.
i am using this code to insert names to table,i have a problem that
I have data stored in a sqlite3 database and have several places that I
I have a problem with deleting a record from my SQLite3 database: conn =
I am have a problem with SQLITE3. I have created 2 tables persons and
I have a problem when pushing data to my sqlite database in iphone application.
I have problem in some JavaScript that I am writing where the Switch statement
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE

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.