Code

oracle plugin: Implement the "Host" option.
[collectd.git] / src / oracle.c
1 /**
2  * collectd - src/oracle.c
3  * Copyright (C) 2008,2009  noris network AG
4  * Copyright (C) 2012       Florian octo Forster
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation; only version 2 of the License is applicable.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  *
19  * Linking src/oracle.c ("the oracle plugin") statically or dynamically with
20  * other modules is making a combined work based on the oracle plugin. Thus,
21  * the terms and conditions of the GNU General Public License cover the whole
22  * combination.
23  *
24  * In addition, as a special exception, the copyright holders of the oracle
25  * plugin give you permission to combine the oracle plugin with free software
26  * programs or libraries that are released under the GNU LGPL and with code
27  * included in the standard release of the Oracle® Call Interface (OCI) under
28  * the Oracle® Technology Network (OTN) License (or modified versions of such
29  * code, with unchanged license). You may copy and distribute such a system
30  * following the terms of the GNU GPL for the oracle plugin and the licenses of
31  * the other code concerned.
32  *
33  * Note that people who make modified versions of the oracle plugin are not
34  * obligated to grant this special exception for their modified versions; it is
35  * their choice whether to do so. The GNU General Public License gives
36  * permission to release a modified version without this exception; this
37  * exception also makes it possible to release a modified version which carries
38  * forward this exception. However, without this exception the OTN License does
39  * not allow linking with code licensed under the GNU General Public License.
40  *
41  * Oracle® is a registered trademark of Oracle Corporation and/or its
42  * affiliates. Other names may be trademarks of their respective owners.
43  *
44  * Authors:
45  *   Florian octo Forster <octo at collectd.org>
46  **/
48 #include "collectd.h"
49 #include "common.h"
50 #include "plugin.h"
51 #include "configfile.h"
52 #include "utils_db_query.h"
54 #include <oci.h>
56 /*
57  * Data types
58  */
59 struct o_database_s
60 {
61   char *name;
62   char *host;
63   char *connect_id;
64   char *username;
65   char *password;
67   udb_query_preparation_area_t **q_prep_areas;
68   udb_query_t **queries;
69   size_t        queries_num;
71   OCISvcCtx *oci_service_context;
72 };
73 typedef struct o_database_s o_database_t;
75 /*
76  * Global variables
77  */
78 static udb_query_t  **queries       = NULL;
79 static size_t         queries_num   = 0;
80 static o_database_t **databases     = NULL;
81 static size_t         databases_num = 0;
83 OCIEnv   *oci_env = NULL;
84 OCIError *oci_error = NULL;
86 /*
87  * Functions
88  */
89 static void o_report_error (const char *where, /* {{{ */
90     const char *what, OCIError *eh)
91 {
92   char buffer[2048];
93   sb4 error_code;
94   int status;
95   unsigned int record_number;
97   /* An operation may cause / return multiple errors. Loop until we have
98    * handled all errors available (with a fail-save limit of 16). */
99   for (record_number = 1; record_number <= 16; record_number++)
100   {
101     memset (buffer, 0, sizeof (buffer));
102     error_code = -1;
104     status = OCIErrorGet (eh, (ub4) record_number,
105         /* sqlstate = */ NULL,
106         &error_code,
107         (text *) &buffer[0],
108         (ub4) sizeof (buffer),
109         OCI_HTYPE_ERROR);
110     buffer[sizeof (buffer) - 1] = 0;
112     if (status == OCI_NO_DATA)
113       return;
115     if (status == OCI_SUCCESS)
116     {
117       size_t buffer_length;
119       buffer_length = strlen (buffer);
120       while ((buffer_length > 0) && (buffer[buffer_length - 1] < 32))
121       {
122         buffer_length--;
123         buffer[buffer_length] = 0;
124       }
126       ERROR ("oracle plugin: %s: %s failed: %s", where, what, buffer);
127     }
128     else
129     {
130       ERROR ("oracle plugin: %s: %s failed. Additionally, OCIErrorGet failed with status %i.",
131           where, what, status);
132       return;
133     }
134   }
135 } /* }}} void o_report_error */
137 static void o_database_free (o_database_t *db) /* {{{ */
139   size_t i;
141   if (db == NULL)
142     return;
144   sfree (db->name);
145   sfree (db->connect_id);
146   sfree (db->username);
147   sfree (db->password);
148   sfree (db->queries);
150   if (db->q_prep_areas != NULL)
151     for (i = 0; i < db->queries_num; ++i)
152       udb_query_delete_preparation_area (db->q_prep_areas[i]);
153   free (db->q_prep_areas);
155   sfree (db);
156 } /* }}} void o_database_free */
158 /* Configuration handling functions {{{
159  *
160  * <Plugin oracle>
161  *   <Query "plugin_instance0">
162  *     Statement "SELECT name, value FROM table"
163  *     <Result>
164  *       Type "gauge"
165  *       InstancesFrom "name"
166  *       ValuesFrom "value"
167  *     </Result>
168  *   </Query>
169  *     
170  *   <Database "plugin_instance1">
171  *     ConnectID "db01"
172  *     Username "oracle"
173  *     Password "secret"
174  *     Query "plugin_instance0"
175  *   </Database>
176  * </Plugin>
177  */
179 static int o_config_set_string (char **ret_string, /* {{{ */
180     oconfig_item_t *ci)
182   char *string;
184   if ((ci->values_num != 1)
185       || (ci->values[0].type != OCONFIG_TYPE_STRING))
186   {
187     WARNING ("oracle plugin: The `%s' config option "
188         "needs exactly one string argument.", ci->key);
189     return (-1);
190   }
192   string = strdup (ci->values[0].value.string);
193   if (string == NULL)
194   {
195     ERROR ("oracle plugin: strdup failed.");
196     return (-1);
197   }
199   if (*ret_string != NULL)
200     free (*ret_string);
201   *ret_string = string;
203   return (0);
204 } /* }}} int o_config_set_string */
206 static int o_config_add_database (oconfig_item_t *ci) /* {{{ */
208   o_database_t *db;
209   int status;
210   int i;
212   if ((ci->values_num != 1)
213       || (ci->values[0].type != OCONFIG_TYPE_STRING))
214   {
215     WARNING ("oracle plugin: The `Database' block "
216         "needs exactly one string argument.");
217     return (-1);
218   }
220   db = (o_database_t *) malloc (sizeof (*db));
221   if (db == NULL)
222   {
223     ERROR ("oracle plugin: malloc failed.");
224     return (-1);
225   }
226   memset (db, 0, sizeof (*db));
227   db->name = NULL;
228   db->host = NULL;
229   db->connect_id = NULL;
230   db->username = NULL;
231   db->password = NULL;
233   status = o_config_set_string (&db->name, ci);
234   if (status != 0)
235   {
236     sfree (db);
237     return (status);
238   }
240   /* Fill the `o_database_t' structure.. */
241   for (i = 0; i < ci->children_num; i++)
242   {
243     oconfig_item_t *child = ci->children + i;
245     if (strcasecmp ("ConnectID", child->key) == 0)
246       status = o_config_set_string (&db->connect_id, child);
247     else if (strcasecmp ("Host", child->key) == 0)
248       status = o_config_set_string (&db->host, child);
249     else if (strcasecmp ("Username", child->key) == 0)
250       status = o_config_set_string (&db->username, child);
251     else if (strcasecmp ("Password", child->key) == 0)
252       status = o_config_set_string (&db->password, child);
253     else if (strcasecmp ("Query", child->key) == 0)
254       status = udb_query_pick_from_list (child, queries, queries_num,
255           &db->queries, &db->queries_num);
256     else
257     {
258       WARNING ("oracle plugin: Option `%s' not allowed here.", child->key);
259       status = -1;
260     }
262     if (status != 0)
263       break;
264   }
266   /* Check that all necessary options have been given. */
267   while (status == 0)
268   {
269     if (db->connect_id == NULL)
270     {
271       WARNING ("oracle plugin: `ConnectID' not given for query `%s'", db->name);
272       status = -1;
273     }
274     if (db->username == NULL)
275     {
276       WARNING ("oracle plugin: `Username' not given for query `%s'", db->name);
277       status = -1;
278     }
279     if (db->password == NULL)
280     {
281       WARNING ("oracle plugin: `Password' not given for query `%s'", db->name);
282       status = -1;
283     }
285     break;
286   } /* while (status == 0) */
288   while ((status == 0) && (db->queries_num > 0))
289   {
290     db->q_prep_areas = (udb_query_preparation_area_t **) calloc (
291         db->queries_num, sizeof (*db->q_prep_areas));
293     if (db->q_prep_areas == NULL)
294     {
295       WARNING ("oracle plugin: malloc failed");
296       status = -1;
297       break;
298     }
300     for (i = 0; i < db->queries_num; ++i)
301     {
302       db->q_prep_areas[i]
303         = udb_query_allocate_preparation_area (db->queries[i]);
305       if (db->q_prep_areas[i] == NULL)
306       {
307         WARNING ("oracle plugin: udb_query_allocate_preparation_area failed");
308         status = -1;
309         break;
310       }
311     }
313     break;
314   }
316   /* If all went well, add this query to the list of queries within the
317    * database structure. */
318   if (status == 0)
319   {
320     o_database_t **temp;
322     temp = (o_database_t **) realloc (databases,
323         sizeof (*databases) * (databases_num + 1));
324     if (temp == NULL)
325     {
326       ERROR ("oracle plugin: realloc failed");
327       status = -1;
328     }
329     else
330     {
331       databases = temp;
332       databases[databases_num] = db;
333       databases_num++;
334     }
335   }
337   if (status != 0)
338   {
339     o_database_free (db);
340     return (-1);
341   }
343   return (0);
344 } /* }}} int o_config_add_database */
346 static int o_config (oconfig_item_t *ci) /* {{{ */
348   int i;
350   for (i = 0; i < ci->children_num; i++)
351   {
352     oconfig_item_t *child = ci->children + i;
353     if (strcasecmp ("Query", child->key) == 0)
354       udb_query_create (&queries, &queries_num, child,
355           /* callback = */ NULL);
356     else if (strcasecmp ("Database", child->key) == 0)
357       o_config_add_database (child);
358     else
359     {
360       WARNING ("oracle plugin: Ignoring unknown config option `%s'.", child->key);
361     }
363     if (queries_num > 0)
364     {
365       DEBUG ("oracle plugin: o_config: queries_num = %zu; queries[0] = %p; udb_query_get_user_data (queries[0]) = %p;",
366           queries_num, (void *) queries[0], udb_query_get_user_data (queries[0]));
367     }
368   } /* for (ci->children) */
370   return (0);
371 } /* }}} int o_config */
373 /* }}} End of configuration handling functions */
375 static int o_init (void) /* {{{ */
377   int status;
379   if (oci_env != NULL)
380     return (0);
382   status = OCIEnvCreate (&oci_env,
383       /* mode = */ OCI_THREADED,
384       /* context        = */ NULL,
385       /* malloc         = */ NULL,
386       /* realloc        = */ NULL,
387       /* free           = */ NULL,
388       /* user_data_size = */ 0,
389       /* user_data_ptr  = */ NULL);
390   if (status != 0)
391   {
392     ERROR ("oracle plugin: OCIEnvCreate failed with status %i.", status);
393     return (-1);
394   }
396   status = OCIHandleAlloc (oci_env, (void *) &oci_error, OCI_HTYPE_ERROR,
397       /* user_data_size = */ 0, /* user_data = */ NULL);
398   if (status != OCI_SUCCESS)
399   {
400     ERROR ("oracle plugin: OCIHandleAlloc (OCI_HTYPE_ERROR) failed "
401         "with status %i.", status);
402     return (-1);
403   }
405   return (0);
406 } /* }}} int o_init */
408 static int o_read_database_query (o_database_t *db, /* {{{ */
409     udb_query_t *q, udb_query_preparation_area_t *prep_area)
411   char **column_names;
412   char **column_values;
413   size_t column_num;
415   OCIStmt *oci_statement;
417   /* List of `OCIDefine' pointers. These defines map columns to the buffer
418    * space declared above. */
419   OCIDefine **oci_defines;
421   int status;
422   size_t i;
424   oci_statement = udb_query_get_user_data (q);
426   /* Prepare the statement */
427   if (oci_statement == NULL) /* {{{ */
428   {
429     const char *statement;
431     statement = udb_query_get_statement (q);
432     assert (statement != NULL);
434     status = OCIHandleAlloc (oci_env, (void *) &oci_statement,
435         OCI_HTYPE_STMT, /* user_data_size = */ 0, /* user_data = */ NULL);
436     if (status != OCI_SUCCESS)
437     {
438       o_report_error ("o_read_database_query", "OCIHandleAlloc", oci_error);
439       oci_statement = NULL;
440       return (-1);
441     }
443     status = OCIStmtPrepare (oci_statement, oci_error,
444         (text *) statement, (ub4) strlen (statement),
445         /* language = */ OCI_NTV_SYNTAX,
446         /* mode     = */ OCI_DEFAULT);
447     if (status != OCI_SUCCESS)
448     {
449       o_report_error ("o_read_database_query", "OCIStmtPrepare", oci_error);
450       OCIHandleFree (oci_statement, OCI_HTYPE_STMT);
451       oci_statement = NULL;
452       return (-1);
453     }
454     udb_query_set_user_data (q, oci_statement);
456     DEBUG ("oracle plugin: o_read_database_query (%s, %s): "
457         "Successfully allocated statement handle.",
458         db->name, udb_query_get_name (q));
459   } /* }}} */
461   assert (oci_statement != NULL);
463   /* Execute the statement */
464   status = OCIStmtExecute (db->oci_service_context, /* {{{ */
465       oci_statement,
466       oci_error,
467       /* iters = */ 0,
468       /* rowoff = */ 0,
469       /* snap_in = */ NULL, /* snap_out = */ NULL,
470       /* mode = */ OCI_DEFAULT);
471   if (status != OCI_SUCCESS)
472   {
473     DEBUG ("oracle plugin: o_read_database_query: status = %i (%#x)", status, status);
474     o_report_error ("o_read_database_query", "OCIStmtExecute", oci_error);
475     ERROR ("oracle plugin: o_read_database_query: "
476         "Failing statement was: %s", udb_query_get_statement (q));
477     return (-1);
478   } /* }}} */
480   /* Acquire the number of columns returned. */
481   do /* {{{ */
482   {
483     ub4 param_counter = 0;
484     status = OCIAttrGet (oci_statement, OCI_HTYPE_STMT, /* {{{ */
485         &param_counter, /* size pointer = */ NULL, 
486         OCI_ATTR_PARAM_COUNT, oci_error);
487     if (status != OCI_SUCCESS)
488     {
489       o_report_error ("o_read_database_query", "OCIAttrGet", oci_error);
490       return (-1);
491     } /* }}} */
493     column_num = (size_t) param_counter;
494   } while (0); /* }}} */
496   /* Allocate the following buffers:
497    * 
498    *  +---------------+-----------------------------------+
499    *  ! Name          ! Size                              !
500    *  +---------------+-----------------------------------+
501    *  ! column_names  ! column_num x DATA_MAX_NAME_LEN    !
502    *  ! column_values ! column_num x DATA_MAX_NAME_LEN    !
503    *  ! oci_defines   ! column_num x sizeof (OCIDefine *) !
504    *  +---------------+-----------------------------------+
505    *
506    * {{{ */
507 #define NUMBER_BUFFER_SIZE 64
509 #define FREE_ALL \
510   if (column_names != NULL) { \
511     sfree (column_names[0]); \
512     sfree (column_names); \
513   } \
514   if (column_values != NULL) { \
515     sfree (column_values[0]); \
516     sfree (column_values); \
517   } \
518   sfree (oci_defines)
520 #define ALLOC_OR_FAIL(ptr, ptr_size) \
521   do { \
522     size_t alloc_size = (size_t) ((ptr_size)); \
523     (ptr) = malloc (alloc_size); \
524     if ((ptr) == NULL) { \
525       FREE_ALL; \
526       ERROR ("oracle plugin: o_read_database_query: malloc failed."); \
527       return (-1); \
528     } \
529     memset ((ptr), 0, alloc_size); \
530   } while (0)
532   /* Initialize everything to NULL so the above works. */
533   column_names  = NULL;
534   column_values = NULL;
535   oci_defines   = NULL;
537   ALLOC_OR_FAIL (column_names, column_num * sizeof (char *));
538   ALLOC_OR_FAIL (column_names[0], column_num * DATA_MAX_NAME_LEN
539       * sizeof (char));
540   for (i = 1; i < column_num; i++)
541     column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN;
543   ALLOC_OR_FAIL (column_values, column_num * sizeof (char *));
544   ALLOC_OR_FAIL (column_values[0], column_num * DATA_MAX_NAME_LEN
545       * sizeof (char));
546   for (i = 1; i < column_num; i++)
547     column_values[i] = column_values[i - 1] + DATA_MAX_NAME_LEN;
549   ALLOC_OR_FAIL (oci_defines, column_num * sizeof (OCIDefine *));
550   /* }}} End of buffer allocations. */
552   /* ``Define'' the returned data, i. e. bind the columns to the buffers
553    * allocated above. */
554   for (i = 0; i < column_num; i++) /* {{{ */
555   {
556     char *column_name;
557     ub4 column_name_length;
558     OCIParam *oci_param;
560     oci_param = NULL;
562     status = OCIParamGet (oci_statement, OCI_HTYPE_STMT, oci_error,
563         (void *) &oci_param, (ub4) (i + 1));
564     if (status != OCI_SUCCESS)
565     {
566       /* This is probably alright */
567       DEBUG ("oracle plugin: o_read_database_query: status = %#x (= %i);", status, status);
568       o_report_error ("o_read_database_query", "OCIParamGet", oci_error);
569       status = OCI_SUCCESS;
570       break;
571     }
573     column_name = NULL;
574     column_name_length = 0;
575     status = OCIAttrGet (oci_param, OCI_DTYPE_PARAM,
576         &column_name, &column_name_length, OCI_ATTR_NAME, oci_error);
577     if (status != OCI_SUCCESS)
578     {
579       OCIDescriptorFree (oci_param, OCI_DTYPE_PARAM);
580       o_report_error ("o_read_database_query", "OCIAttrGet (OCI_ATTR_NAME)",
581           oci_error);
582       continue;
583     }
585     OCIDescriptorFree (oci_param, OCI_DTYPE_PARAM);
586     oci_param = NULL;
588     /* Copy the name to column_names. Warning: The ``string'' returned by OCI
589      * may not be null terminated! */
590     memset (column_names[i], 0, DATA_MAX_NAME_LEN);
591     if (column_name_length >= DATA_MAX_NAME_LEN)
592       column_name_length = DATA_MAX_NAME_LEN - 1;
593     memcpy (column_names[i], column_name, column_name_length);
594     column_names[i][column_name_length] = 0;
596     DEBUG ("oracle plugin: o_read_database_query: column_names[%zu] = %s; "
597         "column_name_length = %"PRIu32";",
598         i, column_names[i], (uint32_t) column_name_length);
600     status = OCIDefineByPos (oci_statement,
601         &oci_defines[i], oci_error, (ub4) (i + 1),
602         column_values[i], DATA_MAX_NAME_LEN, SQLT_STR,
603         NULL, NULL, NULL, OCI_DEFAULT);
604     if (status != OCI_SUCCESS)
605     {
606       o_report_error ("o_read_database_query", "OCIDefineByPos", oci_error);
607       continue;
608     }
609   } /* for (j = 1; j <= param_counter; j++) */
610   /* }}} End of the ``define'' stuff. */
612   status = udb_query_prepare_result (q, prep_area,
613       (db->host != NULL) ? db->host : hostname_g,
614       /* plugin = */ "oracle", db->name, column_names, column_num,
615       /* interval = */ 0);
616   if (status != 0)
617   {
618     ERROR ("oracle plugin: o_read_database_query (%s, %s): "
619         "udb_query_prepare_result failed.",
620         db->name, udb_query_get_name (q));
621     FREE_ALL;
622     return (-1);
623   }
625   /* Fetch and handle all the rows that matched the query. */
626   while (42) /* {{{ */
627   {
628     status = OCIStmtFetch2 (oci_statement, oci_error,
629         /* nrows = */ 1, /* orientation = */ OCI_FETCH_NEXT,
630         /* fetch offset = */ 0, /* mode = */ OCI_DEFAULT);
631     if (status == OCI_NO_DATA)
632     {
633       status = OCI_SUCCESS;
634       break;
635     }
636     else if ((status != OCI_SUCCESS) && (status != OCI_SUCCESS_WITH_INFO))
637     {
638       o_report_error ("o_read_database_query", "OCIStmtFetch2", oci_error);
639       break;
640     }
642     status = udb_query_handle_result (q, prep_area, column_values);
643     if (status != 0)
644     {
645       WARNING ("oracle plugin: o_read_database_query (%s, %s): "
646           "udb_query_handle_result failed.",
647           db->name, udb_query_get_name (q));
648     }
649   } /* }}} while (42) */
651   /* DEBUG ("oracle plugin: o_read_database_query: This statement succeeded: %s", q->statement); */
652   FREE_ALL;
654   return (0);
655 #undef FREE_ALL
656 #undef ALLOC_OR_FAIL
657 } /* }}} int o_read_database_query */
659 static int o_read_database (o_database_t *db) /* {{{ */
661   size_t i;
662   int status;
664   if (db->oci_service_context != NULL)
665   {
666     OCIServer *server_handle;
667     ub4 connection_status;
669     server_handle = NULL;
670     status = OCIAttrGet ((void *) db->oci_service_context, OCI_HTYPE_SVCCTX, 
671         (void *) &server_handle, /* size pointer = */ NULL,
672         OCI_ATTR_SERVER, oci_error);
673     if (status != OCI_SUCCESS)
674     {
675       o_report_error ("o_read_database", "OCIAttrGet", oci_error);
676       return (-1);
677     }
679     if (server_handle == NULL)
680     {
681       connection_status = OCI_SERVER_NOT_CONNECTED;
682     }
683     else /* if (server_handle != NULL) */
684     {
685       connection_status = 0;
686       status = OCIAttrGet ((void *) server_handle, OCI_HTYPE_SERVER,
687           (void *) &connection_status, /* size pointer = */ NULL,
688           OCI_ATTR_SERVER_STATUS, oci_error);
689       if (status != OCI_SUCCESS)
690       {
691         o_report_error ("o_read_database", "OCIAttrGet", oci_error);
692         return (-1);
693       }
694     }
696     if (connection_status != OCI_SERVER_NORMAL)
697     {
698       INFO ("oracle plugin: Connection to %s lost. Trying to reconnect.",
699           db->name);
700       OCIHandleFree (db->oci_service_context, OCI_HTYPE_SVCCTX);
701       db->oci_service_context = NULL;
702     }
703   } /* if (db->oci_service_context != NULL) */
705   if (db->oci_service_context == NULL)
706   {
707     status = OCILogon (oci_env, oci_error,
708         &db->oci_service_context,
709         (OraText *) db->username, (ub4) strlen (db->username),
710         (OraText *) db->password, (ub4) strlen (db->password),
711         (OraText *) db->connect_id, (ub4) strlen (db->connect_id));
712     if ((status != OCI_SUCCESS) && (status != OCI_SUCCESS_WITH_INFO))
713     {
714       o_report_error ("o_read_database", "OCILogon", oci_error);
715       DEBUG ("oracle plugin: OCILogon (%s): db->oci_service_context = %p;",
716           db->connect_id, db->oci_service_context);
717       db->oci_service_context = NULL;
718       return (-1);
719     }
720     else if (status == OCI_SUCCESS_WITH_INFO)
721     {
722       /* TODO: Print NOTIFY message. */
723     }
724     assert (db->oci_service_context != NULL);
725   }
727   DEBUG ("oracle plugin: o_read_database: db->connect_id = %s; db->oci_service_context = %p;",
728       db->connect_id, db->oci_service_context);
730   for (i = 0; i < db->queries_num; i++)
731     o_read_database_query (db, db->queries[i], db->q_prep_areas[i]);
733   return (0);
734 } /* }}} int o_read_database */
736 static int o_read (void) /* {{{ */
738   size_t i;
740   for (i = 0; i < databases_num; i++)
741     o_read_database (databases[i]);
743   return (0);
744 } /* }}} int o_read */
746 static int o_shutdown (void) /* {{{ */
748   size_t i;
750   for (i = 0; i < databases_num; i++)
751     if (databases[i]->oci_service_context != NULL)
752     {
753       OCIHandleFree (databases[i]->oci_service_context, OCI_HTYPE_SVCCTX);
754       databases[i]->oci_service_context = NULL;
755     }
756   
757   for (i = 0; i < queries_num; i++)
758   {
759     OCIStmt *oci_statement;
761     oci_statement = udb_query_get_user_data (queries[i]);
762     if (oci_statement != NULL)
763     {
764       OCIHandleFree (oci_statement, OCI_HTYPE_STMT);
765       udb_query_set_user_data (queries[i], NULL);
766     }
767   }
768   
769   OCIHandleFree (oci_env, OCI_HTYPE_ENV);
770   oci_env = NULL;
772   udb_query_free (queries, queries_num);
773   queries = NULL;
774   queries_num = 0;
776   return (0);
777 } /* }}} int o_shutdown */
779 void module_register (void) /* {{{ */
781   plugin_register_complex_config ("oracle", o_config);
782   plugin_register_init ("oracle", o_init);
783   plugin_register_read ("oracle", o_read);
784   plugin_register_shutdown ("oracle", o_shutdown);
785 } /* }}} void module_register */
787 /*
788  * vim: shiftwidth=2 softtabstop=2 et fdm=marker
789  */