List of usage examples for android.database.sqlite SQLiteDatabase rawQuery
public Cursor rawQuery(String sql, String[] selectionArgs)
From source file:io.vit.vitio.Managers.ConnectDatabase.java
public List<Course> getCoursesList() { List<Course> courses = new ArrayList<>(); String selectQuery = "SELECT * FROM " + TABLE_COURSES; try {/*from ww w . j a v a 2s . c om*/ SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do { Course course = new Course(); course.setCLASS_NUMBER(cursor.getString(0)); course.setCOURSE_TITLE(cursor.getString(1)); course.setCOURSE_SLOT(cursor.getString(2)); course.setCOURSE_TYPE(cursor.getString(3)); course.setCOURSE_TYPE_SHORT(cursor.getString(4)); course.setCOURSE_LTPC(cursor.getString(5)); course.setCOURSE_CODE(cursor.getString(6)); course.setCOURSE_MODE(cursor.getString(7)); course.setCOURSE_OPTION(cursor.getString(8)); course.setCOURSE_VENUE(cursor.getString(9)); course.setCOURSE_FACULTY(cursor.getString(10)); course.setCOURSE_REGISTRATIONSTATUS(cursor.getString(11)); course.setCOURSE_BILL_DATE(cursor.getString(12)); course.setCOURSE_BILL_NUMBER(cursor.getString(13)); course.setCOURSE_PROJECT_TITLE(cursor.getString(14)); course.setJson(new JSONObject(cursor.getString(15))); course.setCOURSE_ATTENDANCE(ParseCourses.getAttendance(new JSONObject(cursor.getString(16)))); course.setCOURSE_TIMING(ParseCourses.getTimings(new JSONArray(cursor.getString(17)))); course.setCOURSE_MARKS(ParseCourses.getCouseMarks(new JSONObject(cursor.getString(18)))); courses.add(course); } while (cursor.moveToNext()); } cursor.close(); db.close(); } catch (Exception e) { e.printStackTrace(); SQLiteDatabase _db = this.getWritableDatabase(); if (_db != null && _db.isOpen()) { _db.close(); } } return courses; }
From source file:heartware.com.heartware_master.DBAdapter.java
public ArrayList<HashMap<String, String>> getAllProfiles() { ArrayList<HashMap<String, String>> profileArrayList; profileArrayList = new ArrayList<HashMap<String, String>>(); String selectQuery = "SELECT * FROM " + PROFILES_TABLE + " ORDER BY " + USERNAME + " ASC"; SQLiteDatabase database = this.getWritableDatabase(); Cursor cursor = database.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do {//ww w . jav a2 s . c o m HashMap<String, String> profileMap = new HashMap<String, String>(); 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)); profileArrayList.add(profileMap); } while (cursor.moveToNext()); } return profileArrayList; }
From source file:heartware.com.heartware_master.DBAdapter.java
public ArrayList<HashMap<String, String>> getAllMeetups() { ArrayList<HashMap<String, String>> workoutList; workoutList = new ArrayList<HashMap<String, String>>(); String selectQuery = "SELECT * FROM " + MEETUPS_TABLE + " ORDER BY " + USER_ID + " ASC"; SQLiteDatabase database = this.getWritableDatabase(); Cursor cursor = database.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do {/*w w w . j a v a2s . com*/ HashMap<String, String> workoutMap = new HashMap<String, String>(); workoutMap.put(USER_ID, cursor.getString(0)); workoutMap.put(NOTE, cursor.getString(1)); workoutMap.put(EXERCISE, cursor.getString(2)); workoutMap.put(LOCATION, cursor.getString(3)); workoutMap.put(DATE, cursor.getString(4)); workoutMap.put(PEOPLE, cursor.getString(5)); workoutList.add(workoutMap); } while (cursor.moveToNext()); } return workoutList; }
From source file:heartware.com.heartware_master.DBAdapter.java
public ArrayList<HashMap<String, String>> getAllMeetups(final String userId) { ArrayList<HashMap<String, String>> workoutList; workoutList = new ArrayList<HashMap<String, String>>(); String selectQuery = "SELECT * FROM " + MEETUPS_TABLE + " WHERE " + USER_ID + " ='" + userId + "' ORDER BY " + USER_ID + " ASC"; SQLiteDatabase database = this.getWritableDatabase(); Cursor cursor = database.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do {//from w w w . j av a 2 s .c om HashMap<String, String> workoutMap = new HashMap<String, String>(); workoutMap.put(USER_ID, cursor.getString(0)); workoutMap.put(NOTE, cursor.getString(1)); workoutMap.put(EXERCISE, cursor.getString(2)); workoutMap.put(LOCATION, cursor.getString(3)); workoutMap.put(DATE, cursor.getString(4)); workoutMap.put(PEOPLE, cursor.getString(5)); workoutList.add(workoutMap); } while (cursor.moveToNext()); } return workoutList; }
From source file:com.acrylicgoat.scrumnotes.DailyNotesActivity.java
private void saveNote() { ContentValues values = new ContentValues(); String noteStr = note.getText().toString(); //Log.d("NoteEditorActivity", "note: " + text); int nlength = noteStr.length(); if (nlength == 0) { Toast.makeText(this, getString(R.string.nothing_to_save), Toast.LENGTH_SHORT).show(); return;/*from w w w .j a v a2 s. co m*/ } values.put(Goals.NOTE, noteStr); //check if a note already exists for today DatabaseHelper dbHelper = new DatabaseHelper(this.getApplicationContext()); SQLiteDatabase db = dbHelper.getReadableDatabase(); cursor = db.rawQuery("select goals_goal from goals", null); if (cursor.getCount() > 0) { //Log.d("MainActivity", "saveNote(): doing update "); StringBuilder sb = new StringBuilder(); sb.append("update goals set goals_note = '"); sb.append(ScrumNotesUtil.escape(noteStr)); sb.append("'"); dbHelper.getReadableDatabase().execSQL(sb.toString()); getContentResolver().update(Goals.CONTENT_URI, values, null, null); } else { getContentResolver().insert(Goals.CONTENT_URI, values); } cursor.close(); db.close(); }
From source file:com.dpcsoftware.mn.EditGroups.java
private void renderGroups() { SQLiteDatabase db = DatabaseHelper.quickDb(this, 1); Cursor c = db.rawQuery("SELECT " + Db.Table3._ID + "," + Db.Table3.COLUMN_NGRUPO + " FROM " + Db.Table3.TABLE_NAME + " ORDER BY " + Db.Table3.COLUMN_NGRUPO + " ASC", null); if (adapter == null) { adapter = new GroupsAdapter(this, c); lv.setAdapter(adapter);/* ww w . j av a 2 s. co m*/ setContentView(lv); } else { adapter.swapCursor(c); adapter.notifyDataSetChanged(); } db.close(); }
From source file:edu.asu.bscs.csiebler.waypointdatabase.MainActivity.java
private JSONArray getJsonResults() { JSONArray resultSet = new JSONArray(); try {//from w ww . ja v a 2 s. c o m WaypointDB db = new WaypointDB(this); db.copyDB(); SQLiteDatabase waypointDB = db.openDB(); waypointDB.beginTransaction(); String searchQuery = "SELECT * FROM waypoint"; Cursor cursor = waypointDB.rawQuery(searchQuery, null); cursor.moveToFirst(); while (cursor.isAfterLast() == false) { int totalColumn = cursor.getColumnCount(); JSONObject rowObject = new JSONObject(); for (int i = 0; i < totalColumn; i++) { if (cursor.getColumnName(i) != null) { try { if (cursor.getString(i) != null) { Log.d("TAG_NAME", cursor.getString(i)); rowObject.put(cursor.getColumnName(i), cursor.getString(i)); } else { rowObject.put(cursor.getColumnName(i), ""); } } catch (Exception e) { Log.d("TAG_NAME", e.getMessage()); } } } resultSet.put(rowObject); cursor.moveToNext(); } cursor.close(); waypointDB.endTransaction(); waypointDB.close(); db.close(); Log.d("TAG_NAME", resultSet.toString()); } catch (Exception ex) { Log.w(getClass().getSimpleName(), "Exception creating adapter: " + ex.getMessage()); } return resultSet; }
From source file:com.example.shutapp.DatabaseHandler.java
/** * @return the amount of chatrooms in the database. */// www . ja v a 2 s . com public int getChatroomsCount() { String countQuery = "SELECT * FROM " + TABLE_CHATROOMS; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(countQuery, null); if (cursor != null) { cursor.moveToFirst(); } int count = cursor.getCount(); cursor.close(); // return count return count; }
From source file:ru.freshartapp.automarka.utils.ImageDetailFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Use the parent activity to load the image asynchronously into the // ImageView (so a single // cache can be used over all pages in the ViewPager if (ImageDetailActivity.class.isInstance(this.getActivity())) { if (this.mModelId != -1) { // Load information about favorites ExternalDbOpenHelper dbFavoritesOpenHelper = new ExternalDbOpenHelper( this.getActivity().getApplicationContext(), this.DB_FAVORITES_NAME); SQLiteDatabase database_favorites = dbFavoritesOpenHelper.openDataBase(); Cursor cur = database_favorites .rawQuery("SELECT status FROM model_favorites WHERE parent=" + this.mModelId, null); cur.moveToFirst();/* w w w .ja v a 2s .c om*/ if (!cur.isAfterLast()) { this.favorites_button_status = (cur.getInt(0) == 1); } cur.close(); database_favorites.close(); database_favorites = null; // Set favorites status this.changeFavorites(this.favorites_button_status); this.favorites_button.setVisibility(View.VISIBLE); this.favorites_button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (ImageDetailFragment.this.favorites_button_status) { ImageDetailFragment.this.changeFavorites(false); ImageDetailFragment.this.removeFromFavorites(); Toast.makeText(ImageDetailFragment.this.getActivity().getApplicationContext(), R.string.imagedetailactivity_favorites_deleted_message, Toast.LENGTH_SHORT) .show(); } else { ImageDetailFragment.this.changeFavorites(true); ImageDetailFragment.this.addToFavorites(); Toast.makeText(ImageDetailFragment.this.getActivity().getApplicationContext(), R.string.imagedetailactivity_favorites_added_message, Toast.LENGTH_SHORT) .show(); } } }); } this.mImageWorker = ((ImageDetailActivity) this.getActivity()).getImageWorker(); this.mImageWorker.loadImage(this.mImageNum, this.mImageView); this.mTextView.setText(this.mTitle); } }
From source file:nz.co.wholemeal.christchurchmetro.Stop.java
public Stop(String platformTag, String platformNumber, Context context) throws InvalidPlatformNumberException { String queryBase = "SELECT platform_tag, platform_number, name, road_name, latitude, longitude FROM platforms "; String whereClause;//from ww w . ja v a 2 s . co m String whereParameter; if (platformTag == null) { whereClause = "WHERE platform_number = ?"; whereParameter = platformNumber; } else { whereClause = "WHERE platform_tag = ?"; whereParameter = platformTag; } DatabaseHelper databaseHelper = new DatabaseHelper(context); SQLiteDatabase database = databaseHelper.getWritableDatabase(); Cursor cursor = database.rawQuery(queryBase + whereClause, new String[] { whereParameter }); if (cursor.moveToFirst()) { this.platformTag = cursor.getString(0); this.platformNumber = cursor.getString(1); this.name = cursor.getString(2); this.roadName = cursor.getString(3); this.latitude = cursor.getDouble(4); this.longitude = cursor.getDouble(5); cursor.close(); database.close(); } else { cursor.close(); database.close(); throw new InvalidPlatformNumberException("Invalid platform"); } }