1 /*$Id: logmsg.c,v 1.10 1999/11/10 04:08:27 lindberg Exp $*/
2 /*$Name: ezmlm-idx-040 $*/
8 #include <mysqld_error.h>
10 static stralloc logline
= {0};
11 static char strnum
[FMT_ULONG
];
13 char *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! */
23 char *table
= (char *) 0;
26 if ((ret
= opensql(dir
,&table
))) {
30 return (char *) 0; /* no SQL => success */
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 ("))
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
)))
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
;
45 if (!stralloc_append(&logline
,"-")) return ERR_NOMEM
;
47 if (!stralloc_catb(&logline
,strnum
,fmt_uint(strnum
,done
))) return ERR_NOMEM
;
48 if (!stralloc_append(&logline
,")")) return ERR_NOMEM
;
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
);