1 /**
2 * collectd - src/utils_db_query.h
3 * Copyright (C) 2008,2009 Florian octo Forster
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Florian octo Forster <octo at collectd.org>
25 **/
27 #ifndef UTILS_DB_QUERY_H
28 #define UTILS_DB_QUERY_H 1
30 /*
31 * Data types
32 */
33 struct udb_query_s;
34 typedef struct udb_query_s udb_query_t;
36 struct udb_query_preparation_area_s;
37 typedef struct udb_query_preparation_area_s udb_query_preparation_area_t;
39 typedef int (*udb_query_create_callback_t) (udb_query_t *q,
40 oconfig_item_t *ci);
42 /*
43 * Public functions
44 */
45 int udb_query_create (udb_query_t ***ret_query_list,
46 size_t *ret_query_list_len, oconfig_item_t *ci,
47 udb_query_create_callback_t cb);
48 void udb_query_free (udb_query_t **query_list, size_t query_list_len);
50 int udb_query_pick_from_list_by_name (const char *name,
51 udb_query_t **src_list, size_t src_list_len,
52 udb_query_t ***dst_list, size_t *dst_list_len);
53 int udb_query_pick_from_list (oconfig_item_t *ci,
54 udb_query_t **src_list, size_t src_list_len,
55 udb_query_t ***dst_list, size_t *dst_list_len);
57 const char *udb_query_get_name (udb_query_t *q);
58 const char *udb_query_get_statement (udb_query_t *q);
60 void udb_query_set_user_data (udb_query_t *q, void *user_data);
61 void *udb_query_get_user_data (udb_query_t *q);
63 /*
64 * udb_query_check_version
65 *
66 * Returns 0 if the query is NOT suitable for `version' and >0 if the
67 * query IS suitable.
68 */
69 int udb_query_check_version (udb_query_t *q, unsigned int version);
71 int udb_query_prepare_result (udb_query_t const *q,
72 udb_query_preparation_area_t *prep_area,
73 const char *host, const char *plugin, const char *db_name,
74 char **column_names, size_t column_num, cdtime_t interval);
75 int udb_query_handle_result (udb_query_t const *q,
76 udb_query_preparation_area_t *prep_area, char **column_values);
77 void udb_query_finish_result (udb_query_t const *q,
78 udb_query_preparation_area_t *prep_area);
80 udb_query_preparation_area_t *
81 udb_query_allocate_preparation_area (udb_query_t *q);
82 void
83 udb_query_delete_preparation_area (udb_query_preparation_area_t *q_area);
85 #endif /* UTILS_DB_QUERY_H */
86 /* vim: set sw=2 sts=2 et : */