]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
db: use offset instead of direct pointer.
authorEric Leblond <eric@regit.org>
Tue, 19 Mar 2013 23:03:35 +0000 (00:03 +0100)
committerEric Leblond <eric@regit.org>
Tue, 21 May 2013 17:55:18 +0000 (19:55 +0200)
Use an offset approach to get the start of values printing area. It
is more generic and will be use soon.

include/ulogd/db.h
util/db.c

index a02afb59907bb69b2cb5c50bc5f7a574a95da9ba..82f37b9086570704ea293d3560b8fbf064ee10ed 100644 (file)
@@ -29,7 +29,7 @@ struct db_stmt {
 
 struct db_instance {
        char *stmt; /* buffer for our insert statement */
-       char *stmt_val; /* pointer to the beginning of the "VALUES" part */
+       int stmt_offset; /* offset to the beginning of the "VALUES" part */
        char *schema;
        time_t reconnect;
        int (*interp)(struct ulogd_pluginstance *upi);
index 91834da224cfd5c98dd2167253603a45b17cfec7..14d9481552ad6a8fb360390d77479269e6395d5c 100644 (file)
--- a/util/db.c
+++ b/util/db.c
@@ -66,6 +66,7 @@ static int sql_createstmt(struct ulogd_pluginstance *upi)
        unsigned int i;
        char *table = table_ce(upi->config_kset).u.string;
        char *procedure = procedure_ce(upi->config_kset).u.string;
+       char *stmt_val = NULL;
 
        if (mi->stmt)
                free(mi->stmt);
@@ -106,7 +107,7 @@ static int sql_createstmt(struct ulogd_pluginstance *upi)
                else
                        sprintf(mi->stmt, "%s (", procedure);
 
-               mi->stmt_val = mi->stmt + strlen(mi->stmt);
+               stmt_val = mi->stmt + strlen(mi->stmt);
 
                for (i = 0; i < upi->input.num_keys; i++) {
                        if (upi->input.keys[i].flags & ULOGD_KEYF_INACTIVE)
@@ -115,19 +116,20 @@ static int sql_createstmt(struct ulogd_pluginstance *upi)
                        strncpy(buf, upi->input.keys[i].name, ULOGD_MAX_KEYLEN);        
                        while ((underscore = strchr(buf, '.')))
                                *underscore = '_';
-                       sprintf(mi->stmt_val, "%s,", buf);
-                       mi->stmt_val = mi->stmt + strlen(mi->stmt);
+                       sprintf(stmt_val, "%s,", buf);
+                       stmt_val = mi->stmt + strlen(mi->stmt);
                }
-               *(mi->stmt_val - 1) = ')';
+               *(stmt_val - 1) = ')';
 
-               sprintf(mi->stmt_val, " values (");
+               sprintf(stmt_val, " values (");
        } else if (strncasecmp(procedure,"CALL", strlen("CALL")) == 0) {
                sprintf(mi->stmt, "CALL %s(", procedure);
        } else {
                sprintf(mi->stmt, "SELECT %s(", procedure);
 
        }
-       mi->stmt_val = mi->stmt + strlen(mi->stmt);
+
+       mi->stmt_offset = strlen(mi->stmt);
 
        ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", mi->stmt);
 
@@ -266,7 +268,7 @@ static void __format_query_db(struct ulogd_pluginstance *upi)
 
        unsigned int i;
 
-       char * stmt_ins = di->stmt_val;
+       char *stmt_ins = di->stmt + di->stmt_offset;
 
        for (i = 0; i < upi->input.num_keys; i++) {
                struct ulogd_key *res = upi->input.keys[i].u.source;