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 **/ 26 27 #ifndef UTILS_DB_QUERY_H 28 #define UTILS_DB_QUERY_H 1 29 30 /* 31 * Data types 32 */ 33 struct udb_query_s; 34 typedef struct udb_query_s udb_query_t; 35 36 struct udb_query_preparation_area_s; 37 typedef struct udb_query_preparation_area_s udb_query_preparation_area_t; 38 39 typedef int (*udb_query_create_callback_t)(udb_query_t *q, oconfig_item_t *ci); 40 41 /* 42 * Public functions 43 */ 44 int udb_query_create(udb_query_t ***ret_query_list, size_t *ret_query_list_len, 45 oconfig_item_t *ci, udb_query_create_callback_t cb); 46 void udb_query_free(udb_query_t **query_list, size_t query_list_len); 47 48 int udb_query_pick_from_list_by_name(const char *name, udb_query_t **src_list, 49 size_t src_list_len, 50 udb_query_t ***dst_list, 51 size_t *dst_list_len); 52 int udb_query_pick_from_list(oconfig_item_t *ci, udb_query_t **src_list, 53 size_t src_list_len, udb_query_t ***dst_list, 54 size_t *dst_list_len); 55 56 const char *udb_query_get_name(udb_query_t *q); 57 const char *udb_query_get_statement(udb_query_t *q); 58 59 void udb_query_set_user_data(udb_query_t *q, void *user_data); 60 void *udb_query_get_user_data(udb_query_t *q); 61 62 /* 63 * udb_query_check_version 64 * 65 * Returns 0 if the query is NOT suitable for `version' and >0 if the 66 * query IS suitable. 67 */ 68 int udb_query_check_version(udb_query_t *q, unsigned int version); 69 70 int udb_query_prepare_result(udb_query_t const *q, 71 udb_query_preparation_area_t *prep_area, 72 const char *host, const char *plugin, 73 const char *db_name, char **column_names, 74 size_t column_num); 75 int udb_query_handle_result(udb_query_t const *q, 76 udb_query_preparation_area_t *prep_area, 77 char **column_values); 78 void udb_query_finish_result(udb_query_t const *q, 79 udb_query_preparation_area_t *prep_area); 80 81 udb_query_preparation_area_t * 82 udb_query_allocate_preparation_area(udb_query_t *q); 83 void udb_query_delete_preparation_area(udb_query_preparation_area_t *q_area); 84 85 #endif /* UTILS_DB_QUERY_H */ 86