@@ -326,7 +326,6 @@ public boolean executeDatabaseOperations(String tableName, String operations,
326
326
// if successful then it will return true
327
327
// return true;
328
328
db .getWritableDatabase ().execSQL (query );
329
- db .close ();
330
329
331
330
return true ;
332
331
}
@@ -356,7 +355,6 @@ public Cursor executeSelectQuery(String query)
356
355
{
357
356
// query execution
358
357
Cursor cursor = db .getWritableDatabase ().rawQuery (query , null );
359
- db .close ();
360
358
361
359
// if cursor is not null then moving the position to first
362
360
// and returning the cursor
@@ -452,7 +450,6 @@ public Cursor executeSelectQuery(String tableName, String values,
452
450
453
451
// executing query
454
452
cursor = db .getWritableDatabase ().rawQuery (query , null );
455
- db .close ();
456
453
457
454
// if cursor is not null then moving the position to first
458
455
// and returning the cursor
@@ -556,7 +553,6 @@ public <T> ArrayList<T> executeSelectQuery(String tableName, String values,
556
553
557
554
// executing query
558
555
cursor = db .getWritableDatabase ().rawQuery (query , null );
559
- db .close ();
560
556
561
557
// if cursor is not null then moving the position to first
562
558
// and returning the cursor
@@ -771,7 +767,6 @@ public boolean isTableExists(String tableName)
771
767
772
768
// executing the query using cursor
773
769
Cursor cursor = db .getWritableDatabase ().rawQuery (query , null );
774
- db .close ();
775
770
776
771
// checking if cursor is not null
777
772
if (cursor != null )
@@ -831,7 +826,6 @@ public int getMaxId(String field, String tableName)
831
826
832
827
String query = "SELECT MAX(" + field + ") AS ID FROM " + tableName ;
833
828
Cursor cursor = db .getWritableDatabase ().rawQuery (query , null );
834
- db .close ();
835
829
836
830
if (cursor != null )
837
831
{
@@ -880,7 +874,6 @@ public boolean executeQuery(String query)
880
874
if (query != null && !query .equalsIgnoreCase ("" ))
881
875
{
882
876
db .getWritableDatabase ().execSQL (query );
883
- db .close ();
884
877
885
878
return true ;
886
879
}
@@ -1006,8 +999,6 @@ public DBHelper createTable(String tableName)
1006
999
Log .e (TAG , "createTable: Create table query is: " + query .toString ());
1007
1000
1008
1001
db .getWritableDatabase ().execSQL (query .toString ());
1009
- db .close ();
1010
-
1011
1002
dbColumnArrayList = new ArrayList <>();
1012
1003
1013
1004
return this ;
@@ -1049,7 +1040,6 @@ public DBHelper alterTable(String tableName)
1049
1040
Log .e (TAG , "alterTable: query for adding new column or altering table is: " + query );
1050
1041
1051
1042
db .getWritableDatabase ().execSQL (query );
1052
- db .close ();
1053
1043
}
1054
1044
else
1055
1045
{
@@ -1112,7 +1102,6 @@ public DBHelper insertData(String tableName)
1112
1102
1113
1103
// executing inserting statement for inserting records in table
1114
1104
db .getWritableDatabase ().insert (tableName , null , contentValues );
1115
- db .close ();
1116
1105
1117
1106
dbDataArrayList = new ArrayList <>();
1118
1107
return this ;
@@ -1164,7 +1153,6 @@ public long insertDataWithReturnId(String tableName)
1164
1153
1165
1154
// executing inserting statement for inserting records in table
1166
1155
long insertedId = db .getWritableDatabase ().insert (tableName , null , contentValues );
1167
- db .close ();
1168
1156
1169
1157
dbDataArrayList = new ArrayList <>();
1170
1158
return insertedId ;
@@ -1311,7 +1299,6 @@ else if (columnData instanceof Double || columnData instanceof Float)
1311
1299
1312
1300
db .getWritableDatabase ().setTransactionSuccessful ();
1313
1301
db .getWritableDatabase ().endTransaction ();
1314
- db .close ();
1315
1302
1316
1303
dbDataArrayList = new ArrayList <>();
1317
1304
}
@@ -1463,7 +1450,6 @@ else if (columnData instanceof Double || columnData instanceof Float)
1463
1450
1464
1451
db .getWritableDatabase ().setTransactionSuccessful ();
1465
1452
db .getWritableDatabase ().endTransaction ();
1466
- db .close ();
1467
1453
1468
1454
dbDataArrayList = new ArrayList <>();
1469
1455
}
@@ -1763,8 +1749,7 @@ public DBHelper updateData(String tableName, String whereClause, String whereArg
1763
1749
// you can directly pass the values to where clause
1764
1750
db .getWritableDatabase ().update (tableName , contentValues , whereClause , null );
1765
1751
}
1766
-
1767
- db .close ();
1752
+
1768
1753
dbDataArrayList = new ArrayList <>();
1769
1754
1770
1755
return this ;
@@ -1849,8 +1834,7 @@ public long updateDataWithReturnId(String tableName, String whereClause, String
1849
1834
// you can directly pass the values to where clause
1850
1835
updatedId = db .getWritableDatabase ().update (tableName , contentValues , whereClause , null );
1851
1836
}
1852
-
1853
- db .close ();
1837
+
1854
1838
dbDataArrayList = new ArrayList <>();
1855
1839
1856
1840
return updatedId ;
@@ -1880,7 +1864,6 @@ public boolean deleteTable(String tableName)
1880
1864
String query = "DELETE TABLE IF EXISTS " + tableName ;
1881
1865
1882
1866
db .getWritableDatabase ().execSQL (query );
1883
- db .close ();
1884
1867
1885
1868
return true ;
1886
1869
}
@@ -1922,7 +1905,7 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
1922
1905
try
1923
1906
{
1924
1907
Cursor cursor ;
1925
- String orderBy = "" ;
1908
+ String orderBy ;
1926
1909
ArrayList <T > tArrayList = new ArrayList <>();
1927
1910
1928
1911
// checking if table name is provided or not
@@ -1963,7 +1946,6 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
1963
1946
1964
1947
// executing generated select query
1965
1948
cursor = db .getWritableDatabase ().rawQuery (query , null );
1966
- db .close ();
1967
1949
1968
1950
// checking if cursor is not null and cursor has moved to first position
1969
1951
if (cursor != null && cursor .moveToFirst ())
@@ -2101,7 +2083,7 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
2101
2083
try
2102
2084
{
2103
2085
Cursor cursor ;
2104
- String orderBy = "" , whereClause = "" ;
2086
+ String orderBy , whereClause = "" ;
2105
2087
ArrayList <T > tArrayList = new ArrayList <>();
2106
2088
2107
2089
// checking if table name is provided or not
@@ -2147,7 +2129,6 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
2147
2129
2148
2130
// executing generated select query
2149
2131
cursor = db .getWritableDatabase ().rawQuery (query , null );
2150
- db .close ();
2151
2132
2152
2133
// checking if cursor is not null and cursor has moved to first position
2153
2134
if (cursor != null && cursor .moveToFirst ())
0 commit comments