Copyright (c) 2014, John Phillips
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
...
If you think the Android project HistoryCleanerPro listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.ayros.historycleaner.helpers;
/*fromwww.java2s.com*/import java.util.ArrayList;
import java.util.List;
import android.content.Context;
publicclass DBHelper
{
publicstatic List<String[]> queryDatabase(Context c, String db, String[] headings, String table, String[] cols, String where)
{
List<String[]> rows = new ArrayList<String[]>();
rows.add(headings);
DatabaseModifier dm = new DatabaseModifier(c, db);
if (!dm.open())
{
dm.clean();
rows.clear();
rows.add(new String[] { "Error: Could not read from database (Error = 0)" });
rows.add(new String[] {});
return rows;
}
List<String[]> queryRows = dm.query(table, cols, where);
dm.clean();
if (queryRows == null)
{
rows.clear();
rows.add(new String[] { "Error: Could not read from database (Error = 1)" });
rows.add(new String[] {});
return rows;
}
for (String[] row : queryRows)
{
rows.add(row);
}
return rows;
}
publicstaticboolean updateDatabase(Context c, String db, String[] queries)
{
DatabaseModifier dm = new DatabaseModifier(c, db);
if (!dm.open())
{
Logger.errorST("Could not update database {" + db + "}");
dm.clean();
return false;
}
for (String q : queries)
{
if (!dm.exec(q))
{
Logger.errorST("Could not execute query {" + q + "} on database {" + db + "}");
dm.clean();
return false;
}
}
boolean result = dm.saveChanges();
dm.clean();
return result;
}
}