From 13d8c6b35b58325941ab9118d6c24684188ea9eb Mon Sep 17 00:00:00 2001 From: "/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org" Date: Sun, 3 Feb 2008 10:59:16 +0000 Subject: From: Eric leblond This patch adds new SQL schema for MySQL and PGsql. The goal is to improve the one line per entry format. There is no more a big table with all fields because this sort of storage is causing bad performance (databases don't like to have a lot of NULL fields to store). Main changes are : * Add new schema for MySQL and PGsql * Use call to configurable procedure in SQL OUTPUT modules * Arguments of a procedure are given by the list of fields of a selected table --- util/db.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'util') diff --git a/util/db.c b/util/db.c index 65d0f39..1702acc 100644 --- a/util/db.c +++ b/util/db.c @@ -7,6 +7,7 @@ * Portions (C) 2001 Alex Janssen , * (C) 2005 Sven Schuster , * (C) 2005 Jozsef Kadlecsik + * (C) 2008 Eric Leblond * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -65,6 +66,7 @@ static int sql_createstmt(struct ulogd_pluginstance *upi) char *underscore; int i; char *table = table_ce(upi->config_kset).u.string; + char *procedure = procedure_ce(upi->config_kset).u.string; if (mi->stmt) free(mi->stmt); @@ -88,25 +90,8 @@ static int sql_createstmt(struct ulogd_pluginstance *upi) return -ENOMEM; } - if (mi->schema) - sprintf(mi->stmt, "insert into %s.%s (", mi->schema, table); - else - sprintf(mi->stmt, "insert into %s (", table); - mi->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) - continue; - - 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); - } - *(mi->stmt_val - 1) = ')'; + sprintf(mi->stmt, "CALL %s(", procedure); - sprintf(mi->stmt_val, " values ("); mi->stmt_val = mi->stmt + strlen(mi->stmt); ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", mi->stmt); @@ -285,7 +270,7 @@ static int __interp_db(struct ulogd_pluginstance *upi) tmpstr = inet_ntoa(addr); di->driver->escape_string(upi, di->stmt_ins, tmpstr, strlen(tmpstr)); - di->stmt_ins = di->stmt + strlen(di->stmt); + di->stmt_ins = di->stmt + strlen(di->stmt); sprintf(di->stmt_ins, "',"); break; } -- cgit v1.2.3