2 * collectd - src/oracle.c
3 * Copyright (C) 2008,2009 Florian octo Forster
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.
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.
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
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
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.
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.
40 * Oracle® is a registered trademark of Oracle Corporation and/or its
41 * affiliates. Other names may be trademarks of their respective owners.
44 * Florian octo Forster <octo at noris.net>
57 typedef struct o_result_s o_result_t;
73 OCIStmt *oci_statement;
77 typedef struct o_query_s o_query_t;
89 OCISvcCtx *oci_service_context;
91 typedef struct o_database_s o_database_t;
96 static o_query_t **queries = NULL;
97 static size_t queries_num = 0;
98 static o_database_t **databases = NULL;
99 static size_t databases_num = 0;
101 OCIEnv *oci_env = NULL;
102 OCIError *oci_error = NULL;
107 static void o_report_error (const char *where, /* {{{ */
108 const char *what, OCIError *eh)
114 status = OCIErrorGet (eh, /* record number = */ 1,
115 /* sqlstate = */ NULL,
118 (ub4) sizeof (buffer),
120 buffer[sizeof (buffer) - 1] = 0;
122 if (status == OCI_SUCCESS)
124 size_t buffer_length;
126 buffer_length = strlen (buffer);
127 while ((buffer_length > 0) && (buffer[buffer_length - 1] < 32))
130 buffer[buffer_length] = 0;
133 ERROR ("oracle plugin: %s: %s failed: %s",
134 where, what, buffer);
138 ERROR ("oracle plugin: %s: %s failed. Additionally, OCIErrorGet failed with status %i.",
139 where, what, status);
141 } /* }}} void o_report_error */
143 static void o_result_free (o_result_t *r) /* {{{ */
152 for (i = 0; i < r->instances_num; i++)
153 sfree (r->instances[i]);
154 sfree (r->instances);
156 for (i = 0; i < r->values_num; i++)
157 sfree (r->values[i]);
160 o_result_free (r->next);
163 } /* }}} void o_result_free */
165 static void o_query_free (o_query_t *q) /* {{{ */
171 sfree (q->statement);
173 o_result_free (q->results);
176 } /* }}} void o_query_free */
178 static void o_database_free (o_database_t *db) /* {{{ */
184 sfree (db->connect_id);
185 sfree (db->username);
186 sfree (db->password);
190 } /* }}} void o_database_free */
192 /* Configuration handling functions {{{
195 * <Query "plugin_instance0">
196 * Statement "SELECT name, value FROM table"
199 * InstancesFrom "name"
204 * <Database "plugin_instance1">
208 * Query "plugin_instance0"
213 static int o_config_set_string (char **ret_string, /* {{{ */
218 if ((ci->values_num != 1)
219 || (ci->values[0].type != OCONFIG_TYPE_STRING))
221 WARNING ("oracle plugin: The `%s' config option "
222 "needs exactly one string argument.", ci->key);
226 string = strdup (ci->values[0].value.string);
229 ERROR ("oracle plugin: strdup failed.");
233 if (*ret_string != NULL)
235 *ret_string = string;
238 } /* }}} int o_config_set_string */
240 static int o_config_add_string (char ***ret_array, /* {{{ */
241 size_t *ret_array_len, oconfig_item_t *ci)
247 if (ci->values_num < 1)
249 WARNING ("oracle plugin: The `%s' config option "
250 "needs at least one argument.", ci->key);
254 for (i = 0; i < ci->values_num; i++)
256 if (ci->values[i].type != OCONFIG_TYPE_STRING)
258 WARNING ("oracle plugin: Argument %i to the `%s' option "
259 "is not a string.", i + 1, ci->key);
264 array_len = *ret_array_len;
265 array = (char **) realloc (*ret_array,
266 sizeof (char *) * (array_len + ci->values_num));
269 ERROR ("oracle plugin: realloc failed.");
274 for (i = 0; i < ci->values_num; i++)
276 array[array_len] = strdup (ci->values[i].value.string);
277 if (array[array_len] == NULL)
279 ERROR ("oracle plugin: strdup failed.");
280 *ret_array_len = array_len;
286 *ret_array_len = array_len;
288 } /* }}} int o_config_add_string */
290 static int o_config_add_query_result (o_query_t *q, /* {{{ */
297 if (ci->values_num != 0)
299 WARNING ("oracle plugin: The `Result' block doesn't accept any arguments. "
300 "Ignoring %i argument%s.",
301 ci->values_num, (ci->values_num == 1) ? "" : "s");
304 r = (o_result_t *) malloc (sizeof (*r));
307 ERROR ("oracle plugin: malloc failed.");
310 memset (r, 0, sizeof (*r));
316 /* Fill the `o_result_t' structure.. */
318 for (i = 0; i < ci->children_num; i++)
320 oconfig_item_t *child = ci->children + i;
322 if (strcasecmp ("Type", child->key) == 0)
323 status = o_config_set_string (&r->type, child);
324 else if (strcasecmp ("InstancesFrom", child->key) == 0)
325 status = o_config_add_string (&r->instances, &r->instances_num, child);
326 else if (strcasecmp ("ValuesFrom", child->key) == 0)
327 status = o_config_add_string (&r->values, &r->values_num, child);
330 WARNING ("oracle plugin: Query `%s': Option `%s' not allowed here.",
331 q->name, child->key);
339 /* Check that all necessary options have been given. */
344 WARNING ("oracle plugin: `Type' not given for "
345 "result in query `%s'", q->name);
348 if (r->instances == NULL)
350 WARNING ("oracle plugin: `InstancesFrom' not given for "
351 "result in query `%s'", q->name);
354 if (r->values == NULL)
356 WARNING ("oracle plugin: `ValuesFrom' not given for "
357 "result in query `%s'", q->name);
362 } /* while (status == 0) */
364 /* If all went well, add this result to the list of results within the
365 * query structure. */
368 if (q->results == NULL)
377 while (last->next != NULL)
391 } /* }}} int o_config_add_query_result */
393 static int o_config_add_query (oconfig_item_t *ci) /* {{{ */
399 if ((ci->values_num != 1)
400 || (ci->values[0].type != OCONFIG_TYPE_STRING))
402 WARNING ("oracle plugin: The `Query' block "
403 "needs exactly one string argument.");
407 q = (o_query_t *) malloc (sizeof (*q));
410 ERROR ("oracle plugin: malloc failed.");
413 memset (q, 0, sizeof (*q));
415 status = o_config_set_string (&q->name, ci);
422 /* Fill the `o_query_t' structure.. */
423 for (i = 0; i < ci->children_num; i++)
425 oconfig_item_t *child = ci->children + i;
427 if (strcasecmp ("Statement", child->key) == 0)
428 status = o_config_set_string (&q->statement, child);
429 else if (strcasecmp ("Result", child->key) == 0)
430 status = o_config_add_query_result (q, child);
433 WARNING ("oracle plugin: Option `%s' not allowed here.", child->key);
441 /* Check that all necessary options have been given. */
444 if (q->statement == NULL)
446 WARNING ("oracle plugin: `Statement' not given for query `%s'", q->name);
449 if (q->results == NULL)
451 WARNING ("oracle plugin: No (valid) `Result' block given for query `%s'",
457 } /* while (status == 0) */
459 /* If all went well, add this query to the list of queries within the
460 * database structure. */
465 temp = (o_query_t **) realloc (queries,
466 sizeof (*queries) * (queries_num + 1));
469 ERROR ("oracle plugin: realloc failed");
475 queries[queries_num] = q;
487 } /* }}} int o_config_add_query */
489 static int o_config_add_database_query (o_database_t *db, /* {{{ */
496 if ((ci->values_num != 1)
497 || (ci->values[0].type != OCONFIG_TYPE_STRING))
499 WARNING ("oracle plugin: The `Query' config option "
500 "needs exactly one string argument.");
505 for (i = 0; i < queries_num; i++)
507 if (strcasecmp (queries[i]->name, ci->values[0].value.string) == 0)
516 WARNING ("oracle plugin: Database `%s': Unknown query `%s'. "
517 "Please make sure that the <Query \"%s\"> block comes before "
518 "the <Database \"%s\"> block.",
519 db->name, ci->values[0].value.string,
520 ci->values[0].value.string, db->name);
524 temp = (o_query_t **) realloc (db->queries,
525 sizeof (*db->queries) * (db->queries_num + 1));
528 ERROR ("oracle plugin: realloc failed");
534 db->queries[db->queries_num] = q;
539 } /* }}} int o_config_add_database_query */
541 static int o_config_add_database (oconfig_item_t *ci) /* {{{ */
547 if ((ci->values_num != 1)
548 || (ci->values[0].type != OCONFIG_TYPE_STRING))
550 WARNING ("oracle plugin: The `Database' block "
551 "needs exactly one string argument.");
555 db = (o_database_t *) malloc (sizeof (*db));
558 ERROR ("oracle plugin: malloc failed.");
561 memset (db, 0, sizeof (*db));
563 status = o_config_set_string (&db->name, ci);
570 /* Fill the `o_database_t' structure.. */
571 for (i = 0; i < ci->children_num; i++)
573 oconfig_item_t *child = ci->children + i;
575 if (strcasecmp ("ConnectID", child->key) == 0)
576 status = o_config_set_string (&db->connect_id, child);
577 else if (strcasecmp ("Username", child->key) == 0)
578 status = o_config_set_string (&db->username, child);
579 else if (strcasecmp ("Password", child->key) == 0)
580 status = o_config_set_string (&db->password, child);
581 else if (strcasecmp ("Query", child->key) == 0)
582 status = o_config_add_database_query (db, child);
585 WARNING ("oracle plugin: Option `%s' not allowed here.", child->key);
593 /* Check that all necessary options have been given. */
596 if (db->connect_id == NULL)
598 WARNING ("oracle plugin: `ConnectID' not given for query `%s'", db->name);
601 if (db->username == NULL)
603 WARNING ("oracle plugin: `Username' not given for query `%s'", db->name);
606 if (db->password == NULL)
608 WARNING ("oracle plugin: `Password' not given for query `%s'", db->name);
613 } /* while (status == 0) */
615 /* If all went well, add this query to the list of queries within the
616 * database structure. */
621 temp = (o_database_t **) realloc (databases,
622 sizeof (*databases) * (databases_num + 1));
625 ERROR ("oracle plugin: realloc failed");
631 databases[databases_num] = db;
638 o_database_free (db);
643 } /* }}} int o_config_add_database */
645 static int o_config (oconfig_item_t *ci) /* {{{ */
649 for (i = 0; i < ci->children_num; i++)
651 oconfig_item_t *child = ci->children + i;
652 if (strcasecmp ("Query", child->key) == 0)
653 o_config_add_query (child);
654 else if (strcasecmp ("Database", child->key) == 0)
655 o_config_add_database (child);
658 WARNING ("snmp plugin: Ignoring unknown config option `%s'.", child->key);
660 } /* for (ci->children) */
663 } /* }}} int o_config */
665 /* }}} End of configuration handling functions */
667 static int o_init (void) /* {{{ */
674 status = OCIEnvCreate (&oci_env,
675 /* mode = */ OCI_THREADED,
676 /* context = */ NULL,
678 /* realloc = */ NULL,
680 /* user_data_size = */ 0,
681 /* user_data_ptr = */ NULL);
684 ERROR ("oracle plugin: OCIEnvCreate failed with status %i.", status);
688 status = OCIHandleAlloc (oci_env, (void *) &oci_error, OCI_HTYPE_ERROR,
689 /* user_data_size = */ 0, /* user_data = */ NULL);
690 if (status != OCI_SUCCESS)
692 ERROR ("oracle plugin: OCIHandleAlloc (OCI_HTYPE_ERROR) failed "
693 "with status %i.", status);
698 } /* }}} int o_init */
700 static void o_submit (o_database_t *db, o_result_t *r, /* {{{ */
701 const data_set_t *ds, char **buffer_instances, char **buffer_values)
703 value_list_t vl = VALUE_LIST_INIT;
706 assert (((size_t) ds->ds_num) == r->values_num);
708 vl.values = (value_t *) malloc (sizeof (value_t) * r->values_num);
709 if (vl.values == NULL)
711 ERROR ("oracle plugin: malloc failed.");
714 vl.values_len = ds->ds_num;
716 for (i = 0; i < r->values_num; i++)
722 if (ds->ds[i].type == DS_TYPE_COUNTER)
723 vl.values[i].counter = (counter_t) strtoll (buffer_values[i],
724 &endptr, /* base = */ 0);
725 else if (ds->ds[i].type == DS_TYPE_GAUGE)
726 vl.values[i].gauge = (gauge_t) strtod (buffer_values[i], &endptr);
730 if ((endptr == buffer_values[i]) || (errno != 0))
732 WARNING ("oracle plugin: o_submit: Parsing `%s' as %s failed.",
734 (ds->ds[i].type == DS_TYPE_COUNTER) ? "counter" : "gauge");
735 vl.values[i].gauge = NAN;
739 vl.time = time (NULL);
740 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
741 sstrncpy (vl.plugin, "oracle", sizeof (vl.plugin));
742 sstrncpy (vl.plugin_instance, db->name, sizeof (vl.type_instance));
743 sstrncpy (vl.type, r->type, sizeof (vl.type));
744 strjoin (vl.type_instance, sizeof (vl.type_instance),
745 buffer_instances, r->instances_num, "-");
746 vl.type_instance[sizeof (vl.type_instance) - 1] = 0;
748 plugin_dispatch_values (&vl);
749 } /* }}} void o_submit */
751 static int o_handle_query_result (o_database_t *db, /* {{{ */
752 o_query_t *q, o_result_t *r,
753 char **column_names, char **column_values, size_t column_num)
755 const data_set_t *ds;
763 #define BAIL_OUT(status) \
768 /* Read `ds' and check number of values {{{ */
769 ds = plugin_get_ds (r->type);
772 ERROR ("oracle plugin: o_handle_query_result (%s, %s): Type `%s' is not "
773 "known by the daemon. See types.db(5) for details.",
774 db->name, q->name, r->type);
778 if (((size_t) ds->ds_num) != r->values_num)
780 ERROR ("oracle plugin: o_handle_query_result (%s, %s): The type `%s' "
781 "requires exactly %i value%s, but the configuration specifies %zu.",
782 db->name, q->name, r->type,
783 ds->ds_num, (ds->ds_num == 1) ? "" : "s",
789 /* Allocate `instances' and `values'. {{{ */
790 instances = (char **) calloc (r->instances_num, sizeof (char *));
791 if (instances == NULL)
793 ERROR ("oracle plugin: o_handle_query_result (%s, %s): malloc failed.",
798 values = (char **) calloc (r->values_num, sizeof (char *));
802 ERROR ("oracle plugin: o_handle_query_result (%s, %s): malloc failed.",
808 /* Fill `instances' with pointers to the appropriate strings from
810 for (i = 0; i < r->instances_num; i++) /* {{{ */
815 for (j = 0; j < column_num; j++)
817 if (strcasecmp (r->instances[i], column_names[j]) == 0)
819 instances[i] = column_values[j];
824 if (instances[i] == NULL)
826 ERROR ("oracle plugin: o_handle_query_result (%s, %s): "
827 "Cannot find column `%s'. Is the statement correct?",
828 db->name, q->name, r->instances[i]);
833 /* Fill `values' with pointers to the appropriate strings from
835 for (i = 0; i < r->values_num; i++) /* {{{ */
840 for (j = 0; j < column_num; j++)
842 if (strcasecmp (r->values[i], column_names[j]) == 0)
844 values[i] = column_values[j];
849 if (values[i] == NULL)
851 ERROR ("oracle plugin: o_handle_query_result (%s, %s): "
852 "Cannot find column `%s'. Is the statement correct?",
853 db->name, q->name, r->values[i]);
858 o_submit (db, r, ds, instances, values);
862 } /* }}} int o_handle_query_result */
864 static int o_read_database_query (o_database_t *db, /* {{{ */
868 char **column_values;
871 /* List of `OCIDefine' pointers. These defines map columns to the buffer
872 * space declared above. */
873 OCIDefine **oci_defines;
878 /* Prepare the statement */
879 if (q->oci_statement == NULL) /* {{{ */
881 status = OCIHandleAlloc (oci_env, (void *) &q->oci_statement,
882 OCI_HTYPE_STMT, /* user_data_size = */ 0, /* user_data = */ NULL);
883 if (status != OCI_SUCCESS)
885 o_report_error ("o_read_database_query", "OCIHandleAlloc", oci_error);
886 q->oci_statement = NULL;
890 status = OCIStmtPrepare (q->oci_statement, oci_error,
891 (text *) q->statement, (ub4) strlen (q->statement),
892 /* language = */ OCI_NTV_SYNTAX,
893 /* mode = */ OCI_DEFAULT);
894 if (status != OCI_SUCCESS)
896 o_report_error ("o_read_database_query", "OCIStmtPrepare", oci_error);
897 OCIHandleFree (q->oci_statement, OCI_HTYPE_STMT);
898 q->oci_statement = NULL;
901 assert (q->oci_statement != NULL);
904 /* Execute the statement */
905 status = OCIStmtExecute (db->oci_service_context, /* {{{ */
910 /* snap_in = */ NULL, /* snap_out = */ NULL,
911 /* mode = */ OCI_DEFAULT);
912 if (status != OCI_SUCCESS)
914 o_report_error ("o_read_database_query", "OCIStmtExecute", oci_error);
915 ERROR ("oracle plugin: o_read_database_query: "
916 "Failing statement was: %s", q->statement);
920 /* Acquire the number of columns returned. */
923 ub4 param_counter = 0;
924 status = OCIAttrGet (q->oci_statement, OCI_HTYPE_STMT, /* {{{ */
925 ¶m_counter, /* size pointer = */ NULL,
926 OCI_ATTR_PARAM_COUNT, oci_error);
927 if (status != OCI_SUCCESS)
929 o_report_error ("o_read_database_query", "OCIAttrGet", oci_error);
933 column_num = (size_t) param_counter;
934 } while (0); /* }}} */
936 /* Allocate the following buffers:
938 * +---------------+-----------------------------------+
940 * +---------------+-----------------------------------+
941 * ! column_names ! column_num x DATA_MAX_NAME_LEN !
942 * ! column_values ! column_num x DATA_MAX_NAME_LEN !
943 * ! oci_defines ! column_num x sizeof (OCIDefine *) !
944 * +---------------+-----------------------------------+
947 #define NUMBER_BUFFER_SIZE 64
950 if (column_names != NULL) { \
951 sfree (column_names[0]); \
952 sfree (column_names); \
954 if (column_values != NULL) { \
955 sfree (column_values[0]); \
956 sfree (column_values); \
960 #define ALLOC_OR_FAIL(ptr, ptr_size) \
962 size_t alloc_size = (size_t) ((ptr_size)); \
963 (ptr) = malloc (alloc_size); \
964 if ((ptr) == NULL) { \
966 ERROR ("oracle plugin: o_read_database_query: malloc failed."); \
969 memset ((ptr), 0, alloc_size); \
972 /* Initialize everything to NULL so the above works. */
974 column_values = NULL;
977 ALLOC_OR_FAIL (column_names, column_num * sizeof (char *));
978 ALLOC_OR_FAIL (column_names[0], column_num * DATA_MAX_NAME_LEN
980 for (i = 1; i < column_num; i++)
981 column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN;
983 ALLOC_OR_FAIL (column_values, column_num * sizeof (char *));
984 ALLOC_OR_FAIL (column_values[0], column_num * DATA_MAX_NAME_LEN
986 for (i = 1; i < column_num; i++)
987 column_values[i] = column_values[i - 1] + DATA_MAX_NAME_LEN;
989 ALLOC_OR_FAIL (oci_defines, column_num * sizeof (OCIDefine *));
990 /* }}} End of buffer allocations. */
992 /* ``Define'' the returned data, i. e. bind the columns to the buffers
993 * allocated above. */
994 for (i = 0; i < column_num; i++) /* {{{ */
997 size_t column_name_length;
998 char column_name_copy[DATA_MAX_NAME_LEN];
1003 status = OCIParamGet (q->oci_statement, OCI_HTYPE_STMT, oci_error,
1004 (void *) &oci_param, (ub4) (i + 1));
1005 if (status != OCI_SUCCESS)
1007 /* This is probably alright */
1008 DEBUG ("oracle plugin: o_read_database_query: status = %#x (= %i);", status, status);
1009 o_report_error ("o_read_database_query", "OCIParamGet", oci_error);
1010 status = OCI_SUCCESS;
1015 column_name_length = 0;
1016 status = OCIAttrGet (oci_param, OCI_DTYPE_PARAM,
1017 &column_name, &column_name_length, OCI_ATTR_NAME, oci_error);
1018 if (status != OCI_SUCCESS)
1020 o_report_error ("o_read_database_query", "OCIAttrGet (OCI_ATTR_NAME)",
1025 /* Copy the name to column_names. Warning: The ``string'' returned by OCI
1026 * may not be null terminated! */
1027 memset (column_names[i], 0, DATA_MAX_NAME_LEN);
1028 if (column_name_length >= DATA_MAX_NAME_LEN)
1029 column_name_length = DATA_MAX_NAME_LEN - 1;
1030 memcpy (column_names[i], column_name, column_name_length);
1031 column_names[i][column_name_length] = 0;
1033 DEBUG ("oracle plugin: o_read_database_query: column_names[%zu] = %s; "
1034 "column_name_length = %zu;",
1035 i, column_name_copy, column_name_length);
1037 status = OCIDefineByPos (q->oci_statement,
1038 &oci_defines[i], oci_error, (ub4) (i + 1),
1039 column_values[i], DATA_MAX_NAME_LEN, SQLT_STR,
1040 NULL, NULL, NULL, OCI_DEFAULT);
1041 if (status != OCI_SUCCESS)
1043 o_report_error ("o_read_database_query", "OCIDefineByPos", oci_error);
1046 } /* for (j = 1; j <= param_counter; j++) */
1047 /* }}} End of the ``define'' stuff. */
1049 /* Fetch and handle all the rows that matched the query. */
1050 while (42) /* {{{ */
1054 status = OCIStmtFetch2 (q->oci_statement, oci_error,
1055 /* nrows = */ 1, /* orientation = */ OCI_FETCH_NEXT,
1056 /* fetch offset = */ 0, /* mode = */ OCI_DEFAULT);
1057 if (status == OCI_NO_DATA)
1059 status = OCI_SUCCESS;
1062 else if ((status != OCI_SUCCESS) && (status != OCI_SUCCESS_WITH_INFO))
1064 o_report_error ("o_read_database_query", "OCIStmtFetch2", oci_error);
1068 for (i = 0; i < column_num; i++)
1070 DEBUG ("oracle plugin: o_read_database_query: [%zu] %s = %s;",
1071 i, column_names[i], column_values[i]);
1074 for (r = q->results; r != NULL; r = r->next)
1075 o_handle_query_result (db, q, r, column_names, column_values, column_num);
1076 } /* }}} while (42) */
1078 /* DEBUG ("oracle plugin: o_read_database_query: This statement succeeded: %s", q->statement); */
1083 #undef ALLOC_OR_FAIL
1084 } /* }}} int o_read_database_query */
1086 static int o_read_database (o_database_t *db) /* {{{ */
1091 if (db->oci_service_context == NULL)
1093 status = OCILogon (oci_env, oci_error,
1094 &db->oci_service_context,
1095 (OraText *) db->username, (ub4) strlen (db->username),
1096 (OraText *) db->password, (ub4) strlen (db->password),
1097 (OraText *) db->connect_id, (ub4) strlen (db->connect_id));
1098 if (status != OCI_SUCCESS)
1100 o_report_error ("o_read_database", "OCILogon", oci_error);
1101 DEBUG ("oracle plugin: OCILogon (%s): db->oci_service_context = %p;",
1102 db->connect_id, db->oci_service_context);
1103 db->oci_service_context = NULL;
1106 assert (db->oci_service_context != NULL);
1109 DEBUG ("oracle plugin: o_read_database: db->connect_id = %s; db->oci_service_context = %p;",
1110 db->connect_id, db->oci_service_context);
1112 for (i = 0; i < db->queries_num; i++)
1113 o_read_database_query (db, db->queries[i]);
1116 } /* }}} int o_read_database */
1118 static int o_read (void) /* {{{ */
1122 for (i = 0; i < databases_num; i++)
1123 o_read_database (databases[i]);
1126 } /* }}} int o_read */
1128 static int o_shutdown (void) /* {{{ */
1132 for (i = 0; i < databases_num; i++)
1133 if (databases[i]->oci_service_context != NULL)
1135 OCIHandleFree (databases[i]->oci_service_context, OCI_HTYPE_SVCCTX);
1136 databases[i]->oci_service_context = NULL;
1139 for (i = 0; i < queries_num; i++)
1140 if (queries[i]->oci_statement != NULL)
1142 OCIHandleFree (queries[i]->oci_statement, OCI_HTYPE_STMT);
1143 queries[i]->oci_statement = NULL;
1146 OCIHandleFree (oci_env, OCI_HTYPE_ENV);
1148 } /* }}} int o_shutdown */
1150 void module_register (void) /* {{{ */
1152 plugin_register_complex_config ("oracle", o_config);
1153 plugin_register_init ("oracle", o_init);
1154 plugin_register_read ("oracle", o_read);
1155 plugin_register_shutdown ("oracle", o_shutdown);
1156 } /* }}} void module_register */
1159 * vim: shiftwidth=2 softtabstop=2 et fdm=marker