EnvImpl::EnvImpl()

try : envh_(NULL), poolMax_(kPoolMax), poolMin_(kPoolMin),
      poolIncrement_(kPoolIncrement), poolTimeout_(kPoolTimeout),
      externalAuth_(false),  stmtCacheSize_(kStmtCacheSize)
{

  sword rc = OCIEnvNlsCreate (&envh_, OCI_THREADED | OCI_OBJECT, NULL, NULL,
                              NULL, NULL, 0, NULL, DPI_AL32UTF8, DPI_AL32UTF8);

  if (rc)
  {
    if (envh_)
      ociCallEnv(rc, envh_);
    else
      throw ExceptionImpl(DpiErrNoEnv);
  }

  DateTimeArrayImpl::initBaseDate ( envh_ ) ;
}

catch (...)
{
  cleanup();
  throw;
}
Exemplo n.º 2
0
/*
   DESCRIPTION
     Constructor for the EnvImpl class.

   PARAMETERS:
     drvName                driver name
     charset                charset id
     ncharset               ncharset id

   RETURNS:
     nothing

   NOTES:

*/
EnvImpl::EnvImpl( const string &drvName,
                  unsigned int charset,
                  unsigned int ncharset )

try : envh_(NULL), poolMax_(kPoolMax), poolMin_(kPoolMin),
      poolIncrement_(kPoolIncrement), poolTimeout_(kPoolTimeout),
      externalAuth_(false),  stmtCacheSize_(kStmtCacheSize), drvName_(drvName),
      charset_ ( charset ), ncharset_ ( ncharset )
{

  sword rc = OCIEnvNlsCreate (&envh_, OCI_THREADED | OCI_OBJECT, NULL, NULL,
                              NULL, NULL, 0, NULL, charset, ncharset);

  if (rc)
  {
    if (envh_)
      ociCallEnv(rc, envh_);
    else
      throw ExceptionImpl(DpiErrNoEnv);
  }

  DateTimeArrayImpl::initBaseDate ( envh_ ) ;
}

catch (...)
{
  cleanup();
  throw;
}
Exemplo n.º 3
0
gboolean
oracle_session_open (GSQLEOracleSession *oracle_session,
                     gchar *username,
                     gchar *password,
                     gchar *database,
                     gchar *buffer)
{
    GSQL_TRACE_FUNC;

    unsigned char buf[64];
    gint ret;


    /* initialize the mode to be the threaded and object environment */
    if ( OCIEnvNlsCreate(&(oracle_session->envhp), OCI_THREADED|OCI_OBJECT, (dvoid *)0,
                         0, 0, 0, (size_t) 0, (dvoid **)0, 0, 0)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIEnvNlsCreate... failed");
        return FALSE;
    };

    /* allocate a server handle */
    if ( OCIHandleAlloc ((dvoid *)(oracle_session->envhp),
                         (dvoid **)&(oracle_session->srvhp),
                         OCI_HTYPE_SERVER, 0, (dvoid **) 0)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIHandleAlloc (allocate a server handle)... failed");
        return FALSE;
    };

    /* allocate an error handle */
    if ( OCIHandleAlloc ((dvoid *)(oracle_session->envhp),
                         (dvoid **)&(oracle_session->errhp),
                         OCI_HTYPE_ERROR, 0, (dvoid **) 0)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIHandleAlloc (allocate an error handle)... failed");
        return FALSE;
    };

    /* create a server context */

    if ( OCIServerAttach (oracle_session->srvhp,
                          oracle_session->errhp,
                          (text *) database,
                          g_utf8_strlen (database, 64),
                          OCI_DEFAULT)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256, "%s",
                    oracle_get_error_string(oracle_session->errhp)
                   );
        return FALSE;
    };

    /* allocate a service handle */
    if ( OCIHandleAlloc ((dvoid *) (oracle_session->envhp),
                         (dvoid **)&(oracle_session->svchp),
                         OCI_HTYPE_SVCCTX, 0, (dvoid **) 0)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIHandleAlloc (allocate a service handle)... failed");
        return FALSE;
    };

    /* set the server attribute in the service context handle*/
    if ( OCIAttrSet ((dvoid *) oracle_session->svchp,
                     OCI_HTYPE_SVCCTX,
                     (dvoid *) oracle_session->srvhp,
                     (ub4) 0,
                     OCI_ATTR_SERVER,
                     oracle_session->errhp)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIAttrSet... failed");
        return FALSE;
    };

    /* allocate a user session handle */
    if ( OCIHandleAlloc ((dvoid *) (oracle_session->envhp),
                         (dvoid **)&(oracle_session->usrhp),
                         OCI_HTYPE_SESSION, 0, (dvoid **) 0)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIHandleAlloc (allocate a user session handle)... failed");
        return FALSE;
    };

    /* set user name attribute in user session handle */

    if ( OCIAttrSet ((dvoid *) oracle_session->usrhp,
                     OCI_HTYPE_SESSION,
                     (dvoid *) username,
                     (ub4) g_utf8_strlen(username, 64),
                     OCI_ATTR_USERNAME,
                     oracle_session->errhp)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIAttrSet (OCI_ATTR_USERNAME)... failed");
        return FALSE;
    };

    /* set password attribute in user session handle */

    if ( OCIAttrSet ((dvoid *)(oracle_session->usrhp),
                     OCI_HTYPE_SESSION,
                     (dvoid *)password,
                     (ub4) g_utf8_strlen(password, 64),
                     OCI_ATTR_PASSWORD,
                     oracle_session->errhp)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256,"OCIAttrSet(OCI_ATTR_PASSWORD)... failed");
        return FALSE;
    };


    /* make the connection*/
    if (  OCISessionBegin ((dvoid *) oracle_session->svchp,
                           oracle_session->errhp,
                           oracle_session->usrhp,
                           OCI_CRED_RDBMS,
                           oracle_session->mode)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256, "%s",
                    oracle_get_error_string(oracle_session->errhp)
                   );
        return FALSE;
    };

    oracle_client_info(oracle_session->client_version);

    if ( OCIAttrSet ((dvoid *)(oracle_session->usrhp),
                     OCI_HTYPE_SESSION,
                     (dvoid *) oracle_session->client_version,
                     (ub4) g_utf8_strlen(oracle_session->client_version, 64),
                     OCI_ATTR_CLIENT_INFO,
                     oracle_session->errhp)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256, "OCIAttrSet(OCI_ATTR_CLIENT_INFO)... failed");
        return FALSE;
    };


    /* set the user session attribute in the service context handle*/
    if ( OCIAttrSet ((dvoid *)oracle_session->svchp,
                     OCI_HTYPE_SVCCTX,
                     (dvoid *) oracle_session->usrhp,
                     (ub4) 0,
                     OCI_ATTR_SESSION, oracle_session->errhp)
            == OCI_ERROR
       )
    {
        g_snprintf (buffer, 256, "OCIAttrSet (OCI_ATTR_SESSION)... failed");
        return FALSE;
    };

    OCIServerVersion ((dvoid *) oracle_session->svchp,
                      oracle_session->errhp,
                      oracle_session->server_version,
                      1024, OCI_HTYPE_SVCCTX);
    GSQL_DEBUG ("oracle_session->server_version=[%s]", oracle_session->server_version);

    oracle_session->dbms_output = FALSE;
    oracle_session->debug_mode = FALSE;

    return TRUE;
};
Exemplo n.º 4
0
/*---------------------------------------------------------------------
 * connect_db - Connect to the database.
 *---------------------------------------------------------------------*/
void connect_db(conn_info_t *conn, oci_t ** ociptr, ub2 char_csid, ub2 nchar_csid)
{
  oci_t        *ocip;

  printf ("\nConnect to Oracle as %.*s/%.*s@%.*s\n",
          conn->userlen, conn->user, conn->passwlen, conn->passw, 
          conn->dbnamelen, conn->dbname);
       
  if (char_csid && nchar_csid)
    printf ("using char csid=%d and nchar csid=%d\n", char_csid, nchar_csid);

  ocip = (oci_t *)malloc(sizeof(oci_t));

  ocip->attached = FALSE;

  /* Create UTF8 environment */
  if (OCIEnvNlsCreate(&ocip->envp, OCI_OBJECT, (dvoid *)0,
                     (dvoid * (*)(dvoid *, size_t)) 0,
                     (dvoid * (*)(dvoid *, dvoid *, size_t))0,
                     (void (*)(dvoid *, dvoid *)) 0,
                      (size_t) 0, (dvoid **) 0, char_csid, nchar_csid))
  {
    ocierror(ocip, (char *)"OCIEnvCreate() failed", TRUE);
  }

  if (OCIHandleAlloc((dvoid *) ocip->envp, (dvoid **) &ocip->errp,
                     (ub4) OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) 0))
  {
    ocierror(ocip, (char *)"OCIHandleAlloc(OCI_HTYPE_ERROR) failed", TRUE);
  }

  /* allocate the server handle */
  OCICALL(ocip,
          OCIHandleAlloc((dvoid *) ocip->envp, (dvoid **) &ocip->srvp,
                         OCI_HTYPE_SERVER, (size_t) 0, (dvoid **) 0));

  /* create a server context */
  OCICALL(ocip,
          OCIServerAttach (ocip->srvp, ocip->errp, 
                           (oratext *)conn->dbname, 
                           (sb4)conn->dbnamelen, OCI_DEFAULT));

  /* allocate the service handle */
  OCICALL(ocip,
          OCIHandleAlloc((dvoid *) ocip->envp, (dvoid **) &ocip->svcp,
                         OCI_HTYPE_SVCCTX, (size_t) 0, (dvoid **) 0));

  /* set attribute server context in the service context */
  OCICALL(ocip,
          OCIAttrSet((dvoid *) ocip->svcp, OCI_HTYPE_SVCCTX,
                     (dvoid *) ocip->srvp, (ub4) 0, OCI_ATTR_SERVER,
                     (OCIError *) ocip->errp));

  /* allocate a session handle */
  OCICALL(ocip,
          OCIHandleAlloc((dvoid *) ocip->envp, (dvoid **)&ocip->authp,
                        (ub4) OCI_HTYPE_SESSION, (size_t) 0, (dvoid **) 0));

  /* set the username in the session */
  OCICALL(ocip,
          OCIAttrSet((dvoid *) ocip->authp, (ub4) OCI_HTYPE_SESSION,
                     (dvoid *) conn->user, (ub4)  conn->userlen,
                     (ub4) OCI_ATTR_USERNAME, ocip->errp));

  /* set the password in the session */
  OCICALL(ocip,
          OCIAttrSet((dvoid *) ocip->authp, (ub4) OCI_HTYPE_SESSION,
                     (dvoid *) conn->passw, (ub4) conn->passwlen,
                     (ub4) OCI_ATTR_PASSWORD, ocip->errp));

  OCICALL(ocip,
          OCISessionBegin(ocip->svcp,  ocip->errp, ocip->authp,
                          OCI_CRED_RDBMS, (ub4)OCI_DEFAULT));

  OCICALL(ocip,
          OCIAttrSet((dvoid *) ocip->svcp, (ub4) OCI_HTYPE_SVCCTX,
                     (dvoid *) ocip->authp, (ub4) 0,
                     (ub4) OCI_ATTR_SESSION, ocip->errp));

  if (OCIHandleAlloc((dvoid *) ocip->envp, (dvoid **) &ocip->stmtp,
                     (ub4) OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0))
  {
    ocierror(ocip, (char *)"OCIHandleAlloc(OCI_HTYPE_STMT) failed", TRUE);
  }

  if (OCIHandleAlloc((dvoid *) ocip->envp, (dvoid **) &ocip->stmt2p,
                     (ub4) OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0))
  {
    ocierror(ocip, (char *)"OCIHandleAlloc(OCI_HTYPE_STMT-2) failed", TRUE);
  }

  if (*ociptr == (oci_t *)NULL)
  {
    *ociptr = ocip;
  }

  /* restore the interrupt signal handler */
  signal(SIGINT, SIG_DFL);
}