在iPhone模拟器中查看sqlite3数据库

时间:2011-11-22 22:10:16

标签: iphone ios xcode4 sqlite

我以编程方式在Xcode 4的iPhone应用程序中以编程方式创建了数据库。我还插入了数据库并从中选择了所需的值。一切似乎工作正常,但我想检查价值是否重复。我无法在Xcode中打开我的数据库文件,那么有没有办法打开数据库并检查其中的值?

2 个答案:

答案 0 :(得分:4)

有两种方法可以做到: -

1)使用SQLite Manager for Firefox浏览器然后使用工具---> sqlite Manager - >打开数据库

现在您可以运行查询

从tablename中选择*; 您现在可以手动检查重复值。

链接以安装SQLite Manager

https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/

2)如果要通过数据库检查重复值

-(NSMutableArray *) readFromDatabase:(NSString *)query{
    // Setup the database object
    sqlite3 *database;

    // Init the animals Array
    MutableArray = [[NSMutableArray alloc] init];
    NSString *readCommand=query;

    //readCommand=[readCommand stringByAppendingFormat:@"%@';",patientID];
    // Open the database from the users filessytem
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
        // Setup the SQL Statement and compile it for faster access
        const char *sqlStatement = [readCommand UTF8String];
        sqlite3_stmt *compiledStatement;
        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
            // Loop through the results and add them to the feeds array
            while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
                // Read the data from the result row
                [MutableArray addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)]];
            }
        }
        // Release the compiled statement from memory
        sqlite3_finalize(compiledStatement);
    }
    sqlite3_close(database);
    return MutableArray;
}

调用此函数。并检查返回的数组值。

答案 1 :(得分:1)

我可以建议为Mozilla Firefox使用SQLite插件。

https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/

相关问题