diff options
author | Pierre Chifflier <chifflier@inl.fr> | 2009-01-06 23:31:14 +0100 |
---|---|---|
committer | Eric Leblond <eric@inl.fr> | 2009-01-07 00:12:56 +0100 |
commit | acc52090393384c8e8d1994b32363895d5afb371 (patch) | |
tree | c2bca8408fb93da969f7e569c5945f58636e7078 /util | |
parent | 916becab13907a64a1901d228390cedc79673e7f (diff) |
Allow plain INSERT instead of procedure
If the procedure name specified in configuration is INSERT, than use
a regular insertion instead of a stored procedure.
This should be used when performance is needed, with a flat SQL schema,
to reduce the cost of SQL procedure calls.
Signed-off-by: Pierre Chifflier <chifflier@inl.fr>
Diffstat (limited to 'util')
-rw-r--r-- | util/db.c | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -91,8 +91,33 @@ static int sql_createstmt(struct ulogd_pluginstance *upi) return -ENOMEM; } - sprintf(mi->stmt, "SELECT %s(", procedure); + if (strcasecmp(procedure,"INSERT") == 0) { + char buf[ULOGD_MAX_KEYLEN]; + char *underscore; + + 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_val, " values ("); + } else { + sprintf(mi->stmt, "SELECT %s(", procedure); + } mi->stmt_val = mi->stmt + strlen(mi->stmt); ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", mi->stmt); |