2011-08-04 30 views
0

當我們運行checkAndCreateDatabase方法時,它說數據庫存在,但sqlite3_error消息在退出方法之前返回「內存不足」錯誤。這怎麼解決?xcode sqlite3「內存不足」錯誤

-(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()時,我遇到了同樣的錯誤消息。我認爲這是默認的錯誤信息。