Skip to content

Commit

Permalink
1. Closing database for no memory leak.
Browse files Browse the repository at this point in the history
2. Releasing new version v1.6.50.
  • Loading branch information
amitjangid80 committed Aug 30, 2019
1 parent 2fdea9c commit 4010802
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 7 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

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

21 changes: 14 additions & 7 deletions app/src/main/java/com/amit/db/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ public Cursor executeSelectQuery(String query)
try
{
// query execution
Cursor cursor = db.getReadableDatabase().rawQuery(query, null);
Cursor cursor = db.getWritableDatabase().rawQuery(query, null);
db.close();

// if cursor is not null then moving the position to first
// and returning the cursor
Expand Down Expand Up @@ -450,7 +451,8 @@ public Cursor executeSelectQuery(String tableName, String values,
}

// executing query
cursor = db.getReadableDatabase().rawQuery(query, null);
cursor = db.getWritableDatabase().rawQuery(query, null);
db.close();

// if cursor is not null then moving the position to first
// and returning the cursor
Expand Down Expand Up @@ -553,7 +555,8 @@ public <T> ArrayList<T> executeSelectQuery(String tableName, String values,
}

// executing query
cursor = db.getReadableDatabase().rawQuery(query, null);
cursor = db.getWritableDatabase().rawQuery(query, null);
db.close();

// if cursor is not null then moving the position to first
// and returning the cursor
Expand Down Expand Up @@ -767,7 +770,8 @@ public boolean isTableExists(String tableName)
String query = "SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name = '" + tableName + "'";

// executing the query using cursor
Cursor cursor = db.getReadableDatabase().rawQuery(query, null);
Cursor cursor = db.getWritableDatabase().rawQuery(query, null);
db.close();

// checking if cursor is not null
if (cursor != null)
Expand Down Expand Up @@ -826,7 +830,8 @@ public int getMaxId(String field, String tableName)
}

String query = "SELECT MAX(" + field + ") AS ID FROM " + tableName;
Cursor cursor = db.getReadableDatabase().rawQuery(query, null);
Cursor cursor = db.getWritableDatabase().rawQuery(query, null);
db.close();

if (cursor != null)
{
Expand Down Expand Up @@ -1957,7 +1962,8 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
Log.e(TAG, "getAllRecords: Select query for getting all records is: " + query);

// executing generated select query
cursor = db.getReadableDatabase().rawQuery(query, null);
cursor = db.getWritableDatabase().rawQuery(query, null);
db.close();

// checking if cursor is not null and cursor has moved to first position
if (cursor != null && cursor.moveToFirst())
Expand Down Expand Up @@ -2140,7 +2146,8 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
Log.e(TAG, "getAllRecords: Select query for getting all records is: " + query);

// executing generated select query
cursor = db.getReadableDatabase().rawQuery(query, null);
cursor = db.getWritableDatabase().rawQuery(query, null);
db.close();

// checking if cursor is not null and cursor has moved to first position
if (cursor != null && cursor.moveToFirst())
Expand Down

0 comments on commit 4010802

Please sign in to comment.