SQLite错误“没有这样的表”

时间:2015-06-11 20:23:12

标签: ios sqlite

我收到了这个错误:

2015-06-11 12:06:42.103 actividadFinaliOS1 [25425:1798557] ***由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'插入数据时出错。 '没有这样的表:recordatorios''

我很确定该表已创建。检查我的代码:

NSString *docsDir;
NSArray *dirPaths;

// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

docsDir = [dirPaths objectAtIndex:0];

// Build the path to the database file
_databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"recordatorios.sqlite"]];

NSFileManager *filemgr = [NSFileManager defaultManager];

if ([filemgr fileExistsAtPath: _databasePath ] == NO)
{

if (!_todoItems) {

    _todoItems = [NSMutableArray new];
}

_databasePath = [[NSBundle mainBundle] pathForResource:@"recordatorios" ofType:@"sqlite"];

if (sqlite3_open([_databasePath UTF8String], &_database) == SQLITE_OK)
{
    _consulta = [NSString stringWithFormat: @"SELECT * FROM recordatorios"];

    const char *query = [_consulta UTF8String];

    sqlite3_stmt  *statement;

    if (sqlite3_prepare_v2(_database, query, -1, &statement, NULL) == SQLITE_OK)
    {
        while (sqlite3_step(statement) == SQLITE_ROW) {

            char *item = (char *) sqlite3_column_text(statement, 0);
            NSString* string = [NSString stringWithFormat:@"%s" , item];
            [_todoItems addObject:string];

        }
        sqlite3_finalize(statement);

    }else
    {
        NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(_database));
    }
    sqlite3_close(_database);
}else
{
    NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(_database));

}
}

0 个答案:

没有答案