| 233 | } |
| 234 | |
| 235 | std::vector<MessageEntity> SQLiteQueryExecutor::fetchMessages( |
| 236 | std::string threadID, |
| 237 | int limit, |
| 238 | int offset) const { |
| 239 | static std::string query = |
| 240 | "SELECT " |
| 241 | " m.id, m.local_id, m.thread, m.user, m.type, m.future_type, " |
| 242 | " m.content, m.time, media.id, media.container, media.thread, " |
| 243 | " media.uri, media.type, media.extras " |
| 244 | "FROM messages AS m " |
| 245 | "LEFT JOIN media " |
| 246 | " ON m.id = media.container " |
| 247 | "WHERE m.thread = :thread " |
| 248 | "UNION " |
| 249 | "SELECT " |
| 250 | " m.id, m.local_id, m.thread, m.user, m.type, m.future_type, " |
| 251 | " m.content, m.time, backup_media.id, backup_media.container, " |
| 252 | " backup_media.thread, backup_media.uri, backup_media.type, " |
| 253 | " backup_media.extras " |
| 254 | "FROM backup_messages AS m " |
| 255 | "LEFT JOIN backup_media " |
| 256 | " ON m.id = backup_media.container " |
| 257 | "WHERE m.thread = :thread " |
| 258 | "ORDER BY m.time DESC, m.id DESC " |
| 259 | "LIMIT :limit OFFSET :offset;"; |
| 260 | SQLiteStatementWrapper preparedSQL( |
| 261 | this->getConnection(), query, "Failed to fetch messages."); |
| 262 | |
| 263 | int thread_index = sqlite3_bind_parameter_index(preparedSQL, ":thread"); |
| 264 | bindStringToSQL(threadID.c_str(), preparedSQL, thread_index); |
| 265 | int limit_index = sqlite3_bind_parameter_index(preparedSQL, ":limit"); |
| 266 | bindIntToSQL(limit, preparedSQL, limit_index); |
| 267 | int offset_index = sqlite3_bind_parameter_index(preparedSQL, ":offset"); |
| 268 | bindIntToSQL(offset, preparedSQL, offset_index); |
| 269 | |
| 270 | return this->processMessagesResults(preparedSQL); |
| 271 | } |
| 272 | |
| 273 | std::vector<MessageEntity> SQLiteQueryExecutor::processMessagesResults( |
| 274 | SQLiteStatementWrapper &preparedSQL) const { |
nothing calls this directly
no test coverage detected