繁体   English   中英

在iPhone的xcode中具有LIKE语句的sqlite

[英]sqlite with LIKE statement in xcode for iphone

这里的第一个(很多)帖子中。

我的陈述有问题。

sqlite3_stmt *statement;
    const char *query = "select * from words where ordet LIKE ?001";

    NSString *wildcard = [NSString stringWithFormat:@"%@%%", fullWordForSQL.text];
    sqlite3_bind_text(statement, 1, [wildcard UTF8String], -1, SQLITE_STATIC);

    if (sqlite3_prepare_v2(dbHandle, query, -1, &statement, NULL) == SQLITE_OK ){
        NSLog(@"in if");
        NSLog(@"Data: %s", query);

我已成功通过查询检索数据:

const char *query = "select * from words where ordet LIKE "_test__";

但是,当我尝试绑定动态创建的单词时,它不会粘住。 我的nslog会打印“数据:从* ordet?001的单词中选择*”,因此我无法使绑定正常工作。 我知道上面的代码还会有其他问题,但现在我被困在这个问题上

调用sqlite3_bind_text()query不会更改。 如果您考虑一下,就不可能更改它,因为您将其声明为const char * 您要执行的操作是使用sqlite3_trace()注册以获取具有最终绑定字符串的回调,以便您了解实际情况。

您是否不需要将值用单引号引起来? “在哪里像'%001'这样的ordet”还是在xcode中不必要? 我不精通xcode。 您是要在语句字符串中已经包含的值前面将通配符注入到sql语句中,还是要在通配符之前添加一个搜索值,然后将该搜索值与-通配符声明? 对我来说,它看起来像前者,但正如我所说,我不了解xcode。 我通常不会在查询语句中包含一部分搜索项,但可以这样做:

       "select * from words where ordet like ?"

      // prepend the wildcard to my search term
      // bind the search term to my query

我认为这要简单得多。

NSString *query = [NSString stringWithFormat:@"SELECT * FROM words WHERE ordet GLOB '*%@*' ", fullWordForSQL.text];

在您的bind_text语句之前,尝试执行您的prepare_v2语句。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM