2012-02-02 69 views
1

我正在使用MySQL C++連接器版本1.1.0。 這是我的代碼看起來像:MySQL C++連接器MySQL_Prepared_Statement :: getUpdateCount錯誤

PreparedStatement *pStatement; 
connection->setAutoCommit(false); 

pStatement = connection->prepareStatement("UPDATE records " 
      "SET is_processed = ? " 
      "WHERE id = ?"); 

    //LOOP BEGIN 
    pStatement->setInt(1, is_processed); 
    pStatement->setString(2, record_id); 

    pStatement->execute(); 
    //LOOP END 

int updated_records; 

try 
{ 
    updated_records = pStatement->getUpdateCount(); 
} 
catch(SQLException&e) 
{ 
    cout << "ERROR: " << e.what(); 
    cout << " (MySQL error code: " << e.getErrorCode(); 
    cout << ", SQLState: " << e.getSQLState() << ")" << endl; 
} 

connection->commit(); 
connection->setAutoCommit(true); 

異常與下面的輸出拋出:

ERROR: MySQL_Prepared_Statement::getUpdateCount (MySQL error code: 0, SQLState:) 

所以說完全沒有。 getUpdateCount()函數有什麼問題?有什麼方法可以獲得更詳細的錯誤報告級別?

編輯

是否有任何其他方式來獲得更新的行計數用mysql C++接口?

回答

1

我終於找到工作的解決方案:受影響的行

int updated_records = 0; 

    //LOOP BEGIN 
    pStatement->setInt(1, is_processed); 
    pStatement->setString(2, record_id); 

    updated_records += pStatement->executeUpdate(); 
    //LOOP END 

cout << updated_records; 

executeUpdate()返回數量和它的作品沒有任何錯誤,所以這對我來說足夠。

1

爲了澄清他人,因爲我很困惑;像這樣做:

pstmt = con->prepareStatement ("UPDATE localdata SET Val = ? WHERE ID = ?"); 
pstmt->setDouble (1, 7.77); // first "?" 
pstmt->setInt (2, 0); // second "?" 
pstmt->executeUpdate(); 

訣竅是根據它們的表類型和順序在語句中設置值。

1

我也遇到了這個問題。我最終看了一下源代碼。看起來源明確會拋出一個異常。

uint64_t 
MySQL_Prepared_Statement::getUpdateCount() 
{ 
    checkClosed(); 
    throw MethodNotImplementedException("MySQL_Prepared_Statement::getUpdateCount"); 
    return 0; // fool compilers 
}