ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
loginfo.c
Go to the documentation of this file.
1/*$Id: logmsg.c 216 2005-01-12 21:39:26Z bruce $*/
2#include "stralloc.h"
3#include "fmt.h"
4#include "subscribe.h"
5#include "errtxt.h"
6#include <unistd.h>
7#include <libpq-fe.h>
8
14
15extern PGconn *pgsql;
16
17static stralloc logline = {0};
18static char strnum[FMT_ULONG];
19
31
32const char *logmsg(const char *dir,unsigned long num,unsigned long listno,unsigned long subs,int done)
33{
34 const char *table = (char *) 0;
35 const char *ret;
36
37 PGresult *result;
38 PGresult *result2;
39
40 if ((ret = opensql(dir,&table))) {
41 if (*ret)
42 return ret;
43 else
44 return (char *) 0; /* no SQL => success */
45 }
46 if (!stralloc_copys(&logline,"INSERT INTO ")) return ERR_NOMEM;
47 if (!stralloc_cats(&logline,table)) return ERR_NOMEM;
48 if (!stralloc_cats(&logline,"_mlog (msgnum,listno,subs,done) VALUES (")) return ERR_NOMEM;
49 if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,num))) return ERR_NOMEM;
50 if (!stralloc_cats(&logline,",")) return ERR_NOMEM;
51 if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,listno))) return ERR_NOMEM;
52 if (!stralloc_cats(&logline,",")) return ERR_NOMEM;
53 if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,subs))) return ERR_NOMEM;
54 if (!stralloc_cats(&logline,",")) return ERR_NOMEM;
55
56 if (done < 0) {
57 done = - done;
58 if (!stralloc_append(&logline,"-")) return ERR_NOMEM;
59 }
60 if (!stralloc_catb(&logline,strnum,fmt_uint(strnum,done))) return ERR_NOMEM;
61 if (!stralloc_append(&logline,")")) return ERR_NOMEM;
62
63 if (!stralloc_0(&logline)) return ERR_NOMEM;
64 result = PQexec(pgsql,logline.s);
65 if (result==NULL)
66 return (PQerrorMessage(pgsql));
67 if (PQresultStatus(result) != PGRES_COMMAND_OK) { /* Check if duplicate */
68 if (!stralloc_copys(&logline,"SELECT msgnum FROM ")) return ERR_NOMEM;
69 if (!stralloc_cats(&logline,table)) return ERR_NOMEM;
70 if (!stralloc_cats(&logline,"_mlog WHERE msgnum = ")) return ERR_NOMEM;
71 if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,num))) return ERR_NOMEM;
72 if (!stralloc_cats(&logline," AND listno = ")) return ERR_NOMEM;
73 if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,listno))) return ERR_NOMEM;
74 if (!stralloc_cats(&logline," AND done = ")) return ERR_NOMEM;
75 if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,done))) return ERR_NOMEM;
76 if (!stralloc_0(&logline)) return ERR_NOMEM;
77
78 /* Query */
79
80 result2 = PQexec(pgsql,logline.s);
81 if (result2 == NULL)
82 return (PQerrorMessage(pgsql));
83 if (PQresultStatus(result2) != PGRES_TUPLES_OK)
84 return (char *) (PQresultErrorMessage(result2));
85
86 /* No duplicate, return ERROR from first query */
87
88 if (PQntuples(result2)<1)
89 return (char *) (PQresultErrorMessage(result));
90 PQclear(result2);
91 }
92 PQclear(result);
93 return (char *) 0;
94}
Error messages. If you translate these, I would urge you to keep the English version as well....
#define ERR_NOMEM
Definition errtxt.h:14
const char * opensql(const char *dir, const char **table)
Definition opensql.c:13
stralloc listno
Definition ezmlm-get.c:78
stralloc num
char * dir
PGconn * pgsql
Definition opensql.c:22
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)
Definition loginfo.c:32