comparison src/main.cpp @ 109:62e570222f66

Return inserted person ID from addPerson() (or negative value in case of errors.)
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 04 Jul 2017 09:53:38 +0300
parents 8ceaafde9b52
children 7a3e9d4c9b71
comparison
equal deleted inserted replaced
108:bb17f6714fa4 109:62e570222f66
1082 updateModel(); 1082 updateModel();
1083 return 0; 1083 return 0;
1084 } 1084 }
1085 1085
1086 1086
1087 int PersonSQLModel::addPerson(const PersonInfo &info) 1087 qint64 PersonSQLModel::addPerson(const PersonInfo &info)
1088 { 1088 {
1089 // beginInsertRows(QModelIndex(), rowCount(), rowCount()); 1089 // beginInsertRows(QModelIndex(), rowCount(), rowCount());
1090 1090
1091 QSqlQuery np; 1091 QSqlQuery np;
1092 np.prepare("INSERT INTO people (first_name,last_name,extra_info,added,updated) VALUES (?,?,?,?,?)"); 1092 np.prepare("INSERT INTO people (first_name,last_name,extra_info,added,updated) VALUES (?,?,?,?,?)");
1100 if (!slCheckAndReportSQLError("PersonSQLModel::addPerson()", np.lastError())) 1100 if (!slCheckAndReportSQLError("PersonSQLModel::addPerson()", np.lastError()))
1101 return -1; 1101 return -1;
1102 1102
1103 QSqlDatabase::database().commit(); 1103 QSqlDatabase::database().commit();
1104 1104
1105 QVariant idp = np.lastInsertId();
1106
1105 // endInsertRows(); 1107 // endInsertRows();
1106 updateModel(); 1108 updateModel();
1107 return 0; 1109 return idp.isValid() ? idp.toInt() : -2;
1108 } 1110 }
1109 1111
1110 1112
1111 int PersonSQLModel::deletePerson(qint64 id) 1113 int PersonSQLModel::deletePerson(qint64 id)
1112 { 1114 {