Example usage for android.database.sqlite SQLiteDatabase rawQuery

List of usage examples for android.database.sqlite SQLiteDatabase rawQuery

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase rawQuery.

Prototype

public Cursor rawQuery(String sql, String[] selectionArgs) 

Source Link

Document

Runs the provided SQL and returns a Cursor over the result set.

Usage

From source file:io.vit.vitio.Managers.ConnectDatabase.java

public void clear() {
    SQLiteDatabase sqLiteDatabase = getWritableDatabase();
    String deleteQuery = "DELETE FROM " + TABLE_COURSES + ";";
    sqLiteDatabase.delete(TABLE_COURSES, "1", null);
    Cursor cursor = sqLiteDatabase.rawQuery(deleteQuery, null);
    cursor.close();/*  w ww . j a v a2s  .c  om*/
    sqLiteDatabase.close();
}

From source file:com.seneca.android.senfitbeta.DbHelper.java

public ArrayList<Calender> getSetE() {
    Log.d("SET_GET", "Geting set exercise");

    String fetchset = "select * from " + CALENDER_TABLE + " ORDER BY " + MONTH + " ASC," + DAY + " ASC";

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(fetchset, null);
    cursor.moveToFirst();//from   w  ww . j  a  va2  s  .  c  o  m

    ArrayList<Calender> temp = new ArrayList<Calender>();

    if (cursor == null) {
        Calender ex = new Calender(0, 0, 0, 0, 0, "empty");
        temp.add(ex);
        Log.d("exiting", "NOTHING");
    }
    if (cursor.getCount() == 0) {
        Log.d("NOTHING", "0 nothing");
    } else {
        cursor.moveToFirst();
        do {
            Calender ex = new Calender();

            ex.setNum(cursor.getInt(cursor.getColumnIndex(CAL_NUM)));
            ex.setMonth(cursor.getInt(cursor.getColumnIndex(MONTH)));
            ex.setDay(cursor.getInt(cursor.getColumnIndex(DAY)));
            ex.setYear(cursor.getInt(cursor.getColumnIndex(YEAR)));
            ex.setName(cursor.getString(cursor.getColumnIndex(CAL_NAME)));

            temp.add(ex);
        } while (cursor.moveToNext());
    }

    cursor.close();
    getReadableDatabase().close();
    return temp;

}

From source file:com.seneca.android.senfitbeta.DbHelper.java

public ArrayList<Exercise> getExByMuscles(int num) {
    Log.d("SELECT EXDB", "Getinging exercise By id");

    String selectQuery = "SELECT * FROM exercises WHERE id LIKE '%" + num + "%' ORDER BY " + EXERCISE_ID
            + " ASC";

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);
    cursor.moveToFirst();//from w w w .j  a v a2s.  co  m

    if (cursor == null) {
        Log.d("exiting", "NOTHING");
    }

    if (cursor.getCount() == 0) {
        Log.d("NOTHING", "0 nothing");
    }

    ArrayList<Exercise> temp = new ArrayList<Exercise>();
    cursor.moveToFirst();
    do {
        Exercise ex = new Exercise();
        ex.setId(cursor.getInt(cursor.getColumnIndex(EXERCISE_ID)));
        ex.setLicense_author(cursor.getString(cursor.getColumnIndex(AUTHOR)));
        ex.setDescription(cursor.getString(cursor.getColumnIndex(DESCRIPTION)));
        ex.setName(cursor.getString(cursor.getColumnIndex(NAMETYPE)));
        ex.setName_original(cursor.getString(cursor.getColumnIndex(ORIGNALNAME)));
        ex.setCreation_date(cursor.getString(cursor.getColumnIndex(CREATIONDATE)));
        ex.setCategory(cursor.getString(cursor.getColumnIndex(CATEGORY)));

        temp.add(ex);
    } while (cursor.moveToNext());

    cursor.close();
    getReadableDatabase().close();

    return temp;

}

From source file:heartware.com.heartware_master.DBAdapter.java

public HashMap<String, String> getProfileById(String id) {
    HashMap<String, String> profileMap = new HashMap<String, String>();
    SQLiteDatabase database = this.getReadableDatabase();
    String selectQuery = "SELECT * FROM " + PROFILES_TABLE + " WHERE " + PROFILE_ID + "='" + id + "'";
    Cursor cursor = database.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
        do {/* w ww  .j a  v  a  2  s  .  c  om*/
            profileMap.put(PROFILE_ID, cursor.getString(0));
            profileMap.put(USERNAME, cursor.getString(1));
            profileMap.put(PASSWORD, cursor.getString(2));
            profileMap.put(DIFFICULTY, cursor.getString(3));
            profileMap.put(DISABILITY, cursor.getString(4));
        } while (cursor.moveToNext());
    }
    return profileMap;
}

From source file:com.nolanlawson.cordova.sqlite.SQLitePlugin.java

private SQLitePLuginResult doSelectInBackgroundAndPossiblyThrow(String sql, String[] bindArgs,
        SQLiteDatabase db) {
    debug("\"all\" query: %s", sql);
    Cursor cursor = null;/*  w ww  .  j  a  v  a  2 s. c  o m*/
    try {
        cursor = db.rawQuery(sql, bindArgs);
        int numRows = cursor.getCount();
        if (numRows == 0) {
            return EMPTY_RESULT;
        }
        int numColumns = cursor.getColumnCount();
        Object[][] rows = new Object[numRows][];
        String[] columnNames = cursor.getColumnNames();
        for (int i = 0; cursor.moveToNext(); i++) {
            Object[] row = new Object[numColumns];
            for (int j = 0; j < numColumns; j++) {
                row[j] = getValueFromCursor(cursor, j, cursor.getType(j));
            }
            rows[i] = row;
        }
        debug("returning %d rows", numRows);
        return new SQLitePLuginResult(rows, columnNames, 0, 0, null);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:bus_vn.gena.bus_vn.com.bus_vn.tabs.Tab_list_bus.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    DbOpenHelper dbOpenHelper = new DbOpenHelper(getActivity());
    SQLiteDatabase db;
    db = dbOpenHelper.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.clear();//w ww  . j  a  v a 2s  . c o m
    String st;
    st = "SELECT Name FROM bus_path_table  WHERE bus_path_table.Type_transport_id='" + typeTransport + "'"
            + "ORDER BY Number";
    Cursor c = db.rawQuery(st, null);
    while (c.moveToNext()) {
        String st2 = "";
        st2 = c.getString(0);
        results.add(st2);
    }
    //  ??
    gridView = (GridView) getView().findViewById(R.id.gridview);
    //? ClickListener ? listview
    gridView.setOnItemClickListener((android.widget.AdapterView.OnItemClickListener) this);
    dataList = new ArrayList<Map<String, Object>>();
    dataList = getData();
    //? ClickListener ? gridView
    simpleAdapter = new SimpleAdapter(getActivity(), dataList, R.layout.gridview_item,
            new String[] { "image", "text" }, new int[] { R.id.image, R.id.text });
    //     listview
    gridView.setAdapter(simpleAdapter);
}

From source file:com.shalzz.attendance.DatabaseHandler.java

public List<Integer> getAbsentSubjects(Date date) {
    SQLiteDatabase db = this.getReadableDatabase();
    List<Integer> subjectIDs = new ArrayList<>();

    try (Cursor cursor = db.rawQuery(AbsentDate.SELECT_ABSENT_SUBJECTS,
            new String[] { String.valueOf(DateHelper.formatToTechnicalFormat(date)) })) {
        while (cursor.moveToNext()) {
            subjectIDs.add(AbsentDate.MAPPER.map(cursor).subject_id());
        }//from  w w  w.  j a v  a  2s  . c  om
    }

    return subjectIDs;
}

From source file:net.willwebberley.gowertides.utils.WeatherDatabase.java

public Cursor getSurfInfo(Calendar dayToGet, int location) {
    SQLiteDatabase db = this.getReadableDatabase();
    int year = dayToGet.get(Calendar.YEAR);
    int month = dayToGet.get(Calendar.MONTH) + 1;
    int day = dayToGet.get(Calendar.DAY_OF_MONTH);
    try {//from   ww  w . j a va 2s .  co m
        Cursor result = db.rawQuery("SELECT * FROM surf WHERE year = " + year + " AND month = " + month
                + " AND day = " + day + " AND location = " + location + " ORDER BY timestamp DESC", null);

        result.moveToFirst();
        return result;
    } catch (Exception e) {
        System.out.println(e);
        return null;
    }
}

From source file:net.willwebberley.gowertides.utils.WeatherDatabase.java

public Cursor getWeatherInfo(Calendar dayToGet) {
    SQLiteDatabase db = this.getReadableDatabase();
    int year = dayToGet.get(Calendar.YEAR);
    int month = dayToGet.get(Calendar.MONTH) + 1;
    int day = dayToGet.get(Calendar.DAY_OF_MONTH);

    try {//from   w  w w .jav a 2  s .  com
        Cursor result = db.rawQuery("SELECT * FROM weather WHERE year = " + year + " AND MONTH = " + month
                + " AND DAY = " + day + " ORDER BY timestamp", null);
        result.moveToLast();
        return result;
    } catch (Exception e) {
        System.out.println(e);
        return null;
    }
}

From source file:com.esri.squadleader.model.GeoPackageReader.java

/**
 * Reads the tables in a GeoPackage, makes a layer from each table, and returns a list containing
 * those layers./*w  w w . j  av a  2 s  .  co  m*/
 *
 * @param gpkgPath       the full path to the .gpkg file.
 * @param sr             the spatial reference to which any raster layers should be projected, typically the
 *                       spatial reference of your map.
 * @param showVectors    if true, this method will include the GeoPackage's vector layers.
 * @param showRasters    if true, this method will include the GeoPackage's raster layer.
 * @param rasterRenderer the renderer to be used for raster layers. One simple option is an RGBRenderer.
 * @param markerRenderer the renderer to be used for point layers.
 * @param lineRenderer   the renderer to be used for polyline layers.
 * @param fillRenderer   the renderer to be used for polygon layers.
 * @return a list of the layers created for all tables in the GeoPackage.
 * @throws IOException if gpkgPath cannot be read. Possible reasons include the file not
 *                     existing, failure to request READ_EXTERNAL_STORAGE or
 *                     WRITE_EXTERNAL_STORAGE permission, or the GeoPackage containing an
 *                     invalid spatial reference.
 */
public List<Layer> readGeoPackageToLayerList(String gpkgPath, SpatialReference sr, boolean showVectors,
        boolean showRasters, RasterRenderer rasterRenderer, Renderer markerRenderer, Renderer lineRenderer,
        Renderer fillRenderer) throws IOException {
    List<Layer> layers = new ArrayList<Layer>();

    if (showRasters) {
        // Check to see if there are any rasters before loading them
        SQLiteDatabase sqliteDb = null;
        Cursor cursor = null;
        try {
            sqliteDb = SQLiteDatabase.openDatabase(gpkgPath, null, SQLiteDatabase.OPEN_READONLY);
            cursor = sqliteDb.rawQuery("SELECT COUNT(*) FROM gpkg_contents WHERE data_type = ?",
                    new String[] { "tiles" });
            if (cursor.moveToNext()) {
                if (0 < cursor.getInt(0)) {
                    cursor.close();
                    sqliteDb.close();
                    FileRasterSource src = new FileRasterSource(gpkgPath);
                    rasterSources.add(src);
                    if (null != sr) {
                        src.project(sr);
                    }
                    RasterLayer rasterLayer = new RasterLayer(src);
                    rasterLayer.setRenderer(rasterRenderer);
                    rasterLayer
                            .setName((gpkgPath.contains("/") ? gpkgPath.substring(gpkgPath.lastIndexOf("/") + 1)
                                    : gpkgPath) + " (raster)");
                    layers.add(rasterLayer);
                }
            }
        } catch (Throwable t) {
            Log.e(TAG, "Could not read raster(s) from GeoPackage", t);
        } finally {
            if (null != cursor) {
                cursor.close();
            }
            if (null != sqliteDb) {
                sqliteDb.close();
            }
        }
    }

    if (showVectors) {
        Geopackage gpkg;
        try {
            gpkg = new Geopackage(gpkgPath);
        } catch (RuntimeException ex) {
            throw new IOException(null != ex.getMessage() && ex.getMessage().contains("unknown wkt")
                    ? "Geopackage " + gpkgPath + " contains an invalid spatial reference."
                    : null, ex);
        }
        geopackages.add(gpkg);
        List<GeopackageFeatureTable> tables = gpkg.getGeopackageFeatureTables();
        if (0 < tables.size()) {
            //First pass: polygons and unknowns
            HashSet<Geometry.Type> types = new HashSet<Geometry.Type>();
            types.add(Geometry.Type.ENVELOPE);
            types.add(Geometry.Type.POLYGON);
            types.add(Geometry.Type.UNKNOWN);
            layers.addAll(getTablesAsLayers(tables, types, fillRenderer));

            //Second pass: lines
            types.clear();
            types.add(Geometry.Type.LINE);
            types.add(Geometry.Type.POLYLINE);
            layers.addAll(getTablesAsLayers(tables, types, lineRenderer));

            //Third pass: points
            types.clear();
            types.add(Geometry.Type.MULTIPOINT);
            types.add(Geometry.Type.POINT);
            layers.addAll(getTablesAsLayers(tables, types, markerRenderer));
        }
    }

    return layers;
}