简体   繁体   中英

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. 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? 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 * 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 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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