1 /*$Id: logmsg.c,v 1.3 1999/12/23 02:40:57 lindberg Exp $*/
2 /*$Name: ezmlm-idx-040 $*/
10 static stralloc logline
= {0};
11 static 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;
29 if ((ret
= opensql(dir
,&table
))) {
33 return (char *) 0; /* no SQL => success */
35 if (!stralloc_copys(&logline
,"INSERT INTO ")) return ERR_NOMEM
;
36 if (!stralloc_cats(&logline
,table
)) return ERR_NOMEM
;
37 if (!stralloc_cats(&logline
,"_mlog (msgnum,listno,subs,done) VALUES ("))
39 if (!stralloc_catb(&logline
,strnum
,fmt_ulong(strnum
,num
))) return ERR_NOMEM
;
40 if (!stralloc_cats(&logline
,",")) return ERR_NOMEM
;
41 if (!stralloc_catb(&logline
,strnum
,fmt_ulong(strnum
,listno
)))
43 if (!stralloc_cats(&logline
,",")) return ERR_NOMEM
;
44 if (!stralloc_catb(&logline
,strnum
,fmt_ulong(strnum
,subs
))) return ERR_NOMEM
;
45 if (!stralloc_cats(&logline
,",")) return ERR_NOMEM
;
48 if (!stralloc_append(&logline
,"-")) return ERR_NOMEM
;
50 if (!stralloc_catb(&logline
,strnum
,fmt_uint(strnum
,done
))) return ERR_NOMEM
;
51 if (!stralloc_append(&logline
,")")) return ERR_NOMEM
;
53 if (!stralloc_0(&logline
)) return ERR_NOMEM
;
54 result
= PQexec(psql
,logline
.s
);
56 return (PQerrorMessage(psql
));
57 if(PQresultStatus(result
) != PGRES_COMMAND_OK
) { /* Check if duplicate */
58 if (!stralloc_copys(&logline
,"SELECT msgnum FROM ")) return ERR_NOMEM
;
59 if (!stralloc_cats(&logline
,table
)) return ERR_NOMEM
;
60 if (!stralloc_cats(&logline
,"_mlog WHERE msgnum = ")) return ERR_NOMEM
;
61 if (!stralloc_catb(&logline
,strnum
,fmt_ulong(strnum
,num
)))
63 if (!stralloc_cats(&logline
," AND listno = ")) return ERR_NOMEM
;
64 if (!stralloc_catb(&logline
,strnum
,fmt_ulong(strnum
,listno
)))
66 if (!stralloc_cats(&logline
," AND done = ")) return ERR_NOMEM
;
67 if (!stralloc_catb(&logline
,strnum
,fmt_ulong(strnum
,done
)))
70 if (!stralloc_0(&logline
)) return ERR_NOMEM
;
71 result2
= PQexec(psql
,logline
.s
);
73 return (PQerrorMessage(psql
));
74 if (PQresultStatus(result2
) != PGRES_TUPLES_OK
)
75 return (char *) (PQresultErrorMessage(result2
));
76 /* No duplicate, return ERROR from first query */
77 if (PQntuples(result2
)<1)
78 return (char *) (PQresultErrorMessage(result
));