Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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