Seafood/populateDB/main.cpp
changeset 9 23f6727b5587
parent 6 e8f500c881af
equal deleted inserted replaced
8:10275049db7b 9:23f6727b5587
    54 void insertEco(int lastID, QString details)
    54 void insertEco(int lastID, QString details)
    55 {
    55 {
    56 
    56 
    57     QSqlQuery query;
    57     QSqlQuery query;
    58 
    58 
    59     query.prepare("INSERT INTO ecoDetails (lastID, details) VALUES (:lastID,:details) ");
    59     query.prepare("INSERT INTO ecoDetails (fid, details) VALUES (:fid,:details) ");
    60     query.bindValue(":lastID", lastID);
    60     query.bindValue(":fid", lastID);
    61     query.bindValue(":details",details);
    61     query.bindValue(":details",details);
    62     if (!query.exec())
    62     if (!query.exec())
    63     {
    63     {
    64         qDebug() << query.lastError();
    64         qDebug() << query.lastError();
    65         qFatal("Failed to add eco detail.");
    65         qFatal("Failed to add eco detail.");
    84     }
    84     }
    85 
    85 
    86     qDebug() << "DB: database opened " << endl;
    86     qDebug() << "DB: database opened " << endl;
    87 
    87 
    88     createTable("create table fish "
    88     createTable("create table fish "
    89                 "(lastID integer primary key, "
    89                 "(fid integer primary key, "
    90                 "name varchar(32),"
    90                 "name varchar(32),"
    91                 "category int,"
    91                 "category int,"
    92                 "calories int,"
    92                 "calories int,"
    93                 "fat float,"
    93                 "fat float,"
    94                 "protein float,"
    94                 "protein float,"
    95                 "omega3 float,"
    95                 "omega3 float,"
    96                 "cholesterol int,"
    96                 "cholesterol int,"
    97                 "sodium int)");
    97                 "sodium int)");
    98 
    98 
    99     createTable ("create table ecoDetails (eid integer primary key, "
    99     createTable ("create table ecoDetails (eid integer primary key, "
   100                  "lastID integer, "
   100                  "fid integer, "
   101                  "details varchar(128))");
   101                  "details varchar(128))");
   102 
   102 
   103     int lastID = -1;
   103     int lastID = -1;
   104     insertFish("Crab, Dungeness",EBEST,86,0.96,17.4,0.3,59,295);
   104     insertFish("Crab, Dungeness",EBEST,86,0.96,17.4,0.3,59,295);
   105     lastID = getLastInsertRowId();
   105     lastID = getLastInsertRowId();