0
이 문제를 이해할 수 없습니다.Insert가 SQLite iOS에서 작동하지 않습니다.
- (void)viewDidLoad {
NSString *docsDir;
NSArray *dirPaths;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
// Build the path to the database file
databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"contacts.sqlite"]];
}
- (IBAction) saveData{
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
NSLog(@"enter %@",name.text);
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO EMP (name) VALUES (\"%@\")", name.text];
//NSLog(@"enter123 %@",dbpath);
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL);
NSLog(@"enter789 ");
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSLog(@"Done success");
/*status.text = @"Contact added";
name.text = @"";
address.text = @"";
phone.text = @"";*/
}
else
{
NSLog(@"fail");
//status.text = @"Failed to add contact";
}
sqlite3_finalize(statement);
sqlite3_close(contactDB);
}
}
어느 것 다른 사람이 귀하의 질문에 그대로 남아있는 경우. 질문을 수정하고보고있는 오류나 경고에 대한 세부 정보를 추가하십시오. 일어날 것으로 예상되는 것과 실제로 발생하는 것을 설명하고 문제를 해결하기 위해 이미 시도한 것을 보여주십시오. 이 문제가 없으면 질문이 매우 빨리 닫힙니다. – Jasarien
정확한 문제는 무엇입니까? 어떤 충돌? 또는 실패? – KingofBliss
** 항상 ** 모든 SQLite 작업의 반환 코드를 확인하십시오. 그리고 연산이 실패하면 ** 항상'sqlite3_errmsg'를 호출하고 결과 메시지를 출력하십시오. –