Skip to content

Instantly share code, notes, and snippets.

@kubo
Created August 15, 2017 00:40
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/394af98c4c541b2e069467a97f0aaec9 to your computer and use it in GitHub Desktop.
Save kubo/394af98c4c541b2e069467a97f0aaec9 to your computer and use it in GitHub Desktop.
test code for odpi issue 27 and a new issue
#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)
static void dummy_callback(void* context, dpiSubscrMessage *message)
{
}
int main()
{
const char *username = "odpicdemo";
const char *password = "welcome";
const char *connectString = ""; // "localhost/orclpdb"
const char *sql = "select * from TestTempTable";
dpiErrorInfo err;
dpiCommonCreateParams commonParams;
dpiConn *conn;
dpiSubscrCreateParams subscrParams;
dpiSubscr *subscr;
struct {
uint32_t id;
uint32_t next4byte;
} subscrId;
dpiStmt *stmt;
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(dpiContext_initCommonCreateParams(g_context, &commonParams));
commonParams.createMode = DPI_MODE_CREATE_EVENTS;
chkerr(dpiConn_create(g_context, username, strlen(username), password, strlen(password),
connectString, strlen(connectString), &commonParams, NULL, &conn));
chkerr(dpiContext_initSubscrCreateParams(g_context, &subscrParams));
subscrParams.callback = dummy_callback;
subscrParams.qos = DPI_SUBSCR_QOS_QUERY | DPI_SUBSCR_QOS_ROWIDS;
subscrId.next4byte = 0xdeadbeaf;
chkerr(dpiConn_newSubscription(conn, &subscrParams, &subscr, &subscrId.id));
if (subscrId.next4byte != 0xdeadbeaf) {
fprintf(stderr, "The next 4 bytes of subscrId.id were overwritten with 0x%08x.\n", subscrId.next4byte);
}
chkerr(dpiSubscr_prepareStmt(subscr, sql, strlen(sql), &stmt));
chkerr(dpiStmt_close(stmt, NULL, 0));
chkerr(dpiStmt_release(stmt));
chkerr(dpiSubscr_close(subscr));
chkerr(dpiSubscr_release(subscr));
chkerr(dpiConn_close(conn, DPI_MODE_CONN_CLOSE_DEFAULT, NULL, 0));
chkerr(dpiConn_release(conn));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment