Changeset 72cd3af for src/sql/sqlengine.cpp
- Timestamp:
- 01/21/10 13:54:58 (13 years ago)
- Branches:
- master, qt5
- Children:
- 606c155
- Parents:
- e662750
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sql/sqlengine.cpp
re662750 r72cd3af 8 8 #include <QDir> 9 9 #include "sqlengine.h" 10 #include <track.h> 10 11 11 12 #include <QDebug> … … 89 90 if (db.isValid() && db.isOpen()) 90 91 { 91 // track has to be handled as the first, since it is necessary to get 92 // track ID from the TRACK table, or to create new TRACK record 93 // and get the ID from newly created record 94 QString queryExist = QString("SELECT id FROM track WHERE name='%1'").arg(aEvent["track"]); 95 QSqlQuery resultExist(queryExist,db); 96 // now we have to check whether TRACK record with 'name' exists or not, 97 // - if it doesn't exist yet, then we have to add that record to 'TRACK' table 98 // - if it exists, then we need to get its 'id' 99 int actId = -1; 100 if(resultExist.next()) // TRACK record with 'name' already exists: we need to get its 'id' 92 //insert event track to table 93 QString name = aEvent["track"]; 94 Track track; 95 int trackId; 96 try 101 97 { 102 actId = resultExist.value(0).toInt(); 98 track = Track::retrieveByName(name); 99 trackId = track.id(); 100 /*qDebug() << QString("DEBUG: Track %1 in DB").arg(name);*/ 103 101 } 104 else // TRACK record doesn't exist yet, need to create it 105 { 106 QString values = QString("'%1'").arg(aEvent["track"]); 107 QString query = QString("INSERT INTO track (name) VALUES (%1)").arg(values); 108 QSqlQuery result (query, db); 109 actId = result.lastInsertId().toInt(); // 'id' is assigned automatically 102 catch (OrmNoObjectException &e) { 103 track.setName(name); 104 trackId = track.insert(); 105 /*qDebug() << QString("DEBUG: Track %1 added to DB").arg(name);*/ 110 106 } 111 112 107 // The items of the Event are divided into the two tables EVENT and VIRTUAL_EVENT 113 108 // VIRTUAL_EVENT is for Full-Text-Serach Support … … 118 113 .arg(QString::number(startDateTime.toTime_t())) \ 119 114 .arg(-QTime::fromString(aEvent["duration"],TIME_FORMAT).secsTo(QTime(0,0))) \ 120 .arg( QString::number(actId)) \115 .arg(trackId) \ 121 116 .arg(aEvent["type"]) \ 122 117 .arg(aEvent["language"]) \ … … 236 231 query.exec("CREATE TABLE TRACK ( \ 237 232 id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , \ 238 name VARCHAR NOT NULL )");233 name VARCHAR UNIQUE NOT NULL )"); 239 234 240 235 query.exec("CREATE TABLE ROOM ( \
Note: See TracChangeset
for help on using the changeset viewer.