@@ -1781,6 +1781,84 @@ else if (object instanceof JSONArray)
1781
1781
}
1782
1782
}
1783
1783
1784
+ //#region COMMENTS FOR updateData method
1785
+ /**
1786
+ * 2019 January 08 - Tuesday - 04:28 PM
1787
+ * update data method
1788
+ *
1789
+ * @param tableName - name of the table on which update query is to be performed
1790
+ *
1791
+ * @param whereClause - name of the column to check whether the record is present so the data is updated
1792
+ * pass this parameter in the way given in example below
1793
+ * Ex: code = ? or ID = ? etc // this is important
1794
+ *
1795
+ * this method will update records of the table in database
1796
+ * this method uses database's update method for updating records
1797
+ *
1798
+ * parameter whereClause and whereArgs must be passed in the form given
1799
+ **/
1800
+ //#endregion COMMENTS FOR updateData method
1801
+ public DBHelper updateData (String tableName , String whereClause )
1802
+ {
1803
+ try
1804
+ {
1805
+ // checking if table name was provided or not
1806
+ if (tableName == null || tableName .isEmpty ())
1807
+ {
1808
+ if (dbDataArrayList != null )
1809
+ {
1810
+ dbDataArrayList .clear ();
1811
+ }
1812
+
1813
+ Log .e (TAG , "updateData: Table name was null or empty." );
1814
+ return this ;
1815
+ }
1816
+
1817
+ // checking if column name was provided or not
1818
+ if (whereClause == null || whereClause .isEmpty ())
1819
+ {
1820
+ if (dbDataArrayList != null )
1821
+ {
1822
+ dbDataArrayList .clear ();
1823
+ }
1824
+
1825
+ Log .e (TAG , "updateData: Column name was null or empty." );
1826
+ return this ;
1827
+ }
1828
+
1829
+ // checking if data was provided or not
1830
+ if (dbDataArrayList == null || dbDataArrayList .size () == 0 )
1831
+ {
1832
+ Log .e (TAG , "updateData: Data was not provided for updating records." );
1833
+ return this ;
1834
+ }
1835
+
1836
+ // content values for putting column name
1837
+ // and data for inserting into database table
1838
+ ContentValues contentValues = new ContentValues ();
1839
+
1840
+ // loop for no of data provided
1841
+ for (int i = 0 ; i < dbDataArrayList .size (); i ++)
1842
+ {
1843
+ // adding column names and column data into content values
1844
+ contentValues .put (dbDataArrayList .get (i ).columnName , dbDataArrayList .get (i ).columnData .toString ());
1845
+ }
1846
+
1847
+ // you can directly pass the values to where clause
1848
+ db .getWritableDatabase ().update (tableName , contentValues , whereClause , null );
1849
+ dbDataArrayList = new ArrayList <>();
1850
+ }
1851
+ catch (Exception e )
1852
+ {
1853
+ Log .e (TAG , "updateData: exception while updating records in table: " + tableName + ":\n " );
1854
+ e .printStackTrace ();
1855
+
1856
+ dbDataArrayList = new ArrayList <>();
1857
+ }
1858
+
1859
+ return this ;
1860
+ }
1861
+
1784
1862
//#region COMMENTS FOR updateData method
1785
1863
/**
1786
1864
* 2019 January 08 - Tuesday - 04:28 PM
@@ -1849,7 +1927,7 @@ public DBHelper updateData(String tableName, String whereClause, String whereArg
1849
1927
}
1850
1928
1851
1929
// checking if column data was provided or not
1852
- if (whereArgs != null && whereArgs .isEmpty ())
1930
+ if (whereArgs != null && ! whereArgs .isEmpty ())
1853
1931
{
1854
1932
db .getWritableDatabase ().update (tableName , contentValues , whereClause , new String []{whereArgs });
1855
1933
}
0 commit comments