Code

Merge remote-tracking branch 'github/pr/387'
[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 *db_name, const char *query_name,
91     const char *what, OCIError *eh)
92 {
93   char buffer[2048];
94   sb4 error_code;
95   int status;
96   unsigned int record_number;
98   if (db_name == NULL)
99     db_name = "(none)";
100   if (query_name == NULL)
101     query_name = "(none)";
103   /* An operation may cause / return multiple errors. Loop until we have
104    * handled all errors available (with a fail-save limit of 16). */
105   for (record_number = 1; record_number <= 16; record_number++)
106   {
107     memset (buffer, 0, sizeof (buffer));
108     error_code = -1;
110     status = OCIErrorGet (eh, (ub4) record_number,
111         /* sqlstate = */ NULL,
112         &error_code,
113         (text *) &buffer[0],
114         (ub4) sizeof (buffer),
115         OCI_HTYPE_ERROR);
116     buffer[sizeof (buffer) - 1] = 0;
118     if (status == OCI_NO_DATA)
119       return;
121     if (status == OCI_SUCCESS)
122     {
123       size_t buffer_length;
125       buffer_length = strlen (buffer);
126       while ((buffer_length > 0) && (buffer[buffer_length - 1] < 32))
127       {
128         buffer_length--;
129         buffer[buffer_length] = 0;
130       }
132       ERROR ("oracle plugin: %s (db = %s, query = %s): %s failed: %s",
133           where, db_name, query_name, what, buffer);
134     }
135     else
136     {
137       ERROR ("oracle plugin: %s (db = %s, query = %s): %s failed. "
138           "Additionally, OCIErrorGet failed with status %i.",
139           where, db_name, query_name, what, status);
140       return;
141     }
142   }
143 } /* }}} void o_report_error */
145 static void o_database_free (o_database_t *db) /* {{{ */
147   size_t i;
149   if (db == NULL)
150     return;
152   sfree (db->name);
153   sfree (db->connect_id);
154   sfree (db->username);
155   sfree (db->password);
156   sfree (db->queries);
158   if (db->q_prep_areas != NULL)
159     for (i = 0; i < db->queries_num; ++i)
160       udb_query_delete_preparation_area (db->q_prep_areas[i]);
161   free (db->q_prep_areas);
163   sfree (db);
164 } /* }}} void o_database_free */
166 /* Configuration handling functions {{{
167  *
168  * <Plugin oracle>
169  *   <Query "plugin_instance0">
170  *     Statement "SELECT name, value FROM table"
171  *     <Result>
172  *       Type "gauge"
173  *       InstancesFrom "name"
174  *       ValuesFrom "value"
175  *     </Result>
176  *   </Query>
177  *     
178  *   <Database "plugin_instance1">
179  *     ConnectID "db01"
180  *     Username "oracle"
181  *     Password "secret"
182  *     Query "plugin_instance0"
183  *   </Database>
184  * </Plugin>
185  */
187 static int o_config_add_database (oconfig_item_t *ci) /* {{{ */
189   o_database_t *db;
190   int status;
191   int i;
193   if ((ci->values_num != 1)
194       || (ci->values[0].type != OCONFIG_TYPE_STRING))
195   {
196     WARNING ("oracle plugin: The `Database' block "
197         "needs exactly one string argument.");
198     return (-1);
199   }
201   db = (o_database_t *) malloc (sizeof (*db));
202   if (db == NULL)
203   {
204     ERROR ("oracle plugin: malloc failed.");
205     return (-1);
206   }
207   memset (db, 0, sizeof (*db));
208   db->name = NULL;
209   db->host = NULL;
210   db->connect_id = NULL;
211   db->username = NULL;
212   db->password = NULL;
214   status = cf_util_get_string (ci, &db->name);
215   if (status != 0)
216   {
217     sfree (db);
218     return (status);
219   }
221   /* Fill the `o_database_t' structure.. */
222   for (i = 0; i < ci->children_num; i++)
223   {
224     oconfig_item_t *child = ci->children + i;
226     if (strcasecmp ("ConnectID", child->key) == 0)
227       status = cf_util_get_string (child, &db->connect_id);
228     else if (strcasecmp ("Host", child->key) == 0)
229       status = cf_util_get_string (child, &db->host);
230     else if (strcasecmp ("Username", child->key) == 0)
231       status = cf_util_get_string (child, &db->username);
232     else if (strcasecmp ("Password", child->key) == 0)
233       status = cf_util_get_string (child, &db->password);
234     else if (strcasecmp ("Query", child->key) == 0)
235       status = udb_query_pick_from_list (child, queries, queries_num,
236           &db->queries, &db->queries_num);
237     else
238     {
239       WARNING ("oracle plugin: Option `%s' not allowed here.", child->key);
240       status = -1;
241     }
243     if (status != 0)
244       break;
245   }
247   /* Check that all necessary options have been given. */
248   while (status == 0)
249   {
250     if (db->connect_id == NULL)
251     {
252       WARNING ("oracle plugin: `ConnectID' not given for query `%s'", db->name);
253       status = -1;
254     }
255     if (db->username == NULL)
256     {
257       WARNING ("oracle plugin: `Username' not given for query `%s'", db->name);
258       status = -1;
259     }
260     if (db->password == NULL)
261     {
262       WARNING ("oracle plugin: `Password' not given for query `%s'", db->name);
263       status = -1;
264     }
266     break;
267   } /* while (status == 0) */
269   while ((status == 0) && (db->queries_num > 0))
270   {
271     db->q_prep_areas = (udb_query_preparation_area_t **) calloc (
272         db->queries_num, sizeof (*db->q_prep_areas));
274     if (db->q_prep_areas == NULL)
275     {
276       WARNING ("oracle plugin: malloc failed");
277       status = -1;
278       break;
279     }
281     for (i = 0; i < db->queries_num; ++i)
282     {
283       db->q_prep_areas[i]
284         = udb_query_allocate_preparation_area (db->queries[i]);
286       if (db->q_prep_areas[i] == NULL)
287       {
288         WARNING ("oracle plugin: udb_query_allocate_preparation_area failed");
289         status = -1;
290         break;
291       }
292     }
294     break;
295   }
297   /* If all went well, add this query to the list of queries within the
298    * database structure. */
299   if (status == 0)
300   {
301     o_database_t **temp;
303     temp = (o_database_t **) realloc (databases,
304         sizeof (*databases) * (databases_num + 1));
305     if (temp == NULL)
306     {
307       ERROR ("oracle plugin: realloc failed");
308       status = -1;
309     }
310     else
311     {
312       databases = temp;
313       databases[databases_num] = db;
314       databases_num++;
315     }
316   }
318   if (status != 0)
319   {
320     o_database_free (db);
321     return (-1);
322   }
324   return (0);
325 } /* }}} int o_config_add_database */
327 static int o_config (oconfig_item_t *ci) /* {{{ */
329   int i;
331   for (i = 0; i < ci->children_num; i++)
332   {
333     oconfig_item_t *child = ci->children + i;
334     if (strcasecmp ("Query", child->key) == 0)
335       udb_query_create (&queries, &queries_num, child,
336           /* callback = */ NULL);
337     else if (strcasecmp ("Database", child->key) == 0)
338       o_config_add_database (child);
339     else
340     {
341       WARNING ("oracle plugin: Ignoring unknown config option `%s'.", child->key);
342     }
344     if (queries_num > 0)
345     {
346       DEBUG ("oracle plugin: o_config: queries_num = %zu; queries[0] = %p; udb_query_get_user_data (queries[0]) = %p;",
347           queries_num, (void *) queries[0], udb_query_get_user_data (queries[0]));
348     }
349   } /* for (ci->children) */
351   return (0);
352 } /* }}} int o_config */
354 /* }}} End of configuration handling functions */
356 static int o_init (void) /* {{{ */
358   int status;
360   if (oci_env != NULL)
361     return (0);
363   status = OCIEnvCreate (&oci_env,
364       /* mode = */ OCI_THREADED,
365       /* context        = */ NULL,
366       /* malloc         = */ NULL,
367       /* realloc        = */ NULL,
368       /* free           = */ NULL,
369       /* user_data_size = */ 0,
370       /* user_data_ptr  = */ NULL);
371   if (status != 0)
372   {
373     ERROR ("oracle plugin: OCIEnvCreate failed with status %i.", status);
374     return (-1);
375   }
377   status = OCIHandleAlloc (oci_env, (void *) &oci_error, OCI_HTYPE_ERROR,
378       /* user_data_size = */ 0, /* user_data = */ NULL);
379   if (status != OCI_SUCCESS)
380   {
381     ERROR ("oracle plugin: OCIHandleAlloc (OCI_HTYPE_ERROR) failed "
382         "with status %i.", status);
383     return (-1);
384   }
386   return (0);
387 } /* }}} int o_init */
389 static int o_read_database_query (o_database_t *db, /* {{{ */
390     udb_query_t *q, udb_query_preparation_area_t *prep_area)
392   char **column_names;
393   char **column_values;
394   size_t column_num;
396   OCIStmt *oci_statement;
398   /* List of `OCIDefine' pointers. These defines map columns to the buffer
399    * space declared above. */
400   OCIDefine **oci_defines;
402   int status;
403   size_t i;
405   oci_statement = udb_query_get_user_data (q);
407   /* Prepare the statement */
408   if (oci_statement == NULL) /* {{{ */
409   {
410     const char *statement;
412     statement = udb_query_get_statement (q);
413     assert (statement != NULL);
415     status = OCIHandleAlloc (oci_env, (void *) &oci_statement,
416         OCI_HTYPE_STMT, /* user_data_size = */ 0, /* user_data = */ NULL);
417     if (status != OCI_SUCCESS)
418     {
419       o_report_error ("o_read_database_query", db->name,
420           udb_query_get_name (q), "OCIHandleAlloc", oci_error);
421       oci_statement = NULL;
422       return (-1);
423     }
425     status = OCIStmtPrepare (oci_statement, oci_error,
426         (text *) statement, (ub4) strlen (statement),
427         /* language = */ OCI_NTV_SYNTAX,
428         /* mode     = */ OCI_DEFAULT);
429     if (status != OCI_SUCCESS)
430     {
431       o_report_error ("o_read_database_query", db->name,
432           udb_query_get_name (q), "OCIStmtPrepare", oci_error);
433       OCIHandleFree (oci_statement, OCI_HTYPE_STMT);
434       oci_statement = NULL;
435       return (-1);
436     }
437     udb_query_set_user_data (q, oci_statement);
439     DEBUG ("oracle plugin: o_read_database_query (%s, %s): "
440         "Successfully allocated statement handle.",
441         db->name, udb_query_get_name (q));
442   } /* }}} */
444   assert (oci_statement != NULL);
446   /* Execute the statement */
447   status = OCIStmtExecute (db->oci_service_context, /* {{{ */
448       oci_statement,
449       oci_error,
450       /* iters = */ 0,
451       /* rowoff = */ 0,
452       /* snap_in = */ NULL, /* snap_out = */ NULL,
453       /* mode = */ OCI_DEFAULT);
454   if (status != OCI_SUCCESS)
455   {
456     o_report_error ("o_read_database_query", db->name, udb_query_get_name (q),
457         "OCIStmtExecute", oci_error);
458     return (-1);
459   } /* }}} */
461   /* Acquire the number of columns returned. */
462   do /* {{{ */
463   {
464     ub4 param_counter = 0;
465     status = OCIAttrGet (oci_statement, OCI_HTYPE_STMT, /* {{{ */
466         &param_counter, /* size pointer = */ NULL, 
467         OCI_ATTR_PARAM_COUNT, oci_error);
468     if (status != OCI_SUCCESS)
469     {
470       o_report_error ("o_read_database_query", db->name,
471           udb_query_get_name (q), "OCIAttrGet", oci_error);
472       return (-1);
473     } /* }}} */
475     column_num = (size_t) param_counter;
476   } while (0); /* }}} */
478   /* Allocate the following buffers:
479    * 
480    *  +---------------+-----------------------------------+
481    *  ! Name          ! Size                              !
482    *  +---------------+-----------------------------------+
483    *  ! column_names  ! column_num x DATA_MAX_NAME_LEN    !
484    *  ! column_values ! column_num x DATA_MAX_NAME_LEN    !
485    *  ! oci_defines   ! column_num x sizeof (OCIDefine *) !
486    *  +---------------+-----------------------------------+
487    *
488    * {{{ */
489 #define NUMBER_BUFFER_SIZE 64
491 #define FREE_ALL \
492   if (column_names != NULL) { \
493     sfree (column_names[0]); \
494     sfree (column_names); \
495   } \
496   if (column_values != NULL) { \
497     sfree (column_values[0]); \
498     sfree (column_values); \
499   } \
500   sfree (oci_defines)
502 #define ALLOC_OR_FAIL(ptr, ptr_size) \
503   do { \
504     size_t alloc_size = (size_t) ((ptr_size)); \
505     (ptr) = malloc (alloc_size); \
506     if ((ptr) == NULL) { \
507       FREE_ALL; \
508       ERROR ("oracle plugin: o_read_database_query: malloc failed."); \
509       return (-1); \
510     } \
511     memset ((ptr), 0, alloc_size); \
512   } while (0)
514   /* Initialize everything to NULL so the above works. */
515   column_names  = NULL;
516   column_values = NULL;
517   oci_defines   = NULL;
519   ALLOC_OR_FAIL (column_names, column_num * sizeof (char *));
520   ALLOC_OR_FAIL (column_names[0], column_num * DATA_MAX_NAME_LEN
521       * sizeof (char));
522   for (i = 1; i < column_num; i++)
523     column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN;
525   ALLOC_OR_FAIL (column_values, column_num * sizeof (char *));
526   ALLOC_OR_FAIL (column_values[0], column_num * DATA_MAX_NAME_LEN
527       * sizeof (char));
528   for (i = 1; i < column_num; i++)
529     column_values[i] = column_values[i - 1] + DATA_MAX_NAME_LEN;
531   ALLOC_OR_FAIL (oci_defines, column_num * sizeof (OCIDefine *));
532   /* }}} End of buffer allocations. */
534   /* ``Define'' the returned data, i. e. bind the columns to the buffers
535    * allocated above. */
536   for (i = 0; i < column_num; i++) /* {{{ */
537   {
538     char *column_name;
539     ub4 column_name_length;
540     OCIParam *oci_param;
542     oci_param = NULL;
544     status = OCIParamGet (oci_statement, OCI_HTYPE_STMT, oci_error,
545         (void *) &oci_param, (ub4) (i + 1));
546     if (status != OCI_SUCCESS)
547     {
548       /* This is probably alright */
549       DEBUG ("oracle plugin: o_read_database_query: status = %#x (= %i);",
550           status, status);
551       o_report_error ("o_read_database_query", db->name,
552           udb_query_get_name (q), "OCIParamGet", oci_error);
553       status = OCI_SUCCESS;
554       break;
555     }
557     column_name = NULL;
558     column_name_length = 0;
559     status = OCIAttrGet (oci_param, OCI_DTYPE_PARAM,
560         &column_name, &column_name_length, OCI_ATTR_NAME, oci_error);
561     if (status != OCI_SUCCESS)
562     {
563       OCIDescriptorFree (oci_param, OCI_DTYPE_PARAM);
564       o_report_error ("o_read_database_query", db->name,
565           udb_query_get_name (q), "OCIAttrGet (OCI_ATTR_NAME)", oci_error);
566       continue;
567     }
569     OCIDescriptorFree (oci_param, OCI_DTYPE_PARAM);
570     oci_param = NULL;
572     /* Copy the name to column_names. Warning: The ``string'' returned by OCI
573      * may not be null terminated! */
574     memset (column_names[i], 0, DATA_MAX_NAME_LEN);
575     if (column_name_length >= DATA_MAX_NAME_LEN)
576       column_name_length = DATA_MAX_NAME_LEN - 1;
577     memcpy (column_names[i], column_name, column_name_length);
578     column_names[i][column_name_length] = 0;
580     DEBUG ("oracle plugin: o_read_database_query: column_names[%zu] = %s; "
581         "column_name_length = %"PRIu32";",
582         i, column_names[i], (uint32_t) column_name_length);
584     status = OCIDefineByPos (oci_statement,
585         &oci_defines[i], oci_error, (ub4) (i + 1),
586         column_values[i], DATA_MAX_NAME_LEN, SQLT_STR,
587         NULL, NULL, NULL, OCI_DEFAULT);
588     if (status != OCI_SUCCESS)
589     {
590       o_report_error ("o_read_database_query", db->name,
591           udb_query_get_name (q), "OCIDefineByPos", oci_error);
592       continue;
593     }
594   } /* for (j = 1; j <= param_counter; j++) */
595   /* }}} End of the ``define'' stuff. */
597   status = udb_query_prepare_result (q, prep_area,
598       (db->host != NULL) ? db->host : hostname_g,
599       /* plugin = */ "oracle", db->name, column_names, column_num,
600       /* interval = */ 0);
601   if (status != 0)
602   {
603     ERROR ("oracle plugin: o_read_database_query (%s, %s): "
604         "udb_query_prepare_result failed.",
605         db->name, udb_query_get_name (q));
606     FREE_ALL;
607     return (-1);
608   }
610   /* Fetch and handle all the rows that matched the query. */
611   while (42) /* {{{ */
612   {
613     status = OCIStmtFetch2 (oci_statement, oci_error,
614         /* nrows = */ 1, /* orientation = */ OCI_FETCH_NEXT,
615         /* fetch offset = */ 0, /* mode = */ OCI_DEFAULT);
616     if (status == OCI_NO_DATA)
617     {
618       status = OCI_SUCCESS;
619       break;
620     }
621     else if ((status != OCI_SUCCESS) && (status != OCI_SUCCESS_WITH_INFO))
622     {
623       o_report_error ("o_read_database_query", db->name,
624           udb_query_get_name (q), "OCIStmtFetch2", oci_error);
625       break;
626     }
628     status = udb_query_handle_result (q, prep_area, column_values);
629     if (status != 0)
630     {
631       WARNING ("oracle plugin: o_read_database_query (%s, %s): "
632           "udb_query_handle_result failed.",
633           db->name, udb_query_get_name (q));
634     }
635   } /* }}} while (42) */
637   /* DEBUG ("oracle plugin: o_read_database_query: This statement succeeded: %s", q->statement); */
638   FREE_ALL;
640   return (0);
641 #undef FREE_ALL
642 #undef ALLOC_OR_FAIL
643 } /* }}} int o_read_database_query */
645 static int o_read_database (o_database_t *db) /* {{{ */
647   size_t i;
648   int status;
650   if (db->oci_service_context != NULL)
651   {
652     OCIServer *server_handle;
653     ub4 connection_status;
655     server_handle = NULL;
656     status = OCIAttrGet ((void *) db->oci_service_context, OCI_HTYPE_SVCCTX, 
657         (void *) &server_handle, /* size pointer = */ NULL,
658         OCI_ATTR_SERVER, oci_error);
659     if (status != OCI_SUCCESS)
660     {
661       o_report_error ("o_read_database", db->name, NULL, "OCIAttrGet",
662           oci_error);
663       return (-1);
664     }
666     if (server_handle == NULL)
667     {
668       connection_status = OCI_SERVER_NOT_CONNECTED;
669     }
670     else /* if (server_handle != NULL) */
671     {
672       connection_status = 0;
673       status = OCIAttrGet ((void *) server_handle, OCI_HTYPE_SERVER,
674           (void *) &connection_status, /* size pointer = */ NULL,
675           OCI_ATTR_SERVER_STATUS, oci_error);
676       if (status != OCI_SUCCESS)
677       {
678         o_report_error ("o_read_database", db->name, NULL, "OCIAttrGet",
679             oci_error);
680         return (-1);
681       }
682     }
684     if (connection_status != OCI_SERVER_NORMAL)
685     {
686       INFO ("oracle plugin: Connection to %s lost. Trying to reconnect.",
687           db->name);
688       OCIHandleFree (db->oci_service_context, OCI_HTYPE_SVCCTX);
689       db->oci_service_context = NULL;
690     }
691   } /* if (db->oci_service_context != NULL) */
693   if (db->oci_service_context == NULL)
694   {
695     status = OCILogon (oci_env, oci_error,
696         &db->oci_service_context,
697         (OraText *) db->username, (ub4) strlen (db->username),
698         (OraText *) db->password, (ub4) strlen (db->password),
699         (OraText *) db->connect_id, (ub4) strlen (db->connect_id));
700     if ((status != OCI_SUCCESS) && (status != OCI_SUCCESS_WITH_INFO))
701     {
702       char errfunc[256];
704       ssnprintf (errfunc, sizeof (errfunc), "OCILogon(\"%s\")", db->connect_id);
706       o_report_error ("o_read_database", db->name, NULL, errfunc, oci_error);
707       DEBUG ("oracle plugin: OCILogon (%s): db->oci_service_context = %p;",
708           db->connect_id, db->oci_service_context);
709       db->oci_service_context = NULL;
710       return (-1);
711     }
712     else if (status == OCI_SUCCESS_WITH_INFO)
713     {
714       /* TODO: Print NOTIFY message. */
715     }
716     assert (db->oci_service_context != NULL);
717   }
719   DEBUG ("oracle plugin: o_read_database: db->connect_id = %s; db->oci_service_context = %p;",
720       db->connect_id, db->oci_service_context);
722   for (i = 0; i < db->queries_num; i++)
723     o_read_database_query (db, db->queries[i], db->q_prep_areas[i]);
725   return (0);
726 } /* }}} int o_read_database */
728 static int o_read (void) /* {{{ */
730   size_t i;
732   for (i = 0; i < databases_num; i++)
733     o_read_database (databases[i]);
735   return (0);
736 } /* }}} int o_read */
738 static int o_shutdown (void) /* {{{ */
740   size_t i;
742   for (i = 0; i < databases_num; i++)
743     if (databases[i]->oci_service_context != NULL)
744     {
745       OCIHandleFree (databases[i]->oci_service_context, OCI_HTYPE_SVCCTX);
746       databases[i]->oci_service_context = NULL;
747     }
748   
749   for (i = 0; i < queries_num; i++)
750   {
751     OCIStmt *oci_statement;
753     oci_statement = udb_query_get_user_data (queries[i]);
754     if (oci_statement != NULL)
755     {
756       OCIHandleFree (oci_statement, OCI_HTYPE_STMT);
757       udb_query_set_user_data (queries[i], NULL);
758     }
759   }
760   
761   OCIHandleFree (oci_env, OCI_HTYPE_ENV);
762   oci_env = NULL;
764   udb_query_free (queries, queries_num);
765   queries = NULL;
766   queries_num = 0;
768   return (0);
769 } /* }}} int o_shutdown */
771 void module_register (void) /* {{{ */
773   plugin_register_complex_config ("oracle", o_config);
774   plugin_register_init ("oracle", o_init);
775   plugin_register_read ("oracle", o_read);
776   plugin_register_shutdown ("oracle", o_shutdown);
777 } /* }}} void module_register */
779 /*
780  * vim: shiftwidth=2 softtabstop=2 et fdm=marker
781  */