Skip to content

Commit 9f76d61

Browse files
committed
1. Fixing issue of db already closed.
2. Releasing new version v1.6.51.
1 parent 4010802 commit 9f76d61

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

app/src/main/java/com/amit/db/DBHelper.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ public boolean executeDatabaseOperations(String tableName, String operations,
326326
// if successful then it will return true
327327
// return true;
328328
db.getWritableDatabase().execSQL(query);
329-
db.close();
330329

331330
return true;
332331
}
@@ -356,7 +355,6 @@ public Cursor executeSelectQuery(String query)
356355
{
357356
// query execution
358357
Cursor cursor = db.getWritableDatabase().rawQuery(query, null);
359-
db.close();
360358

361359
// if cursor is not null then moving the position to first
362360
// and returning the cursor
@@ -452,7 +450,6 @@ public Cursor executeSelectQuery(String tableName, String values,
452450

453451
// executing query
454452
cursor = db.getWritableDatabase().rawQuery(query, null);
455-
db.close();
456453

457454
// if cursor is not null then moving the position to first
458455
// and returning the cursor
@@ -556,7 +553,6 @@ public <T> ArrayList<T> executeSelectQuery(String tableName, String values,
556553

557554
// executing query
558555
cursor = db.getWritableDatabase().rawQuery(query, null);
559-
db.close();
560556

561557
// if cursor is not null then moving the position to first
562558
// and returning the cursor
@@ -771,7 +767,6 @@ public boolean isTableExists(String tableName)
771767

772768
// executing the query using cursor
773769
Cursor cursor = db.getWritableDatabase().rawQuery(query, null);
774-
db.close();
775770

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

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

836830
if (cursor != null)
837831
{
@@ -880,7 +874,6 @@ public boolean executeQuery(String query)
880874
if (query != null && !query.equalsIgnoreCase(""))
881875
{
882876
db.getWritableDatabase().execSQL(query);
883-
db.close();
884877

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

10081001
db.getWritableDatabase().execSQL(query.toString());
1009-
db.close();
1010-
10111002
dbColumnArrayList = new ArrayList<>();
10121003

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

10511042
db.getWritableDatabase().execSQL(query);
1052-
db.close();
10531043
}
10541044
else
10551045
{
@@ -1112,7 +1102,6 @@ public DBHelper insertData(String tableName)
11121102

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

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

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

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

13121300
db.getWritableDatabase().setTransactionSuccessful();
13131301
db.getWritableDatabase().endTransaction();
1314-
db.close();
13151302

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

14641451
db.getWritableDatabase().setTransactionSuccessful();
14651452
db.getWritableDatabase().endTransaction();
1466-
db.close();
14671453

14681454
dbDataArrayList = new ArrayList<>();
14691455
}
@@ -1763,8 +1749,7 @@ public DBHelper updateData(String tableName, String whereClause, String whereArg
17631749
// you can directly pass the values to where clause
17641750
db.getWritableDatabase().update(tableName, contentValues, whereClause, null);
17651751
}
1766-
1767-
db.close();
1752+
17681753
dbDataArrayList = new ArrayList<>();
17691754

17701755
return this;
@@ -1849,8 +1834,7 @@ public long updateDataWithReturnId(String tableName, String whereClause, String
18491834
// you can directly pass the values to where clause
18501835
updatedId = db.getWritableDatabase().update(tableName, contentValues, whereClause, null);
18511836
}
1852-
1853-
db.close();
1837+
18541838
dbDataArrayList = new ArrayList<>();
18551839

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

18821866
db.getWritableDatabase().execSQL(query);
1883-
db.close();
18841867

18851868
return true;
18861869
}
@@ -1922,7 +1905,7 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
19221905
try
19231906
{
19241907
Cursor cursor;
1925-
String orderBy = "";
1908+
String orderBy;
19261909
ArrayList<T> tArrayList = new ArrayList<>();
19271910

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

19641947
// executing generated select query
19651948
cursor = db.getWritableDatabase().rawQuery(query, null);
1966-
db.close();
19671949

19681950
// checking if cursor is not null and cursor has moved to first position
19691951
if (cursor != null && cursor.moveToFirst())
@@ -2101,7 +2083,7 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
21012083
try
21022084
{
21032085
Cursor cursor;
2104-
String orderBy = "", whereClause = "";
2086+
String orderBy, whereClause = "";
21052087
ArrayList<T> tArrayList = new ArrayList<>();
21062088

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

21482130
// executing generated select query
21492131
cursor = db.getWritableDatabase().rawQuery(query, null);
2150-
db.close();
21512132

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

0 commit comments

Comments
 (0)