Merge branch 'collectd-4.5'
[collectd.git] / src / utils_db_query.h
1 /**
2  * collectd - src/utils_db_query.h
3  * Copyright (C) 2008,2009  Florian octo Forster
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  * Authors:
19  *   Florian octo Forster <octo at verplant.org>
20  **/
21
22 #ifndef UTILS_DB_QUERY_H
23 #define UTILS_DB_QUERY_H 1
24
25 #include "configfile.h"
26
27 /*
28  * Data types
29  */
30 struct udb_query_s;
31 typedef struct udb_query_s udb_query_t;
32
33 typedef int (*udb_query_create_callback_t) (udb_query_t *q,
34     oconfig_item_t *ci);
35
36 /* 
37  * Public functions
38  */
39 int udb_query_create (udb_query_t ***ret_query_list,
40     size_t *ret_query_list_len, oconfig_item_t *ci,
41     udb_query_create_callback_t cb, int legacy_mode);
42 void udb_query_free (udb_query_t **query_list, size_t query_list_len);
43
44 int udb_query_pick_from_list_by_name (const char *name,
45     udb_query_t **src_list, size_t src_list_len,
46     udb_query_t ***dst_list, size_t *dst_list_len);
47 int udb_query_pick_from_list (oconfig_item_t *ci,
48     udb_query_t **src_list, size_t src_list_len,
49     udb_query_t ***dst_list, size_t *dst_list_len);
50
51 const char *udb_query_get_name (udb_query_t *q);
52 const char *udb_query_get_statement (udb_query_t *q);
53
54 void  udb_query_set_user_data (udb_query_t *q, void *user_data);
55 void *udb_query_get_user_data (udb_query_t *q);
56
57 /* 
58  * udb_query_check_version
59  *
60  * Returns 0 if the query is NOT suitable for `version' and >0 if the
61  * query IS suitable.
62  */
63 int udb_query_check_version (udb_query_t *q, unsigned int version);
64
65 int udb_query_prepare_result (udb_query_t *q,
66     const char *host, const char *plugin, const char *db_name,
67     char **column_names, size_t column_num);
68 int udb_query_handle_result (udb_query_t *q, char **column_values);
69 void udb_query_finish_result (udb_query_t *q);
70
71 #endif /* UTILS_DB_QUERY_H */
72 /* vim: set sw=2 sts=2 et : */