My purpose is to warn the user whenever he/she insert a value which is not in the table.
Table :
For_Sconti | Cat_Sconti | Sconto
7148 开发者_StackOverflowA1 451.00
Someone cleverly suggested to use mysql_affected_rows() function.
Since it can be used when an update statement is issued, I tried to understand how it works but to no avail.
Here's the code I use:
memset(query, 0, 200);
strcat(query, "UPDATE Sconti SET ");
strcat(query, "Sconto = '");
strcat(query, nuovo_sconto);
strcat(query, "' WHERE For_Sconti ='");
strcat(query, For_Sconti);
strcat(query, "' AND Cat_Sconti='");
strcat(query, Cat_Sconti);
strcat(query, "';");
if ( (mysql_affected_rows()) == 0 )
printf("Warning you tried to modify non existent record\n" );
This is the error message I get:
2.0.c: In function ‘modifica_sconto’:
2.0.c:330: error: too few arguments to function ‘mysql_affected_rows’
Can someone help get out of trouble?
Any help will be highly appreciated.
You have generated the update statement, but you are not executing it. You need to execute your update statement using mysql_query()
You need to pass your mysql connection handle structure (MYSQL *) as a parameter to mysql_affected_rows()
char *stmt = "UPDATE products SET cost=cost*1.25 WHERE group=10"; mysql_query(&mysql,stmt); printf("%ld products updated", (long) mysql_affected_rows(&mysql));
References :
- http://dev.mysql.com/doc/refman/5.0/en/mysql-affected-rows.html
精彩评论