0

This is my code. It is only returning the first row from database. I know something is really wrong but don't know what. Please help.

if(sqlite3_open([databasePath UTF8String],&texttalkdb)==SQLITE_OK)
{
    sqlite3_stmt *statement;

    if(sqlite3_prepare_v2(texttalkdb, [sql UTF8String], -1,&statement, NULL)==SQLITE_OK)
    {
        if(sqlite3_step(statement)==SQLITE_ROW)
        {
            for(int i=0;i<=20;i++)
        {
            char *pass=(char*)sqlite3_column_text(statement,i);
            NSString *passStr = [NSString stringWithFormat:@"%s",pass];

                NSString *msg=[[NSString alloc]initWithUTF8String:pass];
                [arr addObject:msg];
          }
        }
        sqlite3_finalize(statement);
    }
    sqlite3_close(texttalkdb);
}
NSLog(@"%@",arr);
return arr;

2 Answers 2

2

Try this

if(sqlite3_prepare_v2(texttalkdb, [sql UTF8String], -1,&statement, NULL)==SQLITE_OK)
{
            while( sqlite3_step(statement) == SQLITE_ROW )
            {
            //get records   
        }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Step 1: This is for check the getting values is empty or not

 +(NSString*)charToString:(char*)chart
 {
    NSString *string = @" ";
    if(string)
    {
      chart = [self checkEmptyChar:chart];
      string=[NSString stringWithUTF8String:chart];
    }
   return string;
 }

Step 2: This is for checking character

+(char *)checkEmptyChar:(char *)check
{
  NSString *string = @" ";
  if (check == NULL)
    check = string;
  return check;
}

Step 3: To fetch SQLite Coding

 if (sqlite3_prepare_v2(database, [query UTF8String], -1, &stment, nil) == SQLITE_OK)

    {
        while (sqlite3_step(stment) == SQLITE_ROW)

        {

            for(int i=0;i<=20;i++)

            {
                 NSString *msg = [self charToString: (char *)sqlite3_column_text(stment, i)];

                 [array addObject:msg];
            } 

        }

        sqlite3_reset(stment);
    }

    sqlite3_finalize(stment);
 }

sqlite3_close(database);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.