#include "mysql.h" #include int main() { MYSQL *mysql; char out[10]; int len; mysql= mysql_init(NULL); mysql= mysql_real_connect(mysql, "127.0.0.1", "root", "", "test", 4040, NULL, CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS | CLIENT_FOUND_ROWS); char *query = "drop table if exists duprowtest; create table duprowtest (id int(10) primary key, name varchar(255)); insert into duprowtest (id, name) values (1, 'a');"; mysql_real_query(mysql, query, strlen(query)); while (0 == mysql_next_result(mysql)) { mysql_free_result(mysql_store_result(mysql)); } int i = 0; while (2 > i ++) { query = "insert into duprowtest (id, name) values (1, 'a') on duplicate key update name = 'b'"; mysql_real_query(mysql, query, strlen(query)); printf("Affected rows: %d\n", mysql_affected_rows(mysql)); while (0 == mysql_next_result(mysql)) { mysql_free_result(mysql_store_result(mysql)); } } mysql_close(mysql); return 0; }