質問編集履歴
1
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -94,7 +94,7 @@
|
|
94
94
|
|
95
95
|
|
96
96
|
|
97
|
-
public static final String DB_NAME = "
|
97
|
+
public static final String DB_NAME = "Money.db";
|
98
98
|
|
99
99
|
public static final int DB_VERSION = 1;
|
100
100
|
|
@@ -118,6 +118,26 @@
|
|
118
118
|
|
119
119
|
|
120
120
|
|
121
|
+
|
122
|
+
|
123
|
+
public static final String INIT_TABLE =
|
124
|
+
|
125
|
+
"insert into " + SQLContract.Item.TABLE_NAME + "(" +
|
126
|
+
|
127
|
+
SQLContract.Money.ITEM + "," +
|
128
|
+
|
129
|
+
SQLContract.Money.MONEY + ","+
|
130
|
+
|
131
|
+
SQLContract.Money.YEAR + ","+
|
132
|
+
|
133
|
+
SQLContract.Money.MONTH + ","+
|
134
|
+
|
135
|
+
SQLContract.Money.DATE + ") values " +
|
136
|
+
|
137
|
+
"('item1',10,2018,2,1)";
|
138
|
+
|
139
|
+
|
140
|
+
|
121
141
|
public static final String DROP_TABLE =
|
122
142
|
|
123
143
|
"drop table if exists " + SQLContract.Money.TABLE_NAME;
|
@@ -130,6 +150,8 @@
|
|
130
150
|
|
131
151
|
db.execSQL(CREATE_TABLE);
|
132
152
|
|
153
|
+
db.execSQL(INIT_TABLE);
|
154
|
+
|
133
155
|
}
|
134
156
|
|
135
157
|
|
@@ -168,25 +190,15 @@
|
|
168
190
|
|
169
191
|
public class SQLMoney {
|
170
192
|
|
171
|
-
|
193
|
+
|
172
|
-
|
173
|
-
|
194
|
+
|
174
|
-
|
175
|
-
|
195
|
+
Context context;
|
176
|
-
|
177
|
-
|
196
|
+
|
178
|
-
|
179
|
-
|
180
|
-
|
197
|
+
|
198
|
+
|
181
|
-
public SQLMoney
|
199
|
+
public SQLMoney(Context context) {
|
182
|
-
|
183
|
-
|
200
|
+
|
184
|
-
|
185
|
-
ite
|
201
|
+
this.context = context;
|
186
|
-
|
187
|
-
database = openHelper.getWritableDatabase();
|
188
|
-
|
189
|
-
itemDatabase = itemOpenHelper.getReadableDatabase();
|
190
202
|
|
191
203
|
}
|
192
204
|
|
@@ -196,11 +208,15 @@
|
|
196
208
|
|
197
209
|
public int getMoney(int year, int month, int date, int number) {
|
198
210
|
|
211
|
+
SQLMoneyOpenHelper openHelper = new SQLMoneyOpenHelper(context);
|
212
|
+
|
213
|
+
SQLiteDatabase database = openHelper.getWritableDatabase();
|
214
|
+
|
199
215
|
String item = searchItem(number);
|
200
216
|
|
201
217
|
|
202
218
|
|
203
|
-
Cursor cursor
|
219
|
+
Cursor cursor;
|
204
220
|
|
205
221
|
cursor = database.query(
|
206
222
|
|
@@ -246,12 +262,14 @@
|
|
246
262
|
|
247
263
|
public void saveMoney(int year, int month, int date, int number, int money) {
|
248
264
|
|
265
|
+
SQLMoneyOpenHelper openHelper = new SQLMoneyOpenHelper(context);
|
266
|
+
|
267
|
+
SQLiteDatabase database = openHelper.getWritableDatabase();
|
268
|
+
|
249
269
|
String item = searchItem(number);
|
250
270
|
|
251
271
|
|
252
272
|
|
253
|
-
Cursor cursor = null;
|
254
|
-
|
255
273
|
ContentValues newMoney = new ContentValues();
|
256
274
|
|
257
275
|
newMoney.put(SQLContract.Money.MONEY, money);
|
@@ -278,7 +296,11 @@
|
|
278
296
|
|
279
297
|
public String searchItem(int number) {
|
280
298
|
|
299
|
+
SQLItemOpenHelper itemOpenHelper = new SQLItemOpenHelper(context);
|
300
|
+
|
301
|
+
SQLiteDatabase itemDatabase = itemOpenHelper.getReadableDatabase();
|
302
|
+
|
281
|
-
Cursor cursor
|
303
|
+
Cursor cursor;
|
282
304
|
|
283
305
|
cursor = itemDatabase.query(
|
284
306
|
|
@@ -318,6 +340,8 @@
|
|
318
340
|
|
319
341
|
}
|
320
342
|
|
343
|
+
|
344
|
+
|
321
345
|
コード
|
322
346
|
|
323
347
|
```
|