-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSQLiteOpenHelper
More file actions
85 lines (69 loc) · 3.21 KB
/
FileSQLiteOpenHelper
File metadata and controls
85 lines (69 loc) · 3.21 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
package com.zrl.fileguard;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class FileSQLiteOpenHelper extends SQLiteOpenHelper {
private static final String TAG = "FileSQLiteOpenHelper";
private static final String DB_NAME = "guard.db";
private static final int VERSION = 1;
public static final String USER_TABLE = "user";
public static final String FILE_TABLE = "file";
public static final String LOCATION_TABLE = "location";
public FileSQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
public FileSQLiteOpenHelper(Context context) {
super(context, DB_NAME, null, VERSION);
}
public void insert(SQLiteDatabase db, String table, ContentValues values) {
if (null == db || null == table || null == values) {
Log.e(TAG, "null == db || null == table || null == values");
return ;
}
db.insert(table, null, values);
}
public void delete(SQLiteDatabase db, String table, int id) {
if (null == db || null == table || id < 0) {
Log.e(TAG, "null == db || null == table || id < 0");
return ;
}
db.delete(table, "_id", new String[]{"" + id});
}
public void update(SQLiteDatabase db, String table, ContentValues values, int id) {
if (null == db || null == table || null == values || id < 0) {
Log.e(TAG, "null == db || null == table || null == values || id < 0");
return ;
}
db.update(table, values, "_id", new String[]{"" + id});
}
public void query(SQLiteDatabase db, String table, String selection, String[] selectionArgs) {
if (null == db || null == table || null == selection || null == selectionArgs) {
Log.e(TAG, "null == db || null == table || null == selection || null == selectionArgs");
return ;
}
db.query(table, null, selection, selectionArgs, null, null, null, null);
}
@Override
public void onCreate(SQLiteDatabase db) {
String userTable = "create table user (_id integer primary key autoincrement, " +
"job_number char(12), device_info char(50), login_time integer(20), quit_time long(20))";
String fileTable = "create table file (_id integer primary key autoincrement, " +
"job_number char(12), device_info char(50), file_name char(50), file_type char(20), " +
"file_size integer(20), transfer_mode integer(20), transfer_time long(20))";
String locationTable = "create table location (_id integer primary key autoincrement, " +
"job_number char(12), device_info char(50), longitude long(20), latitude long(20), " +
"locate_time long(20))";
db.execSQL(userTable);
db.execSQL(fileTable);
db.execSQL(locationTable);
}
@Override
public void onOpen(SQLiteDatabase db) {
super.onOpen(db);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}