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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:00:14+00:00 2026-05-16T08:00:14+00:00

I am displaying the contacts on the table. Section I pass in the method

  • 0

I am displaying the contacts on the table. Section I pass in the method is name of section i.e. A-Z.. and the index is the index of the row in that particular section. So to get the id based on the row I tapped in particular section,I wrote the following method. I am trying to get the id from the database whose values match with the query I pass. So if I check for the firstnames starting with letter ‘A’ there are around 4 values under section A. So I took a variable i and trying to increment until it finds the correct index such that it returns the id for that particular index. The condition validates but when I am trying to get the sid it throws objc_exception_throw. When I tried to add the debug point, I found that the exception is in this line and on debugger it says NSInvalidArgumentException: NULLcString..

Please help me..Its very urgent and I am clueless on what to do..Thanks for the help!!!

The error is on line where I get sid

Here is the method:

-(NSString *)getSugarIdNSString *)tableName bySectionNSString *)section andIndexint)inde
{
int i=0;
NSString *sid;
NSString *qsql = [[NSString stringWithFormat: @"SELECT sugar_id FROM CONTACTS WHERE first_name LIKE '%@",section] stringByAppendingString:@"%'"];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2( db, [qsql UTF8String], -1, &statement, nil) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
char * utf8string = (char *)sqlite3_column_text(statement, 1);
        if(i==index){
            sid = utf8string ? [[NSString stringWithUTF8String:utf8string] : nil;
        //  sid = [[NSString alloc]initWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
            break;
        }

i++;
}
}
return sid; 
}
  • 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-16T08:00:15+00:00Added an answer on May 16, 2026 at 8:00 am

    It means exactly what it says: you’re passing in a NULL C-string, which often ins’t valid.

    char * utf8string = sqlite3_column_text(statement, 1);
    sid = utf8string ? [NSString stringWithUTF8String:utf8string] : nil;
    

    Other problems:

    • [[NSString stringWithFormat:@"... '%@",section] stringByAppendingString:@"%'"]; is better written as [NSString stringWithFormat:@"... '%@', section].
    • Instead of gluing strings together, consider using prepared statements:
      sqlite3_prepare_v2(db, "SELECT ... WHERE first_name LIKE ?1", -1, &statement, nil);
      sqlite_bind_text(statement, 1, [section UTF8String], -1, SQLITE_TRANSIENT);
    • I don’t think Sqlite3 guarantees the order returned unless you haven an ORDER BY clause. Try “ORDER BY ROWID”.
    • Stepping through all the rows is tedious. Consider “LIMIT 1 OFFSET ?2” (or the equivalent “LIMIT ?2, 1”) and do sqlite3_bind_int(statement, 2, index).
    • Preparing a statement is expensive (often more expensive than actually executing it); it’s worth caching them. You can use sqlite3_reset() to reset the statement and then bind new values to it.
    • Executing a statement for every query is also expensive. Why don’t you just save all the rows returned into an array?
    • Your code leaks sid (just use +[NSString stringWithUTF8String:]).
    • Your code leaks statement (it should be freed with sqlite3_finalize()).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.