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

  • Home
  • SEARCH
  • 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 6940867
In Process

The Archive Base Latest Questions

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

Ok, so I’m getting better with SQLite queries … but obviously not a master

  • 0

Ok, so I’m getting better with SQLite queries … but obviously not a master yet.

I am trying to loop through the array this returns, and all I am getting is 0 for every entry.

Here is what is making the query call and returning the result (this particular query should currently return 6 lines of data):

-(NSMutableArray *)getMyAthleteList
{
NSMutableArray *athleteList = [[NSMutableArray alloc] init];

NSString *getAthleteListSQL = [[NSString alloc] initWithFormat:@"SELECT * FROM athletes"];

sqlite3_stmt *selectStmt;

if (sqlite3_prepare_v2(database, [getAthleteListSQL UTF8String], -1, &selectStmt, nil)==SQLITE_OK)
{
    while (sqlite3_step(selectStmt)==SQLITE_ROW)
    {
        //NSLog(@"Adding athletes to the array");
        Athletes *athlete_array = [Athletes alloc];
        athlete_array.athlete_image = [[NSString alloc] initWithFormat:@"%d",sqlite3_column_int(selectStmt, 0)];
        athlete_array.athlete_id = [[NSString alloc] initWithFormat:@"%d",sqlite3_column_int(selectStmt, 1)];
        athlete_array.athlete_name = [[NSString alloc] initWithFormat:@"%d",sqlite3_column_int(selectStmt, 2)];
        athlete_array.school_name = [[NSString alloc] initWithFormat:@"%d",sqlite3_column_int(selectStmt, 3)];
        athlete_array.sport_name = [[NSString alloc] initWithFormat:@"%d",sqlite3_column_int(selectStmt, 4)];
        athlete_array.athlete_flag = [[NSString alloc] initWithFormat:@"%d",sqlite3_column_int(selectStmt, 5)];
        [athleteList addObject:athlete_array];
    }
}
else
{
    NSLog(@"Did not make a good query");
}

return athleteList;
}

Now here is what I am doing when calling and looping through it:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

NSArray *myAthleteList = [[NSArray alloc] initWithArray:[appDelegate getMyAthleteList]];

for (Athletes *athlete in myAthleteList) {
    NSLog(@"Athlete Name: %@", athlete.athlete_name);
    NSLog(@"Athlete ID: %@", athlete.athlete_id);
}

And the output is:

Athlete Name: 0
Athlete ID: 0

My strings (athlete_name, athlete_id, etc.) are all defined correctly (in my Athletes.m and .h files).

I’m sure I’m missing something simple, but any help would be highly appreciated.

Thanks!

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

    Are you expecting lines like this to return a string from the DB?

    athlete_array.athlete_name = [[NSString alloc] initWithFormat:@"%d",
                                  sqlite3_column_int(selectStmt, 2)];
    

    If so, you might want to look into sqlite3_column_text or text16

    See: http://www.sqlite.org/capi3ref.html#sqlite3_column_blob

    You also may want to use this since it returns a const char *:

    [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(...)
    

    For example, here’s a similar snippet from one of my samples:

    contact = [[Contact alloc] init];
    while (sqlite3_step(statement) == SQLITE_ROW)
    {
        int idx = 0;
    
        NSNumber *idField = [NSNumber numberWithLongLong:sqlite3_column_int64(statement, idx++)];
        [contact setId:idField];
    
        NSString *nameField = [[NSString alloc] initWithUTF8String:
                               (const char *) sqlite3_column_text(statement, idx++)];
        [contact setName:nameField];
    
        NSString *addressField = [[NSString alloc] initWithUTF8String:
                                (const char *) sqlite3_column_text(statement, idx++)];
        [contact setAddress:addressField];
    
        NSString *phoneField = [[NSString alloc] initWithUTF8String:
                                (const char *) sqlite3_column_text(statement, idx)];
        [contact setPhone:phoneField];
    
        NSLog(@"id: %@", [contact id]);
        NSLog(@"name: %@", [contact name]);            
        NSLog(@"address: %@", [contact address]);
        NSLog(@"phone: %@", [contact phone]);
    
        // Code to do something with extracted data here
    
        [nameField release];
        [phoneField release];
        [addressField release];
    }
    

    Also, look into saving off your compiled statement &selectStmt and calling sqlite3_reset to use again. It’s compiled into byte code at that point and you don’t need to parse and compile your sql statement over and over.

    See: http://www.sqlite.org/capi3ref.html#sqlite3_prepare

    When you’re done with the statement (completely if you save it off), don’t forget to call sqlite3_finalize.

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

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.