데이터를 삽입하거나 sqlite 데이터베이스로 바꿀 때 예기치 않은 결과가 발생합니다. 문제를 해결하기 위해 아래 코드에서 준비된 sqlite3_stmt (문)을 전체 인쇄하려고합니다. 내가하고 싶은 무엇iOS/sqlite - 준비된 sqlite3_stmt를 NSLog로 인쇄하는 방법
이 같은 것입니다,하지만 난 그것을 작동하지 않습니다 알고
if (sqlite3_step(statement) == SQLITE_DONE) {
NSLog(@"%@", statement);
는이를 위해 어쨌든 있나요?
감사합니다.
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);
업데이트 : 이 질문에 대한 답변을 찾지 못했습니다. 하지만 NSLog()를 사용하여 문자열을 구성하기 만하면됩니다. 내 테이블의 각각에 대해 다음과 같이 나는 확인했다 :
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);
무엇 문제가 있습니까? 오류가 무엇입니까? 그 plz 게시 할 수 있습니까? –
나는 어떤 오류도 내지 않는다. 그것은 내 데이터베이스의 동작이 예상대로 작동하지 않는다는 것입니다. sqlite manager 프로그램에서 문제를 해결하고 싶습니다.이 프로그램을 사용하면이 구문과 다른 구문의 다양한 변형을 빠르게 시도 할 수 있습니다. 진행중인 작업을 인쇄 할 수 있다면 붙여 넣기를 복사하는 것이 매우 빠를 것입니다. 감사합니다 – KevinM
당신이 컴파일 된 문을 인쇄 할 수 있다고 생각하지 않지만 당신은 SQL 쿼리를 인쇄 할 수 있습니다 .. 만약 당신이 iOS에서 sqlite를 처음 사용한다면 FMDB를 강력히 추천 할 것입니다. sqlite에 대한 아주 좋은 래퍼입니다. 찾을 수 있습니다. it github https://github.com/ccgus/fmdb – Saurabh