lundi 7 mars 2016

What is the proper way to populate table in sqlite

I want to add data into sqlite table. I created string arrays like this

String idPriceArray = "1, 2, 3, 4, 5";
String priceSort = "Sort1, Sort2, Sort3, Sort4, Sort5";
String priceGrade = "A, B, C, D, E";
String priceDiameter = "45+, 40+, 35+, 32+, 28+";
String priceLength = "300, 250, 250, 220, 200";
String stumpPrice1 = "1900.00, 1300.00, 700.00, 450.00, 1400.00";
String stumpPrice2 = "248, 170, 144, 91, 59";
String roadPrice1 = "2000.00, 1400.00, 1200.00, 800.00, 550.00";
String roadPrice2 = "261, 183, 157, 104, 72";
String crustDeduction = "4, 4, 3, 3, 2";

And then I pass them into addPrices method like this.

public void addPrice() {
        SQLiteDatabase db = this.getWritableDatabase();
        for (int i=0; i < idPriceArray.length(); i++) {
            ContentValues cv = new ContentValues();
            cv.put(PRICE_SORT, priceSort);
            cv.put(PRICE_GRADE, priceGrade);
            cv.put(PRICE_DIAMETER, priceDiameter);
            cv.put(PRICE_LENGTH, priceLength);
            cv.put(PRICE_STUMP_KN, stumpPrice1);
            cv.put(PRICE_STUMP_EUR, stumpPrice2);
            cv.put(PRICE_ROAD_KN, roadPrice1);
            cv.put(PRICE_ROAD_EUR, roadPrice1);
            cv.put(PRICE_CRUST, crustDeduction);
            db.insert(TABLE_PRICE, null, cv);
        }
        db.close();
    }

Problem is that i get all sorts, grades and everything else in one row. When I display them in layout I get like this:
Sort: Sort1, Sort2, Sort3..
Grades: A, B, C, D, E.
But I want to get it like this:
Sort: Sort1
Grades: A
And all like this.
I would like to know what is the proper way to populate table like this?

Aucun commentaire:

Enregistrer un commentaire