14
14
* Created by txiaozhe on 12/02/2017.
15
15
*/
16
16
17
+ /**
18
+ * 数据库名:images_info.db
19
+ * 表名:images
20
+ */
21
+
17
22
public class DBManager {
18
23
private DBHelper helper ;
19
24
private SQLiteDatabase db ;
@@ -25,19 +30,20 @@ public DBManager(Context context) {
25
30
db = helper .getWritableDatabase ();
26
31
}
27
32
28
- public void add (List <MyImage > images ) {
33
+ public int add (MyImage image ) {
34
+ int stateCode = 0 ;
29
35
db .beginTransaction (); //开始事务
30
36
try {
31
- for (MyImage image : images ) {
32
- db .execSQL ("INSERT INTO images VALUES(null, ?, ?, ?, ?, ?, ?, ?, ?, ?)" , new Object []{image .getImagename (),
33
- image .getPath (), image .getType (), image .getSize (), image .getImagetime (),
34
- image .getMaxtemperature (), image .getMaxtemplocalx (), image .getMaxtemplocaly (),
35
- image .getMeantemperature ()});
36
- }
37
+ db .execSQL ("INSERT INTO heatimages VALUES(null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" , new Object []{image .getIsUpLoad (),
38
+ image .getTeleimei (), image .getBarcode (), image .getPath (), image .getImagename (),
39
+ image .getImagetime (), image .getMaxtemperature (), image .getMaxtemplocalx (),
40
+ image .getMaxtemplocaly (), image .getMeantemperature ()});
37
41
db .setTransactionSuccessful (); //设置事务成功完成
38
42
} finally {
39
- db .endTransaction (); //结束事务
43
+ db .endTransaction ();//结束事务
44
+ stateCode = -1 ;
40
45
}
46
+ return stateCode ;
41
47
}
42
48
43
49
public void updateAge (MyImage image ) {
@@ -52,35 +58,39 @@ public void deleteOldPerson(MyImage image) {
52
58
53
59
/**
54
60
* query all persons, return list
61
+ *
55
62
* @return List<Person>
56
63
*/
57
64
public List <MyImage > query () {
58
65
ArrayList <MyImage > images = new ArrayList <MyImage >();
59
66
Cursor c = queryTheCursor ();
60
67
while (c .moveToNext ()) {
61
68
MyImage image = new MyImage ();
62
- image .setImagename (c .getString (c .getColumnIndex ("name" )));
69
+ image .setIsUpLoad (c .getString (c .getColumnIndex ("isUpload" )));
70
+ image .setTeleimei (c .getString (c .getColumnIndex ("teleimei" )));
71
+ image .setBarcode (c .getString (c .getColumnIndex ("barcode" )));
63
72
image .setPath (c .getString (c .getColumnIndex ("path" )));
64
- image .setType (c .getString (c .getColumnIndex ("type" )));
65
- image .setSize (c .getString (c .getColumnIndex ("size" )));
66
- image .setImagetime (c .getString (c .getColumnIndex ("time" )));
67
- image .setMaxtemperature (c .getString (c .getColumnIndex ("maxTemp" )));
68
- image .setMaxtemplocalx (c .getString (c .getColumnIndex ("maxTempX" )));
69
- image .setMaxtemplocaly (c .getString (c .getColumnIndex ("maxTempY" )));
70
- image .setMeantemperature (c .getString (c .getColumnIndex ("averageTemp" )));
73
+ image .setImagename (c .getString (c .getColumnIndex ("imagename" )));
74
+ image .setImagetime (c .getString (c .getColumnIndex ("imagetime" )));
75
+ image .setMaxtemperature (c .getString (c .getColumnIndex ("maxtemperature" )));
76
+ image .setMaxtemplocalx (c .getString (c .getColumnIndex ("maxtemplocalx" )));
77
+ image .setMaxtemplocaly (c .getString (c .getColumnIndex ("maxtemplocaly" )));
78
+ image .setMeantemperature (c .getString (c .getColumnIndex ("meantemperature" )));
71
79
72
80
images .add (image );
73
81
}
74
82
c .close ();
83
+ closeDB ();
75
84
return images ;
76
85
}
77
86
78
87
/**
79
88
* query all persons, return cursor
80
- * @return Cursor
89
+ *
90
+ * @return Cursor
81
91
*/
82
92
public Cursor queryTheCursor () {
83
- Cursor c = db .rawQuery ("SELECT * FROM images " , null );
93
+ Cursor c = db .rawQuery ("SELECT * FROM heatimages " , null );
84
94
return c ;
85
95
}
86
96
0 commit comments