2012-07-31 2 views
0

.. <시도는 읽기 전용 데이터베이스를 쓰기> 내가 어떻게 오류가 나는 오류 가 계속 나는 아이폰 프로그래밍에 새로운 오전

SQLite는

에 대한 권한을 변경하는 아무 생각이 없다 업데이트하는 동안 오류가 발생했습니다. 읽기 전용 데이터베이스

쓰기를 시도하고 다음 내이

있는 NSString *적인 filePath =

코딩입니다 [[NSBundle mainBundle] pathForResource를 "카드"ofType @ : @ "sqlite가"];
sqlite3_stmt * 문;

(sqlite3_open ([여기서 filePath UTF8String에, & DB) == SQLITE_OK)
{
  CONST 숯불 * query_stmt = "UPDATE 카드 SET isActivate =?"경우;
  오류 "@ (sqlite3_prepare_v2 (dB, query_stmt, -1, & 문, NULL)! = SQLITE_OK)
        {
                NSAssert1 (0 업데이트를 만드는 동안 경우 문 '% s' ", sqlite3_errmsg (db));
       
}}


sqlite3_bind_int (성명, 1, 1);
경우 (SQLITE_DONE = sqlite3_step (문)!)
      {
          NSLog ("업데이트하는 동안 오류 % s의."@, sqlite3_errmsg (dB));
     }

sqlite3_finalize (문);
sqlite3_close (db); 이 정말 나를 좌절 느낌 때문에 누군가가 나를 도울 수

희망 .. 당신은 올바르게 사용하기 위해 캐시 디렉토리로 SQL 파일을 복사해야

답변

1

. '

NSString *sqlFile = @"database.sql"; 
NSArray *cachePath= NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
NSString *cacheDir = [cachePathobjectAtIndex:0]; 
databasePath = [cacheDirstringByAppendingPathComponent:sqlFile]; 

NSFileManager *fileManager = [NSFileManager defaultManager]; 
// Copy the database sql file from the resourcepath to the documentpath 
if (![fileManager fileExistsAtPath:databasePath]) { 
    NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:sqlFile]; 
    NSError *error; 
    [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:&error]; 
    if (error != nil) { 
     NSLog(@"[Database:Error] %@", error); 
    } 
} 
+0

그래 .. 내가 뭔가를 완벽하게 선택할 수 있습니다 내 디렉토리 .. 로 데이터베이스를 복사 한하지만, 업데이트 할 때, 그냥 아무 당신에게 – Sunny

+1

... 천국 작동하지 :
여기 내 코드의 일부입니다 그것을 당신의 문서 디렉토리에 복사하지 않았습니다. 번들에서 직접 데이터베이스를 여는 중입니다. 이 작업은 캐시 (또는 문서) 디렉토리에서 수행해야합니다. 이들은 서로 다른 두 가지입니다. 'NSCachesDirectory! = NSBundle' – basvk

+1

basvk가 말한 것은 그가 당신에게 준 코드를 실행 한 다음 파일 경로 문자열을 NSString * filePath = databasePath로 바꾼다는 것입니다. –

관련 문제