mysql_row从不兼容的指针类型返回赋值?在C.

时间:2011-02-27 08:59:39

标签: mysql c

人,

请参阅以下代码:

 gboolean auto_refresh_host_list(bahan *unit)
    {
//assuming unit->setting->handle_conn has initiated and connected
mysql_query(unit->setting->handle_conn,"select * from host");
unit->setting->handle_result = mysql_store_result(unit->setting->handle_conn);

guint num_fields = mysql_num_fields(unit->setting->handle_result);

line:148 while((unit->setting->handle_row = mysql_fetch_row(unit->setting->handle_result)))
{
    guint i;
    for(i=0; i<= num_fields; i++)
    {
    line:153    printf("%s", (unit->setting->handle_row[i] ? unit->setting->handle_row[i] : "NULL" ));
    }
    printf("\n");
}
mysql_free_result(unit->setting->handle_result);
line:158}

但是一旦我编译它会显示如下警告:

main.c:148: warning: assignment from incompatible pointer type
main.c:153: warning: pointer type mismatch in conditional expression
main.c:153: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘void * const’
main.c:158: warning: control reaches end of non-void function

无论如何,结构假设如下:

MYSQL *handle_conn;
MYSQL_RES *handle_result;
MYSQL_ROW *handle_row;
MYSQL_FIELD *handle_field;
阅读http://zetcode.com/tutorials/mysqlcapitutorial/后,我有点困惑,好吧,有人有任何想法吗?

1 个答案:

答案 0 :(得分:2)

mysql_fetch_row()会返回MYSQL_ROW,而不是MYSQL_ROW *