Skip to content

Commit

Permalink
Longdescription in contributories : database access
Browse files Browse the repository at this point in the history
  • Loading branch information
aroquemaurel committed Mar 9, 2015
1 parent ddaf38b commit 83c802b
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/database/billingdatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ bool BillingDatabase::isBillingPaid(const int pId) {

q.next();

return value(q, "nb_p").toInt() == 1;
return value(q, "nb_b").toInt() == 1;

}

Expand Down
17 changes: 10 additions & 7 deletions src/database/contributorydatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Models::Contributory* ContributoryDatabase::getContributory(QSqlQuery& q) {
contributory->setId(value(q, "idContributory").toInt());
contributory->setNbHours(value(q, "nbHours").toDouble());
contributory->setDescription(value(q, "cdescription").toString());
contributory->setLongDescription(value(q, "clongdescription").toString());

QSqlQuery q2;
q2.prepare("SELECT p.idProject, name, p.description as pdescription, "
Expand Down Expand Up @@ -52,7 +53,7 @@ Models::Contributory* ContributoryDatabase::getContributory(const int idContribu
QSqlQuery q;
Models::Contributory* contributory;

q.prepare("SELECT idContributory, description as cdescription, nbhours "
q.prepare("SELECT idContributory, description as cdescription, longdescription as clongdescription, nbhours "
"FROM Contributory WHERE idContributory = :pId");
q.bindValue(":pId", idContributory);

Expand Down Expand Up @@ -83,6 +84,7 @@ Models::ContributoriesList ContributoryDatabase::getContributoriesByBilling(cons
" project.name as name, project.description as pdescription, "
" project.dailyRate as dailyRate, project.idCustomer, "
" contributory.idContributory, contributory.description as cdescription, "
"contributory.longdescription as clongdescription, "
" billing.idBilling, nbHours "
" FROM BillingProject, project, billing, contributory "
" WHERE billingProject.idBilling = :idBilling "
Expand Down Expand Up @@ -112,14 +114,14 @@ int ContributoryDatabase::addContributory(const Models::Contributory& pContribut
QSqlQuery q;
q.prepare(
"INSERT INTO Contributory "
"(description, nbHours)"
"(description, longdescription, nbHours)"
" VALUES "
"(:description, :nbHours)"
"(:description, :longdescription, :nbHours)"
);

q.bindValue(":description", pContributory.getDescription());
q.bindValue(":nbHours", pContributory.getNbHours());

q.bindValue(":longdescription", pContributory.getLongDescription());
if(!q.exec()) {
throw new DbException(
"Impossible d'ajouter la Contributory",
Expand All @@ -134,12 +136,13 @@ int ContributoryDatabase::addContributory(const Models::Contributory& pContribut
void ContributoryDatabase::updateContributory(const Models::Contributory& pContributory) {
QSqlQuery q;
q.prepare("UPDATE Contributory SET "
"description=:description, "
"nbHours =:nbHours "
"description=:description, longdescription=:longdescription,"
"nbHours=:nbHours "
"WHERE idContributory=:idContributory"
);

q.bindValue(":description", pContributory.getDescription());
q.bindValue(":longdescription", pContributory.getLongDescription());
q.bindValue(":nbHours", pContributory.getNbHours());
q.bindValue(":idContributory",pContributory.getId());

Expand Down Expand Up @@ -193,7 +196,7 @@ Models::ContributoriesList ContributoryDatabase::getContributoriesByBillingAndPr
"SELECT DISTINCT project.idProject as idProject,"
" project.name as name, project.description as pdescription, "
" project.dailyRate as dailyRate, project.idCustomer, "
" contributory.idContributory, contributory.description as cdescription, "
" contributory.idContributory, contributory.description as cdescription, contributory.longdescription as clongdescription, "
" billing.idBilling, nbHours "
" FROM BillingProject, project, billing, contributory "
" WHERE billingProject.idBilling = :idBilling "
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/widgetsmodels/contributoriestablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool ContributoriesTableModel::setData(const QModelIndex &index, const QVariant
_contributories[index.row()].setDescription(value.toString());
break;
case 1:
_contributories[index.row()].setDescription(value.toString());
_contributories[index.row()].setLongDescription(value.toString());
break;
case 2:
_contributories[index.row()].setNbHours(value.toDouble()*r.getNbDailyHours());
Expand Down
1 change: 1 addition & 0 deletions src/sql/createtables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CREATE TABLE Contributory
(
idContributory INTEGER PRIMARY KEY AUTOINCREMENT,
description TEXT,
longdescription TEXT,
nbHours INTEGER
);

Expand Down
163 changes: 81 additions & 82 deletions src/sql/tests/contributories.sql
Original file line number Diff line number Diff line change
@@ -1,82 +1,81 @@
INSERT INTO "Contributory" VALUES(1,'Une descriptoin',42);
INSERT INTO "Contributory" VALUES(2,'Chouette',1);
INSERT INTO "Contributory" VALUES(3,'Salut !',5);
INSERT INTO "Contributory" VALUES(4,'Manger',0);
INSERT INTO "Contributory" VALUES(5,'Salut',10);
INSERT INTO "Contributory" VALUES(6,'Coucou',5);
INSERT INTO "Contributory" VALUES(7,'Nooon',2);
INSERT INTO "Contributory" VALUES(8,'Ouiiii!',5);
INSERT INTO "Contributory" VALUES(9,'Allo',10);
INSERT INTO "Contributory" VALUES(10,'Manger',2);
INSERT INTO "Contributory" VALUES(11,'Trouver',12);
INSERT INTO "Contributory" VALUES(12,'Danser',5);
INSERT INTO "Contributory" VALUES(13,'Checher',5);
INSERT INTO "Contributory" VALUES(14,'Un',0);
INSERT INTO "Contributory" VALUES(15,'Soleil',10);
INSERT INTO "Contributory" VALUES(16,'Deux',14);
INSERT INTO "Contributory" VALUES(17,'Trois',12);
INSERT INTO "Contributory" VALUES(18,'Coucou',7);
INSERT INTO "Contributory" VALUES(19,'Boubou',14);
INSERT INTO "Contributory" VALUES(20,'Babar',14);
INSERT INTO "Contributory" VALUES(21,'eau',2);
INSERT INTO "Contributory" VALUES(22,'feu',4);
INSERT INTO "Contributory" VALUES(23,'terre',3);
INSERT INTO "Contributory" VALUES(24,'Manger',14);
INSERT INTO "Contributory" VALUES(25,'tuy',3);
INSERT INTO "Contributory" VALUES(26,'MACHIN',2);
INSERT INTO "Contributory" VALUES(27,'ouiu',1);
INSERT INTO "Contributory" VALUES(28,'feu',14);
INSERT INTO "Contributory" VALUES(29,'gui',4);
INSERT INTO "Contributory" VALUES(30,'oui',1);
INSERT INTO "Contributory" VALUES(31,'41',14);
INSERT INTO "Contributory" VALUES(32,'Diner',4);
INSERT INTO "Contributory" VALUES(33,'FUmer',4);
INSERT INTO "Contributory" VALUES(34,'Fraise',1);
INSERT INTO "Contributory" VALUES(35,'Des bois',7);
INSERT INTO "Contributory" VALUES(36,'lili',7);
INSERT INTO "Contributory" VALUES(37,'lio',4);
INSERT INTO "Contributory" VALUES(38,'Manger',4);
INSERT INTO "Contributory" VALUES(39,'Puiser',4);
INSERT INTO "Contributory" VALUES(40,'',0);
INSERT INTO "Contributory" VALUES(41,'PAPA',4);
INSERT INTO "Contributory" VALUES(42,'Avaler',2);
INSERT INTO "Contributory" VALUES(43,'Macher',4);
INSERT INTO "Contributory" VALUES(44,'Recracher',1);
INSERT INTO "Contributory" VALUES(45,'Manger',1);
INSERT INTO "Contributory" VALUES(46,'Donut',6);
INSERT INTO "Contributory" VALUES(47,'Lion',14);
INSERT INTO "Contributory" VALUES(48,'No homo',3);
INSERT INTO "Contributory" VALUES(49,'Puits',4);
INSERT INTO "Contributory" VALUES(50,'Pétrole',1);
INSERT INTO "Contributory" VALUES(51,'Meurt',3);
INSERT INTO "Contributory" VALUES(52,'Vit',4);
INSERT INTO "Contributory" VALUES(53,'Maman',4);
INSERT INTO "Contributory" VALUES(54,'Porte une robe',2);

INSERT INTO "Contributory" VALUES(55,'Chouette !',12);
INSERT INTO "Contributory" VALUES(56,'Kamoulox',0);
INSERT INTO "Contributory" VALUES(57,'Salut !',21);
INSERT INTO "Contributory" VALUES(58,'Chouette !',0);
INSERT INTO "Contributory" VALUES(59,'Coucou.',12);
INSERT INTO "Contributory" VALUES(60,'Salut :-)',3);
INSERT INTO "Contributory" VALUES(61,'Chouette la descriptoin',1337);
INSERT INTO "Contributory" VALUES(62,'Youhou !',1);
INSERT INTO "Contributory" VALUES(63,'=)',2);
INSERT INTO "Contributory" VALUES(64,'^_^',2);
INSERT INTO "Contributory" VALUES(65,'Chose machin chose',23);
INSERT INTO "Contributory" VALUES(66,'^qsdlbfj lq sdl jsq jsd',21);
INSERT INTO "Contributory" VALUES(67,'J''aime bien Doctor Who ! ',21);
INSERT INTO "Contributory" VALUES(68,'Coucou la descriptoin de la mort qui tue ',22);
INSERT INTO "Contributory" VALUES(69,'Un bon steak bien saignant !',2);
INSERT INTO "Contributory" VALUES(70,'Découpe de jambon',22);
INSERT INTO "Contributory" VALUES(71,'Ahaha',23);
INSERT INTO "Contributory" VALUES(72,'Coucou.',22);
INSERT INTO "Contributory" VALUES(73,'Ouais, et toi ? ',22);
INSERT INTO "Contributory" VALUES(74,'Tranquillou :)',1);
INSERT INTO "Contributory" VALUES(75,'Salut',1);
INSERT INTO "Contributory" VALUES(76,'Ça va ?',21);
INSERT INTO "Contributory" VALUES(77,'Café-pas-mal-de-la-fac',6);
INSERT INTO "Contributory" VALUES(78,'Café-pas-bon-de-la-fac',1);
INSERT INTO "Contributory" VALUES(79,'Expresso',21);
INSERT INTO "Contributory" VALUES(80,'Ristretto',30);
INSERT INTO "Contributory" VALUES(81,'Café-pas-mal-de-liut',8);
INSERT INTO "Contributory" VALUES(1,'Une descriptoin', 'une description un petit peu longue',42);
INSERT INTO "Contributory" VALUES(2,'Chouette', 'une description un petit peu longue',1);
INSERT INTO "Contributory" VALUES(3,'Salut !', 'une description un petit peu longue',5);
INSERT INTO "Contributory" VALUES(4,'Manger', 'une description un petit peu longue', 0);
INSERT INTO "Contributory" VALUES(5,'Salut', 'une description un petit peu longue',10);
INSERT INTO "Contributory" VALUES(6,'Coucou', 'une description un petit peu longue',5);
INSERT INTO "Contributory" VALUES(7,'Nooon', 'une description un petit peu longue',2);
INSERT INTO "Contributory" VALUES(8,'Ouiiii!', 'une description un petit peu longue',5);
INSERT INTO "Contributory" VALUES(9,'Allo', 'une description un petit peu longue',10);
INSERT INTO "Contributory" VALUES(10,'Manger', 'une description un petit peu longue',2);
INSERT INTO "Contributory" VALUES(11,'Trouver', 'une description un petit peu longue',12);
INSERT INTO "Contributory" VALUES(12,'Danser', 'une description un petit peu longue',5);
INSERT INTO "Contributory" VALUES(13,'Checher', 'une description un petit peu longue',5);
INSERT INTO "Contributory" VALUES(14,'Un', 'une description un petit peu longue',0);
INSERT INTO "Contributory" VALUES(15,'Soleil', 'une description un petit peu longue',10);
INSERT INTO "Contributory" VALUES(16,'Deux', 'une description un petit peu longue',14);
INSERT INTO "Contributory" VALUES(17,'Trois', 'une description un petit peu longue',12);
INSERT INTO "Contributory" VALUES(18,'Coucou', 'une description un petit peu longue',7);
INSERT INTO "Contributory" VALUES(19,'Boubou', 'une description un petit peu longue',14);
INSERT INTO "Contributory" VALUES(20,'Babar', 'une description un petit peu longue',14);
INSERT INTO "Contributory" VALUES(21,'eau', 'une description un petit peu longue',2);
INSERT INTO "Contributory" VALUES(22,'feu', 'une description un petit peu longue',4);
INSERT INTO "Contributory" VALUES(23,'terre', 'une description un petit peu longue',3);
INSERT INTO "Contributory" VALUES(24,'Manger', 'une description un petit peu longue',14);
INSERT INTO "Contributory" VALUES(25,'tuy', 'une description un petit peu longue',3);
INSERT INTO "Contributory" VALUES(26,'MACHIN', 'une description un petit peu longue',2);
INSERT INTO "Contributory" VALUES(27,'ouiu', 'une description un petit peu longue',1);
INSERT INTO "Contributory" VALUES(28,'feu', 'une description un petit peu longue',14);
INSERT INTO "Contributory" VALUES(29,'gui', 'une description un petit peu longue',4);
INSERT INTO "Contributory" VALUES(30,'oui', 'une description un petit peu longue',1);
INSERT INTO "Contributory" VALUES(31,'41', 'une description un petit peu longue',14);
INSERT INTO "Contributory" VALUES(32,'Diner', 'une description un petit peu longue',4);
INSERT INTO "Contributory" VALUES(33,'FUmer', 'une description un petit peu longue',4);
INSERT INTO "Contributory" VALUES(34,'Fraise', 'une description un petit peu longue',1);
INSERT INTO "Contributory" VALUES(35,'Des bois', 'une description un petit peu longue',7);
INSERT INTO "Contributory" VALUES(36,'lili', 'une description un petit peu longue',7);
INSERT INTO "Contributory" VALUES(37,'lio', 'une description un petit peu longue',4);
INSERT INTO "Contributory" VALUES(38,'Manger', 'une description un petit peu longue',4);
INSERT INTO "Contributory" VALUES(39,'Puiser', 'une description un petit peu longue',4);
INSERT INTO "Contributory" VALUES(40,'', 'une description un petit peu longue',0);
INSERT INTO "Contributory" VALUES(41,'PAPA', 'une description un petit peu longue',4);
INSERT INTO "Contributory" VALUES(42,'Avaler', 'une description un petit peu longue',2);
INSERT INTO "Contributory" VALUES(43,'Macher', 'une description un petit peu longue',4);
INSERT INTO "Contributory" VALUES(44,'Recracher', 'une description un petit peu longue',1);
INSERT INTO "Contributory" VALUES(45,'Manger', 'une description un petit peu longue',1);
INSERT INTO "Contributory" VALUES(46,'Donut', 'une description un petit peu longue',6);
INSERT INTO "Contributory" VALUES(47,'Lion', 'une description un petit peu longue',14);
INSERT INTO "Contributory" VALUES(48,'No homo', 'une description un petit peu longue',3);
INSERT INTO "Contributory" VALUES(49,'Puits', 'une description un petit peu longue',4);
INSERT INTO "Contributory" VALUES(50,'Pétrole', 'une description un petit peu longue',1);
INSERT INTO "Contributory" VALUES(51,'Meurt', 'une description un petit peu longue',3);
INSERT INTO "Contributory" VALUES(52,'Vit', 'une description un petit peu longue',4);
INSERT INTO "Contributory" VALUES(53,'Maman', 'une description un petit peu longue',4);
INSERT INTO "Contributory" VALUES(54,'Porte une robe', 'une description un petit peu longue',2);
INSERT INTO "Contributory" VALUES(55,'Chouette !', 'une description un petit peu longue',12);
INSERT INTO "Contributory" VALUES(56,'Kamoulox', 'une description un petit peu longue',0);
INSERT INTO "Contributory" VALUES(57,'Salut !', 'une description un petit peu longue',21);
INSERT INTO "Contributory" VALUES(58,'Chouette !', 'une description un petit peu longue',0);
INSERT INTO "Contributory" VALUES(59,'Coucou.', 'une description un petit peu longue',12);
INSERT INTO "Contributory" VALUES(60,'Salut :-)', 'une description un petit peu longue',3);
INSERT INTO "Contributory" VALUES(61,'Chouette la descriptoin', 'une description un petit peu longue',1337);
INSERT INTO "Contributory" VALUES(62,'Youhou !', 'une description un petit peu longue',1);
INSERT INTO "Contributory" VALUES(63,'=)', 'une description un petit peu longue',2);
INSERT INTO "Contributory" VALUES(64,'^_^', 'une description un petit peu longue',2);
INSERT INTO "Contributory" VALUES(65,'Chose machin chose', 'une description un petit peu longue',23);
INSERT INTO "Contributory" VALUES(66,'^qsdlbfj lq sdl jsq jsd', 'une description un petit peu longue',21);
INSERT INTO "Contributory" VALUES(67,'J''aime bien Doctor Who ! ', 'une description un petit peu longue',21);
INSERT INTO "Contributory" VALUES(68,'Coucou la descriptoin de la mort qui tue ', 'une description un petit peu longue',22);
INSERT INTO "Contributory" VALUES(69,'Un bon steak bien saignant !', 'une description un petit peu longue',2);
INSERT INTO "Contributory" VALUES(70,'Découpe de jambon', 'une description un petit peu longue',22);
INSERT INTO "Contributory" VALUES(71,'Ahaha', 'une description un petit peu longue',23);
INSERT INTO "Contributory" VALUES(72,'Coucou.', 'une description un petit peu longue',22);
INSERT INTO "Contributory" VALUES(73,'Ouais, et toi ? ', 'une description un petit peu longue',22);
INSERT INTO "Contributory" VALUES(74,'Tranquillou :)', 'une description un petit peu longue',1);
INSERT INTO "Contributory" VALUES(75,'Salut', 'une description un petit peu longue',1);
INSERT INTO "Contributory" VALUES(76,'Ça va ?', 'une description un petit peu longue',21);
INSERT INTO "Contributory" VALUES(77,'Café-pas-mal-de-la-fac', 'une description un petit peu longue',6);
INSERT INTO "Contributory" VALUES(78,'Café-pas-bon-de-la-fac', 'une description un petit peu longue',1);
INSERT INTO "Contributory" VALUES(79,'Expresso', 'une description un petit peu longue',21);
INSERT INTO "Contributory" VALUES(80,'Ristretto', 'une description un petit peu longue',30);
INSERT INTO "Contributory" VALUES(81,'Café-pas-mal-de-liut', 'une description un petit peu longue',8);
4 changes: 3 additions & 1 deletion tests/database/contributoriesdatabasetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ void ContributoriesDatabaseTest::update()
c1->setToRemoved(false);
Databases::ContributoryDatabase::instance()->updateContributory(*c1);
Contributory *c2 = Databases::ContributoryDatabase::instance()->getContributory(_lastInsert);
QVERIFY(*c1 == *c2);

bool ret = *c1 == *c2;
QVERIFY(ret);
}

void ContributoriesDatabaseTest::selectContributoryNotFound()
Expand Down
2 changes: 2 additions & 0 deletions tests/models/contributorymodeltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void ContributoryModelTest::commitUpdate()
c1.setDescription("New description");
c1.commit();
c2 = *(Databases::ContributoryDatabase::instance()->getContributory(3));
qDebug() << (c1.getProject() == c2.getProject());

QVERIFY(c1 == c2);
}

Expand Down

0 comments on commit 83c802b

Please sign in to comment.