DBHelper.java
8.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package com.example.dataextraction;
import android.content.ContentValues;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
public class DBHelper {
private static final String DATABASE_NAME = "InnerDatabase.db";
private static final int DATABASE_VERSION = 1;
public static SQLiteDatabase mDB;
private DatabaseHelper mDBHelper;
private Context mCtx;
private class DatabaseHelper extends SQLiteOpenHelper {
public DatabaseHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(PhotoDataBase.CreateDB._CREATE0);
db.execSQL(VideoDataBase.CreateDB._CREATE0);
db.execSQL(AudioDataBase.CreateDB._CREATE0);
db.execSQL(CalendarDataBase.CreateDB._CREATE0);
db.execSQL(CallLogDataBase.CreateDB._CREATE0);
db.execSQL(ContactDataBase.CreateDB._CREATE0);
db.execSQL(SMSDataBase.CreateDB._CREATE0);
db.execSQL(WifiDataBase.CreateDB._CREATE0);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + PhotoDataBase.CreateDB._TABLENAME0);
db.execSQL("DROP TABLE IF EXISTS " + VideoDataBase.CreateDB._TABLENAME0);
db.execSQL("DROP TABLE IF EXISTS " + AudioDataBase.CreateDB._TABLENAME0);
db.execSQL("DROP TABLE IF EXISTS " + CalendarDataBase.CreateDB._TABLENAME0);
db.execSQL("DROP TABLE IF EXISTS " + CallLogDataBase.CreateDB._TABLENAME0);
db.execSQL("DROP TABLE IF EXISTS " + ContactDataBase.CreateDB._TABLENAME0);
db.execSQL("DROP TABLE IF EXISTS " + SMSDataBase.CreateDB._TABLENAME0);
db.execSQL("DROP TABLE IF EXISTS " + WifiDataBase.CreateDB._TABLENAME0);
onCreate(db);
}
}
public DBHelper(Context context){
this.mCtx = context;
}
public DBHelper open() throws SQLException {
mDBHelper = new DatabaseHelper(mCtx, DATABASE_NAME, null, DATABASE_VERSION);
mDB = mDBHelper.getWritableDatabase();
return this;
}
public void close(){
mDB.close();
}
public long insertPColumn(String title, int id, String date_added, String display_name
, String mime_type, String path, String latitude, String longitude){
ContentValues values = new ContentValues();
values.put(PhotoDataBase.CreateDB.TITLE, title);
values.put(PhotoDataBase.CreateDB.ID, id);
values.put(PhotoDataBase.CreateDB.DATE_ADDED, date_added);
values.put(PhotoDataBase.CreateDB.DISPLAY_NAME, display_name);
values.put(PhotoDataBase.CreateDB.MIME_TYPE, mime_type);
values.put(PhotoDataBase.CreateDB.PATH, path);
values.put(PhotoDataBase.CreateDB.LATITUDE, latitude);
values.put(PhotoDataBase.CreateDB.LONGITUDE, longitude);
return mDB.insert(PhotoDataBase.CreateDB._TABLENAME0, null, values);
}
public long insertVColumn(String title, String date_added, String display_name, String mime_type
, String path, String latitude, String longitude, String album, String artist, String bookmark
,String category, String description, String language, String resolution, String tags){
ContentValues values = new ContentValues();
values.put(VideoDataBase.CreateDB.TITLE, title);
values.put(VideoDataBase.CreateDB.DATE_ADDED, date_added);
values.put(VideoDataBase.CreateDB.DISPLAY_NAME, display_name);
values.put(VideoDataBase.CreateDB.MIME_TYPE, mime_type);
values.put(VideoDataBase.CreateDB.PATH, path);
values.put(VideoDataBase.CreateDB.LATITUDE, latitude);
values.put(VideoDataBase.CreateDB.LONGITUDE, longitude);
values.put(VideoDataBase.CreateDB.ALBUM, album);
values.put(VideoDataBase.CreateDB.ARTIST, artist);
values.put(VideoDataBase.CreateDB.BOOKMARK, bookmark);
values.put(VideoDataBase.CreateDB.CATEGORY, category);
values.put(VideoDataBase.CreateDB.DESCRIPTION, description);
values.put(VideoDataBase.CreateDB.LANGUAGE, language);
values.put(VideoDataBase.CreateDB.RESOLUTION, resolution);
values.put(VideoDataBase.CreateDB.TAGS, tags);
return mDB.insert(VideoDataBase.CreateDB._TABLENAME0, null, values);
}
public long insertAColumn(String title, String date_added, String mime_type, String path
,String album, String artist, String composer, String year, String size){
ContentValues values = new ContentValues();
values.put(AudioDataBase.CreateDB.TITLE, title);
values.put(AudioDataBase.CreateDB.DATE_ADDED, date_added);
values.put(AudioDataBase.CreateDB.MIME_TYPE, mime_type);
values.put(AudioDataBase.CreateDB.PATH, path);
values.put(AudioDataBase.CreateDB.ALBUM, album);
values.put(AudioDataBase.CreateDB.ARTIST, artist);
values.put(AudioDataBase.CreateDB.COMPOSER, composer);
values.put(AudioDataBase.CreateDB.YEAR, year);
values.put(AudioDataBase.CreateDB.SIZE, size);
return mDB.insert(AudioDataBase.CreateDB._TABLENAME0, null, values);
}
public long insertCColumn(String calendar_id, String title, String event_location, String description
, String dtstart, String dtend, String duration, String all_day, String display_name
, String account_name, String owner_name, String r_rule, String r_date){
ContentValues values = new ContentValues();
values.put(CalendarDataBase.CreateDB.TITLE, title);
values.put(CalendarDataBase.CreateDB.CALENDAR_ID, calendar_id);
values.put(CalendarDataBase.CreateDB.EVENT_LOCATION, event_location);
values.put(CalendarDataBase.CreateDB.DESCRIPTION, description);
values.put(CalendarDataBase.CreateDB.DTSTART, dtstart);
values.put(CalendarDataBase.CreateDB.DTEND, dtend);
values.put(CalendarDataBase.CreateDB.DURATION, duration);
values.put(CalendarDataBase.CreateDB.ALL_DAY, all_day);
values.put(CalendarDataBase.CreateDB.DISPLAY_NAME, display_name);
values.put(CalendarDataBase.CreateDB.ACCOUNT_NAME, account_name);
values.put(CalendarDataBase.CreateDB.OWNER_NAME, owner_name);
values.put(CalendarDataBase.CreateDB.RRULE, r_rule);
values.put(CalendarDataBase.CreateDB.RDATE, r_date);
return mDB.insert(CalendarDataBase.CreateDB._TABLENAME0, null, values);
}
public long insertCallLogColumn(String type, String name, String number, String duration
, String date){
ContentValues values = new ContentValues();
values.put(CallLogDataBase.CreateDB.TYPE, type);
values.put(CallLogDataBase.CreateDB.NAME, name);
values.put(CallLogDataBase.CreateDB.NUMBER, number);
values.put(CallLogDataBase.CreateDB.DURATION, duration);
values.put(CallLogDataBase.CreateDB.DATE, date);
return mDB.insert(CallLogDataBase.CreateDB._TABLENAME0, null, values);
}
public long insertContactColumn(String number, String name, String photo_id, String person_id){
ContentValues values = new ContentValues();
values.put(ContactDataBase.CreateDB.NUMBER, number);
values.put(ContactDataBase.CreateDB.NAME, name);
values.put(ContactDataBase.CreateDB.PHOTO_ID, photo_id);
values.put(ContactDataBase.CreateDB.PERSON_ID, person_id);
return mDB.insert(ContactDataBase.CreateDB._TABLENAME0, null, values);
}
public long insertSMSColumn(String mid, String tid, String type, String address, String person
, String creator, String date, String body, String read){
ContentValues values = new ContentValues();
values.put(SMSDataBase.CreateDB.MID, mid);
values.put(SMSDataBase.CreateDB.TID, tid);
values.put(SMSDataBase.CreateDB.TYPE, type);
values.put(SMSDataBase.CreateDB.ADDRESS, address);
values.put(SMSDataBase.CreateDB.PERSON, person);
values.put(SMSDataBase.CreateDB.CREATOR, creator);
values.put(SMSDataBase.CreateDB.DATE, date);
values.put(SMSDataBase.CreateDB.BODY, body);
values.put(SMSDataBase.CreateDB.READ, read);
return mDB.insert(SMSDataBase.CreateDB._TABLENAME0, null, values);
}
public long insertWifiColumn(String id, String ssid, String bssid, String wepkeys){
ContentValues values = new ContentValues();
values.put(WifiDataBase.CreateDB.ID, id);
values.put(WifiDataBase.CreateDB.SSID, ssid);
values.put(WifiDataBase.CreateDB.BSSID, bssid);
values.put(WifiDataBase.CreateDB.WEPKEYS, wepkeys);
return mDB.insert(WifiDataBase.CreateDB._TABLENAME0, null, values);
}
}