</Query>
<Writer sqlstore>
- Statement "SELECT collectd_insert($1, $2, $3, $4, $5, $6, $7, $8);"
+ Statement "SELECT collectd_insert($1, $2, $3, $4, $5, $6, $7, $8, $9);"
+ StoreRates true
</Writer>
<Database foo>
each submitted value. A single SQL statement is allowed only. Anything after
the first semicolon will be ignored.
-Eight parameters will be passed to the statement and should be specified as
-tokens B<$1>, B<$2>, through B<$8> in the statement string. The following
+Nine parameters will be passed to the statement and should be specified as
+tokens B<$1>, B<$2>, through B<$9> in the statement string. The following
values are made available through those parameters:
=over 4
=item B<$8>
+An array of types for the submitted values (i.E<nbsp>e., the type of the data
+sources of the submitted value-list; C<counter>, C<gauge>, ...). Note, that if
+B<StoreRates> is enabled (which is the default, see below), all types will be
+C<gauge>.
+
+=item B<$9>
+
An array of the submitted values. The dimensions of the value name and value
arrays match.
return string;
} /* values_name_to_sqlarray */
+static char *values_type_to_sqlarray (const data_set_t *ds,
+ char *string, size_t string_len, _Bool store_rates)
+{
+ char *str_ptr;
+ size_t str_len;
+
+ int i;
+
+ str_ptr = string;
+ str_len = string_len;
+
+ for (i = 0; i < ds->ds_num; ++i) {
+ int status;
+
+ if (store_rates)
+ status = ssnprintf(str_ptr, str_len, ",'gauge'");
+ else
+ status = ssnprintf(str_ptr, str_len, ",'%s'",
+ DS_TYPE_TO_STRING (ds->ds[i].type));
+
+ if (status < 1) {
+ str_len = 0;
+ break;
+ }
+ else if ((size_t)status >= str_len) {
+ str_len = 0;
+ break;
+ }
+ else {
+ str_ptr += status;
+ str_len -= (size_t)status;
+ }
+ }
+
+ if (str_len <= 2) {
+ log_err ("c_psql_write: Failed to stringify value types");
+ return NULL;
+ }
+
+ /* overwrite the first comma */
+ string[0] = '{';
+ str_ptr[0] = '}';
+ str_ptr[1] = '\0';
+
+ return string;
+} /* values_type_to_sqlarray */
+
static char *values_to_sqlarray (const data_set_t *ds, const value_list_t *vl,
char *string, size_t string_len, _Bool store_rates)
{
char time_str[32];
char values_name_str[1024];
+ char values_type_str[1024];
char values_str[1024];
- const char *params[8];
+ const char *params[9];
int success = 0;
int i;
writer = db->writers[i];
+ if (values_type_to_sqlarray (ds,
+ values_type_str, sizeof (values_type_str),
+ writer->store_rates) == NULL)
+ return -1;
+
if (values_to_sqlarray (ds, vl,
values_str, sizeof (values_str),
writer->store_rates) == NULL)
return -1;
- params[7] = values_str;
+ params[7] = values_type_str;
+ params[8] = values_str;
res = PQexecParams (db->conn, writer->statement,
STATIC_ARRAY_SIZE (params), NULL,