質問編集履歴

2

追記の削除

2020/04/28 02:11

投稿

Peanuts888
Peanuts888

スコア6

test CHANGED
File without changes
test CHANGED
@@ -187,83 +187,3 @@
187
187
  ```
188
188
 
189
189
  このColumnsに問題があるのでしょうか...
190
-
191
- 追記 2020/04/27
192
-
193
- ---
194
-
195
- 回答を参考に実行したDB処理文
196
-
197
- ```Java
198
-
199
- @Override
200
-
201
- public boolean onMove(@NonNull RecyclerView recyclerView,
202
-
203
- @NonNull RecyclerView.ViewHolder viewHolder,
204
-
205
- @NonNull RecyclerView.ViewHolder target) {
206
-
207
- final int fromPos = viewHolder.getAdapterPosition();
208
-
209
- final int toPos = target.getAdapterPosition();
210
-
211
- myDataset.add(toPos, myDataset.remove(fromPos));
212
-
213
- SQLiteDatabase db = helper.getWritableDatabase();
214
-
215
- try {
216
-
217
- Cursor c = db.rawQuery("SELECT body, date FROM MemoTable ORDER BY id", null);
218
-
219
- c.moveToPosition(fromPos);
220
-
221
- String bodyF = c.getString(0);
222
-
223
- String dateF = c.getString(1);
224
-
225
- c.moveToPosition(toPos);
226
-
227
- String bodyT = c.getString(0);
228
-
229
- String dateT = c.getString(1);
230
-
231
- int fpPlus = fromPos +1;
232
-
233
- int tpPlus = toPos +1;
234
-
235
- db.execSQL("UPDATE MT SET body = '"+ bodyF +"', date = '"+ dateF +"'FROM MemoTable MT WHERE id = "+ tpPlus +"");
236
-
237
- db.execSQL("UPDATE MT SET body = '"+ bodyT +"', date = '"+ dateT +"'FROM MemoTable MT WHERE id = "+ fpPlus +"");
238
-
239
- } finally { db.close(); }
240
-
241
- mAdapter.notifyItemMoved(fromPos, toPos);
242
-
243
- return true;
244
-
245
- }
246
-
247
- ```
248
-
249
- エラー
250
-
251
- ```
252
-
253
- 2020-04-27 20:35:25.030 10039-10039/com.example.recyclerview_practice E/SQLiteLog: (1) near "FROM": syntax error
254
-
255
- 2020-04-27 20:35:25.033 10039-10039/com.example.recyclerview_practice E/InputEventReceiver: Exception dispatching input event.
256
-
257
- 2020-04-27 20:35:25.034 10039-10039/com.example.recyclerview_practice D/AndroidRuntime: Shutting down VM
258
-
259
- 2020-04-27 20:35:25.037 10039-10039/com.example.recyclerview_practice E/AndroidRuntime: FATAL EXCEPTION: main
260
-
261
- Process: com.example.recyclerview_practice, PID: 10039
262
-
263
- android.database.sqlite.SQLiteException: near "FROM": syntax error (code 1): , while compiling: UPDATE MT SET body = 'いち', date = '2020/04/27'FROM MemoTable MT WHERE id = 2
264
-
265
- at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
266
-
267
-     atが続く...
268
-
269
- ```

1

DB処理文の追加とそれによるエラー

2020/04/28 02:11

投稿

Peanuts888
Peanuts888

スコア6

test CHANGED
File without changes
test CHANGED
@@ -187,3 +187,83 @@
187
187
  ```
188
188
 
189
189
  このColumnsに問題があるのでしょうか...
190
+
191
+ 追記 2020/04/27
192
+
193
+ ---
194
+
195
+ 回答を参考に実行したDB処理文
196
+
197
+ ```Java
198
+
199
+ @Override
200
+
201
+ public boolean onMove(@NonNull RecyclerView recyclerView,
202
+
203
+ @NonNull RecyclerView.ViewHolder viewHolder,
204
+
205
+ @NonNull RecyclerView.ViewHolder target) {
206
+
207
+ final int fromPos = viewHolder.getAdapterPosition();
208
+
209
+ final int toPos = target.getAdapterPosition();
210
+
211
+ myDataset.add(toPos, myDataset.remove(fromPos));
212
+
213
+ SQLiteDatabase db = helper.getWritableDatabase();
214
+
215
+ try {
216
+
217
+ Cursor c = db.rawQuery("SELECT body, date FROM MemoTable ORDER BY id", null);
218
+
219
+ c.moveToPosition(fromPos);
220
+
221
+ String bodyF = c.getString(0);
222
+
223
+ String dateF = c.getString(1);
224
+
225
+ c.moveToPosition(toPos);
226
+
227
+ String bodyT = c.getString(0);
228
+
229
+ String dateT = c.getString(1);
230
+
231
+ int fpPlus = fromPos +1;
232
+
233
+ int tpPlus = toPos +1;
234
+
235
+ db.execSQL("UPDATE MT SET body = '"+ bodyF +"', date = '"+ dateF +"'FROM MemoTable MT WHERE id = "+ tpPlus +"");
236
+
237
+ db.execSQL("UPDATE MT SET body = '"+ bodyT +"', date = '"+ dateT +"'FROM MemoTable MT WHERE id = "+ fpPlus +"");
238
+
239
+ } finally { db.close(); }
240
+
241
+ mAdapter.notifyItemMoved(fromPos, toPos);
242
+
243
+ return true;
244
+
245
+ }
246
+
247
+ ```
248
+
249
+ エラー
250
+
251
+ ```
252
+
253
+ 2020-04-27 20:35:25.030 10039-10039/com.example.recyclerview_practice E/SQLiteLog: (1) near "FROM": syntax error
254
+
255
+ 2020-04-27 20:35:25.033 10039-10039/com.example.recyclerview_practice E/InputEventReceiver: Exception dispatching input event.
256
+
257
+ 2020-04-27 20:35:25.034 10039-10039/com.example.recyclerview_practice D/AndroidRuntime: Shutting down VM
258
+
259
+ 2020-04-27 20:35:25.037 10039-10039/com.example.recyclerview_practice E/AndroidRuntime: FATAL EXCEPTION: main
260
+
261
+ Process: com.example.recyclerview_practice, PID: 10039
262
+
263
+ android.database.sqlite.SQLiteException: near "FROM": syntax error (code 1): , while compiling: UPDATE MT SET body = 'いち', date = '2020/04/27'FROM MemoTable MT WHERE id = 2
264
+
265
+ at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
266
+
267
+     atが続く...
268
+
269
+ ```