1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
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.
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.
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/>.
18 package com
.owncloud
.android
.db
;
20 import java
.util
.Vector
;
22 import com
.owncloud
.android
.OwnCloudSession
;
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
;
32 * Custom database helper for ownCloud
34 * @author Bartek Przybylski
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;
44 private final String TABLE_INSTANT_UPLOAD
= "instant_upload";
46 public DbHandler(Context context
) {
47 mHelper
= new OpenerHepler(context
);
48 mDB
= mHelper
.getWritableDatabase();
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;
62 public Cursor
getAwaitingFiles() {
63 return mDB
.query(TABLE_INSTANT_UPLOAD
, null
, null
, null
, null
, null
, null
);
66 public void clearFiles() {
67 mDB
.delete(TABLE_INSTANT_UPLOAD
, null
, null
);
70 private class OpenerHepler
extends SQLiteOpenHelper
{
71 public OpenerHepler(Context context
) {
72 super(context
, mDatabaseName
, null
, mDatabaseVersion
);
76 public void onCreate(SQLiteDatabase db
) {
77 db
.execSQL("CREATE TABLE " + TABLE_INSTANT_UPLOAD
+ " ("
78 + " _id INTEGET PRIMARY KEY, "
84 public void onUpgrade(SQLiteDatabase db
, int oldVersion
, int newVersion
) {