jeudi 30 juillet 2015

DELETE A BUTON FROM A BUTTON BOX AS WELL AS FROM DATABASE

When I want to delete a selected button(created dynamically) from vertical button box(created in glade). My code works only for the end row button which is seen instantly as I press a delete button in my gtk window,means it gets destroyed at the same time, but for every other row it does not work...however it is getting deleted but can only be seen when I run my codes again for the next time.my problem is this...i am using sqlite database in my codes... A Little help is very much appreciated...Thanks in advance!

/*delete button created and called*/  
  DeleteButton = GTK_WIDGET( gtk_builder_get_object( builder, "DeleteButton" ) );
  gtk_signal_connect (GTK_OBJECT (DeleteButton), "clicked", GTK_SIGNAL_FUNC (Delete_Data), NULL);

/*delete function*/
void Delete_Data( GtkWidget *widget, gpointer data)
{
    char sql[100];
    sprintf(sql, "DELETE FROM SURVEILLANCE \nwhere ID= %s;",updateid);
                    "SELECT * from SURVEILLANCE";

    deleteData(sql);
    Delete_Button();

}

/*for deletion*/
void Delete_Button()
{
    gtk_signal_connect (GTK_OBJECT (sW_Button), "clicked", GTK_SIGNAL_FUNC (camera3), sW_VBbox);
    gtk_widget_destroy(sW_Button);
}

/*database file*/
void deleteData(char *sql)
{
   sqlite3 *db;
   char *zErrMsg = 0;
   int rc;

   const char* data = "Callback function called";

/* Open database */
   rc = sqlite3_open("Database_Surveillance.db", &db);
   if( rc )
   {
      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      exit(0);
   }
   else
   {
      fprintf(stderr, "deleteData_Opened database successfully\n");
   }

//   /* Create merged SQL statement */
//   sql = "DELETE from SURVEILLANCE where ID=2; " \
//         "SELECT * from SURVEILLANCE";

/* Execute SQL statement */
   rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
   if( rc != SQLITE_OK )
   {
      fprintf(stderr, "SQL error: %s\n", zErrMsg);
      sqlite3_free(zErrMsg);
   }
   else
   {
      fprintf(stdout, "deleteData_Operation done successfully\n");
   }
   sqlite3_close(db);
}

this are my codes for deletion...if required I will show my codes for everything I am working!

Aucun commentaire:

Enregistrer un commentaire