Skip to content

Commit

Permalink
1. Modified Get all records method for order by feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
amitjangid80 committed Aug 7, 2019
1 parent bbd9e09 commit 2fdea9c
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions app/src/main/java/com/amit/db/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1926,13 +1926,24 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
Log.e(TAG, "getAllRecords: Table name was null or empty.");
return null;
}

// checking if order by column name is not null and not empty for ascending order
if (orderByColumnName != null && !orderByColumnName.isEmpty())
{
Log.e(TAG, "getAllRecords: order by column name was null or empty.");
return null;
}

// checking if isAscending is false
// and order by column name is not null and not empty for descending order
if (!isAscending && (orderByColumnName != null && !orderByColumnName.isEmpty()))
if (!isAscending)
{
orderBy = " ORDER BY " + orderByColumnName + " DESC";
}
else
{
orderBy = " ORDER BY " + orderByColumnName + " ASC";
}

// checking if model class was provided or not
// it not then not proceeding further
Expand Down Expand Up @@ -2098,13 +2109,24 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
{
whereClause = " WHERE " + conditionalValues;
}


// checking if order by column name is not null and not empty for ascending order
if (orderByColumnName != null && !orderByColumnName.isEmpty())
{
Log.e(TAG, "getAllRecords: order by column name was null or empty.");
return null;
}

// checking if isAscending is false
// and order by column name is not null and not empty for descending order
if (!isAscending && (orderByColumnName != null && !orderByColumnName.isEmpty()))
if (!isAscending)
{
orderBy = " ORDER BY " + orderByColumnName + " DESC";
}
else
{
orderBy = " ORDER BY " + orderByColumnName + " ASC";
}

// checking if model class was provided or not
// it not then not proceeding further
Expand Down

0 comments on commit 2fdea9c

Please sign in to comment.