mercredi 9 mars 2016

What I did wrong with sql query and how to parse it

I want to get 4 different prices from table Price based on parameters from table Logs.
It has length, sort, grade and diameter in both tables (only in table Price I set upper limit and lower limit - diameter range).
And then when I get values from query I want to parse them into double and multiply them with getResult(method).
I did this in my logs class code will be posted below.

I would like to know what I did wrong with my sql query and parsing that values from query?

This is how I did it. Please help.

public double getResult() {
        double log_length, log_diameter, length, diameter, result;
        log_length = Integer.parseInt(getLength().toString());
        log_diameter = Integer.parseInt(getDiameter().toString());
        length = log_length / 100;
        diameter = log_diameter * log_diameter * 3.14159265;
        result = length * diameter / 40000;
        return result;
    }

    public void  getParsedPrice() {
        try {
        Cursor cursor = db.query("Price", new String[]{"price_stump_kn", "price_stump_eur", "road_price_kn", "road_price_eur"}, "sort = ? AND grade = ? AND length = ? BETWEEN diameter_dg = ? AND diameter_gg = ?",
                new String[]{getSort_id(), getGrade(), getLength(), getDiameter(), getDiameter()}, null, null, null);
            System.out.print("result" + cursor.toString());
        if (cursor.getCount() > 0) {
             while (cursor.moveToNext()) {
                 double price1 = cursor.getDouble(0);
                 double price2 = cursor.getDouble(1);
                 double price3 = cursor.getDouble(2);
                 double price4 = cursor.getDouble(3);
             }
        }

        }catch (Exception e) {
            e.printStackTrace();
        }
        calculatePrice();
    }

    public double calculatePrice() {
        double price, parsedPrice;
        parsedPrice = Integer.parseInt(getParsedPrice());
        price = getResult() * getParsedPrice();
    }

Aucun commentaire:

Enregistrer un commentaire