0

I've created a final table that fetched data from two other tables by UNION ALL statement with this Guide
Now I have new problem with updating table final.
When I want update "final_qty" , "firts_qty" or "second_qty" must be updated.
But I don't know how can I do it !
This is my codes:

// Table Names

public static final String TBL_FIRST = "table_first"; 
public static final String TBL_SECOND = "table_second"; 
public static final String TBL_FINAL = "table_final"; 

//Table Fisrt Columns

private static final String KEY_FIRST_ID = "first_id"; 
private static final String KEY_FIRST_PRODUCT = "first_product"; 
private static final String KEY_FIRST_QTY = "first_qty"; 

//Table Second Columns

private static final String KEY_SECOND_ID = "second_id"; 
private static final String KEY_SECOND_PRODUCT = "second_product"; 
private static final String KEY_SECOND_QTY = "second_qty"; 

//Table Final Columns

private static final String KEY_FINAL_ID = "final_id"; 
private static final String KEY_FINAL_PRODUCT = "final_product"; 
private static final String KEY_FINAL_QTY = "final_qty"; 

// Create Statements

private static final String CREATE_TABLE_FIRST = "CREATE TABLE " + TBL_FIRST + "(" + 
KEY_FIRST_ID+ " INTEGER PRIMARY KEY AUTOINCREMENT," + 
KEY_FIRST_PRODUCT + " TEXT," + 
KEY_FIRST_QTY + " INTEGER" + ")"; 

private static final String CREATE_TABLE_SECOND = "CREATE TABLE " + TBL_SECOND + "(" + 
KEY_SECOND_ID+ " INTEGER PRIMARY KEY AUTOINCREMENT," + 
KEY_SECOND_PRODUCT + " TEXT," + 
KEY_SECOND_QTY + " INTEGER" + ")"; 

private static final String CREATE_TABLE_FINAL = "CREATE TABLE " + TBL_FINAL + "(" + 
KEY_FINAL_ID+ " INTEGER PRIMARY KEY AUTOINCREMENT," + 
KEY_FINAL_PRODUCT + " TEXT," + 
KEY_FINAL_QTY + " INTEGER" + ")"; 

// INSERT DATA TO FINAL TABLE

"INSERT INTO " + TBL_FINAL + "(" + 
KEY_FINAL_PRODUCT + "," + KEY_FINAL_QTY + ")" + 
" SELECT " + KEY_FIRST_PRODUCT + "," + KEY_FIRST_QTY +  
" FROM " + TBL_FIRST + " WHERE " + KEY_FIRST_QTY + ">" + 0 + 
"UNION ALL SELECT " + KEY_SECOND_PRODUCT + "," + KEY_SECOND_QTY + 
" FROM " + TBL_SECOND + " WHERE " + KEY_SECOND_QTY + ">" + 0  ;

This is sample of my activities.

Sample image

In main activity I can go to first or second or final activities. When I'm in first or second activities, I change their items quantities and I return to the main activity.
Then I click on Final button in actionBar and go to Final Activity. In this Activity I'm going to change items quantities, so in addition to final_table, first_table and second_table items quantities must be updated.


Also When I go to my first activity and update "first_qty", in my "Final Table" I have two same rows with different qty.

Any offers would be appreciated.

Community
  • 1
  • 1
Farshad Kazemi
  • 358
  • 1
  • 4
  • 16

0 Answers0