开发者

Checking if value is not in the table ..help..please (Mysql + C)

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.


  1. You have generated the update statement, but you are not executing it. You need to execute your update statement using mysql_query()

  2. 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 :

  1. http://dev.mysql.com/doc/refman/5.0/en/mysql-affected-rows.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜