xcode sqlite3“内存不足”错误

发布于 2024-11-28 05:39:35 字数 1950 浏览 0 评论 0原文

当我们运行 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];
}

When we run the checkAndCreateDatabase method it says that the database exists but the sqlite3_error message returns an "out of memory" error before exiting the method. How can this be fixed?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

且行且努力 2024-12-05 05:39:35

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

Where is the database variable being initialized? I've run into this same error message when I have accidentally passed in an undefined or incorrect parameter to sqlite3_errmsg(). I think this is the default error message.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文