diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-07-05 22:28:51 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-07-05 22:28:51 +0200 |
commit | 4b4b42877fc81ad055f5326185e80530d23361e7 (patch) | |
tree | 5fcda074409854f921ca83f07bda5ae60b62d1d3 /db.c | |
parent | 7c30c3f9c9312500bbb86a98f81ce15982b6907a (diff) |
server: Get history before id
Diffstat (limited to 'db.c')
-rw-r--r-- | db.c | 35 |
1 files changed, 26 insertions, 9 deletions
@@ -304,18 +304,35 @@ void db_create_message(i64 roomid,i64 userid,i64 timestamp,const char *message){ } struct db_message_list db_get_messages(i64 roomid,i64 count){ + return db_get_messages_before(roomid,count,-1); +} + +struct db_message_list db_get_messages_before(i64 roomid,i64 count,i64 beforeid){ assert(count>=0); sqlite3_stmt *stmt; - SQLITE(prepare_v2,database, - "select id, user, time, message " - "from Messages " - "where room = ? " - "order by time desc " - "limit ?" - ,-1,&stmt,NULL); - SQLITE(bind_int64,stmt,1,roomid); - SQLITE(bind_int64,stmt,2,count); + if(beforeid<0){ + SQLITE(prepare_v2,database, + "select id, user, time, message " + "from Messages " + "where room = ? " + "order by time desc " + "limit ?" + ,-1,&stmt,NULL); + SQLITE(bind_int64,stmt,1,roomid); + SQLITE(bind_int64,stmt,2,count); + } else { + SQLITE(prepare_v2,database, + "select id, user, time, message " + "from Messages " + "where room = ? and time < (select time from Messages where id = ?) " + "order by time desc " + "limit ?" + ,-1,&stmt,NULL); + SQLITE(bind_int64,stmt,1,roomid); + SQLITE(bind_int64,stmt,2,beforeid); + SQLITE(bind_int64,stmt,3,count); + } struct db_message_list ml; i64 cap=count; |