Skip to content

Instantly share code, notes, and snippets.

@kubo
Created November 4, 2017 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubo/17189baff057bb8fdd5797ae80750518 to your computer and use it in GitHub Desktop.
Save kubo/17189baff057bb8fdd5797ae80750518 to your computer and use it in GitHub Desktop.
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment