Skip to content

Instantly share code, notes, and snippets.

@kubo
Created February 13, 2017 13:35
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/a4ea764a15044a0a8c1e57e0b1d3b6d8 to your computer and use it in GitHub Desktop.
Save kubo/a4ea764a15044a0a8c1e57e0b1d3b6d8 to your computer and use it in GitHub Desktop.
ODPI-C issue
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dpi.h>
static dpiContext *gContext = NULL;
#define CHK_WITH_ERR(func, err) do { \
int rv = (func); \
if (rv < 0) { \
dpiErrorInfo *errinfo = (err); \
dpiErrorInfo errinfobuf; \
if (errinfo == NULL) { \
dpiContext_getError(gContext, &errinfobuf); \
errinfo = &errinfobuf; \
} \
fprintf(stderr, "FUNC: %s\nERROR: %.*s (%s: %s)\n", #func, \
errinfo->messageLength, errinfo->message, errinfo->fnName, errinfo->action); \
exit(1); \
} \
} while(0)
#define CHK(func) CHK_WITH_ERR(func, NULL)
int main()
{
dpiErrorInfo err;
const char *username = "scott";
const char *password = "tiger";
const char *connect_string = "";
const char *sqltext = "select UTL_RAW.CAST_TO_NUMBER('7F0202020202020202020202020202020202020202') from dual";
dpiConn *conn;
dpiStmt *stmt;
dpiVar *var;
dpiData *data;
uint32_t num_cols;
int found;
uint32_t buffer_row_index;
CHK_WITH_ERR(dpiContext_create(DPI_MAJOR_VERSION, DPI_MINOR_VERSION, &gContext, &err), &err);
CHK(dpiConn_create(gContext, username, strlen(username),
password, strlen(password), connect_string, strlen(connect_string),
NULL, NULL, &conn));
CHK(dpiConn_prepareStmt(conn, 0, sqltext, strlen(sqltext), NULL, 0, &stmt));
CHK(dpiStmt_setFetchArraySize(stmt, 1));
printf("define as DPI_ORACLE_TYPE_VARCHAR and DPI_NATIVE_TYPE_BYTES\n");
CHK(dpiStmt_execute(stmt, 0, &num_cols));
CHK(dpiConn_newVar(conn, DPI_ORACLE_TYPE_VARCHAR, DPI_NATIVE_TYPE_BYTES, 1,
180, 0, 0, NULL, &var, &data));
CHK(dpiStmt_define(stmt, 1, var));
CHK(dpiStmt_fetch(stmt, &found, &buffer_row_index));
printf(" isNull=0x%x\n", data->isNull);
printf(" len=%u\n", data->value.asBytes.length);
printf(" str=%.*s\n\n", data->value.asBytes.length, data->value.asBytes.ptr);
dpiVar_release(var);
printf("define as DPI_ORACLE_TYPE_NUMBER and DPI_NATIVE_TYPE_BYTES\n");
CHK(dpiStmt_execute(stmt, 0, &num_cols));
CHK(dpiConn_newVar(conn, DPI_ORACLE_TYPE_NUMBER, DPI_NATIVE_TYPE_BYTES, 1,
180, 0, 0, NULL, &var, &data));
CHK(dpiStmt_define(stmt, 1, var));
CHK(dpiStmt_fetch(stmt, &found, &buffer_row_index));
printf(" isNull=0x%x\n", data->isNull);
printf(" len=%u\n", data->value.asBytes.length);
printf(" str=%p\n", data->value.asBytes.ptr);
dpiVar_release(var);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment