Skip to content

Instantly share code, notes, and snippets.

@kubo
Created October 25, 2017 10:03
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/d8b623072b755edd508896940be86e81 to your computer and use it in GitHub Desktop.
Save kubo/d8b623072b755edd508896940be86e81 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;
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
#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)
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 *sqltext = "merge info ..."; // not a valid sql but enought to call dpiStmt_getInfo().
dpiErrorInfo err;
dpiConn *conn;
dpiStmt *stmt;
dpiStmtInfo stmtInfo;
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_prepareStmt(conn, 0, sqltext, strlen(sqltext), NULL, 0, &stmt));
chkerr(dpiStmt_getInfo(stmt, &stmtInfo));
printf("SQL: %s\n"
" isQuery: %d\n"
" isPLSQL: %d\n"
" isDDL: %d\n"
" isDML: %d\n"
" statementType: %d\n"
" isReturning: %d\n",
sqltext, stmtInfo.isQuery, stmtInfo.isPLSQL,
stmtInfo.isDDL, stmtInfo.isDML,
stmtInfo.statementType, stmtInfo.isReturning);
chkerr(dpiStmt_release(stmt));
chkerr(dpiConn_release(conn));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment