X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Foracle.c;h=ab0812b703ec441c745d4afbe2bcdaf2ca79025f;hb=59dded4cc1a2077ad11c6e9b507e15ad19e0e38c;hp=86643ca3b09d608ca9272eec0b9d462c063d8f1f;hpb=0abfaa6a32babf3b2cbb34fce097d9f62fb2bc44;p=collectd.git diff --git a/src/oracle.c b/src/oracle.c index 86643ca3..ab0812b7 100644 --- a/src/oracle.c +++ b/src/oracle.c @@ -87,6 +87,7 @@ OCIError *oci_error = NULL; * Functions */ static void o_report_error (const char *where, /* {{{ */ + const char *db_name, const char *query_name, const char *what, OCIError *eh) { char buffer[2048]; @@ -94,6 +95,11 @@ static void o_report_error (const char *where, /* {{{ */ int status; unsigned int record_number; + if (db_name == NULL) + db_name = "(none)"; + if (query_name == NULL) + query_name = "(none)"; + /* 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++) @@ -123,12 +129,14 @@ static void o_report_error (const char *where, /* {{{ */ buffer[buffer_length] = 0; } - ERROR ("oracle plugin: %s: %s failed: %s", where, what, buffer); + ERROR ("oracle plugin: %s (db = %s, query = %s): %s failed: %s", + where, db_name, query_name, what, buffer); } else { - ERROR ("oracle plugin: %s: %s failed. Additionally, OCIErrorGet failed with status %i.", - where, what, status); + ERROR ("oracle plugin: %s (db = %s, query = %s): %s failed. " + "Additionally, OCIErrorGet failed with status %i.", + where, db_name, query_name, what, status); return; } } @@ -408,7 +416,8 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ OCI_HTYPE_STMT, /* user_data_size = */ 0, /* user_data = */ NULL); if (status != OCI_SUCCESS) { - o_report_error ("o_read_database_query", "OCIHandleAlloc", oci_error); + o_report_error ("o_read_database_query", db->name, + udb_query_get_name (q), "OCIHandleAlloc", oci_error); oci_statement = NULL; return (-1); } @@ -419,7 +428,8 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ /* mode = */ OCI_DEFAULT); if (status != OCI_SUCCESS) { - o_report_error ("o_read_database_query", "OCIStmtPrepare", oci_error); + o_report_error ("o_read_database_query", db->name, + udb_query_get_name (q), "OCIStmtPrepare", oci_error); OCIHandleFree (oci_statement, OCI_HTYPE_STMT); oci_statement = NULL; return (-1); @@ -443,10 +453,8 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ /* mode = */ OCI_DEFAULT); if (status != OCI_SUCCESS) { - DEBUG ("oracle plugin: o_read_database_query: status = %i (%#x)", status, status); - o_report_error ("o_read_database_query", "OCIStmtExecute", oci_error); - ERROR ("oracle plugin: o_read_database_query: " - "Failing statement was: %s", udb_query_get_statement (q)); + o_report_error ("o_read_database_query", db->name, udb_query_get_name (q), + "OCIStmtExecute", oci_error); return (-1); } /* }}} */ @@ -459,7 +467,8 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ OCI_ATTR_PARAM_COUNT, oci_error); if (status != OCI_SUCCESS) { - o_report_error ("o_read_database_query", "OCIAttrGet", oci_error); + o_report_error ("o_read_database_query", db->name, + udb_query_get_name (q), "OCIAttrGet", oci_error); return (-1); } /* }}} */ @@ -537,8 +546,10 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ if (status != OCI_SUCCESS) { /* This is probably alright */ - DEBUG ("oracle plugin: o_read_database_query: status = %#x (= %i);", status, status); - o_report_error ("o_read_database_query", "OCIParamGet", oci_error); + DEBUG ("oracle plugin: o_read_database_query: status = %#x (= %i);", + status, status); + o_report_error ("o_read_database_query", db->name, + udb_query_get_name (q), "OCIParamGet", oci_error); status = OCI_SUCCESS; break; } @@ -550,8 +561,8 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ if (status != OCI_SUCCESS) { OCIDescriptorFree (oci_param, OCI_DTYPE_PARAM); - o_report_error ("o_read_database_query", "OCIAttrGet (OCI_ATTR_NAME)", - oci_error); + o_report_error ("o_read_database_query", db->name, + udb_query_get_name (q), "OCIAttrGet (OCI_ATTR_NAME)", oci_error); continue; } @@ -576,7 +587,8 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ NULL, NULL, NULL, OCI_DEFAULT); if (status != OCI_SUCCESS) { - o_report_error ("o_read_database_query", "OCIDefineByPos", oci_error); + o_report_error ("o_read_database_query", db->name, + udb_query_get_name (q), "OCIDefineByPos", oci_error); continue; } } /* for (j = 1; j <= param_counter; j++) */ @@ -608,7 +620,8 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ } else if ((status != OCI_SUCCESS) && (status != OCI_SUCCESS_WITH_INFO)) { - o_report_error ("o_read_database_query", "OCIStmtFetch2", oci_error); + o_report_error ("o_read_database_query", db->name, + udb_query_get_name (q), "OCIStmtFetch2", oci_error); break; } @@ -645,7 +658,8 @@ static int o_read_database (o_database_t *db) /* {{{ */ OCI_ATTR_SERVER, oci_error); if (status != OCI_SUCCESS) { - o_report_error ("o_read_database", "OCIAttrGet", oci_error); + o_report_error ("o_read_database", db->name, NULL, "OCIAttrGet", + oci_error); return (-1); } @@ -661,7 +675,8 @@ static int o_read_database (o_database_t *db) /* {{{ */ OCI_ATTR_SERVER_STATUS, oci_error); if (status != OCI_SUCCESS) { - o_report_error ("o_read_database", "OCIAttrGet", oci_error); + o_report_error ("o_read_database", db->name, NULL, "OCIAttrGet", + oci_error); return (-1); } } @@ -684,7 +699,11 @@ static int o_read_database (o_database_t *db) /* {{{ */ (OraText *) db->connect_id, (ub4) strlen (db->connect_id)); if ((status != OCI_SUCCESS) && (status != OCI_SUCCESS_WITH_INFO)) { - o_report_error ("o_read_database", "OCILogon", oci_error); + char errfunc[256]; + + ssnprintf (errfunc, sizeof (errfunc), "OCILogon(\"%s\")", db->connect_id); + + o_report_error ("o_read_database", db->name, NULL, errfunc, oci_error); DEBUG ("oracle plugin: OCILogon (%s): db->oci_service_context = %p;", db->connect_id, db->oci_service_context); db->oci_service_context = NULL;