Methods are based on each ModelObject which inherits OEDatabase class.
Used to create new record in Local database.
Syntax:
ModelObject model = new ModelObject(context);
OEValues values = new OEValues();
values.put("name", "ABC");
values.put("age", 10);
long new_id = model.create(values); // Create new record and return new created id.
Used to create record if not exits otherwise, update record. It takes OEValues list as parameter.
Syntax:
ModelObject model = new ModelObject(context);
List<OEValues> records = new OEValues();
OEValues values1 = new OEValues(); // will going to create because there is no record in db.
values1.put("name", "XYZ");
values1.put("age", 15);
records.add(values1);
OEValues values2 = new OEValues(); // will going to update record because local id exists
values2.put("name", "ABC");
values2.put("age", 12);
records.add(values2);
List<Long> mAffectedIds = model.createORReplace(records); // will return affected ids.
Used to select records from Local SQLite database.
Syntax:
ModelObject model = new ModelObject(context);
List<OEDataRow> records = model.select(); // Select all record from SQLite
OEDataRow record = model.select(id); // Select specific record.
List<OEDataRow> records = model.select("age > ?", new String[] { "10" }); // select records with custom where clause
Used to update local record.
Syntax:
ModelObject model = new ModelObject(context);
OEValues values = new OEValues();
values.put("name", "ABC");
values.put("age", 15);
int affected_rows = model.update(values, 10); // will return affected rows.
values = new OEValues();
values.put("age", 15);
affected_rows = model.update(values, "age = ?", new String[] {"10"});
Used to update many to many records of related column.
Possible operation to update Many to many records.
Operation.ADD
Add given ids to related table
Operation.APPEND
Append given ids with existing rows
Operation.REMOVE
Remove given ids from many to many relation table
Operation.REPLACE
It first remove all related rows and than replace with new one
Syntax:
ModelObject model = new ModelObject(context);
List<Integer> ids = new ArrayList<Integer>();
ids.put(10);
ids.put(12);
ids.put(13);
// updateManyToManyRecords("relation_column_name", Operation, "record_id", "relation_record_ids OR id")
model.updateManyToManyRecords("subject_ids", Operation.REPLACE, 10, ids);
Used to delete record from local database
Syntax:
ModelObject model = new ModelObject(context);
int count = model.delete(10); // returns number of record deleted.
count = model.delete("age > ? ", new String[] {"20"}); // returns number of record deleted.
Used to clean table records.
Syntax:
ModelObject model = new ModelObject(context);
boolean cleaned = model.truncateTable(); // returns boolean flag
Used to count number of records available in local SQLite database
Syntax:
ModelObject model = new ModelObject(context);
int count = model.count(); // returns total number of records
int mCount = model.count("age > ?", new String[] {"5"}); // returns total number of records based on condition
Used to get table records last id.
Syntax:
ModelObject model = new ModelObject(context);
int last_id = model.lastId();
Used to check whether table is empty or not
Syntax:
ModelObject model = new ModelObject(context);
if(model.isEmptyTable()){
//TODO: next stuff
}