【问题标题】:xcode sqlite3 "out of memory" errorxcode sqlite3“内存不足”错误
【发布时间】:2011-10-20 06:55:46
【问题描述】:

当我们运行 checkAndCreateDatabase 方法时,它表示数据库存在,但 sqlite3_error 消息在退出该方法之前返回“内存不足”错误。如何解决这个问题?

-(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];
}

【问题讨论】:

  • 当我们运行 checkAndCreateDatabase 方法时,它说数据库存在,但 sqlite3_error 消息在退出方法之前返回“内存不足”错误。如何解决这个问题?
  • 您可能希望将其添加到问题中。现在它只是一段代码。
  • 我编辑了帖子并将问题添加到顶部,谢谢提醒。

标签: database xcode memory-management memory-leaks xcode4


【解决方案1】:

正在初始化的数据库变量在哪里?当我不小心将未定义或不正确的参数传递给 sqlite3_errmsg() 时,我遇到了同样的错误消息。我认为这是默认的错误消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-15
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 2020-10-15
    • 2014-10-21
    相关资源
    最近更新 更多