2 * Copyright (C) 2011, BMW AG
6 * \file DataBaseHandler.cpp
9 * \author Christian Müller (christian.ei.mueller@bmw.de)
12 * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13 * Copyright (C) 2011, BMW AG – Christian Müller Christian.ei.mueller@bmw.de
15 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
17 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
18 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
20 * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
21 * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
26 #include "DataBaseHandler.h"
28 DataBaseHandler::DataBaseHandler() {
31 QString path = (QDir::home().path());
33 path.append(QDir::separator()).append(AUDIO_DATABASE);
34 path = QDir::toNativeSeparators(path);
37 if (db_file.exists()) {
40 if (!this->open_database()) {
41 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Problems with opening the database"));
45 DataBaseHandler::~DataBaseHandler() {
46 this->close_database();
49 bool DataBaseHandler::open_database() {
50 m_database = QSqlDatabase::addDatabase("QSQLITE");
51 QString path = (QDir::home().path());
53 path.append(QDir::separator()).append(AUDIO_DATABASE);
54 path = QDir::toNativeSeparators(path);
55 m_database.setDatabaseName(path);
56 return m_database.open();
59 void DataBaseHandler::close_database() {
60 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Closed Database"));
64 bool DataBaseHandler::delete_data(QString table) {
66 QString comand = "DELETE FROM " + table;
67 return query.exec(comand);
70 bool DataBaseHandler::create_tables() {
75 "CREATE TABLE " + QString(DOMAIN_TABLE)
76 + " (ID INTEGER NOT NULL, DomainName VARCHAR(50), BusName VARCHAR(50), NodeName VARCHAR(50), EarlyMode BOOL, PRIMARY KEY(ID));";
77 if (query.exec(command) != true) {
78 DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Databasehandler: Could not create table"), DLT_STRING(DOMAIN_TABLE));
83 = "CREATE TABLE " + QString(SOURCE_CLASS_TABLE)
84 + " (ID INTEGER NOT NULL, ClassName VARCHAR(50), VolumeOffset INTEGER, IsInterrupt BOOL, IsMixed BOOL, PRIMARY KEY(ID));";
85 if (query.exec(command) != true) {
86 DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Databasehandler: Could not create table"), DLT_STRING(SOURCE_CLASS_TABLE));
90 command = "CREATE TABLE " + QString(SINK_CLASS_TABLE)
91 + " (ID INTEGER NOT NULL, ClassName VARCHAR(50), PRIMARY KEY(ID));";
92 if (query.exec(command) != true) {
93 DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Databasehandler: Could not create table"), DLT_STRING(SINK_CLASS_TABLE));
98 = "CREATE TABLE " + QString(SOURCE_TABLE)
99 + " (ID INTEGER NOT NULL, Name VARCHAR(50), Class_ID INTEGER, Domain_ID INTEGER, IsGateway BOOL, PRIMARY KEY(ID), FOREIGN KEY (Domain_ID) REFERENCES "
100 + DOMAIN_TABLE + "(ID), FOREIGN KEY (Class_ID) REFERENCES "
101 + SOURCE_CLASS_TABLE + "(ID));";
102 if (query.exec(command) != true) {
103 DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Databasehandler: Could not create table"), DLT_STRING(SOURCE_TABLE));
108 = "CREATE TABLE " + QString(SINK_TABLE)
109 + " (ID INTEGER NOT NULL, Name VARCHAR(50), Class_ID INTEGER, Domain_ID INTEGER, IsGateway BOOL, PRIMARY KEY(ID), FOREIGN KEY (DOMAIN_ID) REFERENCES "
110 + DOMAIN_TABLE + "(ID), FOREIGN KEY (Class_ID) REFERENCES "
111 + SOURCE_CLASS_TABLE + "(ID));";
112 if (query.exec(command) != true) {
113 DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Databasehandler: Could not create table"), DLT_STRING(SOURCE_CLASS_TABLE));
118 = "CREATE TABLE " + QString(GATEWAY_TABLE)
119 + " (ID INTEGER NOT NULL, Name VARCHAR(50), Sink_ID INTEGER, Source_ID INTEGER, DomainSource_ID INTEGER, DomainSink_ID INTEGER, ControlDomain_ID Integer, IsBlocked BOOL, PRIMARY KEY(ID), FOREIGN KEY (Sink_ID) REFERENCES "
120 + SINK_TABLE + "(ID), FOREIGN KEY (Source_ID) REFERENCES "
122 + "(ID),FOREIGN KEY (DomainSource_ID) REFERENCES "
124 + "(ID),FOREIGN KEY (DomainSink_ID) REFERENCES "
125 + DOMAIN_TABLE + "(ID));";
126 if (query.exec(command) != true) {
127 DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Databasehandler: Could not create table"), DLT_STRING(GATEWAY_TABLE));
132 = "CREATE TABLE " + QString(CONNECTION_TABLE)
133 + " (ID INTEGER NOT NULL, Source_ID INTEGER, Sink_ID INTEGER, PRIMARY KEY(ID));";
134 if (query.exec(command) != true) {
135 DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Databasehandler: Could not create table"), DLT_STRING(CONNECTION_TABLE));
140 = "CREATE TABLE " + QString(INTERRUPT_TABLE)
141 + " (ID INTEGER NOT NULL, Source_ID INTEGER, Sink_ID INTEGER, Connection_ID INTEGER, mixed BOOL, listInterruptedSources INTEGER, PRIMARY KEY(ID));";
142 if (query.exec(command) != true) {
143 DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Databasehandler: Could not create table"), DLT_STRING(INTERRUPT_TABLE));
148 = "CREATE TABLE " + QString(MAIN_TABLE)
149 + " (ID INTEGER NOT NULL, Source_ID INTEGER, Sink_ID INTEGER, route INTEGER, PRIMARY KEY(ID));";
150 if (query.exec(command) != true) {
151 DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Databasehandler: Could not create table"), DLT_STRING(MAIN_TABLE));
159 domain_t DataBaseHandler::insert_into_Domains_table(QString DomainName,
160 QString BusName, QString NodeName, bool EarlyMode) {
162 QString _EarlyMode = "false";
167 QString command = "SELECT BusName,ID FROM " + QString(DOMAIN_TABLE)
168 + " WHERE DomainName=\"" + DomainName + "\";";
170 if (query.exec(command) == true) {
172 if (!query.value(0).toString().isEmpty()) {
173 return query.value(1).toInt();
175 command = "UPDATE " + QString(DOMAIN_TABLE) + "SET Busname="
176 + BusName + " Nodename=" + NodeName + " EarlyMode="
177 + _EarlyMode + " WHERE DomainName=" + DomainName;
180 command = "INSERT INTO " + QString(DOMAIN_TABLE)
181 + " (DomainName, BusName, NodeName, EarlyMode) VALUES (\""
182 + DomainName + "\",\"" + BusName + "\",\"" + NodeName
183 + "\",\"" + _EarlyMode + "\")";
187 if (query.exec(command) != true) {
190 return get_Domain_ID_from_Name(DomainName);
193 sourceClass_t DataBaseHandler::insert_into_Source_Class_table(
194 QString ClassName, volume_t VolumeOffset, bool IsInterrupt,
197 QString _IsInterrupt = "false";
198 QString _IsMixed = "false";
201 _IsInterrupt = "true";
207 QString command = "SELECT ID FROM " + QString(SOURCE_CLASS_TABLE)
208 + " WHERE ClassName=\"" + ClassName + "\";";
210 if (query.exec(command) == true) {
212 return query.value(0).toInt();
216 command = "INSERT INTO " + QString(SOURCE_CLASS_TABLE)
217 + " (ClassName, VolumeOffset, IsInterrupt, IsMixed) VALUES (\""
218 + ClassName + "\"," + QString::number(VolumeOffset) + ",\""
219 + _IsInterrupt + "\",\"" + _IsMixed + "\")";
221 if (query.exec(command) != true) {
224 return query.lastInsertId().toInt();
228 sink_t DataBaseHandler::insert_into_Sink_Class_table(QString ClassName) {
231 QString command = "SELECT ID FROM " + QString(SINK_CLASS_TABLE)
232 + " WHERE ClassName=\"" + ClassName + "\";";
234 if (query.exec(command) == true) {
236 return query.value(0).toInt();
240 command = "INSERT INTO " + QString(SINK_CLASS_TABLE)
241 + " (ClassName) VALUES (\"" + ClassName + "\")";
243 if (query.exec(command) != true) {
246 return query.lastInsertId().toInt();
250 source_t DataBaseHandler::insert_into_Source_table(QString Name,
251 sourceClass_t Class_ID, domain_t Domain_ID, bool IsGateway) {
253 QString _IsGateway = "false";
259 QString command = "SELECT ID FROM " + QString(SOURCE_TABLE)
260 + " WHERE Name=\"" + Name + "\";";
262 if (query.exec(command) == true) {
264 return query.value(0).toInt();
268 command = "INSERT INTO " + QString(SOURCE_TABLE)
269 + " (Name, Class_ID, Domain_ID, IsGateway) VALUES (\"" + Name
270 + "\"," + QString::number(Class_ID) + ",\"" + QString::number(
271 Domain_ID) + "\",\"" + _IsGateway + "\")";
273 if (query.exec(command) != true) {
276 emit signal_numberOfSourcesChanged();
277 return query.lastInsertId().toInt();
281 sink_t DataBaseHandler::insert_into_Sink_table(QString Name,
282 sinkClass_t Class_ID, domain_t Domain_ID, bool IsGateway) {
284 QString _IsGateway = "false";
290 QString command = "SELECT ID FROM " + QString(SINK_TABLE)
291 + " WHERE Name=\"" + Name + "\";";
293 if (query.exec(command) == true) {
295 return query.value(0).toInt();
299 command = "INSERT INTO " + QString(SINK_TABLE)
300 + " (Name, Class_ID, Domain_ID, IsGateway) VALUES (\"" + Name
301 + "\"," + QString::number(Class_ID) + ",\"" + QString::number(
302 Domain_ID) + "\",\"" + _IsGateway + "\")";
304 if (query.exec(command) != true) {
307 emit signal_numberOfSinksChanged();
308 return query.lastInsertId().toInt();
312 gateway_t DataBaseHandler::insert_into_Gatway_table(QString Name,
313 sink_t Sink_ID, source_t Source_ID, domain_t DomainSource_ID,
314 domain_t DomainSink_ID, domain_t ControlDomain_ID) {
316 QString command = "SELECT ID FROM " + QString(GATEWAY_TABLE)
317 + " WHERE Name=\"" + Name + "\";";
319 if (query.exec(command) == true) {
321 return query.value(0).toInt();
326 = "INSERT INTO " + QString(GATEWAY_TABLE)
327 + " (Name, Sink_ID, Source_ID, DomainSource_ID, DomainSink_ID, ControlDomain_ID, IsBlocked) VALUES (\""
328 + Name + "\"," + QString::number(Sink_ID) + ","
329 + QString::number(Source_ID) + "," + QString::number(
330 DomainSource_ID) + "," + QString::number(DomainSink_ID)
331 + "," + QString::number(ControlDomain_ID) + ",\"false\")";
332 if (query.exec(command) != true) {
335 return query.lastInsertId().toInt();
339 genInt_t DataBaseHandler::reserveInterrupt(sink_t Sink_ID, source_t Source_ID) {
342 "INSERT INTO " + QString(INTERRUPT_TABLE) + "(Source_ID, Sink_ID)"
343 " VALUES(:Source_ID, :Sink_ID)");
344 query.bindValue(":Source_ID", Source_ID);
345 query.bindValue(":Sink_ID", Sink_ID);
346 if (query.exec() != true) {
349 return query.lastInsertId().toInt();
353 genError_t DataBaseHandler::updateInterrupt(const genInt_t intID,
354 connection_t connID, bool mixed,
355 QList<source_t> listInterruptedSources) {
357 QString _mixed = "false";
363 //This information is not handy to be stored directly in the database. So we put it on the heap and store the pointer to it.
364 QList<source_t>* pointer = new QList<source_t> (listInterruptedSources);
367 "UPDATE " + QString(INTERRUPT_TABLE)
368 + " SET Connection_ID=:Connection_ID, mixed=:mixed ,listInterruptedSources=:listInterruptedSources WHERE ID=:id");
369 query.bindValue(":Connection_ID", connID);
370 query.bindValue(":mixed", _mixed);
371 query.bindValue(":listInterruptedSources", int(pointer));
372 query.bindValue(":id", intID);
373 if (query.exec() != true) {
374 return GEN_DATABASE_ERROR;
380 genError_t DataBaseHandler::getInterruptDatafromID(const genInt_t intID,
381 connection_t* return_connID, sink_t* return_Sink_ID,
382 source_t* return_Source_ID, bool* return_mixed,
383 QList<source_t>** return_listInterruptedSources) {
387 "SELECT Connection_ID, Sink_ID, Source_ID, mixed, listInterruptedSources FROM "
388 + QString(INTERRUPT_TABLE) + " WHERE ID="
389 + QString::number(intID) + ";";
391 if (query.exec(command) != true) {
392 return GEN_DATABASE_ERROR;
395 *return_connID = query.value(0).toInt();
396 *return_Sink_ID = query.value(1).toInt();
397 *return_Source_ID = query.value(2).toInt();
398 *return_mixed = query.value(3).toBool();
399 *return_listInterruptedSources
400 = reinterpret_cast<QList<source_t>*> (query.value(4).toInt());
408 genError_t DataBaseHandler::removeInterrupt(const genInt_t intID) {
410 QString command = "SELECT listInterruptedSources FROM " + QString(
411 INTERRUPT_TABLE) + " WHERE ID=" + QString::number(intID) + ";";
412 if (query.exec(command) != true) {
413 return GEN_DATABASE_ERROR;
416 delete reinterpret_cast<QList<source_t>*> (query.value(0).toInt());
417 command = "DELETE FROM " + QString(INTERRUPT_TABLE)
418 + " WHERE ID=\"" + QString::number(intID) + "\";";
419 if (query.exec(command) != true) {
420 return GEN_DATABASE_ERROR;
429 domain_t DataBaseHandler::peek_Domain_ID(QString DomainName) {
432 QString command = "SELECT ID FROM " + QString(DOMAIN_TABLE)
433 + " WHERE DomainName=\"" + DomainName + "\";";
436 return query.value(0).toInt();
438 command = "INSERT INTO " + QString(DOMAIN_TABLE)
439 + " (DomainName) VALUES (\"" + DomainName + "\")";
442 if (query.exec(command) != true) {
445 return query.lastInsertId().toInt();
449 domain_t DataBaseHandler::get_Domain_ID_from_Source_ID(source_t Source_ID) {
451 QString command = "SELECT Domain_ID FROM " + QString(SOURCE_TABLE)
452 + " WHERE ID=" + QString::number(Source_ID) + ";";
454 if (query.exec(command) != true) {
458 return query.value(0).toInt();
462 domain_t DataBaseHandler::get_Domain_ID_from_Sink_ID(sink_t Sink_ID) {
464 QString command = "SELECT Domain_ID FROM " + QString(SINK_TABLE)
465 + " WHERE ID=" + QString::number(Sink_ID) + ";";
467 if (query.exec(command) != true) {
471 return query.value(0).toInt();
475 source_t DataBaseHandler::get_Source_ID_from_Name(QString name) {
477 QString command = "SELECT ID FROM " + QString(SOURCE_TABLE)
478 + " WHERE Name=\"" + name + "\";";
480 if (query.exec(command) != true) {
484 return query.value(0).toInt();
491 sourceClass_t DataBaseHandler::get_Source_Class_ID_from_Name(QString name) {
493 QString command = "SELECT ID FROM " + QString(SOURCE_CLASS_TABLE)
494 + " WHERE ClassName=\"" + name + "\";";
495 if (query.exec(command) != true) {
499 return query.value(0).toInt();
506 domain_t DataBaseHandler::get_Domain_ID_from_Name(QString name) {
508 QString command = "SELECT ID FROM " + QString(DOMAIN_TABLE)
509 + " WHERE DomainName=\"" + name + "\";";
511 if (query.exec(command) != true) {
515 return query.value(0).toInt();
522 gateway_t DataBaseHandler::get_Gateway_ID_with_Domain_ID(
523 domain_t startDomain_ID, domain_t targetDomain_ID) {
525 QString command = "SELECT ID FROM " + QString(GATEWAY_TABLE)
526 + " WHERE DomainSource_ID=" + QString::number(startDomain_ID)
527 + " AND DomainSink_ID=" + QString::number(targetDomain_ID) + ";";
529 if (query.exec(command) != true) {
533 return query.value(0).toInt();
540 genError_t DataBaseHandler::get_Gateway_Source_Sink_Domain_ID_from_ID(
541 gateway_t Gateway_ID, source_t* return_Source_ID,
542 sink_t* return_Sink_ID, domain_t* return_ControlDomain_ID) {
544 QString command = "SELECT Source_ID, Sink_ID, ControlDomain_ID FROM "
545 + QString(GATEWAY_TABLE) + " WHERE ID=" + QString::number(
548 if (query.exec(command) != true) {
549 return GEN_DATABASE_ERROR;
552 *return_Source_ID = query.value(0).toInt();
553 *return_Sink_ID = query.value(1).toInt();
554 *return_ControlDomain_ID = query.value(2).toInt();
562 void DataBaseHandler::get_Domain_ID_Tree(bool onlyfree, RoutingTree* Tree,
563 QList<RoutingTreeItem*>* allItems) {
565 int RootID = Tree->returnRootDomainID();
566 RoutingTreeItem *parent = Tree->returnRootItem();
567 QString _onlyfree = "false";
575 "SELECT ID,DomainSource_ID FROM " + QString(GATEWAY_TABLE)
576 + " WHERE DomainSink_ID=:id AND IsBlocked=:flag;");
579 query.bindValue(":id", RootID);
580 query.bindValue(":flag", _onlyfree);
582 while (query.next()) {
584 Tree->insertItem(query.value(1).toInt(),
585 query.value(0).toInt(), parent));
587 parent = allItems->value(i);
588 RootID = parent->returnDomainID();
590 } while (allItems->length() > i);
593 QString DataBaseHandler::get_Bus_from_Domain_ID(domain_t Domain_ID) {
595 QString command = "SELECT BusName FROM " + QString(DOMAIN_TABLE)
596 + " WHERE ID=" + QString::number(Domain_ID) + ";";
598 if (query.exec(command) != true) {
602 return query.value(0).toString();
606 domain_t DataBaseHandler::get_Domain_ID_from_Connection_ID(connection_t ID) {
608 QString command = "SELECT Source_ID FROM " + QString(CONNECTION_TABLE)
609 + " WHERE ID=" + QString::number(ID) + ";";
611 if (query.exec(command) != true) {
615 int SourceID = query.value(0).toInt();
616 command = "SELECT Domain_ID FROM " + QString(SOURCE_TABLE) + " WHERE ID="
617 + QString::number(SourceID) + ";";
618 if (query.exec(command) != true) {
622 return query.value(0).toInt();
626 void DataBaseHandler::getListofSources(QList<SourceType>* SourceList) {
629 QString command = "SELECT ID,NAME FROM " + QString(SOURCE_TABLE)
630 + " WHERE isGateway=\"false\";";
631 if (query.exec(command) != true) {
634 while (query.next()) {
635 sType.ID = query.value(0).toInt();
636 sType.name = query.value(1).toString();
637 SourceList->append(sType);
642 void DataBaseHandler::getListofSinks(QList<SinkType>* SinkList) {
645 QString command = "SELECT ID,NAME FROM " + QString(SINK_TABLE) + ";";
646 if (query.exec(command) != true) {
649 while (query.next()) {
650 sType.ID = query.value(0).toInt();
651 sType.name = query.value(1).toString();
652 SinkList->append(sType);
657 void DataBaseHandler::getListofConnections(
658 QList<ConnectionType>* ConnectionList) {
660 ConnectionType sType;
661 QString command = "SELECT Source_ID,Sink_ID FROM " + QString(
662 CONNECTION_TABLE) + ";";
663 if (query.exec(command) != true) {
666 while (query.next()) {
667 sType.Source_ID = query.value(0).toInt();
668 sType.Sink_ID = query.value(1).toInt();
669 ConnectionList->append(sType);
674 bool DataBaseHandler::is_source_Mixed(source_t source) {
678 QString command = "SELECT Class_ID FROM " + QString(SOURCE_TABLE)
679 + " WHERE ID=\"" + QString::number(source) + "\";";
680 if (query.exec(command) == true) {
682 classID = query.value(0).toInt();
685 command = "SELECT isMixed FROM " + QString(SOURCE_CLASS_TABLE)
686 + " WHERE ID=\"" + QString::number(classID) + "\";";
688 if (query.exec(command) == true) {
690 if (query.value(0).toString().compare("true") == 0) {
698 sink_t DataBaseHandler::get_Sink_ID_from_Name(QString name) {
700 QString command = "SELECT ID FROM " + QString(SINK_TABLE)
701 + " WHERE Name=\"" + name + "\";";
703 if (query.exec(command) != true) {
707 return query.value(0).toInt();
714 connection_t DataBaseHandler::getConnectionID(source_t SourceID, sink_t SinkID) {
717 "SELECT ID FROM " + QString(MAIN_TABLE)
718 + " WHERE Source_ID=:sourceID AND Sink_ID=:sinkID");
719 query.bindValue(":sourceID", SourceID);
720 query.bindValue(":sinkID", SinkID);
721 if (query.exec() != true) {
725 return query.value(0).toInt();
732 connection_t DataBaseHandler::insertConnection(source_t SourceID, sink_t SinkID) {
734 QString command = "INSERT INTO " + QString(CONNECTION_TABLE)
735 + " (Source_ID, Sink_ID) VALUES (" + QString::number(SourceID)
736 + "," + QString::number(SinkID) + ");";
737 if (query.exec(command) != true) {
740 return query.lastInsertId().toInt();
744 genError_t DataBaseHandler::removeConnection(connection_t ConnectionID) {
746 QString command = "DELETE FROM " + QString(CONNECTION_TABLE)
747 + " WHERE ID=\"" + QString::number(ConnectionID) + "\";";
748 if (query.exec(command) != true) {
749 return GEN_DATABASE_ERROR;
755 connection_t DataBaseHandler::reserveMainConnection(source_t source,
758 query.prepare("INSERT INTO " + QString(MAIN_TABLE) + "(Source_ID, Sink_ID)"
759 " VALUES(:Source_ID, :Sink_ID)");
760 query.bindValue(":Source_ID", source);
761 query.bindValue(":Sink_ID", sink);
762 if (query.exec() != true) {
765 return query.lastInsertId().toInt();
769 genError_t DataBaseHandler::updateMainConnection(connection_t connID,
773 //This information is not handy to be stored directly in the database. So we put it on the heap and store the pointer to it.
774 genRoute_t* routeheap = new genRoute_t(route);
777 "UPDATE " + QString(MAIN_TABLE)
778 + " SET route=:route WHERE ID=:connID");
779 query.bindValue(":connID", connID);
780 query.bindValue(":route", int(routeheap));
781 if (query.exec() != true) {
782 return GEN_DATABASE_ERROR;
788 genError_t DataBaseHandler::getMainConnectionDatafromID(
789 const connection_t connID, sink_t* return_sinkID,
790 source_t* return_sourceID, genRoute_t** return_route) {
792 QString command = "SELECT Sink_ID, Source_ID, route FROM " + QString(
793 MAIN_TABLE) + " WHERE ID=" + QString::number(connID) + ";";
795 if (query.exec(command) != true) {
796 return GEN_DATABASE_ERROR;
799 *return_sinkID = query.value(0).toInt();
800 *return_sourceID = query.value(1).toInt();
802 = reinterpret_cast<genRoute_t*> (query.value(2).toInt());
810 connection_t DataBaseHandler::returnMainconnectionIDforSinkSourceID(
811 sink_t sink, source_t source) {
814 "SELECT ID FROM " + QString(MAIN_TABLE)
815 + " WHERE Sink_ID=:sinkID AND Source_ID=:SourceID");
816 query.bindValue(":SinkID", sink);
817 query.bindValue(":SourceID", source);
819 if (query.exec() != true) {
823 return query.value(0).toInt();
829 QList<source_t> DataBaseHandler::getSourceIDsForSinkID(sink_t sink) {
830 QList<source_t> list;
833 "SELECT Source_ID FROM " + QString(MAIN_TABLE)
834 + " WHERE Sink_ID=:sinkID");
835 query.bindValue(":sinkID", sink);
836 if (query.exec() == true) {
837 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("query good"));
838 while (query.next()) {
839 int p = query.value(0).toInt();
840 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("SourceID"), DLT_INT(p));
841 list.append(query.value(0).toInt());
847 QList<ConnectionType> DataBaseHandler::getListAllMainConnections() {
848 QList<ConnectionType> connectionList;
850 QString command = "SELECT Sink_ID, Source_ID FROM " + QString(
853 if (query.exec(command) != true) {
856 while (query.next()) {
858 temp.Sink_ID = query.value(0).toInt();
859 temp.Source_ID = query.value(1).toInt();
860 connectionList.append(temp);
861 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Added Connection"), DLT_INT(temp.Sink_ID),DLT_INT(temp.Source_ID));
864 return connectionList;
867 genError_t DataBaseHandler::removeMainConnection(connection_t connID) {
869 QString command = "SELECT route FROM " + QString(MAIN_TABLE) + " WHERE ID="
870 + QString::number(connID) + ";";
871 if (query.exec(command) != true) {
872 return GEN_DATABASE_ERROR;
875 delete reinterpret_cast<genRoute_t*> (query.value(0).toInt());
876 command = "DELETE FROM " + QString(MAIN_TABLE) + " WHERE ID=\""
877 + QString::number(connID) + "\";";
878 if (query.exec(command) != true) {
879 return GEN_DATABASE_ERROR;