-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.cpp
37 lines (34 loc) · 854 Bytes
/
contact.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "contact.h"
Contact::Contact(QString name, QString number)
{
this->name = name;
this->number = number;
}
bool Contact::saveToLocal()
{
QSqlQuery requete;
requete.prepare("INSERT INTO Contacts (number,name) VALUES (:number,:name)");
requete.bindValue(":number",number);
requete.bindValue(":name",name);
bool ok = requete.exec();
if(!ok)
{
qDebug()<< requete.lastError();
}
}
QList<Contact> Contact::getFromDatabase()
{
QList<Contact> contacts = QList<Contact>();
QSqlQuery requete;
bool ok = requete.exec("SELECT name,number FROM Contacts");
if(!ok)
{
qDebug()<< requete.lastError();
return contacts;
}
while(requete.next())
{
contacts.append(Contact(requete.value(0).toString(),requete.value(1).toString()));
}
return contacts;
}