Created
July 2, 2018 12:05
-
-
Save kubo/0186ff03601eaf6b554a4440321fa9dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <dpi.h> | |
static dpiContext *g_context; | |
#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) | |
#define NUM_ATTRS 12 | |
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 *sql = "begin :1 := :2; end;"; | |
const char *num_str = "-123456789012345678901234567890123456789"; | |
dpiErrorInfo err; | |
dpiConn *conn; | |
dpiStmt *stmt; | |
dpiVar *var1, *var2; | |
dpiData *data1, *data2; | |
uint32_t numQueryColumns; | |
uint32_t bufferRowIndex; | |
int found; | |
int i; | |
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_newVar(conn, DPI_ORACLE_TYPE_NUMBER, DPI_NATIVE_TYPE_BYTES, 1, 0, 0, 0, NULL, &var1, &data1)); | |
chkerr(dpiConn_newVar(conn, DPI_ORACLE_TYPE_NUMBER, DPI_NATIVE_TYPE_BYTES, 1, 0, 0, 0, NULL, &var2, &data2)); | |
chkerr(dpiVar_setFromBytes(var2, 0, num_str, strlen(num_str))); | |
chkerr(dpiConn_prepareStmt(conn, 0, sql, strlen(sql), NULL, 0, &stmt)); | |
chkerr(dpiStmt_bindByPos(stmt, 1, var1)); | |
chkerr(dpiStmt_bindByPos(stmt, 2, var2)); | |
chkerr(dpiStmt_execute(stmt, 0, &numQueryColumns)); | |
chkerr(dpiStmt_release(stmt)); | |
chkerr(dpiVar_release(var1)); | |
chkerr(dpiVar_release(var2)); | |
chkerr(dpiConn_release(conn)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment