X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdbi.c;h=223e159f3f9ab88293a8a7edd4d68df1bc661459;hb=dbeee0cfad69e701ea2665001fd9f2bce49c9489;hp=779c723f91741de5f5db273993a4929a1bcb2a78;hpb=c7c13abc4c3c72b9baf58dfeec059c9c71e815ea;p=collectd.git diff --git a/src/dbi.c b/src/dbi.c index 779c723f..223e159f 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -2,18 +2,23 @@ * collectd - src/dbi.c * Copyright (C) 2008-2013 Florian octo Forster * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; only version 2 of the License is applicable. + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Florian octo Forster @@ -27,6 +32,9 @@ #include +#ifdef HAVE_LIBDBI_R + dbi_inst inst = NULL; +#endif /* * Data types */ @@ -126,7 +134,7 @@ static int cdbi_result_get_field (dbi_result res, /* {{{ */ else if (src_type == DBI_TYPE_STRING) { const char *value; - + value = dbi_result_get_string_idx (res, index); if (value == NULL) sstrncpy (buffer, "", buffer_size); @@ -192,7 +200,7 @@ static void cdbi_database_free (cdbi_database_t *db) /* {{{ */ * * ... * - * + * * * Driver "mysql" * DriverOption "hostname" "localhost" @@ -446,7 +454,11 @@ static int cdbi_init (void) /* {{{ */ return (-1); } +#ifdef HAVE_LIBDBI_R + status = dbi_initialize_r (NULL, &inst); +#else status = dbi_initialize (NULL); +#endif if (status < 0) { ERROR ("dbi plugin: cdbi_init: dbi_initialize failed with status %i.", @@ -667,16 +679,26 @@ static int cdbi_connect_database (cdbi_database_t *db) /* {{{ */ db->connection = NULL; } +#ifdef HAVE_LIBDBI_R + driver = dbi_driver_open_r (db->driver, inst); +#else driver = dbi_driver_open (db->driver); +#endif if (driver == NULL) { ERROR ("dbi plugin: cdbi_connect_database: dbi_driver_open (%s) failed.", db->driver); INFO ("dbi plugin: Maybe the driver isn't installed? " "Known drivers are:"); +#ifdef HAVE_LIBDBI_R + for (driver = dbi_driver_list_r (NULL, inst); + driver != NULL; + driver = dbi_driver_list_r (driver, inst)) +#else for (driver = dbi_driver_list (NULL); driver != NULL; driver = dbi_driver_list (driver)) +#endif { INFO ("dbi plugin: * %s", dbi_driver_get_name (driver)); }