问题描述
有许多教程可用于将SQLite数据库导出到csv文件,但没有足够的东西可用于从会议室数据库导出.
There are many tutorials available for exporting SQLite database to csv file but not enough stuff for exporting from room database.
使用sqlite导出参考将SQLite数据库导出到android中的csv文件手动解析行的每一列以留出空间.以下是我的代码:
Using sqlite export reference Exporting SQLite Database to csv file in android parsing each column of row manually for room. Following is my code:
@Dao
interface CategoryDao {
@Query("SELECT * FROM Category")
fun getAllCategory(): List<Category>
}
// Export csv logic
val categoryList = categoryDao.getAllCategory()
val csvWrite = CSVWriter(FileWriter(file))
for (item in categoryList) {
val arrStr = arrayOf<String>(item.categoryId, item.categoryName)
csvWrite.writeNext(arrStr)
}
是否还有其他方法可以导出csv.即使在房间中,也无法实用地获取表的列名,因此无法为所有表动态创建通用逻辑.
Is there any other way to export csv. Even in room not getting columns name of table pragmatically so not able to create dynamically common logic for all table.
推荐答案
这可能是您正在搜索的答案.
This might be Answer that you are searching.
链接: https://stackoverflow.com/a/49133574/9994604
还有一种手动方法可以做到这一点.导出数据库
There is also a Manual way to do it.Export Database,
链接: https://stackoverflow.com/a/6542214/9994604
在Sqlite浏览器中打开: https://sqlitebrowser.org (免费)
Open in Sqlite Browser: https://sqlitebrowser.org (Free)
以CSV/JSON,SQL格式导出.
Export in CSV/JSON,SQL whichever you like.
这篇关于将会议室数据库导出到android中的csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!