mercredi 1 juillet 2015

IOS error inserting data on sqlite

i am on final project making GOLyrics apps for ios. my apps can search lyric and favorited it. but i have problems in my add favorite lyric, and i do not know why, im newbie in objective C especially in ios programming. help me please.

here's my add to favorite method:

  -(void)insertFav:(Favorite*)favssssdsd{

fileMgrs = [NSFileManager defaultManager];
sqlite3_stmt *stmt=nil;

NSString *sqlQuery=[NSString stringWithFormat:@"INSERT or REPLACE INTO fav (username,title,artist,image,song,lyric) VALUES ('%@','%@','%@','%@','%@','%@');",favssssdsd.username,favssssdsd.lirikTitle,favssssdsd.lirikArtist,favssssdsd.lirikImage,favssssdsd.lirikSong,favssssdsd.lirik];
NSLog(@"query:%@",sqlQuery);
const char *sql =[sqlQuery cStringUsingEncoding:NSUTF8StringEncoding];

//NSLog(@"row:%d",row);
//Open db
NSString *cruddatabase = [self.GetCacheDirectory stringByAppendingPathComponent:@"TB.sqlite"];
sqlite3_open([cruddatabase UTF8String], &db);
sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
@try
{
    if(sqlite3_step(stmt)==SQLITE_DONE)
    {
        NSLog(@"Succes insert fav");
    }
    else  NSLog(@"failed insert fav");


}
@catch (NSException *exception) {
    NSLog(@"An exception occured: %@", [exception reason]);
}

sqlite3_reset(stmt);

sqlite3_finalize(stmt);
sqlite3_close(db);
   }

the output is :

TestYey[1505:47536] query:INSERT or REPLACE INTO fav      (username,title,artist,image,song,lyric) VALUES ('shasapo','Stay','Rihanna','18.jpg','Stay.mp3','the lyrics in here');

TestYey[1505:47536] failed insert fav

Someone help me please :") i dont know why it isn't inserting

Aucun commentaire:

Enregistrer un commentaire