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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:51:08+00:00 2026-05-19T06:51:08+00:00

a noob here asking for help after a day of head-banging…. I am working

  • 0

a noob here asking for help after a day of head-banging….

I am working on an app with sqlite3 database with one database and two tables. I have now come to a step where I want to select from the table with an argument. The code is here:

-(NSMutableArray*) getGroupsPeopleWhoseGroupName:(NSString*)gn;{

 NSMutableArray *groupedPeopleArray = [[NSMutableArray alloc] init];

 const char *sql = "SELECT * FROM Contacts WHERE groupName='?'";

 @try { 
     NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);  
     NSString *docsDir = [paths objectAtIndex:0];  
     NSString *theDBPath = [docsDir stringByAppendingPathComponent:@"ContactBook.sqlite"];

     if (!(sqlite3_open([theDBPath UTF8String], &database) == SQLITE_OK))
     { NSLog(@"An error opening database."); }

     sqlite3_stmt *st;
     NSLog(@"debug004 - sqlite3_stmt success.");   

     if (sqlite3_prepare_v2(database, sql, -1, &st, NULL) != SQLITE_OK)
     { NSLog(@"Error, failed to prepare statement."); }

     //DB is ready for accessing, now start getting all the info.
     while (sqlite3_step(st) == SQLITE_ROW)
     {   

        MyContacts * aContact = [[MyContacts alloc] init];

        //get contactID from DB.
        aContact.contactID = sqlite3_column_int(st, 0);

        if (sqlite3_column_text(st, 1) != NULL)
        { aContact.firstName = [NSString stringWithUTF8String:(char *) sqlite3_column_text(st, 1)]; }
        else { aContact.firstName = @""; }

        // here retrieve other columns data ....

       //store these info retrieved into the newly created array.
       [groupedPeopleArray addObject:aContact];

       [aContact release];

    }

    if(sqlite3_finalize(st) != SQLITE_OK)
    { NSLog(@"Failed to finalize data statement."); }

    if (sqlite3_close(database) != SQLITE_OK)
    { NSLog(@"Failed to close database."); }

    }

 @catch (NSException *e) {
 NSLog(@"An exception occurred: %@", [e reason]);
 return nil;  }

 return groupedPeopleArray;}

MyContacts is the class where I put up all the record variables.

My problem is sqlite3_step(st) always return SQLITE_DONE, so that it i can never get myContacts. (i verified this by checking the return value).

What am I doing wrong here?

Many thanks in advance!

  • 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-19T06:51:10+00:00Added an answer on May 19, 2026 at 6:51 am

    I think you are not binding the value, if not use this

    sqlite3_bind_text(stmt, 1, [groupName UTF8String], -1, SQLITE_STATIC);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(ruby noob here..apologies if I'm not asking the question correctly) So I have two
Noob here - I'm working on a simple Javascript calculator, and I'm using lists
Python noob here, Currently I'm working with SQLAlchemy, and I have this: from __init__
Groovy noob here, I'm working through my first Groovy book and it has example
Spring noob here. I have an osgi service defined as follows in one of
Ruby noob here. Any help with a little issue I'm having would be appreciated.
I feel like a real noob asking this, but here's my problem: I want
Rails noob here. I am using carrierwave in a rails 3 app so users
Noob here... :) I'm working on a small and personal project that is already
XNA noob here, learning every day. I just worked out how to composite multiple

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.