There was an issue in OCILIB that was not reporting SQL Warnings properly. This is fixed and OCILIB repository is up to date with the fix :)
CREATE PROCEDURE - how to check if successfully compiled?
-
30-06-2022 - |
Вопрос
I'm using OCILIB.
Statements of the form CREATE OR REPLACE PROCEDURE AA1 AS BEGIN XXX; END;
are always successful (ie, no error or warning is reported). How can I check whether the statement was compiled correctly?
There should be a function to get that information (I hope).
Here is a quick & dirty example that shows the issue:
#include <stdio.h>
#include <ocilib.h>
void print_error() {
printf("Error:");
OCI_Error *err = OCI_GetLastError();
if (err) printf(" %d: %s\n", OCI_ErrorGetOCICode(err), OCI_ErrorGetString(err));
else printf(" no error.");
printf("\n");
}
int main (int argc, char **argv) {
OCI_Connection *cn;
OCI_Statement *st;
OCI_EnableWarnings(TRUE);
if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT | OCI_ENV_CONTEXT)) {
puts("Failed to initialize OCI");
return 2;
}
cn = OCI_ConnectionCreate("XE", "<your user>", "<your pwd>", OCI_SESSION_DEFAULT);
print_error();
OCI_SetAutoCommit(cn, TRUE); print_error();
st = OCI_StatementCreate(cn); print_error();
OCI_ExecuteStmt(st, "create or replace procedure aaa as begin garbage end;");
print_error();
OCI_Cleanup();
return 0;
}
Output:
$ ./ocitest
Error: no error.
Error: no error.
Error: no error.
Error: no error.
Решение
Другие советы
You can check the status in the user_objects
view:
select status
from user_objects
where object_type = 'PROCEDURE'
and object_name = 'AA1';
If that is not VALID
, you can get the actual errors by querying the user_errors
view:
select * -- or just line, position and text
from user_errors
where type = 'PROCEDURE'
and name = 'AA1'
order by sequence;
I'm surprised you don't get an exception, but this isn't a stack I use...
Не связан с StackOverflow