I just don't get it (another caso of segmentation fault)



I'm trying to make a program with gtk and mysql, but
there are segmentations faults whitch I just can't
explain, one is in the clist, when I get the text from
it, it seems to me that the text just go away and it
becomes garbage, but I still have the text I got, I
tryed to put the text back but it didn't take effect,
and the other is with a simple entry, I have a form
and I update it with a new query whem the user clicks
on first, next, provious or last button but only one
entry get segmentation fault when I use
gtk_entry_set_text(). If anyone wanna see the hole
code I can send it.


Problem with the entry:

void
on_button_item_prox_clicked            (GtkButton     
 *button,
                                        gpointer      
  user_data)
{
  char  query[1024];
  int   item_max;
  gpointer      ponteiro;
  MYSQL_RES *result;
  MYSQL_ROW row, row_aux;

  strcpy(query,"SELECT COUNT(x) FROM itens");
  if(mysql_query(&mysql,query))
  {  g_print(mysql_error(&mysql));fflush(stdout); }

  result=mysql_store_result(&mysql);
  row=mysql_fetch_row(result);
  g_print("\núltimo item é o da posição %s",
row[0]);fflush(stdout);
  item_max=atoi(row[0]);
  item_max--;
  mysql_free_result(result);

  if(item_atual<item_max)
    item_atual++;

  sprintf(query,"SELECT x, seq, fornecedor,
fabricante, original, descricao, grupo, marca,
unidade, tributado, classe_fiscal, custo, custo1,
custo2, bruto, desconto, prazo, vista, locacao,
locacao_exec, data_cadastro, data_entrada, data_saida,
data_conferencia, data_alteracao, qtd_minima,
qtd_maxima, qtd_itu, qtd_salto, qtd_ituf,
qtd_sorocaba, nota_compra, fornecedor_nota FROM itens
LIMIT %d,1", item_atual);
  if(!mysql_query(&mysql,query))
    {g_print("\nQuery bem sucedida %s",
query);fflush(stdout);
     result=mysql_store_result(&mysql);
     row=mysql_fetch_row(result);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_x");
     gtk_entry_set_text(ponteiro, row[0]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_seq");
     gtk_entry_set_text(ponteiro, row[1]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_fornecedor_codigo");
     gtk_entry_set_text(ponteiro, row[2]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_fabricante");
     gtk_entry_set_text(ponteiro, row[3]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_original");
     gtk_entry_set_text(ponteiro, row[4]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_descricao");
     gtk_entry_set_text(ponteiro, row[5]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_grupo_codigo");
     gtk_entry_set_text(ponteiro, row[6]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_marca");
     gtk_entry_set_text(ponteiro, row[7]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_unidade");
     gtk_entry_set_text(ponteiro, row[8]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_tributado");
     gtk_entry_set_text(ponteiro, row[9]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_classe_fiscal");
     gtk_entry_set_text(ponteiro, row[10]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_custo");
     gtk_entry_set_text(ponteiro, row[11]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_custo1");
     gtk_entry_set_text(ponteiro, row[12]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_custo2");
     gtk_entry_set_text(ponteiro, row[13]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_bruto");
     gtk_entry_set_text(ponteiro, row[14]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_desconto");
     gtk_entry_set_text(ponteiro, row[15]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_prazo");
     gtk_entry_set_text(ponteiro, row[16]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_vista");
     gtk_entry_set_text(ponteiro, row[17]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_locacao");
     gtk_entry_set_text(ponteiro, row[18]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_locacao_exec");
     gtk_entry_set_text(ponteiro, row[19]);
     my2br(row[20]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_data_cadastro");
     gtk_entry_set_text(ponteiro, row[20]);
     my2br(row[21]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_data_entrada");
     gtk_entry_set_text(ponteiro, row[21]);
     my2br(row[22]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_data_saida");
     gtk_entry_set_text(ponteiro, row[22]);
     my2br(row[23]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_data_conferencia");
     gtk_entry_set_text(ponteiro, row[23]);
     my2br(row[24]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_data_alteracao");
     gtk_entry_set_text(ponteiro, row[24]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_qtd_minima");
     gtk_entry_set_text(ponteiro, row[25]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_qtd_maxima");
     gtk_entry_set_text(ponteiro, row[26]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_qtd_itu");
     gtk_entry_set_text(ponteiro, row[27]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_qtd_salto");
     gtk_entry_set_text(ponteiro, row[28]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_qtd_ituf");
     gtk_entry_set_text(ponteiro, row[29]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_qtd_sorocaba");
     gtk_entry_set_text(ponteiro, row[30]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_nota_fornecedor");
     gtk_entry_set_text(ponteiro, row[31]);
    
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_fornecedor_compra");
     gtk_entry_set_text(ponteiro, row[32]);
     mysql_free_result(result);

     sprintf(query, "SELECT razao_social FROM
fornecedores WHERE codigo=%s", row[2]);
     g_print("\nQUERY : %s", query);fflush(stdout);
     if(mysql_query(&mysql,query))
     {  g_print(mysql_error(&mysql));fflush(stdout);
       
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_fornecedor");
        gtk_entry_set_text(ponteiro, "***ERRO:
FORNECEDOR NÃO EXISTE***");
     }
     else
     {  result=mysql_store_result(&mysql);
        row_aux=mysql_fetch_row(result);
       
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_fornecedor");
        gtk_entry_set_text(ponteiro, row_aux[0]);
        mysql_free_result(result);
     }


     sprintf(query, "SELECT descricao FROM grupos
WHERE codigo=%s", row[6]);
     g_print("\nQUERY : %s", query);fflush(stdout);
     if(mysql_query(&mysql,query))
     {  g_print(mysql_error(&mysql));
       
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_grupo");
        gtk_entry_set_text(ponteiro, "***ERRO: GRUPO
NÃO EXISTE***");
     }
     else
     {  result=mysql_store_result(&mysql);
        row=mysql_fetch_row(result);
       
ponteiro=gtk_object_get_data(GTK_OBJECT(windowItem),"entry_item_grupo");
        gtk_entry_set_text(ponteiro, row[0]);
        mysql_free_result(result);
     }
    }
  else
    {g_print("\nNem foi bem sucedida\nRazão: %s\nQuery
%s", mysql_error(&mysql), query);fflush(stdout);}

}




Problem with the clist : 


int LINHA=-1;

void
on_clist1_select_row(GtkCList *clist,gint row         
                             gint column,GdkEvent
*event,gpointer user_data)
{
        gchar   *dados;

        LINHA=row;
        g_print("\nLINHA %d e COLUNA %d selicionadas", row,
column);
        gtk_clist_get_text(clist, row, column, &dados);
        g_print("\nCÉLULA: %s", dados);
        g_free(dados);
        gtk_clist_get_text(clist, row, 0, &dados);
        g_print("\nLINHA: Numero %s\t", dados);
        gtk_clist_set_text(clist, row, 0, dados);
        g_free(dados);
        gtk_clist_get_text(clist, row, 1, &dados);
        g_print("Cor %s\t", dados);
        gtk_clist_set_text(clist, row, 1, dados);
        g_free(dados);
        gtk_clist_get_text(clist, row, 2, &dados);
        g_print("Cidade %s\t", dados);
        gtk_clist_set_text(clist, row, 2, dados);
        g_free(dados);
}


______________________________________________________________________

Conheça a nova central de informações anti-spam do Yahoo! Mail:
http://www.yahoo.com.br/antispam



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]