Advertisement
Guest User

Untitled

a guest
Feb 13th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dpi.h>
  5.  
  6. static dpiContext *gContext = NULL;
  7.  
  8. #define CHK_WITH_ERR(func, err) do { \
  9. int rv = (func); \
  10. if (rv < 0) { \
  11. dpiErrorInfo *errinfo = (err); \
  12. dpiErrorInfo errinfobuf; \
  13. if (errinfo == NULL) { \
  14. dpiContext_getError(gContext, &errinfobuf); \
  15. errinfo = &errinfobuf; \
  16. } \
  17. fprintf(stderr, "FUNC: %s\nERROR: %.*s (%s: %s)\n", #func, \
  18. errinfo->messageLength, errinfo->message, errinfo->fnName, errinfo->action); \
  19. exit(1); \
  20. } \
  21. } while(0)
  22.  
  23. #define CHK(func) CHK_WITH_ERR(func, NULL)
  24.  
  25. int main()
  26. {
  27. dpiErrorInfo err;
  28. const char *username = "scott";
  29. const char *password = "tiger";
  30. const char *connect_string = "";
  31. const char *sqltext = "select UTL_RAW.CAST_TO_NUMBER('7F0202020202020202020202020202020202020202') from dual";
  32. dpiConn *conn;
  33. dpiStmt *stmt;
  34. dpiVar *var;
  35. dpiData *data;
  36. uint32_t num_cols;
  37. int found;
  38. uint32_t buffer_row_index;
  39.  
  40. CHK_WITH_ERR(dpiContext_create(DPI_MAJOR_VERSION, DPI_MINOR_VERSION, &gContext, &err), &err);
  41.  
  42. CHK(dpiConn_create(gContext, username, strlen(username),
  43. password, strlen(password), connect_string, strlen(connect_string),
  44. NULL, NULL, &conn));
  45.  
  46. CHK(dpiConn_prepareStmt(conn, 0, sqltext, strlen(sqltext), NULL, 0, &stmt));
  47. CHK(dpiStmt_setFetchArraySize(stmt, 1));
  48.  
  49. printf("define as DPI_ORACLE_TYPE_VARCHAR and DPI_NATIVE_TYPE_BYTES\n");
  50. CHK(dpiStmt_execute(stmt, 0, &num_cols));
  51. CHK(dpiConn_newVar(conn, DPI_ORACLE_TYPE_VARCHAR, DPI_NATIVE_TYPE_BYTES, 1,
  52. 180, 0, 0, NULL, &var, &data));
  53. CHK(dpiStmt_define(stmt, 1, var));
  54. CHK(dpiStmt_fetch(stmt, &found, &buffer_row_index));
  55. printf(" isNull=0x%x\n", data->isNull);
  56. printf(" len=%u\n", data->value.asBytes.length);
  57. printf(" str=%.*s\n\n", data->value.asBytes.length, data->value.asBytes.ptr);
  58. dpiVar_release(var);
  59.  
  60. printf("define as DPI_ORACLE_TYPE_NUMBER and DPI_NATIVE_TYPE_BYTES\n");
  61. CHK(dpiStmt_execute(stmt, 0, &num_cols));
  62. CHK(dpiConn_newVar(conn, DPI_ORACLE_TYPE_NUMBER, DPI_NATIVE_TYPE_BYTES, 1,
  63. 180, 0, 0, NULL, &var, &data));
  64. CHK(dpiStmt_define(stmt, 1, var));
  65. CHK(dpiStmt_fetch(stmt, &found, &buffer_row_index));
  66. printf(" isNull=0x%x\n", data->isNull);
  67. printf(" len=%u\n", data->value.asBytes.length);
  68. printf(" str=%p\n", data->value.asBytes.ptr);
  69. dpiVar_release(var);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement