Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <dpi.h>
- static dpiContext *g_context;
- #define chkerr(func) do { \
- if ((func) < 0) { \
- dpiErrorInfo err; \
- dpiContext_getError(g_context, &err); \
- printf("ERROR at line %d\n %s\n %s\n", __LINE__, #func, err.message); \
- exit(1); \
- } \
- } while (0)
- #define NUM_ATTRS 12
- static const char *env(const char *name, const char *default_value)
- {
- const char *value = getenv(name);
- if (value == NULL) {
- value = default_value;
- }
- return value;
- }
- int main()
- {
- const char *username = env("ODPIC_SAMPLES_MAIN_USER", "odpicdemo");
- const char *password = env("ODPIC_SAMPLES_MAIN_PASSWORD", "welcome");
- const char *connectString = env("ODPIC_SAMPLES_CONNECT_STRING", "localhost/orclpdb");
- const char *typename = "UDT_OBJECTDATATYPES";
- dpiErrorInfo err;
- dpiConn *conn;
- dpiObjectType *objType;
- dpiObjectAttr *attrs[NUM_ATTRS];
- int i;
- if (dpiContext_create(DPI_MAJOR_VERSION, DPI_MINOR_VERSION, &g_context, &err) < 0) {
- printf("ERROR\n dpiContext_create()\n %s\n", err.message);
- exit(1);
- }
- chkerr(dpiConn_create(g_context, username, strlen(username), password, strlen(password),
- connectString, strlen(connectString), NULL, NULL, &conn));
- chkerr(dpiConn_getObjectType(conn, typename, strlen(typename), &objType));
- chkerr(dpiObjectType_getAttributes(objType, NUM_ATTRS, attrs));
- for (i = 0; i < NUM_ATTRS; i++) {
- dpiObjectAttrInfo info;
- chkerr(dpiObjectAttr_getInfo(attrs[i], &info));
- printf("%.*s - %d\n", info.nameLength, info.name, info.typeInfo.oracleTypeNum);
- chkerr(dpiObjectAttr_release(attrs[i]));
- }
- chkerr(dpiObjectType_release(objType));
- chkerr(dpiConn_release(conn));
- return 0;
- }
Add Comment
Please, Sign In to add comment