Domanda

Ho problemi di esecuzione di una dinamica SIMILE dichiarazione nel mio progetto:questa query funziona come un fascino, e restituisce tutti gli elementi con una 't' nel loro nome:

const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%t%%'";

Quando provo a fare questo in modo dinamico faccio a non fare errori, ma solo un risultato vuoto.Sembra che il valore è null.Cerco di associare un valore di stringa 's' che restituisce un valore corretto

NSLog(@"bbc_ : search menu items from db based on: %@",s);
const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%?%%'";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
sqlite3_bind_text(statement, 1, [s UTF8String],-1,SQLITE_TRANSIENT);

Come devo collegare questo valore invece di usare:

const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%?%%'";
È stato utile?

Soluzione

Appena trovato una grande spiegazione http://www.innerexception.com/2008/10/using-like-statement-in-sqlite-3-from.html

Ho cambiato le seguenti linee:

const char *sql = "select * from bbc_ipad_v1_node where name LIKE ?001";

e

NSString *searchInput = [NSString stringWithFormat:@"%@%%", s];
sqlite3_bind_text(statement, 1, [searchInput UTF8String],-1,SQLITE_TRANSIENT); 

Altri suggerimenti

Si può effettivamente dire basta

const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%t%'";

(Nota singolo%s)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top