Results 1 to 6 of 6

Thread: Importing a local storage csv into sqlite database table?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jul 2020
    Location
    Michigan
    Posts
    8
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Windows Android

    Default Re: Importing a local storage csv into sqlite database table?

    I am still learning Qt / coding / etc so bare with me. I am trying to replicate an application in Qt that we already have available to users so that we can get out of our current development environment and our developer is no longer with us.

    I have the Network Download example code in a separate .cpp file versus my main file to keep things clean. It downloads, locally, 3 csv files from our secure ftp - these csv files are updated periodically and the app needs to reflect those changes. What I want to do is take the information from those csv files and put the data an Sqlite database so that it can be queried, etc. This is how we have had our app set up for the last few years so maybe in Qt there is an easier way to handle this?

    I currently have this, which creates the local database and the 3 tables:

    Qt Code:
    1. QString dbName( "mydatabase.db" );
    2. QFile::remove( dbName ); // delete sqlite file if it exists from a previous run
    3. QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" );
    4. db.setDatabaseName( dbName );
    5. db.open();
    6.  
    7. //Create Tables
    8.  
    9. QSqlQuery query;
    10. query.prepare("CREATE TABLE IF NOT EXISTS misin_species_list (cname VARCHAR, family VARCHAR, fdetail VARCHAR, genus VARCHAR, id VARCHAR, kingdom VARCHAR, species VARCHAR, habit VARCHAR)");
    11. if(!query.exec()){
    12. qDebug()<<"error:" << query.lastError().text();
    13. }
    14.  
    15. QSqlQuery queryanimals;
    16. queryanimals.prepare("CREATE TABLE IF NOT EXISTS misin_factsheet_animals (cname VARCHAR, description VARCHAR, edrr VARCHAR, family VARCHAR, fdetail VARCHAR, genus VARCHAR, habitat VARCHAR, hdetail VARCHAR, id VARCHAR, damage VARCHAR, reproduction VARCHAR, similar VARCHAR, source VARCHAR, species VARCHAR)");
    17. if(!queryanimals.exec()){
    18. qDebug()<<"error:" << queryanimals.lastError().text();
    19. }
    20.  
    21. QSqlQuery queryplants;
    22. queryplants.prepare("CREATE TABLE IF NOT EXISTS misin_factsheet_plants(cname VARCHAR, description VARCHAR, duration VARCHAR, edrr VARCHAR, family VARCHAR,fdetail VARCHAR, flowers VARCHAR, fruitseeds VARCHAR, genus VARCHAR, habit VARCHAR, habitat VARCHAR, hdetail VARCHAR, id VARCHAR, impact VARCHAR, kingdom VARCHAR, leaves VARCHAR, pcode VARCHAR, reproduction VARCHAR, similar VARCHAR, source VARCHAR, species VARCHAR, stems VARCHAR, tmodule VARCHAR)");
    23. if(!queryplants.exec()){
    24. qDebug()<<"error:" << queryplants.lastError().text();
    25. }
    To copy to clipboard, switch view to plain text mode 

    I guess what I am wondering is if the steps above, along with the additional code required to insert the data into the database, should be incorporated into the network download .cpp versus in my main.cpp like it is now (separate from the network download code. I pretty much just need some clarification as to how to go about reading the csv files and importing them into the local sqlite tables.
    Last edited by luckachi; 17th September 2020 at 18:40.

Similar Threads

  1. Replies: 7
    Last Post: 27th March 2015, 15:43
  2. Accessing sql local storage from C++?
    By Koying in forum Qt Quick
    Replies: 1
    Last Post: 27th February 2014, 20:49
  3. Replies: 3
    Last Post: 26th February 2014, 04:56
  4. Importing a sqlite database into another...
    By mtnbiker66 in forum Qt Programming
    Replies: 0
    Last Post: 26th April 2012, 22:00
  5. QStandardItemModel to sqlite database table
    By sattu in forum Qt Programming
    Replies: 19
    Last Post: 10th March 2011, 23:01

Tags for this Thread

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.