2012-05-12 1 views
2
query->prepare("INSERT INTO businessweek (id, source, date, headline, body) VALUES (NULL, ?, ?, ?, ?)"); 
query->bindValue(1, "source"); 
query->bindValue(2, "date"); 
query->bindValue(3, "headline"); 
query->bindValue(4, "body"); 

if (query->exec()) { 
    tt << "Query success"; 
} else { 
    qDebug() << db.lastError(); 
    return; 
} 

QMYSQL을 사용하고 있습니다. 그리고 오류가 Qt SQL 쿼리가 실패했습니다.

query->exec("INSERT INTO businessweek (id, source, date, headline, body) VALUES (NULL, 'google', 'may 0, 23', 'head', 'fjsdflksjdlkfdsjlfkjd');") 

가 잘 작동되고

QSqlError(-1, "", "") 

그러나

입니다.

답변

3

문제를 추측하기 어렵습니다. 하지만 내가 상상할 수있는 한 가지 확실한 것은 코드가 bindValue 인 필드 번호가 0부터 시작한다는 것입니다 (here 참조).

따라서, 나는

query->prepare("INSERT INTO businessweek (id, source, date, headline, body) VALUES (NULL, ?, ?, ?, ?)"); 
query->bindValue(0, "source"); 
query->bindValue(1, "date"); 
query->bindValue(2, "headline"); 
query->bindValue(3, "body"); 

if (query->exec()) { 
    tt << "Query success"; 
} else { 
    qDebug() << db.lastError(); 
    return; 
} 
+0

감사를 시도하는 것이 좋습니다 것입니다. 0으로 시작합니다 :) – Dewsworld