Update the database's user record
| 99 | |
| 100 | // Update the database's user record |
| 101 | void UserTable::updateUser(User &user) { |
| 102 | QLOG_TRACE_IN(); |
| 103 | NSqlQuery query(db); |
| 104 | db->lockForWrite(); |
| 105 | query.prepare("delete from UserTable where key != :lastdate and key != :lastnumber;"); |
| 106 | query.bindValue(":lastdate", USER_SYNC_LAST_DATE); |
| 107 | query.bindValue(":lastnumber", USER_SYNC_LAST_NUMBER); |
| 108 | query.exec(); |
| 109 | |
| 110 | if (user.id.isSet()) { |
| 111 | query.prepare("Insert into UserTable (key, data) values (:key, :data);"); |
| 112 | query.bindValue(":key", USER_EVERNOTE_ACCOUNT); |
| 113 | qint32 id = user.id; |
| 114 | query.bindValue(":data", id); |
| 115 | query.exec(); |
| 116 | } |
| 117 | |
| 118 | if (user.email.isSet()) { |
| 119 | QString email = user.email; |
| 120 | query.prepare("Insert into UserTable (key, data) values (:key, :data);"); |
| 121 | query.bindValue(":key", USER_EMAIL); |
| 122 | query.bindValue(":data", email); |
| 123 | query.exec(); |
| 124 | } |
| 125 | |
| 126 | if (user.name.isSet()) { |
| 127 | query.prepare("Insert into UserTable (key, data) values (:key, :data);"); |
| 128 | QString name = user.name; |
| 129 | query.bindValue(":key", USER_NAME); |
| 130 | query.bindValue(":data",name); |
| 131 | query.exec(); |
| 132 | } |
| 133 | |
| 134 | if (user.timezone.isSet()) { |
| 135 | query.prepare("Insert into UserTable (key, data) values (:key, :data);"); |
| 136 | query.bindValue(":key", USER_TIMEZONE); |
| 137 | QString tz = user.timezone; |
| 138 | query.bindValue(":data", tz); |
| 139 | query.exec(); |
| 140 | } |
| 141 | |
| 142 | if (user.privilege.isSet()) { |
| 143 | query.prepare("Insert into UserTable (key, data) values (:key, :data);"); |
| 144 | query.bindValue(":key", USER_PRIVILEGE); |
| 145 | int priv = user.privilege; |
| 146 | query.bindValue(":data", priv); |
| 147 | query.exec(); |
| 148 | } |
| 149 | |
| 150 | if (user.created.isSet()) { |
| 151 | query.prepare("Insert into UserTable (key, data) values (:key, :data);"); |
| 152 | query.bindValue(":key", USER_CREATED); |
| 153 | qlonglong created = user.created; |
| 154 | query.bindValue(":data", created); |
| 155 | query.exec(); |
| 156 | } |
| 157 | |
| 158 | if (user.updated.isSet()) { |
no test coverage detected