Guest User

Untitled

a guest
Oct 26th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 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. #ifndef ARRAY_SIZE
  9. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  10. #endif
  11.  
  12. #define chkerr(func) do { \
  13. if ((func) < 0) { \
  14. dpiErrorInfo err; \
  15. dpiContext_getError(g_context, &err); \
  16. printf("ERROR at line %d\n %s\n %s\n", __LINE__, #func, err.message); \
  17. exit(1); \
  18. } \
  19. } while (0)
  20.  
  21. static const char *env(const char *name, const char *default_value)
  22. {
  23. const char *value = getenv(name);
  24. if (value == NULL) {
  25. value = default_value;
  26. }
  27. return value;
  28. }
  29.  
  30. int main()
  31. {
  32. const char *username = env("ODPIC_SAMPLES_MAIN_USER", "odpicdemo");
  33. const char *password = env("ODPIC_SAMPLES_MAIN_PASSWORD", "welcome");
  34. const char *connectString = env("ODPIC_SAMPLES_CONNECT_STRING", "localhost/orclpdb");
  35. const char *sqltext = "merge info ..."; // not a valid sql but enought to call dpiStmt_getInfo().
  36. dpiErrorInfo err;
  37. dpiConn *conn;
  38. dpiStmt *stmt;
  39. dpiStmtInfo stmtInfo;
  40.  
  41. if (dpiContext_create(DPI_MAJOR_VERSION, DPI_MINOR_VERSION, &g_context, &err) < 0) {
  42. printf("ERROR\n dpiContext_create()\n %s\n", err.message);
  43. exit(1);
  44. }
  45.  
  46. chkerr(dpiConn_create(g_context, username, strlen(username), password, strlen(password),
  47. connectString, strlen(connectString), NULL, NULL, &conn));
  48. chkerr(dpiConn_prepareStmt(conn, 0, sqltext, strlen(sqltext), NULL, 0, &stmt));
  49. chkerr(dpiStmt_getInfo(stmt, &stmtInfo));
  50. printf("SQL: %s\n"
  51. " isQuery: %d\n"
  52. " isPLSQL: %d\n"
  53. " isDDL: %d\n"
  54. " isDML: %d\n"
  55. " statementType: %d\n"
  56. " isReturning: %d\n",
  57. sqltext, stmtInfo.isQuery, stmtInfo.isPLSQL,
  58. stmtInfo.isDDL, stmtInfo.isDML,
  59. stmtInfo.statementType, stmtInfo.isReturning);
  60. chkerr(dpiStmt_release(stmt));
  61. chkerr(dpiConn_release(conn));
  62. return 0;
  63. }
Add Comment
Please, Sign In to add comment