iosdev iosdev - 1 year ago 74
iOS Question

How to add nsmutable array into sqlite database table

How to add nsmutablearray into the sqlite database table?Can any one help me to code?

Answer Source

Use looping Controls to sort the array and insert each values


for(int itemIndex = 0; itemIndex < [yourArray count];itemIndex++){

     NSString *myname = [yourArray objectAtIndex:itemIndex];

    //insert myname to database.


To retrieve, you can use the sample below code

        if(sqlite3_open([path UTF8String], &dataBase) == SQLITE_OK)
            NSString *query = [NSString stringWithFormat:@"select name from syncTable where Crc = %d",crc];         const char *sql = [query UTF8String];
            sqlite3_stmt *statement;
            if (sqlite3_prepare(dataBase, sql, -1, &statement, NULL) == SQLITE_OK)
                char *name;
                unsigned int value;
                while(sqlite3_step(statement) == SQLITE_ROW)
                    name = (char *)sqlite3_column_text(statement, 0);   
                    [yourArray addObject:[NSString stringWithUTF8String:name]];

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download