没有这样的表错误 [英] No Such Table error

查看:29
本文介绍了没有这样的表错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不搜索许多关于这些错误的帖子,但仍然无法解决问题.这是我的代码,谁能帮我看看出了什么问题?

I had to search for many posts regarding these errors, but still I cannot fix the problem. Here is my code, can anyone help me to see what is going wrong?

- (void) copyDatabaseIfNeeded {


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
   NSString *path = [documentsDirectory stringByAppendingPathComponent:@"SQL.sqlite"];

    if (sqlite3_open([path UTF8String], &newDBconnection) == SQLITE_OK) 
    {
        NSLog(@"Database opened successfully");

if(updateStmt == nil) {
            NSString *updStmt = [NSString stringWithFormat: @"UPDATE Coffee SET CoffeeName = '500 Plus', Price = '1.40' Where CoffeeID= '3'"];
   const char *mupdate_stmt = [updStmt UTF8String]; 

if(sqlite3_prepare_v2(newDBconnection, mupdate_stmt, -1, &updateStmt, NULL) != SQLITE_OK){
NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(newDBconnection));
            } else {
                NSLog(@"Update successful");
            }

        }
        if(SQLITE_DONE != sqlite3_step(updateStmt))
            NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(newDBconnection));
        else {
            sqlite3_reset(updateStmt);
            NSLog(@"Step successful");

        }
    } 
    else 
    {
        NSLog(@"Error in opening database  ");
    }
}

推荐答案

SQL.sqlite中没有表Coffee.

如果数据库文件不存在,SQLite 会静默创建该文件.因此,如果path 错误,您将打开一个空的数据库文件,其中当然不包含任何表.确保数据库文件存在于那里并且它不为空.

SQLite silently creates the database file if it does not exist. So if you've got the path wrong, you are opening an empty database file, which of course does not contain any tables. Make sure the database file exists there and it is not empty.

您可以通过运行SELECT * FROM sqlite_master; 查询来查看数据库中有哪些表.

You can see what tables are there in the database by running SELECT * FROM sqlite_master; query.

这篇关于没有这样的表错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆