안녕하세요 저는 sqlitedb를 사용하는 앱을 개발하고 있습니다. 몇 가지 예를 읽고 내 앱을 만들려고했습니다. 삽입하려는 테이블에 3 개의 열이 있습니다. ID INTEGER 기본 키 자동 침입, 이름 텍스트, 실제 시간, 실제 시간 읽은 예제를 기반으로 아래 코드를 작성합니다. 하지만 항상 레코드를 추가하지 못했습니다. 추신 : 나는 db 생성을 테스트했다. 나는 이것을 tuterial에 사용했는데 다른 응용 프로그램에서는 괜찮 았습니다. 직접 쓸 수 없습니다 자원 folder.it에 database
에 데이터를 쓰고 있기 때문에 여기에 먼저 document directory
에 database
을 복사해야iphone에서 sqlite에 데이터를 삽입 (& 실패)하려고합니다.
NSTimeInterval endTime = [[NSDate date] timeIntervalSinceReferenceDate];
double elapsedTime = endTime-startcache;
NSString *my=[NSString stringWithFormat:@"%f",elapsedTime];
TextField1.text=my;
// saving in database
NSString * durationstring=[NSString stringWithFormat:@"%f",elapsedTime];
NSString * timestring=[NSString stringWithFormat:@"%f",endTime];
sqlite3_stmt *statement;
const char *dbpath = [_databasePath UTF8String];
if (sqlite3_open(dbpath, &_activityDB) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat:
@"INSERT INTO ACTIVITYTABLE (name, duration,time) VALUES (\"%@\", \"%@\", \"%@\")",
activityname, durationstring,timestring];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(_activityDB, insert_stmt,
-1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
self.status.text = @"record added";
} else {
self.status.text = @"Failed to add record";
}
sqlite3_finalize(statement);
sqlite3_close(_activityDB);
}
내가이 튜토리얼 http://www.techotopia.com/index.php/An_Example_SQLite_based_iOS_6_iPhone_Application는 괜찮아요을 사용하지만 난 다른 데이터 유형을 시도 할 때 나는 –