Code example for SQLiteStatement

Methods: bindLong, simpleQueryForString

0
    static final String GET_REF = "SELECT ref from rides WHERE _id IS ?";
 
    public String getLatestRef(int id) {
        if (getLatestRef == null)
            getLatestRef = getReadableDatabase().compileStatement(GET_REF);
        getLatestRef.bindLong(1, id);
        return getLatestRef.simpleQueryForString();
    } 
 
    static final String INSERT_RIDE = "INSERT OR REPLACE INTO rides "
            + "('type', from_id, to_id, dep, arr, mode, operator, who, details," 
            + " price, seats, marked, dirty, active, parent_id, ref, refresh)" 
            + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; 
 
    public int insertRide(ContentValues cv) {
        if (!cv.containsKey(Ride.FROM_ID)) cv.put(Ride.FROM_ID, -3);
        if (!cv.containsKey(Ride.TO_ID)) cv.put(Ride.TO_ID, -3);
        return insertRide(cv.getAsInteger(Ride.PARENT_ID),
                cv.getAsInteger(Ride.FROM_ID),
                cv.getAsInteger(Ride.TO_ID), cv);
    }