diff options
| author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-11-24 20:14:54 +0100 | 
|---|---|---|
| committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-11-24 20:14:54 +0100 | 
| commit | af19cbb098d6c8c1bea311b628ccb5f1ce897828 (patch) | |
| tree | fc71001f4c1cc6aea623a04580c32785e3e9d916 /pg.pgc | |
| parent | 58c8a81222b9f4ad96255f94d2173dd17112d804 (diff) | |
Store last active time.
Diffstat (limited to 'pg.pgc')
| -rw-r--r-- | pg.pgc | 16 | 
1 files changed, 10 insertions, 6 deletions
| @@ -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;  } | 
