/**
* collectd - src/oracle.c
- * Copyright (C) 2008,2009 Florian octo Forster
+ * Copyright (C) 2008,2009 noris network AG
+ * Copyright (C) 2012 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* affiliates. Other names may be trademarks of their respective owners.
*
* Authors:
- * Florian octo Forster <octo at noris.net>
+ * Florian octo Forster <octo at collectd.org>
**/
#include "collectd.h"
char buffer[2048];
sb4 error_code;
int status;
+ unsigned int record_number;
- status = OCIErrorGet (eh, /* record number = */ 1,
- /* sqlstate = */ NULL,
- &error_code,
- (text *) &buffer[0],
- (ub4) sizeof (buffer),
- OCI_HTYPE_ERROR);
- buffer[sizeof (buffer) - 1] = 0;
-
- if (status == OCI_SUCCESS)
+ /* An operation may cause / return multiple errors. Loop until we have
+ * handled all errors available (with a fail-save limit of 16). */
+ for (record_number = 1; record_number <= 16; record_number++)
{
- size_t buffer_length;
+ memset (buffer, 0, sizeof (buffer));
+ error_code = -1;
+
+ status = OCIErrorGet (eh, (ub4) record_number,
+ /* sqlstate = */ NULL,
+ &error_code,
+ (text *) &buffer[0],
+ (ub4) sizeof (buffer),
+ OCI_HTYPE_ERROR);
+ buffer[sizeof (buffer) - 1] = 0;
- buffer_length = strlen (buffer);
- while ((buffer_length > 0) && (buffer[buffer_length - 1] < 32))
+ if (status == OCI_NO_DATA)
+ return;
+
+ if (status == OCI_SUCCESS)
{
- buffer_length--;
- buffer[buffer_length] = 0;
- }
+ size_t buffer_length;
- ERROR ("oracle plugin: %s: %s failed: %s",
- where, what, buffer);
- }
- else
- {
- ERROR ("oracle plugin: %s: %s failed. Additionally, OCIErrorGet failed with status %i.",
- where, what, status);
+ buffer_length = strlen (buffer);
+ while ((buffer_length > 0) && (buffer[buffer_length - 1] < 32))
+ {
+ buffer_length--;
+ buffer[buffer_length] = 0;
+ }
+
+ ERROR ("oracle plugin: %s: %s failed: %s", where, what, buffer);
+ }
+ else
+ {
+ ERROR ("oracle plugin: %s: %s failed. Additionally, OCIErrorGet failed with status %i.",
+ where, what, status);
+ return;
+ }
}
} /* }}} void o_report_error */
&column_name, &column_name_length, OCI_ATTR_NAME, oci_error);
if (status != OCI_SUCCESS)
{
+ OCIDescriptorFree (oci_param, OCI_DTYPE_PARAM);
o_report_error ("o_read_database_query", "OCIAttrGet (OCI_ATTR_NAME)",
oci_error);
continue;
}
+ OCIDescriptorFree (oci_param, OCI_DTYPE_PARAM);
+ oci_param = NULL;
+
/* Copy the name to column_names. Warning: The ``string'' returned by OCI
* may not be null terminated! */
memset (column_names[i], 0, DATA_MAX_NAME_LEN);
(OraText *) db->username, (ub4) strlen (db->username),
(OraText *) db->password, (ub4) strlen (db->password),
(OraText *) db->connect_id, (ub4) strlen (db->connect_id));
- if (status != OCI_SUCCESS)
+ if ((status != OCI_SUCCESS) && (status != OCI_SUCCESS_WITH_INFO))
{
o_report_error ("o_read_database", "OCILogon", oci_error);
DEBUG ("oracle plugin: OCILogon (%s): db->oci_service_context = %p;",
db->oci_service_context = NULL;
return (-1);
}
+ else if (status == OCI_SUCCESS_WITH_INFO)
+ {
+ /* TODO: Print NOTIFY message. */
+ }
assert (db->oci_service_context != NULL);
}
}
OCIHandleFree (oci_env, OCI_HTYPE_ENV);
+ oci_env = NULL;
udb_query_free (queries, queries_num);
queries = NULL;