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