开发者

How to use LIKE query in sqlite & iPhone

I'm using the following for a LIKE query. Is this technique for LIKE correct?

selectstmtSearch = nil;

if(selectstmtSearch == nil){
  const char *sql = "SELECT col1, col2 FROM table1 t1 JOIN table2 t2 ON t1.cityid = t2.cityid where t1.cityname like ?001 order by t1.cityname";

  if(sqlite3_prepare_v2(databaseSearch, sql, -1, &selectstmtSearch, NULL) == SQLITE_OK) 
  {
     sqlite3_bind_text(selectstmtSearch, 1, [[NSString stringWithFormat:@"%%%@%%", searchText] UTF8String], -1, SQLITE_TRANSIENT);
  }
}

The problem I'm having is after a few uses of this, I get an error 14 on sqlite3_open(), which is unable to open database. If I replace the LIKE with som开发者_StackOverflow中文版ething such as:

SELECT col1, col2 
  FROM table1 t1  
  JOIN table2 t2 ON t1.cityid = t2.cityid 
 where t1.cityname = ? 
order by t1.cityname

It works fine. I do open/close the DB before after the above code. Is there a way to troubleshoot exactly why the database can't be opened and what its relationship to my LIKE syntax is?


You must sqlite3_reset or sqlite3_finalize(selectstmtSearch) before you close the database connection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜