19
19
20
20
package com .sample .encrypt .database ;
21
21
22
+ import android .annotation .SuppressLint ;
22
23
import android .content .ContentValues ;
23
24
import android .content .Context ;
24
25
import android .database .Cursor ;
25
26
26
- import net .sqlcipher .DatabaseUtils ;
27
- import net .sqlcipher .database .SQLiteDatabase ;
28
- import net .sqlcipher .database .SQLiteOpenHelper ;
27
+ import net .zetetic . database .DatabaseUtils ;
28
+ import net .zetetic .database . sqlcipher .SQLiteDatabase ;
29
+ import net .zetetic .database . sqlcipher .SQLiteOpenHelper ;
29
30
30
31
import java .util .ArrayList ;
31
32
@@ -39,10 +40,12 @@ public class PersonDBHelper extends SQLiteOpenHelper {
39
40
public static final String PERSON_COLUMN_ADDRESS = "address" ;
40
41
private static final String DB_PASSWORD = "a_password" ;
41
42
42
- public PersonDBHelper (Context context ) {
43
+ static {
44
+ System .loadLibrary ("sqlcipher" );
45
+ }
43
46
44
- super ( context , DATABASE_NAME , null , 1 );
45
- SQLiteDatabase . loadLibs (context );
47
+ public PersonDBHelper ( Context context ) {
48
+ super (context , DATABASE_NAME , DB_PASSWORD , null , 1 , 0 , null , null , false );
46
49
}
47
50
48
51
@ Override
@@ -60,7 +63,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
60
63
}
61
64
62
65
public boolean insertPerson (String firstName , String lastName , String address ) {
63
- SQLiteDatabase db = this .getWritableDatabase (DB_PASSWORD );
66
+ SQLiteDatabase db = this .getWritableDatabase ();
64
67
ContentValues contentValues = new ContentValues ();
65
68
contentValues .put ("first_name" , firstName );
66
69
contentValues .put ("last_name" , lastName );
@@ -71,19 +74,19 @@ public boolean insertPerson(String firstName, String lastName, String address) {
71
74
}
72
75
73
76
public Cursor getData (int id ) {
74
- SQLiteDatabase db = this .getReadableDatabase (DB_PASSWORD );
77
+ SQLiteDatabase db = this .getReadableDatabase ();
75
78
Cursor res = db .rawQuery ("select * from person where id=" + id + "" , null );
76
79
return res ;
77
80
}
78
81
79
82
public int numberOfRows () {
80
- SQLiteDatabase db = this .getReadableDatabase (DB_PASSWORD );
83
+ SQLiteDatabase db = this .getReadableDatabase ();
81
84
int numRows = (int ) DatabaseUtils .queryNumEntries (db , PERSON_TABLE_NAME );
82
85
return numRows ;
83
86
}
84
87
85
88
public boolean updatePerson (Integer id , String firstName , String lastName , String address , float mileage ) {
86
- SQLiteDatabase db = this .getWritableDatabase (DB_PASSWORD );
89
+ SQLiteDatabase db = this .getWritableDatabase ();
87
90
ContentValues contentValues = new ContentValues ();
88
91
contentValues .put ("first_name" , firstName );
89
92
contentValues .put ("last_name" , lastName );
@@ -94,16 +97,17 @@ public boolean updatePerson(Integer id, String firstName, String lastName, Strin
94
97
}
95
98
96
99
public Integer deletePerson (Integer id ) {
97
- SQLiteDatabase db = this .getWritableDatabase (DB_PASSWORD );
100
+ SQLiteDatabase db = this .getWritableDatabase ();
98
101
return db .delete ("person" ,
99
102
"id = ? " ,
100
103
new String []{Integer .toString (id )});
101
104
}
102
105
106
+ @ SuppressLint ("Range" )
103
107
public ArrayList <String > getAllPerson () {
104
108
ArrayList <String > arrayList = new ArrayList <>();
105
109
106
- SQLiteDatabase db = this .getReadableDatabase (DB_PASSWORD );
110
+ SQLiteDatabase db = this .getReadableDatabase ();
107
111
Cursor res = db .rawQuery ("select * from person" , null );
108
112
res .moveToFirst ();
109
113
@@ -119,7 +123,7 @@ public ArrayList<String> getAllPerson() {
119
123
}
120
124
121
125
public int count () {
122
- SQLiteDatabase db = getReadableDatabase (DB_PASSWORD );
126
+ SQLiteDatabase db = getReadableDatabase ();
123
127
Cursor cursor = db .rawQuery ("select * from person" , null );
124
128
try {
125
129
if (cursor != null && cursor .getCount () > 0 ) {
0 commit comments