public static void InsertPreferredStockEntry(PreferredStockModel model, Context ctx) { SQLiteDatabase db = GetDB(true, ctx); // Check if item exists String selection = PreferredStockEntry.COLUMN_SYMBOL + "=?"; String[] selectionArgs = new String[] {model.getLookupResultModel().symbol}; Cursor c = db.query(PreferredStockEntry.TABLE_NAME, null, selection, selectionArgs, null, null, null); ContentValues cv = PreferredStockEntry.MakeContentValues(model); db.insert(PreferredStockEntry.TABLE_NAME, null, cv); c.close(); db.close(); }
public static List<PreferredStockModel> GetPreferredStocks(Context ctx) { SQLiteDatabase db = GetDB(false, ctx); List<PreferredStockModel> preferredStocks = new ArrayList<PreferredStockModel>(); Cursor c = db.query(PreferredStockEntry.TABLE_NAME, null, null, null, null, null, null); while (c.moveToNext()) { PreferredStockModel stock = PreferredStockEntry.MakeModel(c); preferredStocks.add(stock); } c.close(); db.close(); return preferredStocks; }
public static QuoteModel GetStockQuote(Context ctx, String symbol) { SQLiteDatabase db = GetDB(false, ctx); // String[] columns = new String[]{PreferredStockEntry.COLUMN_HIGH, // PreferredStockEntry.COLUMN_LOW, PreferredStockEntry.COLUMN_OPEN}; Cursor c = db.query( PreferredStockEntry.TABLE_NAME, /*columns*/ null, null /*PreferredStockEntry.COLUMN_SYMBOL + "=?"*/, null /*new String[]{symbol}*/, null, null, null); c.moveToFirst(); PreferredStockModel stock = PreferredStockEntry.MakeModel(c); c.close(); db.close(); return stock.getQuoteModel(); }