diff options
author | /C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org> | 2008-02-03 10:59:16 +0000 |
---|---|---|
committer | /C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org> | 2008-02-03 10:59:16 +0000 |
commit | 13d8c6b35b58325941ab9118d6c24684188ea9eb (patch) | |
tree | 114a87f26eb27a879c1e9f8562cba3c6af843e29 /util/db.c | |
parent | a532e3ec873e74bf3837e3e62ba7208efd1c78db (diff) |
From: Eric leblond <eric@inl.fr>
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
Diffstat (limited to 'util/db.c')
-rw-r--r-- | util/db.c | 23 |
1 files changed, 4 insertions, 19 deletions
@@ -7,6 +7,7 @@ * Portions (C) 2001 Alex Janssen <alex@ynfonatic.de>, * (C) 2005 Sven Schuster <schuster.sven@gmx.de>, * (C) 2005 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> + * (C) 2008 Eric Leblond <eric@inl.fr> * * 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; } |