Skip to content

Commit

Permalink
added raw query and finder support. Also finder methods take varargs …
Browse files Browse the repository at this point in the history
…now.
  • Loading branch information
satya committed Nov 24, 2012
1 parent fea8880 commit 81b1984
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions library/src/com/orm/SugarRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public SugarRecord(Context context) {
this.database = application.database;
}


public void delete() {
SQLiteDatabase db = this.database.openDB();
db.delete(this.tableName, "Id=?", new String[]{getId().toString()});
Expand Down Expand Up @@ -90,10 +89,36 @@ public static <T extends SugarRecord> T findById(Class<T> type, Long id) {
}

public static <T extends SugarRecord> List<T> find(Class<T> type,
String whereClause, String[] whereArgs) {
String whereClause, String... whereArgs) {
return find(type, whereClause, whereArgs, null, null, null);
}

public static <T extends SugarRecord> List<T> findWithQuery(Class<T> type, String query, String... arguments){

Database db = getSugarContext().database;
SQLiteDatabase sqLiteDatabase = db.openDB();
T entity;
List<T> toRet = new ArrayList<T>();
Cursor c = sqLiteDatabase.rawQuery(query, arguments);

try {
while (c.moveToNext()) {
entity = type.getDeclaredConstructor(Context.class).newInstance(getSugarContext());
entity.inflate(c);
toRet.add(entity);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
c.close();
}
return toRet;
}

public static void executeQuery(String query, String... arguments){
getSugarContext().database.openDB().execSQL(query, arguments);
}

public static <T extends SugarRecord> List<T> find(Class<T> type,
String whereClause, String[] whereArgs,
String groupBy, String orderBy, String limit) {
Expand Down

0 comments on commit 81b1984

Please sign in to comment.