Here is my code.
I want to update column data in copied quote2.db file.
/*copy database*/ FILE *src,*dst; char srcURL[PATH_MAX]; char dstURL[PATH_MAX]; int ch; sprintf(srcURL,"%s%s",app_get_resource_path(),"quote.db"); sprintf(dstURL,"%s%s",app_get_shared_data_path(),"quote2.db"); dlog_print(DLOG_DEBUG,"self","%s",srcURL); dlog_print(DLOG_DEBUG,"self","%s",dstURL); src=fopen(srcURL,"r"); dst=fopen(dstURL,"w"); while( ( ch = getc(src) ) != EOF ) fputc(ch, dst); fclose(src); fclose(dst);
I opened quote2.db here.
char *errmsg; char *resource_path = app_get_shared_data_path(); dlog_print(DLOG_DEBUG, LOG_TAG, "shared data path is : %s",resource_path); int size = strlen(resource_path) + 10; char path2[255]; strcpy(path2,resource_path); strncat(path2,"quote2.db",size); dlog_print(DLOG_DEBUG, LOG_TAG, "shared db path is : %s", path2); int ret = sqlite3_open_v2(path2, &db_handle,SQLITE_OPEN_READWRITE, NULL); if (ret == SQLITE_OK) { dlog_print(DLOG_DEBUG, LOG_TAG, "shared db open success %d",ret); } else { dlog_print(DLOG_DEBUG, LOG_TAG, "shared db open failed %s",&errmsg); }
Here i have performed update query but it is not working and not giving any error.
int image_set_cb(void *data,int argc,char **argv, char **azColName) { appdata_s *ad=data; dlog_print(DLOG_DEBUG,LOG_TAG,"success"); const char *path = app_get_resource_path(); char img[PATH_MAX]; snprintf(img, sizeof(img), "%sicons/favourite.png", path); elm_image_file_set(ad->fav_img, img, NULL); return 0; } int fav_col_change_cb(void *data,int argc,char **argv, char **azColName) { appdata_s *ad=data; if (argv[3]==NULL) { int ret; char sql[255], *errmsg; sprintf(sql,"UPDATE quotes SET Favourites=1 WHERE QuoteID=%d;",o_array[array_index]); ret = sqlite3_exec(db_handle, sql,image_set_cb, ad, &errmsg); if (ret == SQLITE_OK) { dlog_print(DLOG_DEBUG, LOG_TAG,"fav_col_change_cb READ SUCCESSFULLY: %s",sql); } else { dlog_print(DLOG_DEBUG, LOG_TAG, "fav_col_change_cb READ FAILED: %s",errmsg); } } return 0; } void add_to_fav_cb(void *data, Evas_Object *obj, void *event_info) { appdata_s *ad=data; { int ret; char sql[255], *errmsg; cnt++; sprintf(sql, "SELECT * FROM quotes WHERE QuoteID=%d;",o_array[array_index]); ret = sqlite3_exec(db_handle, sql,fav_col_change_cb, ad, &errmsg); if (ret == SQLITE_OK) { dlog_print(DLOG_DEBUG, LOG_TAG,"add_to_fav_cb SUCCESS: %d", ret); } else { dlog_print(DLOG_DEBUG, LOG_TAG, "add_to_fav_cb FAILED: %s",errmsg); } } }