为什么 SQLite 没有从我的数据库中带回任何结果 [英] Why does SQLite not bring back any results from my database

查看:27
本文介绍了为什么 SQLite 没有从我的数据库中带回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一个基于 SQLite 的 iPhone 应用程序,我试图让它从我的数据库中读取菜单层次结构.

This is my first SQLite based iPhone app and I am trying to get it to read a menu hierarchy from my database.

数据库似乎注册良好,因为编译的语句没有错误(尝试输入有效的表名进行测试)但由于某种原因sqlite3_step(compiledStmt) 永远不等于 SQLITE_ROW 好像在暗示那里没有数据;有.

The database appears to be registered fine as the compiled statement doesnt error (tried putting in valid table name to test) but for some reason sqlite3_step(compiledStmt) doesnt ever equal SQLITE_ROW as if to suggest there is no data in there; which there is.

sqlite3 *database;

menu = [[NSMutableArray alloc] init]; 

if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
    const char *sqlStmt = "SELECT * FROM Menu";
    sqlite3_stmt *compiledStmt;

    if (sqlite3_prepare_v2(database, sqlStmt, -1, &compiledStmt, NULL) == SQLITE_OK) {
        while (sqlite3_step(compiledStmt) == SQLITE_ROW) {
            NSString *aTitle = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStmt, 1)];

            MenuItem *menuItem = [[MenuItem alloc] init];
            menuItem.title = aTitle;

            [menu addObject:menuItem];

            [menuItem release];
        }
    }
    else {
        NSLog(@"There is an error with the SQL Statement");
    }

    sqlite3_finalize(compiledStmt);

}

sqlite3_close(database);

推荐答案

尽管大多数建议使用 Core Data,但我花了一个下午的时间研究它,它完全不适合我的需求.我需要在加载时在应用程序中存储/导入超过 1000 行的数据,而 Core Data 无法以任何简单的方式执行此操作.

Despite most suggestions to use Core Data, I have spent the afternoon researching it and it is completely inappropriate to my needs. I need to store/import over 1000 rows of data in the application on load and Core Data has NO way to do this in any easy fashion.

SQLite 仍然是理想的解决方案,但我仍然没有解决问题的方法.

SQLite will still be the ideal solution, but I still dont have a solution to the problem.

进一步的研究使我发现了这个惊人的例子:

Further research led me to this AMAZING example:

http://cocoawithlove.com/2009/11/writing-parser-using-nsscanner-csv.html

通过一点点jiggary pockery,您可以将您的CSV 等导入到SQLite 文件中,以便嵌入到您的应用程序中

With a little jiggary pockery you can import your CSV etc into a SQLite file for embedding in your application

这篇关于为什么 SQLite 没有从我的数据库中带回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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