void Base::AddTrack(Track& newTrack){ QSqlQuery mainTrackQuery(db);//всвтавка в таблицу треков QString mainQueryString("INSERT INTO Tracks( :title, :path ) \ VALUES( :titleV, :pathV)"); mainTrackQuery.exec(); if(newTrack.path == "") { mainQueryString.remove(":path,"); mainQueryString.remove(":pathV,"); } else { mainQueryString.replace(":pathV", "SELECT id FROM Genres WHERE value = :pathV"); } if(newTrack.title == "") { mainQueryString.remove(":tetle,"); mainQueryString.remove(":tetleV,"); } else { mainQueryString.replace(":titleV", "SELECT id FROM Titles WHERE value = :titleV"); }//вставка значений в строку запроса! mainTrackQuery.prepare(mainQueryString); mainTrackQuery.bindValue(":path", "pathId"); mainTrackQuery.bindValue(":pathV", newTrack.path); mainTrackQuery.bindValue(":title", "titleId"); mainTrackQuery.bindValue(":titleV", newTrack.title); cout <<mainTrackQuery.exec()<<endl; cout <<"MEGATRACK_"<< mainTrackQuery.lastError().text().toStdString()<<endl; cout << mainTrackQuery.executedQuery().toStdString()<<endl;}
INSERT INTO Tracks(, ?, ? ) VALUES( SELECT id FROM Titles WHERE value = ?, SELECT id FROM Paths WHERE value = ?)
C++ (Qt)Tracks( :title, :path )VALUES( :titleV, :pathV)
C++ (Qt)mainQueryString.remove(":path,");mainQueryString.remove(":pathV,");
... VALUES( SELECT id FROM Titles WHERE value = ?, SELECT id FROM Paths WHERE value = ?)