From 4633d18db3aae81a05d2c93b00aaf66df046cb8b Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Fri, 7 Mar 2008 19:38:43 +0000 Subject: [PATCH] Calculate index for automatically incremented preset attributes by searching all old messages for the highest used index SVN revision: 2073 --- src/elogd.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/elogd.c b/src/elogd.c index 01d5c931..c9830dfb 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -8620,14 +8620,22 @@ auto-increment tags */ return; } - el_retrieve(lbs, message_id, NULL, attr_list, attrib, lbs->n_attr, NULL, 0, NULL, NULL, att, NULL, NULL); + /* search all entries to find largest index */ + old_index = 0; + do { + el_retrieve(lbs, message_id, NULL, attr_list, attrib, lbs->n_attr, NULL, 0, NULL, NULL, att, NULL, NULL); - /* if date part changed, start over with inded */ - if (strncmp(attrib[index], retstr, loc) != 0) - old_index = 0; - else - /* retrieve old index */ - old_index = atoi(attrib[index] + loc); + /* if date part changed, start over with index */ + if (strncmp(attrib[index], retstr, loc) != 0) + old_index = 0; + else + /* retrieve old index */ + if (atoi(attrib[index] + loc) > old_index) + old_index = atoi(attrib[index] + loc); + + message_id = el_search_message(lbs, EL_PREV, message_id, FALSE); + + } while (message_id); /* increment index */ sprintf(retstr + loc, "%0*d", len, old_index + 1);