From af19cbb098d6c8c1bea311b628ccb5f1ce897828 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 24 Nov 2010 20:14:54 +0100 Subject: Store last active time. --- pg.pgc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'pg.pgc') diff --git a/pg.pgc b/pg.pgc index f9ebaac..ff9c182 100644 --- a/pg.pgc +++ b/pg.pgc @@ -53,6 +53,7 @@ int pg_init() { channel_id integer, path varchar, lastpos integer default 0, + lasttime integer, PRIMARY KEY (id), FOREIGN KEY (channel_id) REFERENCES channel (id) ); @@ -157,14 +158,15 @@ int pg_channel_get(struct channel_t *channel) { return id; } -long pg_channel_file_get(int channel_id, struct channel_file_t *file) { +void pg_channel_file_get(int channel_id, struct channel_file_t *file, long *pos, time_t *time) { EXEC SQL BEGIN DECLARE SECTION; int id = channel_id; const char *path = file->path; long lastpos = 0; + int lasttime = 0; EXEC SQL END DECLARE SECTION; - EXEC SQL SELECT lastpos INTO :lastpos FROM channel_file WHERE channel_id = :id AND path = :path; + EXEC SQL SELECT lastpos, lasttime INTO :lastpos, :lasttime FROM channel_file WHERE channel_id = :id AND path = :path; int do_insert = iserror() && testerror("02000"); if(iserror() && !do_insert) { @@ -178,19 +180,21 @@ long pg_channel_file_get(int channel_id, struct channel_file_t *file) { EXEC SQL INSERT INTO channel_file (channel_id, path) VALUES (:id, :path); if(iserror()) sqlprint(); EXEC SQL COMMIT; + } else { + *pos = lastpos; + *time = lasttime; } - - return lastpos; } -void pg_channel_file_set(int channel_id, struct channel_file_t *file, long pos) { +void pg_channel_file_set(int channel_id, struct channel_file_t *file, long pos, time_t time) { EXEC SQL BEGIN DECLARE SECTION; int id = channel_id; const char *path = file->path; long lastpos = pos; + int lasttime = time; EXEC SQL END DECLARE SECTION; - EXEC SQL UPDATE channel_file SET lastpos = :lastpos WHERE channel_id = :id AND path = :path; + EXEC SQL UPDATE channel_file SET lastpos = :lastpos, lasttime = :lasttime WHERE channel_id = :id AND path = :path; EXEC SQL COMMIT; } -- cgit v1.2.3