Skip to content

Commit

Permalink
1. Fixing issue of db already closed.
Browse files Browse the repository at this point in the history
2. Releasing new version v1.6.51.
  • Loading branch information
amitjangid80 committed Aug 30, 2019
1 parent 4010802 commit 9f76d61
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions app/src/main/java/com/amit/db/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ public boolean executeDatabaseOperations(String tableName, String operations,
// if successful then it will return true
// return true;
db.getWritableDatabase().execSQL(query);
db.close();

return true;
}
Expand Down Expand Up @@ -356,7 +355,6 @@ public Cursor executeSelectQuery(String query)
{
// query execution
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 @@ -452,7 +450,6 @@ public Cursor executeSelectQuery(String tableName, String values,

// executing query
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 @@ -556,7 +553,6 @@ public <T> ArrayList<T> executeSelectQuery(String tableName, String values,

// executing query
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 @@ -771,7 +767,6 @@ public boolean isTableExists(String tableName)

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

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

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

if (cursor != null)
{
Expand Down Expand Up @@ -880,7 +874,6 @@ public boolean executeQuery(String query)
if (query != null && !query.equalsIgnoreCase(""))
{
db.getWritableDatabase().execSQL(query);
db.close();

return true;
}
Expand Down Expand Up @@ -1006,8 +999,6 @@ public DBHelper createTable(String tableName)
Log.e(TAG, "createTable: Create table query is: " + query.toString());

db.getWritableDatabase().execSQL(query.toString());
db.close();

dbColumnArrayList = new ArrayList<>();

return this;
Expand Down Expand Up @@ -1049,7 +1040,6 @@ public DBHelper alterTable(String tableName)
Log.e(TAG, "alterTable: query for adding new column or altering table is: " + query);

db.getWritableDatabase().execSQL(query);
db.close();
}
else
{
Expand Down Expand Up @@ -1112,7 +1102,6 @@ public DBHelper insertData(String tableName)

// executing inserting statement for inserting records in table
db.getWritableDatabase().insert(tableName, null, contentValues);
db.close();

dbDataArrayList = new ArrayList<>();
return this;
Expand Down Expand Up @@ -1164,7 +1153,6 @@ public long insertDataWithReturnId(String tableName)

// executing inserting statement for inserting records in table
long insertedId = db.getWritableDatabase().insert(tableName, null, contentValues);
db.close();

dbDataArrayList = new ArrayList<>();
return insertedId;
Expand Down Expand Up @@ -1311,7 +1299,6 @@ else if (columnData instanceof Double || columnData instanceof Float)

db.getWritableDatabase().setTransactionSuccessful();
db.getWritableDatabase().endTransaction();
db.close();

dbDataArrayList = new ArrayList<>();
}
Expand Down Expand Up @@ -1463,7 +1450,6 @@ else if (columnData instanceof Double || columnData instanceof Float)

db.getWritableDatabase().setTransactionSuccessful();
db.getWritableDatabase().endTransaction();
db.close();

dbDataArrayList = new ArrayList<>();
}
Expand Down Expand Up @@ -1763,8 +1749,7 @@ public DBHelper updateData(String tableName, String whereClause, String whereArg
// you can directly pass the values to where clause
db.getWritableDatabase().update(tableName, contentValues, whereClause, null);
}

db.close();

dbDataArrayList = new ArrayList<>();

return this;
Expand Down Expand Up @@ -1849,8 +1834,7 @@ public long updateDataWithReturnId(String tableName, String whereClause, String
// you can directly pass the values to where clause
updatedId = db.getWritableDatabase().update(tableName, contentValues, whereClause, null);
}

db.close();

dbDataArrayList = new ArrayList<>();

return updatedId;
Expand Down Expand Up @@ -1880,7 +1864,6 @@ public boolean deleteTable(String tableName)
String query = "DELETE TABLE IF EXISTS " + tableName;

db.getWritableDatabase().execSQL(query);
db.close();

return true;
}
Expand Down Expand Up @@ -1922,7 +1905,7 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
try
{
Cursor cursor;
String orderBy = "";
String orderBy;
ArrayList<T> tArrayList = new ArrayList<>();

// checking if table name is provided or not
Expand Down Expand Up @@ -1963,7 +1946,6 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,

// executing generated select query
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 @@ -2101,7 +2083,7 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
try
{
Cursor cursor;
String orderBy = "", whereClause = "";
String orderBy, whereClause = "";
ArrayList<T> tArrayList = new ArrayList<>();

// checking if table name is provided or not
Expand Down Expand Up @@ -2147,7 +2129,6 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,

// executing generated select query
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 9f76d61

Please sign in to comment.