Results 1 to 3 of 3

Thread: duplicate recordset

  1. #1
    Join Date
    Apr 2008
    Location
    Karaj,Iran
    Posts
    43
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default duplicate recordset

    there is some data on my database which is updated rarely like name of cities so I want to download them into a local database on client computer rendering avoidance of overhead on my database server,now what is the best way to retrieve a mysql table records and paste those records to a sqlite database table?
    I have done the following but it's VERY slow,takes 5 seconds to just copy 30 records
    Qt Code:
    1. QSqlDatabase citiesDB = QSqlDatabase::addDatabase("QMYSQL","CitiesConnection");
    2. QSqlDatabase localDB = QSqlDatabase::addDatabase("QSQLITE","localDB");
    3.  
    4. localDB.setDatabaseName(singletonConfig::Instance()->configHash().value("kavoshFolder")+"/localCitiesDB");
    5. localDB.open();
    6. citiesDB.setHostName("192.168.1.2");
    7. citiesDB.setDatabaseName("Kavosh8");
    8. citiesDB.setUserName("root");
    9. citiesDB.setPassword("secret");
    10. citiesDB.open();
    11. QSqlQuery mainDbQuery("select * from province",citiesDB);
    12. QSqlQuery localDbProQuery("CREATE TABLE `province` (province_id int(11) NOT NULL\
    13. ,province varchar(100)\
    14. ,PRIMARY KEY (province_id))",localDB);
    15. localDbProQuery.exec();
    16. mainDbQuery.exec();
    17. mainDbQuery.first();
    18. QVariantList provinceID,province;
    19.  
    20. do
    21. {
    22. provinceID<<mainDbQuery.value(0);
    23. province<<mainDbQuery.value(1).toString();
    24.  
    25. }
    26. while(mainDbQuery.next() );
    27. localDbProQuery.prepare("insert into province values(?,?)");
    28. localDbProQuery.addBindValue(provinceID);
    29. localDbProQuery.addBindValue(province);
    30. qDebug()<<localDbProQuery.execBatch();
    31.  
    32. provinceID.clear();
    33. QVariantList cityID,city,type;
    34. mainDbQuery.prepare("select * from city");
    35. mainDbQuery.exec();
    36. mainDbQuery.first();
    37. int i=0;
    38. do
    39. {
    40. qDebug()<<mainDbQuery.value(0).toInt();
    41. cityID<<mainDbQuery.value(0);
    42. provinceID<<mainDbQuery.value(1);
    43. city<<mainDbQuery.value(2).toString();
    44. type<<mainDbQuery.value(3);
    45. }
    46. while(mainDbQuery.next() );
    47. QSqlQuery localDbCityQuery("CREATE TABLE `city` ( \
    48. `city_ID` int(11) NOT NULL, \
    49. `province_ID` int(11) NOT NULL,\
    50. `city` varchar(100) NOT NULL,\
    51. `type` varchar(3) DEFAULT '0',\
    52. PRIMARY KEY (`city_ID`))",localDB);
    53.  
    54. localDbCityQuery.exec();
    55. localDbCityQuery.prepare("insert into city values(?,?,?,?)");
    56. localDbCityQuery.addBindValue(cityID);
    57. localDbCityQuery.addBindValue(provinceID);
    58. localDbCityQuery.addBindValue(city);
    59. localDbCityQuery.addBindValue(type);
    60. localDbCityQuery.execBatch();
    To copy to clipboard, switch view to plain text mode 
    ---
    A situtation never gets so complicated that it can't get any more complicated!

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: duplicate recordset

    see
    http://www.qtcentre.org/forum/f-gene...lite-4180.html

    i.e.: use a transaction; read up on bulk inserts; if nothing helps: write a csv file and import that

    HTH

  3. The following user says thank you to caduel for this useful post:

    sepehr (4th February 2009)

  4. #3
    Join Date
    Apr 2008
    Location
    Karaj,Iran
    Posts
    43
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: duplicate recordset

    I wrapped up the insert statement in
    localDB.transaction ();
    //batch insert statement
    localDB.commit () ;
    it works just fine now!
    ---
    A situtation never gets so complicated that it can't get any more complicated!

Similar Threads

  1. How to remove duplicate enteries from QStringList.
    By merry in forum Qt Programming
    Replies: 5
    Last Post: 7th March 2019, 15:02
  2. Replies: 13
    Last Post: 6th February 2009, 21:27
  3. Remove Duplicate Lines in a file
    By nmuntz in forum Qt Programming
    Replies: 4
    Last Post: 12th January 2009, 00:04
  4. Duplicate SLOTS
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2008, 12:32
  5. Replies: 3
    Last Post: 22nd June 2006, 16:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.