Thanks, did as you said and found a mistake I made. It works perfectly now!
On Jan 29, 4:14 pm, Kostya Vasilyev <[email protected]> wrote: > Your query looks ok to me. > > Check how you insert data, and make sure that the value that's stored in > the database is what you expect. > > Oh, and before you call "recentC.getLong(recentC.getColumnIndexOrThrow", > make sure you've moved the cursor to the first row. > > -- Kostya > > 29.01.2011 18:02, André пишет: > > > > > > > > > > > Thanks for quick answers guys! > > > It works very well with getCount(). Do you have any suggestions about > > the query thou? Because it still returns 0 on get count when I try to > > look for the already existing entry. > > > mCursor = mDb.query(true, RECENT_TABLE, new String[] {RECENT_ROWID, > > RECENT_NAME, RECENT_FILE, RECENT_TIME}, RECENT_FILE + " = ?", new > > String[]{file}, null, null, null, null); > > > Any suggestions there? > > > On Jan 29, 3:50 pm, kernelpanic<[email protected]> wrote: > >> I just went through this myself, but my logic is inverted to yours, so > >> ignore my previous > > >> probably better to use > > >> if (recentC.getCount() != 0) { > > >> On Jan 29, 8:41 am, André<[email protected]> wrote: > > >>> This is doing my head in. > >>> I have a database where there is currently one entry. What I want to > >>> do is to check if this entry exists. If it does I want to update it, > >>> if not create a new one. > >>> recentC = db.fetchExisting(file); > >>> if (recentC != null){ > >>> long rwId = > >>> recentC.getLong(recentC.getColumnIndexOrThrow(SilverDbManager.RECENT_ROWID) > >>> ); > >>> db.updateRecent(rwId, name, file, time);} else { > >>> db.createRecent(name, file, time); > >>> } > >>> public Cursor fetchExisting(String file) throws SQLException { > >>> Cursor mCursor = null; > >>> mCursor = mDb.query(true, RECENT_TABLE, new String[] > >>> {RECENT_ROWID, RECENT_NAME, RECENT_FILE, RECENT_TIME}, RECENT_FILE + " > >>> = ?", new String[]{file}, null, null, null, null); > >>> return mCursor; > >>> } > >>> I know that recentC != null is probably wrong but I dont know what to > >>> change it to. And its some problem with the query because it can't > >>> find the entry I already have there when I search for it. > >>> Any suggestions? > >>> //André > > -- > Kostya Vasilyev -- WiFi Manager + pretty widget > --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

