SQL 쿼리를 준비하고 sqlite db에 대해 실행하는 함수를 작성하고 있습니다. 나는 테이블에 값을 삽입하는 쿼리를 사용하고, 쿼리는이sqlite 쿼리가 준비되지 않았습니다. 값이 없습니다.
"insert into files values (?, ?, ?, ?, ?, 0)";
행이 삽입되지만 텍스트 필드의 모든 값이 0으로 처음 5 개 필드는있는 마지막 필드를 제외하고 비어있는 것 같습니다 내 문자열 인수에 물음표를 교체되지 않는 이유의 전체 기능이 calller에 의해 스택에 생성 below.The 목록이 표시됩니다
// If I hard code a value for value.data() then the row is inserted correctly with my hardcoded data, the exact line is below
status = sqlite3_bind_text(ppStmt, index, /* if I hardcode it works*/ value.data(), -1, SQLITE_STATIC);
텍스트를 입력, 나는 확실하지 오전, 하드 사람이없는 ..하지만 일 오류 코드가 반환됩니다.
//db is already open before I call this
void MediaCache::prepareAndExecuteQuery(string query, list<string> args)
{
sqlite3_stmt *ppStmt = 0;
const char **pzTail = 0;
int status = 0;
if(sqlite3_prepare_v2(db, query.data(), query.length(), &ppStmt, pzTail) != SQLITE_OK)
{
string error = sqlite3_errmsg(db);
//throw an exception
}
if(ppStmt)
{
list<string>::iterator current = args.begin();
int index = 1;
for(current = args.begin() ; current != args.end(); current++)
{
string value = *current;
status = sqlite3_bind_text(ppStmt, index, value.data(), -1, SQLITE_STATIC);
if(status != SQLITE_OK)
{
//log error;
}
index++;
}
status = sqlite3_step(ppStmt);
status = sqlite3_finalize(ppStmt);
//sqlite3_exec(db, "COMMIT", NULL, NULL, NULL);
}
else
{
//ppStmt is null
//throw an exception
}
}
나는이 문제를 의심
0-4 열의 데이터 유형은 무엇입니까? ? – Arpit
유형이 처음 5 개 필드의 경우 TEXT입니다. – Ahmed
이전 질문에서 이미 답변했습니다. 인수 바인딩 방법 [여기] (http://stackoverflow.com/questions/14483120/how-to-prepare-a-c-string-for-sql-query/14483389#14483389)을 참조하십시오. – m0skit0