简体   繁体   English

如何从SQLite数据库转储行并将其导入另一个数据库?

[英]How to dump a row from a SQLite database and import it into another database?

I currently want to dump a row from a SQLite database, transfer it over a network, and import it into the SQLite database on another phone. 我目前想从SQLite数据库中转储一行,通过网络传输它,然后将其导入另一部手机上的SQLite数据库。 How would I properly dump the row and import it later? 我如何正确地转储行并在以后导入它? I looked around and I see a number of people mentioning .sql files, but is there an Android-specific way to do it? 我环顾四周,看到很多人提到.sql文件,但有没有特定于Android的方法呢? Thanks. 谢谢。

I assume that you have exact same table structure on both source and target sides (otherwise question would not make much sense), and you probably already know your table structure. 我假设你在源端和目标端都有完全相同的表结构(否则问题没有多大意义),你可能已经知道了你的表结构。

In that case, if you simply SELECT row you want to export (for example using Java code): 在这种情况下,如果您只是想要导出的SELECT行(例如使用Java代码):

SELECT * FROM mytable WHERE id = 12345;

you would know row contents, so you can construct INSERT statement for target table, which should look like this: 你会知道行内容,所以你可以为目标表构造INSERT语句,它应该如下所示:

INSERT INTO mytable ( col1,   col2,  ...)
             VALUES ('val1', 'val2', ...);

All you need now is to execute this insert statement on target side (using Java or sqlite3 command line). 您现在需要的只是在目标端执行此insert语句(使用Java或sqlite3命令行)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM