Fixed crash when the device is turned while the warning dialog about server certifica...
[pub/Android/ownCloud.git] / src / com / owncloud / android / db / DbHandler.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18 package com.owncloud.android.db;
19
20 import java.util.Vector;
21
22 import com.owncloud.android.OwnCloudSession;
23
24
25 import android.content.ContentValues;
26 import android.content.Context;
27 import android.database.Cursor;
28 import android.database.sqlite.SQLiteDatabase;
29 import android.database.sqlite.SQLiteOpenHelper;
30
31 /**
32 * Custom database helper for ownCloud
33 *
34 * @author Bartek Przybylski
35 *
36 */
37 public class DbHandler {
38 private SQLiteDatabase mDB;
39 private OpenerHepler mHelper;
40 private final String mDatabaseName = "ownCloud";
41 private final String TABLE_SESSIONS = "sessions";
42 private final int mDatabaseVersion = 1;
43
44 private final String TABLE_INSTANT_UPLOAD = "instant_upload";
45
46 public DbHandler(Context context) {
47 mHelper = new OpenerHepler(context);
48 mDB = mHelper.getWritableDatabase();
49 }
50
51 public void close() {
52 mDB.close();
53 }
54
55 public boolean putFileForLater(String filepath, String account) {
56 ContentValues cv = new ContentValues();
57 cv.put("path", filepath);
58 cv.put("account", account);
59 return mDB.insert(TABLE_INSTANT_UPLOAD, null, cv) != -1;
60 }
61
62 public Cursor getAwaitingFiles() {
63 return mDB.query(TABLE_INSTANT_UPLOAD, null, null, null, null, null, null);
64 }
65
66 public void clearFiles() {
67 mDB.delete(TABLE_INSTANT_UPLOAD, null, null);
68 }
69
70 private class OpenerHepler extends SQLiteOpenHelper {
71 public OpenerHepler(Context context) {
72 super(context, mDatabaseName, null, mDatabaseVersion);
73 }
74
75 @Override
76 public void onCreate(SQLiteDatabase db) {
77 db.execSQL("CREATE TABLE " + TABLE_INSTANT_UPLOAD + " ("
78 + " _id INTEGET PRIMARY KEY, "
79 + " path TEXT,"
80 + " account TEXT);");
81 }
82
83 @Override
84 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
85 }
86 }
87 }