android-room - INSERT query type is not supported yet. You can use:SELECT, DELETE, UPDATE
问题描述
I am getting this compile error when I try this query.
INSERT query type is not supported yet. You can use:SELECT, DELETE, UPDATE
@Query("INSERT INTO table SELECT name, etc from temp_table;")
void insertIntoTable();
Is there any other way to do a batch insert?
解决方案
I was able to do it using RawQuery:
public void addRecordsFromTempTable() {
mDatabase.rawDao().insertRecords(new SimpleSQLiteQuery("INSERT INTO my_table (name, etc) SELECT name, et from temp_table;"));
}
Raw query file:
@Dao
public interface RawDao {
@RawQuery()
boolean insertRecords(SupportSQLiteQuery query);
推荐阅读
- discord.py - Discord.py 如何下载服务器图标?
- java - 快速排序算法 ArrayOutOfBounds
- c - 在 linux 中从 C 代码调用汇编程序函数
- php - 使用php将文件从一个目录传输到另一个项目目录
- html - 为什么我的页脚周围有一个空框?
- android - android SDK 地图提供了错误的用户位置
- node.js - Async/Await & UnhandlePromiseRejectWarning
- spring - Spring shell 块测试
- go - 在 Go 中通过语句或数据库使用 QueryRow
- scala - 如何使用scala在spark中使用foreach正确调用函数?