Lawrencce Clarke
Lawrencce Clarke

Reputation: 57

Android raw query problem

I have a database which has a column of dates in milliseconds. I'm trying to perform a query which allows me to retrieve only the dates that are greater than the current system time and in ascending order.

This is what I have done, but it doesn't seem to work, help would be most appreciative.

    long lowestDate = 0;
    long currentTime = System.currentTimeMillis(); 
    String CT = Long.toString(currentTime);
    String[] args = {CT};
    mDb = mDbHelper.getReadableDatabase();
    String mySQL =   " select dt" 
                   + " from reminders"
                   + " where dt > " + args[0]
                   + " orderby dt Asc ";
    Cursor c1 = mDb.rawQuery(mySQL, null);

Upvotes: 1

Views: 767

Answers (3)

piotrpo
piotrpo

Reputation: 12626

String mySQL =   " select dt" 
                   + " from reminders"
                   + " where dt > " + System.currentTimeMillis()
                   + " order by dt Asc ";

"Order by" not "orderby", long to string cast is automatic.

Upvotes: 2

Rasel
Rasel

Reputation: 15477

Try

 String mySQL =   "select dt" 
                       + " from reminders"
                       + " where dt > '" + args[0]
                       + "' orderby dt Asc";

Upvotes: 0

 long lowestDate = 0;
    long currentTime = System.currentTimeMillis(); 
    String CT = Long.toString(currentTime);
    String[] args = {CT};
    mDb = mDbHelper.getReadableDatabase();
    String mySQL =   " select dt" 
                   + " from reminders"
                   + " where dt > '" + args[0]
                   + "' orderby dt Asc ";
    Cursor c1 = mDb.rawQuery(mySQL, null);

try this

Upvotes: 1

Related Questions