René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

The most simple adpoci programm

This programm tries to connect to a database and waits then for a key to be hit. The created session can then be viewed in v$session. If this works, use the create table example.
This programm uses adpoci to be able to compile it.
Be sure to first compile and link the library into a shared library or dll.
After doing so, the programm can be compiled and linked like so
On Linux with gcc:
gcc -I##A($ORACLE_HOME,/ora/misc/env_vars.html#oracle_home/rdbms/demo -I$ORACLE_HOME/rdbms/public first.c -o first -L. -L$ORACLE_HOME/lib -ladpoci -lclntsh
On Windows with mingw:
gcc -I%ORACLE_HOME%\oci\include first.c -o first.exe -L. -ladpoci %ORACLE_HOME%\bin\oci.dll

Usage

./first username/password@db

first.c

#include <oci.h>
#include <stdio.h>
#include <stdlib.h>

#include "adpoci.h"

int main(int argc, char* argv[]) {
         char           err_msg   [512];
         sword          r;
  struct oci_connection conn;

  if (argc < 2) {
    printf("usage %s username/password[@dbname]\n", argv[0]);
    exit (-1);
  }

  text  username[30];
  text  password[30];
  text  dbname  [30];

  parse_connect_string(argv[1],username, password, dbname);

  if (!oci_connect(username, password, dbname,&conn, err_msg)) {
    printf(err_msg);
    goto clean_up;
  }

  printf("A connection has been established and should be visible\n");
  printf("in the v$session view.\n");

  getc(stdin);

clean_up:

  OCITerminate(OCI_DEFAULT);

  return 0;
}