誰でも私を助けてください。データを sqlite に挿入できません。
出力は「ニュースの追加に失敗しました」です。
注 : - データベースは既に作成されています。- ニュースはオブジェクトですが、問題はこの機能にあると思います。私のコードの何が問題なのか教えていただけますか? ありがとう。
- (void)addNews:(NSString *)content_caption content_date:(NSString *)content_date content_desk:(NSString *)content_desk content_id:(NSString *)content_id content_img:(NSString *)content_img content_type:(NSString *)content_type content_web_url:(NSString *)content_web_url{
char *error;
if (sqlite3_open([databasePath UTF8String], &database)==SQLITE_OK) {
NSString *inserStmt = [NSString stringWithFormat:@"INSERT INTO dBase(CONTENT_CAPTION,CONTENT_DATE, CONTENT_DESK, CONTENT_ID, CONTENT_IMG, CONTENT_TYPE, CONTENT_WEB_URL) values (\'%@\',\'%@\',\'%@\',\'%@\',\'%@\',\'%@\',\'%@\')",content_caption, content_date, content_desk, content_id, content_img, content_type ,content_web_url];
const char *insert_stmt = [inserStmt UTF8String];
if (sqlite3_exec(database, insert_stmt, NULL, NULL, &error)==SQLITE_OK) {
NSLog(@"News added");
News *news = [[News alloc]init];
[news setContent_caption:content_caption];
[news setContent_date:content_date];
[news setContent_desk:content_desk];
[news setContent_id:content_id];
[news setContent_img:content_img];
[news setContent_type:content_type];
[news setContent_web_url:content_web_url];
[arrayOfNews addObject:news];
}else{
NSLog(@"News added failed");
}
sqlite3_close(database);
}
}