jeudi 31 mars 2016

How to fetch data from sqlite db in list of objects in objective-c?

I want to fetch data from sqlite db in objective-c in the form of listArray(like in java android).

Here i have java class models for this

How can i convert these classes into objective c code confused in deceleration(.h) and implementation(.m)

Class 1

public class RecordingList {

public  ArrayList<RecordingItem> Items = new ArrayList<RecordingItem>();
}

class 2

public class RecordingItem {

public int ID;
public String RecordingTitle;
public String RecordingSubTitle;
public String RecordingAudioPath;
public String RecordingDuration;
public String RecordingNotePath;
public String Date;
public String Time;
public String PlayListId;
public ArrayList<RecordingAttachments> recordingAttachmentses = new   ArrayList<RecordingAttachments>();
}

I have try to get data in objective-c like this

- (NSArray*) getAllNotes
    {
        const char *dbpath = [databasePath UTF8String];
        if (sqlite3_open(dbpath, &database) == SQLITE_OK)
        {
            NSString *querySQL = [NSString stringWithFormat:
                                  @"SELECT * FROM recordingItem"];
            const char *query_stmt = [querySQL UTF8String];
            NSMutableArray *resultArray = [[NSMutableArray alloc]init];
            if (sqlite3_prepare_v2(database,
                                   query_stmt, -1, &statement, NULL) == SQLITE_OK)
            {
                if (sqlite3_step(statement) == SQLITE_ROW)
                {
                    NSString *name = [[NSString alloc] initWithUTF8String:
                                      (const char *) sqlite3_column_text(statement, 0)];
                    [resultArray addObject:name];
                    NSString *department = [[NSString alloc] initWithUTF8String:
                                            (const char *) sqlite3_column_text(statement, 1)];
                    [resultArray addObject:department];
                    NSString *year = [[NSString alloc]initWithUTF8String:
                                      (const char *) sqlite3_column_text(statement, 2)];
                    [resultArray addObject:year];
                    return resultArray;
                }
                else{
                    NSLog(@"Not found");
                    return nil;
                }
                sqlite3_reset(statement);
            }
        }
        return nil;
    }

But this is not what i want i want to get data in list of objects how can i do this?

Thanks in Advance

Aucun commentaire:

Enregistrer un commentaire