2012-02-02 14 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()の何が問題なのですか?私はより詳細なエラー報告レベルを得ることができるいくつかの方法はありますか?

EDIT

行は、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 
} 
関連する問題