ActiveRecord¶
-
public class
ActiveRecord
¶ A simple set of helper methods to query for data on android sqlite database.
To get the instance of theis Active record use the getInstance method, this method takes just one parameter. an instance of SQLiteDatabase.
this class is implemented as a singleton meaning only one instance of ActiveRecord ever exists in your application life time.
NB:: the instance of SQLiteDatabase passed in getInstance method is destroyed once the garbage collector destroys the instance of the ActiveRecord.
Methods¶
all¶
-
public List<Map>
all
(String tableName, String[] queryCols)¶ Returns an list of maps, where the map represents each record in the database.
with keys of the map as the column name and values of the map as the values of the respective columns.
something like this:
[{id:1, username:ken, age:50}, {id:2, username:matt, age:70}]
Parameters: - tableName –
- queryCols –
all¶
-
public List<Map>
all
(String tableName)¶ Returns an list of maps, where the map represents each record in the database.
with keys of the map as the column name and values of the map as the values of the respective columns.
something like this:
[{id:1, username:ken, age:50}, {id:2, username:matt, age:70}]
Parameters: - tableName –
exists¶
exists¶
find¶
-
public List<Map>
find
(String sql, String[] args)¶ Returns an list of maps, where the map represents each record in the database.
with keys of the map as the column name and values of the map as the values of the respective columns.
something like this:
[{id:1, username:ken, age:50}, {id:2, username:matt, age:70}]
Parameters: - sql –
- args –
get¶
getDb¶
-
public SQLiteDatabase
getDb
()¶ REturn instance of SQLiteDatabase that the activerecord instance is using.
getInstance¶
-
public static ActiveRecord
getInstance
(SQLiteDatabase database)¶ Returns an instance of the the activerecord class
Parameters: - database –