+/* DatabaseManager.java
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package de.dhbwloe.campusapp.database;
-
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
*/
public class DatabaseManager {
private static final String DATABASE_NAME = "DHBWLoe.CampusApp.db";
- private static final int DATABASE_VERSION = 2;
+ private static final int DATABASE_VERSION = 2; // Datenbank Version - muss bei strukturellen Anpassungen erhöht werden
+
private CampusAppContext AppContext;
private SQLiteDatabase database;
private NewsDatabaseHelper newsDBHelper;
openDatabase();
database.execSQL("CREATE TABLE IF NOT EXISTS Version(Version INT);");
+ // Abfragen der Datenbank Version
Cursor resultSet = database.rawQuery("Select * from Version", null);
int version;
if(resultSet.moveToFirst()) {
}
resultSet.close();
- if(version < DATABASE_VERSION)
+ if(version < DATABASE_VERSION) // Upgrade der Datenbank Struktur (oder auch Initialisierung)
upgradeTables(version, DATABASE_VERSION);
-
- //database.execSQL("DELETE FROM CourseCalendar");
- //database.execSQL("DELETE FROM CourseCalendarEvent");
}
private void upgradeTables(int oldVersion, int newVersion) {
- if(oldVersion == 0 && newVersion > 0) {
+ if(oldVersion == 0 && newVersion > 0) { // Initialisierung (noch keine Datenbank)
database.execSQL("CREATE TABLE IF NOT EXISTS RuntimeCache " +
"(" +
"Reference TEXT, " +
"StaticEntry INT, " +
"UpdateTime INT, " +
"TargetPage TEXT);");
+
+ // Vorlesungsplan
database.execSQL("CREATE TABLE IF NOT EXISTS CourseCalendar " +
"(" +
"Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
"PRIMARY KEY (EventId, EventFrom, EventTo)" +
");");
database.execSQL("CREATE INDEX CourseCalendarEventIdx ON CourseCalendarEvent (EventFrom, EventTo);");
- database.execSQL("CREATE TABLE IF NOT EXISTS NfcCardStore " +
- "(" +
- "CardId INT, " +
- "UpdateTime INT," +
- "CardBalance INT, " +
- "CardLastTransaction INT, " +
- "PRIMARY KEY (CardId, UpdateTime)" +
- ");");
database.execSQL("CREATE TABLE IF NOT EXISTS CourseCalendarGroup " +
"(" +
"GroupId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
"UNIQUE (GroupName)" +
");");
database.execSQL("CREATE INDEX CourseCalendarGroupIdx ON CourseCalendarGroup (CourseName, GroupName);");
+
+ // Mensa Karten History is this actually used?)
+ database.execSQL("CREATE TABLE IF NOT EXISTS NfcCardStore " +
+ "(" +
+ "CardId INT, " +
+ "UpdateTime INT," +
+ "CardBalance INT, " +
+ "CardLastTransaction INT, " +
+ "PRIMARY KEY (CardId, UpdateTime)" +
+ ");");
+
+ // Mensaplan
database.execSQL("CREATE TABLE IF NOT EXISTS MensaPlan " +
"(" +
"PlanDate INT, " +
"PriceSchool INT, " +
"PRIMARY KEY (PlanDate, MenuName)" +
");");
+
+ // News
database.execSQL("CREATE TABLE IF NOT EXISTS News " +
"(" +
"Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
}
public void addSearchIndices(SearchIndices[] indices) {
+ // Hinzufügen oder Updaten mehrerer SearchIndice Objekte
openDatabase();
for(int i = 0; i < indices.length; i++) {
String[] whereArgs = new String[] {
}
public SearchIndices[] performSearchRequest(String query, int maxResults) {
+ // App Suche
openDatabase();
String[] whereArgs = new String[] {
"%" + query + "%"
}
public void setRuntimeCache(String name, String value) {
+ // Simple cache for runtime options
openDatabase();
long now = (new Date()).getTime() / 1000;
String[] whereArgs = new String[] {