mardi 8 mars 2016

How create sql query to get data from table Price based on submitted parameters

I created sql query for getting data from table Price in which I'm passing 4 arguments from table Logs. I want to retrieve 4 price values.
I create this in my Logs class and arguments that I'm passing are Logs getters.
I have probably messed up sql query. And after that I need to parse into double and multiply with method getResult().

My question is how properly create this sql query and parse it to double or int?
Here is my code. 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 Cursor getPrice() {
        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);
        if (cursor.moveToFirst()) {
            do {
                Price price = new Price();
                price.setStumpPrice_kn(cursor.getString(0));
                price.setStumpPrice_eur(cursor.getString(1));
                price.setRoadPrice_kn(cursor.getString(2));
                price.setRoadPrice_eur(cursor.getString(3));
            } while (cursor.moveToNext());
        }
        return cursor;
    }

Aucun commentaire:

Enregistrer un commentaire