SQLite problem

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

SQLite problem

Postby waideman » Wed May 06, 2009 2:33 pm

Hi all!

I'm a newbie in Android and i'm studying/doing some apps using sqlite. I need build a method that returns the following query

select max(rowid) from DB_TABLE

i did this method, but it doesnt log anything and doesn't return any value. the database opens, creates and insert data in the table normally. somebody can help me???

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         public int getMaxRowID(){
  3.  
  4.                 int x = 0;
  5.  
  6.  
  7.  
  8.                 Cursor result = mDB.query(true, DB_TABLE, new String[]{"max(rowid)"}, null, null, null, null, null, null);
  9.  
  10.        
  11.  
  12.                 Log.i(TAG, "X = " + x+1 + "fudeu");
  13.  
  14.                 return result.getInt(x);
  15.  
  16.  
  17.  
  18.         }
  19.  
  20.  
  21.  
  22. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
waideman
Freshman
Freshman
 
Posts: 5
Joined: Thu Apr 09, 2009 1:13 pm

Top

Postby nmc » Wed May 06, 2009 4:31 pm

Do you have a column named 'rowid' in your table?
In my projects, I always use db.rawQuery(sql, null); with 'sql' being a fully specified sql-statement;
with this, a db.rawQuery("select max(id) from mytable", null) works just fine.
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby waideman » Wed May 06, 2009 5:10 pm

nmc wrote:Do you have a column named 'rowid' in your table?
In my projects, I always use db.rawQuery(sql, null); with 'sql' being a fully specified sql-statement;
with this, a db.rawQuery("select max(id) from mytable", null) works just fine.


wow, thanks!!
i'll try using rawQuery instead of just query.. =D
waideman
Freshman
Freshman
 
Posts: 5
Joined: Thu Apr 09, 2009 1:13 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: Exabot [Bot] and 4 guests