1

please help me for: how to copy all tables in sqlite's database from one database to another using c++

I have a database file,I want to copy all table to another database and using c++ language,I don't know how to Loop read all table in the original database an how to copy them to another database using c++.

MikeT
  • 51,415
  • 16
  • 49
  • 68
Cheetah
  • 11
  • 2
  • 3
    Does this answer your question? [Copying data from one SQLite database to another](https://stackoverflow.com/questions/2359205/copying-data-from-one-sqlite-database-to-another) – Vlam Dec 20 '19 at 02:07
  • Read up on the backup api. – Shawn Dec 20 '19 at 02:16

1 Answers1

0

You can just create a copy of the database file with the new database name, that is assuming you want all the data as well. This can be done without connecting to/opening the database by standard File handling.

  • The database name is only significant as the file name.

Another way is to use VACUUM INTO 'file'; again this copies all data, this does require the database to have been connected as the above is an SQL statement.

  • e.g. VACUUM INTO 'E:\Navicat\SQlite Databases\myOtherDBName'; (Windows)
  • see VACUUM

If you don't want the data then when connected to the new database you can delete the rows in all the tables followed by a VACUUM (if you wish). This would probably be best done within a transaction.

MikeT
  • 51,415
  • 16
  • 49
  • 68