2011-08-04 3 views
0

checkAndCreateDatabase 메서드를 실행하면 데이터베이스가 있지만 메서드를 종료하기 전에 sqlite3_error 메시지가 "메모리 부족"오류를 반환한다고 표시됩니다. 이 문제를 어떻게 해결할 수 있습니까?xcode sqlite3 "out of memory"오류

-(void) checkAndCreateDatabase{ 
NSLog(@"Run Method: checkAndCreateDatabase"); 
// Check if the SQL database has already been saved to the users phone, if not then copy it over 
BOOL success; 

// Create a FileManager object, we will use this to check the status 
// of the database and to copy it over if required 
// Check if the database has already been created in the users filesystem 
success = [[NSFileManager defaultManager] fileExistsAtPath:databasePath]; 

// If the database already exists then return without doing anything 
if(success){ 
    NSLog(@"Database Exists"); 
} else { 

    // If not then proceed to copy the database from the application to the users filesystem 
    NSLog(@"Database Does Not Exist"); 

    // Get the path to the database in the application package 
    NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; 

    // Copy the database from the package to the users filesystem 
    [[NSFileManager defaultManager] copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; 
    NSLog(@"Database Copied To filesystem And Exists"); 
} 
NSLog(@"Method checkAndCreateDatabase Finished Message: %s",sqlite3_errmsg(database)); 
return; 
} 

- (void)viewDidLoad { 
NSLog(@"Run Method: viewDidLoad"); 
// Setup some globals 
databaseName = @"w2w.db"; 
NSLog(@"Database Name: %@",databaseName); 

// Get the path to the documents directory and append the databaseName 
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDir = [documentPaths objectAtIndex:0]; 
databasePath = [documentsDir stringByAppendingPathComponent:databaseName]; 
NSLog(@"Database Path: %@",databasePath); 

// Execute the "checkAndCreateDatabase" function 
[self checkAndCreateDatabase]; 

[super viewDidLoad]; 
} 
+0

그리고 질문은 무엇입니까? – Bart

+0

checkAndCreateDatabase 메서드를 실행하면 데이터베이스가 있지만 메서드를 종료하기 전에 sqlite3_error 메시지가 "메모리 부족"오류를 반환한다고 표시됩니다. 이 문제를 어떻게 해결할 수 있습니까? – Turningpoint

+0

질문에 질문을 추가 할 수 있습니다. 이제는 코드 조각 일뿐입니다. – Bart

답변

0

데이터베이스 변수는 어디에 초기화됩니까? 실수로 정의되지 않은 매개 변수 나 잘못된 매개 변수를 실수로 sqlite3_errmsg()에 전달하면이 동일한 오류 메시지가 표시됩니다. 기본 오류 메시지라고 생각합니다.