0

working with PySide. I have a sqlite database as default database:

db1 = QtSql.QSqlDatabase.addDatabase("QSQLITE")
db1.setDatabaseName(path_of_db)
db1.open()

and a second database with connection name "second_db":

db2 = QtSql.QSqlDatabase.addDatabase("QSQLITE", "second_db")
db2.setDatabaseName(path_of_db)
db2.open()
query = QSql.QSqlQuery("second_db")
query.exec_("SELECT * FROM table_name")

Now i want to insert records from a table from db1 into a table from db2. I have a model for db1. I know that I can insert record per record through the models. I also thought about writing the records from db1 in a file/variable and then insert these into db2. Is there a simpler/quicker solution maybe a sql-query? How can I solve the problem?

Thank you for your help ;-)

Chris
  • 3
  • 1

1 Answers1

0

I'd probably try row by row insertion, and see how fast it is. Might be all you need. A few tips on bulk insertions are here; basically,if you use BEGIN and END TRANSACTION, and an in-memory journal then you greatly speed up inserts. Oh and create indexes after you're done, not before.

Community
  • 1
  • 1
Karel Kubat
  • 1,635
  • 11
  • 12