Objective c Sqlite3步骤==SQLITE\u行不适用于我

Objective c Sqlite3步骤==SQLITE\u行不适用于我,objective-c,sqlite,Objective C,Sqlite,因为我是Xcode新手,所以不知道如何解决这个问题。请帮我解决实际问题 数据库连接已建立,查询已执行,但在执行查询后,我始终收到消息:Result not found.:( Sqlite3\u步骤(SQLStatement)==SQLITE\u行\uuuu或工作有时阅读以下内容会有所帮助: 如果nByte参数小于零,则zSql将被读取到 第一个零终止符。如果nByte为非负,则为 从zSql读取的最大字节数 是的,我解决了这个问题…!!!! 实际上,我只是将目录的路径更改为指向我的DB路径。 这

因为我是Xcode新手,所以不知道如何解决这个问题。请帮我解决实际问题

数据库连接已建立,查询已执行,但在执行查询后,我始终收到消息:Result not found.:(


Sqlite3\u步骤(SQLStatement)==SQLITE\u行\uuuu或工作有时阅读以下内容会有所帮助:

如果nByte参数小于零,则zSql将被读取到 第一个零终止符。如果nByte为非负,则为 从zSql读取的最大字节数


是的,我解决了这个问题…!!!! 实际上,我只是将目录的路径更改为指向我的DB路径。 这是我最后的工作代码……无论如何,谢谢@HotLicks、、、@CL.:):)

这就像一个符咒……:)


}


虽然这种访问数据库的方式令人困惑…:/

NSString *MyDirectory;
NSArray *DirectoryPaths;
// Get the documents directory
DirectoryPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
MyDirectory = [DirectoryPaths objectAtIndex:0];
// Build the path to the database file
MyDBPath = [[NSString alloc]initWithString: [MyDirectory stringByAppendingPathComponent:@"mydb.db"]];
//Status.text = MyDBPath;

请记住,您不能在手机上使用该DB路径运行应用程序——您必须在应用程序的读/写目录中分配DB。这就是为什么整个搜索路径。。。在你们看到的例子中使用了thing。当然,如果你想预创建数据库,你必须将预创建的版本放在包中,并在第一次运行应用程序时将其复制到读/写空间。(网上有很多这样的例子——大约20行代码序列。)@HotLicks噢,不……:'(你的意思是说我必须将may DB复制到那个目录中…,这是应用程序以前使用的…???如果你想要一个“预加载”的DB,那么是的,你需要包括“首次通过”应用程序中用于将数据库从捆绑包复制到可写文件系统的逻辑。@HotLicks我应该如何做…?请告诉我将预创建的数据库添加到exact-Ware的正确方法。提前感谢。;)如果您搜索,这里很容易就有十几个相应代码的示例。
- (void) Find
{
MyDBPath = @"/Users/zaibi/Documents/IOSProjects/mydb.db";
MyDatabase = [MyDBPath UTF8String];
sqlite3_stmt    *SQLStatement;
NSString *Query;
//NSString *decode = [[NSString alloc]initWithCString:Database encoding:NSUTF8StringEncoding];
//NSLog(@"%@",decode);
if (sqlite3_open(MyDatabase, &MyConnection) == SQLITE_OK)
{
    Query = [NSString stringWithFormat:@"SELECT EmpName FROM EmpLogin WHERE EmpID=\"%@\"",MyText.text];
    if (sqlite3_prepare_v2(MyConnection, [Query UTF8String], -1, &SQLStatement, nil) == SQLITE_OK)
    {
        if (sqlite3_step(SQLStatement) == SQLITE_ROW)
        {
            NSString *Name = [[NSString alloc]
                              initWithUTF8String:(const char *) sqlite3_column_text(SQLStatement, 0)];
            TextResult.text = Name;
            Status.text = @"Result found";
        }
        else
        {
            NSLog(@"%s", sqlite3_errmsg(MyConnection));
            Status.text = @"Result not found";
            TextResult.text = @"";
        }
        sqlite3_finalize(SQLStatement);
    }
    else
    {
        NSLog(@"%s", sqlite3_errmsg(MyConnection));
        Status.text = @"Query execution Failed...!";
    }
    sqlite3_close(MyConnection);
}
NSString *MyDirectory;
NSArray *DirectoryPaths;
// Get the documents directory
DirectoryPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
MyDirectory = [DirectoryPaths objectAtIndex:0];
// Build the path to the database file
MyDBPath = [[NSString alloc]initWithString: [MyDirectory stringByAppendingPathComponent:@"mydb.db"]];
//Status.text = MyDBPath;