diff options
-rw-r--r-- | parsing.c | 7 | ||||
-rw-r--r-- | pg.h | 6 | ||||
-rw-r--r-- | pg.pgc | 16 |
3 files changed, 19 insertions, 10 deletions
@@ -370,15 +370,18 @@ void process() { } else printf("\tParsing %s\n", file->path); - long pos = pg_channel_file_get(channel_id, file); + long pos; + time_t time; + pg_channel_file_get(channel_id, file, &pos, &time); fseek(f, pos, SEEK_SET); + localtime_r(&time, &now_global); last_user = NULL; in_monolog = monolog_len = 0; process_file(f, channel, rs); - pg_channel_file_set(channel_id, file, ftell(f)); + pg_channel_file_set(channel_id, file, ftell(f), mktime(&now_global)); fclose(f); file = file->next; @@ -1,6 +1,8 @@ #ifndef PG_H #define PG_H +#include <time.h> + #include "channel.h" #include "user.h" #include "word.h" @@ -11,8 +13,8 @@ int pg_init(); int pg_upgrade(); void pg_dropall(); int pg_channel_get(struct channel_t *channel); -long pg_channel_file_get(int channel_id, struct channel_file_t *file); -void pg_channel_file_set(int channel_id, struct channel_file_t *file, long pos); +void pg_channel_file_get(int channel_id, struct channel_file_t *file, long *pos, time_t *time); +void pg_channel_file_set(int channel_id, struct channel_file_t *file, long pos, time_t time); void pg_user_set(int channel_id, struct user_t *user); void pg_users_get(int channel_id); void pg_word_set(int channel, struct word_t *word); @@ -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; } |