Skip to content

Commit

Permalink
new fix for short time
Browse files Browse the repository at this point in the history
  • Loading branch information
Avishek committed Feb 26, 2019
1 parent 5634400 commit ed3f535
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 55 deletions.
Binary file added .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
10 changes: 3 additions & 7 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 5 additions & 35 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.wisdomrider.sqliteclosedhelper;

public class Checks {
public class Checks {

private String first, lastname;
private int age;
private float hell;


public float getHell() {
return hell;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ protected void onCreate(Bundle savedInstanceState) {


Checks checks = new Checks();
// helper.createTableFromClass(checks);
// checks.setAge(10);
// checks.setFirst("hey");
// checks.setHell(1.34234134154f);
// checks.setLastname("ASda");
// checks.setOops(1);
helper.createTableFromClass(checks);
checks.setAge(70);
checks.setFirst("heya1");
checks.setHell(1.34234134154f);
checks.setLastname("ASda71");
checks.setOops(1);

// helper.insertTableFromClass(checks);
//


ArrayList<Checks> checks1 = helper.getAll(new Checks());
checks.setAge(10);
ArrayList<Checks> checks2 = helper.getWhere(checks);
// Log.e("ERQ!", checks1.get(0).getFirst());
// Log.e("ERQ!", checks2.get(0).getFirst());

helper.updateTableFromClass(checks,checks.getFirst());



}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ interface Interface {

<T> SqliteClosedHelper insertTableFromClass(T table);

<T> SqliteClosedHelper updateTableFromClass(T table,T key);

<T> ArrayList<T> getAll(T table);

<T> ArrayList<T> getWhere(T table);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@ public Cursor get(String query) {

@Override
public SqliteClosedHelper delete(String where, Object Value) {

database.execSQL("delete from " + TABLENAME + " where " + where + "= '" + Value + "' ;");

return this;
}

Expand Down Expand Up @@ -399,9 +397,47 @@ public <T> ArrayList<T> getWhere(T table) {
return lists;
}

private boolean checkType(Object aClass) {

return aClass instanceof Integer || aClass instanceof Float || aClass instanceof Double;
@Override
public <T> SqliteClosedHelper updateTableFromClass(T table, T key) {
for (Field f : table.getClass().getDeclaredFields()) {
f.setAccessible(true);
try {
if (f.get(table) != null && f.get(table).equals(key)) {
String field_name = f.getName();
Object value = f.get(table);
boolean ifExist = isFieldExist(field_name, value);
if (ifExist) {
Log.e("CHECK","GOT");
setTable(table.getClass().getSimpleName());
clearAll();
Field[] items = table.getClass().getDeclaredFields();
for (int i = 0; i < items.length - 2; i++) {
try {
items[i].setAccessible(true);
String parameter = items[i].getName();
Object object = items[i].get(table);
updateFields(parameter, object);
} catch (IllegalAccessException e) {
throw new Error(e.getMessage());
}
}
Log.e("CHECK","CALL");
update(field_name, value);

} else {
insertTableFromClass(table);
}
return this;
}
} catch (IllegalAccessException e) {

}

}


return this;
}

private Object getItem(Class<?> type, Cursor cursor, int i) {
Expand Down

0 comments on commit ed3f535

Please sign in to comment.