ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
loginfo.c
Go to the documentation of this file.
1#include "stralloc.h"
2#include "fmt.h"
3#include "subscribe.h"
4#include "errtxt.h"
5#include <mysql.h>
6#include <mysqld_error.h>
7
8#define WHO "loginfo"
9
14
15extern MYSQL *mysql;
16
17static stralloc logline = {0};
18static char strnum[FMT_ULONG];
19
30
31const char *loginfo(const char *dir,unsigned long num,unsigned long listno,unsigned long subs,int done)
32{
33 const char *table = (char *) 0;
34 const char *ret;
35
36 if ((ret = opensql(dir,&table))) {
37 if (*ret)
38 return ret;
39 else
40 return (char *) 0; /* no SQL => success */
41 }
42
43 if (!stralloc_copys(&logline,"INSERT INTO ")) return ERR_NOMEM;
44 if (!stralloc_cats(&logline,table)) return ERR_NOMEM;
45 if (!stralloc_cats(&logline,"_mlog (msgnum,listno,subs,done) VALUES ("))
46 return ERR_NOMEM;
47 if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,num))) return ERR_NOMEM;
48 if (!stralloc_cats(&logline,",")) return ERR_NOMEM;
49 if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,listno)))
50 return ERR_NOMEM;
51 if (!stralloc_cats(&logline,",")) return ERR_NOMEM;
52 if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,subs))) return ERR_NOMEM;
53 if (!stralloc_cats(&logline,",")) return ERR_NOMEM;
54 if (done < 0) {
55 done = - done;
56 if (!stralloc_append(&logline,"-")) return ERR_NOMEM;
57 }
58 if (!stralloc_catb(&logline,strnum,fmt_uint(strnum,done))) return ERR_NOMEM;
59 if (!stralloc_append(&logline,")")) return ERR_NOMEM;
60
61 if (mysql_real_query(mysql,logline.s,logline.len)) /* log query */
62 if (mysql_errno(mysql) != ER_DUP_ENTRY) /* ignore dups */
63 return mysql_error(mysql);
64
65 return (char *) 0;
66}
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
const char * loginfo(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)
Definition loginfo.c:12
MYSQL * mysql
Definition opensql.c:23