Import ezmlm-idx 0.40
[ezmlm] / sub_mysql / logmsg.c
CommitLineData
f8beb284
MW
1/*$Id: logmsg.c,v 1.10 1999/11/10 04:08:27 lindberg Exp $*/
2/*$Name: ezmlm-idx-040 $*/
3#include "stralloc.h"
4#include "fmt.h"
5#include "subscribe.h"
6#include "errtxt.h"
7#include <mysql.h>
8#include <mysqld_error.h>
9
10static stralloc logline = {0};
11static char strnum[FMT_ULONG];
12
13char *logmsg(dir,num,listno,subs,done)
14/* creates an entry for message num and the list listno and code "done". */
15/* Returns NULL on success, "" if dir/sql was not found, and the error */
16/* string on error. NOTE: This routine does nothing for non-sql lists! */
17char *dir;
18unsigned long num;
19unsigned long listno;
20unsigned long subs;
21int done;
22{
23 char *table = (char *) 0;
24 char *ret;
25
26 if ((ret = opensql(dir,&table))) {
27 if (*ret)
28 return ret;
29 else
30 return (char *) 0; /* no SQL => success */
31 }
32 if (!stralloc_copys(&logline,"INSERT INTO ")) return ERR_NOMEM;
33 if (!stralloc_cats(&logline,table)) return ERR_NOMEM;
34 if (!stralloc_cats(&logline,"_mlog (msgnum,listno,subs,done) VALUES ("))
35 return ERR_NOMEM;
36 if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,num))) return ERR_NOMEM;
37 if (!stralloc_cats(&logline,",")) return ERR_NOMEM;
38 if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,listno)))
39 return ERR_NOMEM;
40 if (!stralloc_cats(&logline,",")) return ERR_NOMEM;
41 if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,subs))) return ERR_NOMEM;
42 if (!stralloc_cats(&logline,",")) return ERR_NOMEM;
43 if (done < 0) {
44 done = - done;
45 if (!stralloc_append(&logline,"-")) return ERR_NOMEM;
46 }
47 if (!stralloc_catb(&logline,strnum,fmt_uint(strnum,done))) return ERR_NOMEM;
48 if (!stralloc_append(&logline,")")) return ERR_NOMEM;
49
50 if (mysql_real_query((MYSQL *) psql,logline.s,logline.len)) /* log query */
51 if (mysql_errno((MYSQL *) psql) != ER_DUP_ENTRY) /* ignore dups */
52 return mysql_error((MYSQL *) psql);
53 return (char *) 0;
54}