Sto avendo alcuni risultati inaspettati con i dati che sto inserendo o sostituendo nel mio database SQLite. Per risolvere il problema, sto cercando di ottenere una stampa completa dello sqlite3_stmt (istruzione) preparato nel seguente codice.iOS/sqlite - Come stampare un sqlite3_stmt preparato in NSLog
Quello che vorrei fare è qualcosa di simile, ma so che non funziona:
if (sqlite3_step(statement) == SQLITE_DONE) {
NSLog(@"%@", statement);
Esiste un modo per ottenere questo risultato?
Grazie !!
sqlite3_stmt *statement;
const char *dbPath = [databasePath UTF8String];
if (true) {
ListingsObject *temp = (ListingsObject *) DatabaseObject;
if (sqlite3_open(dbPath, &conyDB) == SQLITE_OK) {
const char *insertReplaceStmt = "INSERT OR REPLACE INTO listings (id, association_id, name, email, phone, toll_free_phone, fax, website, street, city, state, zipcode, county, bio, featured, hours, lat, lng, updated, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
if (sqlite3_prepare_v2(conyDB, insertReplaceStmt, -1, &statement, NULL) == SQLITE_OK) {
sqlite3_bind_text(statement, 1, [temp._id UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 2, [temp.associationId UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 3, [temp.name UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 4, [temp.email UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 5, [temp.phone UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 6, [temp.tollFreePhone UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 7, [temp.fax UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 8, [temp.website UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 9, [temp.street UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 10, [temp.city UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 11, [temp.state UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 12, [temp.zipcode UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 13, [temp.county UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 14, [temp.bio UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 15, [temp.featured UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 16, [temp.hours UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 17, [temp.lat UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 18, [temp.lng UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 19, [temp.updated UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 20, [temp.status UTF8String], -1, SQLITE_TRANSIENT);
}
if (sqlite3_step(statement) == SQLITE_DONE) {
NSLog(@"Insert or Replace to Listing Table successful Listing = %@", temp.name);
}else {
NSLog(@"Failed to add to Listing table Listing = %@", temp.name);
}
sqlite3_finalize(statement);
}
sqlite3_close(conyDB);
UPDATE: non ho trovato una risposta a questa domanda. Ma avevo bisogno di andare avanti così ho finito solo costruendo una stringa con NSLog(); come di seguito per ciascuno dei miei tavoli ho dovuto controllare:
NSLog(@" INSERT OR REPLACE INTO listings (id, association_id, name, email, phone, toll_free_phone, fax, website, street, city, state, zipcode, county, bio, featured, hours, lat, lng, updated, status) VALUES (\"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\")", temp._id, temp.associationId, temp.name, temp.email, temp.phone, temp.tollFreePhone, temp.fax
, temp.website, temp.street, temp.city, temp.state, temp.zipcode, temp.county, temp.bio, temp.featured, temp.hours, temp.lat, temp.lng, temp.updated, temp.status);
Cosa problema che stai ottenendo? Qual è l'errore? Puoi postare questo? –
Non ricevo alcun errore. È solo che il comportamento del mio database non funziona come previsto. Vorrei fare dei problemi con un programma manager in sqlite in cui posso provare rapidamente diverse varianti di questa e di altre dichiarazioni. Se potessi stampare ciò che sta accadendo, sarebbe molto veloce per me copiare qualsiasi copia su di esso. Grazie – KevinM
Non penso che tu possa stampare l'istruzione compilata ma puoi stampare la query sql .. se sei nuovo in sqlite in iOS ti consiglio vivamente FMDB .. è un ottimo wrapper per sqlite .. puoi trovare su github https://github.com/ccgus/fmdb – Saurabh