質問編集履歴
1
参考文献を修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,11 +1,141 @@
|
|
1
|
-
[
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
[Roomで動的に生成したクエリ(SQL文)を扱う方法 - Qiita](https://qiita.com/towor/items/fd7043abdf6ebe41c4b7)@RawQueryを使用すると実装でsきそうですが、実際に、PRAGMA keyを指定したい場合の記述方法がわからず、質問させて頂きました。不躾なご質問で恐縮ですが、よろしくお願いします。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
ViewModelは以下です。
|
6
6
|
|
7
7
|
```kotlin
|
8
8
|
|
9
|
+
class RequestDocumentsViewModel(application: Application): AndroidViewModel(application) {
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
private val requestDocumentsPersonInfoDao: RequestDocumentsPersonInfoDao
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
init {
|
20
|
+
|
21
|
+
val query = SimpleSQLiteQuery("PRAGMA key = 'passphrase'")
|
22
|
+
|
23
|
+
val db = RequestDocumentsPersonInfoDatabase.buildDatabase(application)
|
24
|
+
|
25
|
+
requestDocumentsPersonInfoDao = db.requestDocumentsPersonInfoDao()
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
val personData = requestDocumentsPersonInfoDao.loadAllRequestDocumentsPersonInfo()
|
36
|
+
|
37
|
+
val personDataAll = requestDocumentsPersonInfoDao.loadAllRequestDocumentsPersonInfoLiveData()
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
fun insert(name: String, phoneticGuides: String, birthday: String, mailAddress: String, phoneNumber: String) {
|
46
|
+
|
47
|
+
viewModelScope.launch(Dispatchers.IO) {
|
48
|
+
|
49
|
+
requestDocumentsPersonInfoDao.saveRequestDocumentsPersonInfo(
|
50
|
+
|
51
|
+
RequestDocumentsPersonInfo(
|
52
|
+
|
53
|
+
id = 0,
|
54
|
+
|
55
|
+
name = name,
|
56
|
+
|
57
|
+
phoneticGuides = phoneticGuides,
|
58
|
+
|
59
|
+
birthday = birthday,
|
60
|
+
|
61
|
+
mailAddress = mailAddress,
|
62
|
+
|
63
|
+
phoneNumber = phoneNumber,
|
64
|
+
|
65
|
+
zipStr = "",
|
66
|
+
|
67
|
+
prefecture = "",
|
68
|
+
|
69
|
+
city = "",
|
70
|
+
|
71
|
+
address = "",
|
72
|
+
|
73
|
+
disableCertifidate = "",
|
74
|
+
|
75
|
+
sendingMaterials = "",
|
76
|
+
|
77
|
+
remarks = ""
|
78
|
+
|
79
|
+
)
|
80
|
+
|
81
|
+
)
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
fun updateAddress(zipStr: String, prefecture: String, city: String, address: String) {
|
90
|
+
|
91
|
+
viewModelScope.launch (Dispatchers.IO) {
|
92
|
+
|
93
|
+
val editPersonInfo = personData.first()
|
94
|
+
|
95
|
+
editPersonInfo.zipStr = zipStr
|
96
|
+
|
97
|
+
editPersonInfo.prefecture = prefecture
|
98
|
+
|
99
|
+
editPersonInfo.city = city
|
100
|
+
|
101
|
+
editPersonInfo.address = address
|
102
|
+
|
103
|
+
requestDocumentsPersonInfoDao.updateRequestDocumentsPersonInfo(editPersonInfo)
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
fun updateParam(disableCertificate: String, sendingMaterials: String, remarks: String) {
|
112
|
+
|
113
|
+
viewModelScope.launch (Dispatchers.IO) {
|
114
|
+
|
115
|
+
val editPersonInfo = personData.first()
|
116
|
+
|
117
|
+
editPersonInfo.disableCertifidate = disableCertificate
|
118
|
+
|
119
|
+
editPersonInfo.sendingMaterials = sendingMaterials
|
120
|
+
|
121
|
+
editPersonInfo.remarks = remarks
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
Entityは以下です。
|
136
|
+
|
137
|
+
```kotlin
|
138
|
+
|
9
139
|
import androidx.room.ColumnInfo
|
10
140
|
|
11
141
|
import androidx.room.Entity
|