Guest User

Untitled

a guest
Nov 6th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dpi.h>
  5.  
  6. static dpiContext *g_context;
  7.  
  8. #define chkerr(func) do { \
  9. if ((func) < 0) { \
  10. dpiErrorInfo err; \
  11. dpiContext_getError(g_context, &err); \
  12. printf("ERROR at line %d\n %s\n %s\n", __LINE__, #func, err.message); \
  13. exit(1); \
  14. } \
  15. } while (0)
  16.  
  17. #define NUM_ATTRS 12
  18.  
  19. static const char *env(const char *name, const char *default_value)
  20. {
  21. const char *value = getenv(name);
  22. if (value == NULL) {
  23. value = default_value;
  24. }
  25. return value;
  26. }
  27.  
  28. int main()
  29. {
  30. const char *username = env("ODPIC_SAMPLES_MAIN_USER", "odpicdemo");
  31. const char *password = env("ODPIC_SAMPLES_MAIN_PASSWORD", "welcome");
  32. const char *connectString = env("ODPIC_SAMPLES_CONNECT_STRING", "localhost/orclpdb");
  33. const char *typename = "UDT_OBJECTDATATYPES";
  34. dpiErrorInfo err;
  35. dpiConn *conn;
  36. dpiObjectType *objType;
  37. dpiObjectAttr *attrs[NUM_ATTRS];
  38. int i;
  39.  
  40. if (dpiContext_create(DPI_MAJOR_VERSION, DPI_MINOR_VERSION, &g_context, &err) < 0) {
  41. printf("ERROR\n dpiContext_create()\n %s\n", err.message);
  42. exit(1);
  43. }
  44.  
  45. chkerr(dpiConn_create(g_context, username, strlen(username), password, strlen(password),
  46. connectString, strlen(connectString), NULL, NULL, &conn));
  47. chkerr(dpiConn_getObjectType(conn, typename, strlen(typename), &objType));
  48. chkerr(dpiObjectType_getAttributes(objType, NUM_ATTRS, attrs));
  49. for (i = 0; i < NUM_ATTRS; i++) {
  50. dpiObjectAttrInfo info;
  51. chkerr(dpiObjectAttr_getInfo(attrs[i], &info));
  52. printf("%.*s - %d\n", info.nameLength, info.name, info.typeInfo.oracleTypeNum);
  53. chkerr(dpiObjectAttr_release(attrs[i]));
  54. }
  55. chkerr(dpiObjectType_release(objType));
  56. chkerr(dpiConn_release(conn));
  57. return 0;
  58. }
Add Comment
Please, Sign In to add comment