/** * @param Id * @return */ public CategoryEntry fetchCategory(long Id) { CategoryEntry row = new CategoryEntry(); try { Cursor c = db.query( true, TABLE_CATEGORIES, new String[] {"id", "name"}, "id=" + Id, null, null, null, null, null); if (c.getCount() > 0) { c.moveToFirst(); row.id = c.getLong(0); row.name = c.getString(1); } else { row.id = -1; row.name = null; } c.close(); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } return row; }
/** Close database connection */ public void close() { try { db.close(); } catch (SQLException e) { Log.d(TAG, "close exception: " + e.getLocalizedMessage()); } }
/** @param Id */ public void deletePassword(long Id) { try { db.delete(TABLE_PASSWORDS, "id=" + Id, null); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } }
/** Commit all changes since the begin transaction on an open database. */ public void commit() { try { db.execSQL("commit;"); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } }
/** Rollback all changes since the begin transaction on an open database. */ public void rollback() { try { db.execSQL("rollback;"); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } }
/** @param Id */ public void deleteCategory(long Id) { try { db.delete(TABLE_CATEGORIES, "id=" + Id, null); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } }
@SuppressWarnings("nls") public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.database_list); Bundle extras = getIntent().getExtras(); String query = extras.getString(LibraryConstants.PREFS_KEY_QUERY); SQLiteDatabase database = null; try { database = ADbHelper.getInstance().getDatabase(); } catch (IOException e) { e.printStackTrace(); } try { if (database != null && query != null) { cursor = database.rawQuery(query, null); startManagingCursor(cursor); DbCursorAdapter data = new DbCursorAdapter(this, cursor); setListAdapter(data); } } catch (SQLException e) { Utilities.messageDialog( this, "An error occurred while launching the query: " + e.getLocalizedMessage(), new Runnable() { public void run() { finish(); } }); } }
/** * Begin a transaction on an open database. * * @return true if successful */ public boolean beginTransaction() { try { db.execSQL("begin transaction;"); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); return false; } return true; }
/** @param PBEKey */ public void storeMasterKey(String MasterKey) { ContentValues args = new ContentValues(); try { db.delete(TABLE_MASTER_KEY, "1=1", null); args.put("encryptedkey", MasterKey); db.insert(TABLE_MASTER_KEY, null, args); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } }
/** * @param Id * @param entry */ public void updateCategory(long Id, CategoryEntry entry) { ContentValues args = new ContentValues(); args.put("name", entry.name); try { db.update(TABLE_CATEGORIES, args, "id=" + Id, null); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } }
public void deleteDatabase() { try { db.execSQL(PASSWORDS_DROP); db.execSQL(PASSWORDS_CREATE); db.execSQL(CATEGORIES_DROP); db.execSQL(CATEGORIES_CREATE); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } }
/** * No se borrará sobre SCORE * * @see mx.v1ctor.android.bd.BDObject#delete() */ public boolean delete() { try { sqldb.delete(pbd.getTA_NOTES(), pbd.getID() + "=" + id, null); } catch (SQLException sql) { Log.e("ERROR", sql.getLocalizedMessage()); return false; } return true; }
/** @param entry */ public long addCategory(CategoryEntry entry) { ContentValues initialValues = new ContentValues(); initialValues.put("name", entry.name); long ret = -1; try { ret = db.insert(TABLE_CATEGORIES, null, initialValues); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } return ret; }
/** @return */ public List<PassEntry> fetchAllRows(Long CategoryId) { ArrayList<PassEntry> ret = new ArrayList<PassEntry>(); try { Cursor c; if (CategoryId == 0) { c = db.query( TABLE_PASSWORDS, new String[] { "id", "password", "description", "username", "website", "note", "category" }, null, null, null, null, null); } else { c = db.query( TABLE_PASSWORDS, new String[] { "id", "password", "description", "username", "website", "note", "category" }, "category=" + CategoryId, null, null, null, null); } int numRows = c.getCount(); c.moveToFirst(); for (int i = 0; i < numRows; ++i) { PassEntry row = new PassEntry(); row.id = c.getLong(0); row.password = c.getString(1); row.description = c.getString(2); row.username = c.getString(3); row.website = c.getString(4); row.note = c.getString(5); row.category = c.getLong(6); ret.add(row); c.moveToNext(); } c.close(); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } return ret; }
/** * Only update the category field of the password entry. * * @param Id the id of the password entry * @param newCategoryId the updated category id */ public void updatePasswordCategory(long Id, long newCategoryId) { if (Id < 0 || newCategoryId < 0) { // make sure values appear valid return; } ContentValues args = new ContentValues(); args.put("category", newCategoryId); try { db.update(TABLE_PASSWORDS, args, "id=" + Id, null); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } }
/** * @param Id * @param entry */ public void updatePassword(long Id, PassEntry entry) { ContentValues args = new ContentValues(); args.put("description", entry.description); args.put("username", entry.username); args.put("password", entry.password); args.put("website", entry.website); args.put("note", entry.note); try { db.update(TABLE_PASSWORDS, args, "id=" + Id, null); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } }
/** @param ctx */ public DBHelper(Context ctx) { myCtx = ctx; try { db = myCtx.openOrCreateDatabase(DATABASE_NAME, 0, null); // Check for the existence of the DBVERSION table // If it doesn't exist than create the overall data, // otherwise double check the version Cursor c = db.query( "sqlite_master", new String[] {"name"}, "type='table' and name='" + TABLE_DBVERSION + "'", null, null, null, null); int numRows = c.getCount(); if (numRows < 1) { CreateDatabase(db); } else { int version = 0; Cursor vc = db.query( true, TABLE_DBVERSION, new String[] {"version"}, null, null, null, null, null, null); if (vc.getCount() > 0) { vc.moveToFirst(); version = vc.getInt(0); } vc.close(); if (version != DATABASE_VERSION) { needsUpgrade = true; Log.e(TAG, "database version mismatch"); } } c.close(); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } }
/** @param entry */ public void addPassword(PassEntry entry) { ContentValues initialValues = new ContentValues(); initialValues.put("category", entry.category); initialValues.put("password", entry.password); initialValues.put("description", entry.description); initialValues.put("username", entry.username); initialValues.put("website", entry.website); initialValues.put("note", entry.note); try { db.insert(TABLE_PASSWORDS, null, initialValues); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } }
/** @see mx.v1ctor.android.bd.BDObject#create() */ public boolean create() { try { ContentValues values = new ContentValues(); // values.put(pbd.getID(), id); values.put(pbd.getTEXT(), note); sqldb.insert(pbd.getTA_NOTES(), null, values); } catch (SQLException sql) { Log.e("ERROR", sql.getLocalizedMessage()); return false; } return true; }
private void CreateDatabase(SQLiteDatabase db) { try { db.execSQL(DBVERSION_CREATE); ContentValues args = new ContentValues(); args.put("version", DATABASE_VERSION); db.insert(TABLE_DBVERSION, null, args); db.execSQL(CATEGORIES_CREATE); needsPrePopulation = true; db.execSQL(PASSWORDS_CREATE); db.execSQL(MASTER_KEY_CREATE); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } }
public int fetchVersion() { int version = 0; try { Cursor c = db.query( true, TABLE_DBVERSION, new String[] {"version"}, null, null, null, null, null, null); if (c.getCount() > 0) { c.moveToFirst(); version = c.getInt(0); } c.close(); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } return version; }
public String fetchOldConfirm() { String key = ""; try { Cursor c = db.query( true, TABLE_VERIFY, new String[] {"confirm"}, null, null, null, null, null, null); if (c.getCount() > 0) { c.moveToFirst(); key = c.getString(0); } c.close(); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } return key; }
/** @return */ public List<CategoryEntry> fetchAllCategoryRows() { ArrayList<CategoryEntry> ret = new ArrayList<CategoryEntry>(); try { Cursor c = db.query(TABLE_CATEGORIES, new String[] {"id", "name"}, null, null, null, null, null); int numRows = c.getCount(); c.moveToFirst(); for (int i = 0; i < numRows; ++i) { CategoryEntry row = new CategoryEntry(); row.id = c.getLong(0); row.name = c.getString(1); ret.add(row); c.moveToNext(); } c.close(); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } return ret; }
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w( TAG + "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); try { db.execSQL("DROP TABLE IF EXISTS profiles"); db.execSQL("DROP TABLE IF EXISTS contacts"); db.execSQL("DROP TABLE IF EXISTS notifications"); onCreate(db); } catch (SQLException e) { Log.e(TAG + "getting exception " + e.getLocalizedMessage().toString()); } }
/** @param categoryId */ public int countPasswords(long categoryId) { int count = 0; try { Cursor c = db.query( TABLE_PASSWORDS, new String[] {"count(*)"}, "category=" + categoryId, null, null, null, null); c.moveToFirst(); count = c.getInt(0); c.close(); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } Log.i(TAG, "count=" + count); return count; }
/** * @param Id * @return */ public PassEntry fetchPassword(long Id) { PassEntry row = new PassEntry(); try { Cursor c = db.query( true, TABLE_PASSWORDS, new String[] { "id", "password", "description", "username", "website", "note", "category" }, "id=" + Id, null, null, null, null, null); if (c.getCount() > 0) { c.moveToFirst(); row.id = c.getLong(0); row.password = c.getString(1); row.description = c.getString(2); row.username = c.getString(3); row.website = c.getString(4); row.note = c.getString(5); row.category = c.getLong(6); } else { row.id = -1; row.description = row.password = null; } c.close(); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } return row; }
/** @return */ public String fetchMasterKey() { String key = ""; try { Cursor c = db.query( true, TABLE_MASTER_KEY, new String[] {"encryptedkey"}, null, null, null, null, null, null); if (c.getCount() > 0) { c.moveToFirst(); key = c.getString(0); } c.close(); } catch (SQLException e) { Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); } return key; }